Package Exports
- optumflex-subscription-core
- optumflex-subscription-core/dist/index.esm.js
- optumflex-subscription-core/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (optumflex-subscription-core) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
OptumFlex Subscription Core
A framework-agnostic core library for subscription management, pricing calculations, and data processing. This package provides all the business logic and utilities needed to handle subscription data without any UI dependencies.
🎯 Features
- Framework Agnostic: Works with React, Vue, Angular, or any JavaScript framework
- TypeScript Support: Full type safety with comprehensive interfaces
- API Key Validation: Built-in domain validation and security
- Data Processing: Transform raw API responses into structured data
- Pricing Calculations: Discount calculations, price formatting, and cycle management
- State Management: React hooks for subscription state management
- Utility Functions: Comprehensive set of helper functions
📦 Installation
npm install optumflex-subscription-core🚀 Quick Start
1. Set API Key
import { setApiKey } from 'optumflex-subscription-core';
// Set once at app startup
setApiKey('your-api-key-here');2. Use with React
import { useSubscriptionData, formatPrice } from 'optumflex-subscription-core';
function MyComponent() {
const {
subscriptionPlans,
selectedCycles,
setSelectedCycle,
processApiResponse,
getDisplayedPlans,
getDiscountInfo
} = useSubscriptionData();
// Process API response
useEffect(() => {
const fetchData = async () => {
const response = await fetch('/api/pricing');
const data = await response.json();
processApiResponse(data);
};
fetchData();
}, [processApiResponse]);
return (
<div>
{getDisplayedPlans().map(plan => (
<div key={plan.id}>
<h3>{plan.title}</h3>
<p>{formatPrice(plan.prices.monthly)}</p>
</div>
))}
</div>
);
}3. Use with Vanilla JavaScript
import {
processSubscriptionData,
formatPrice,
calculateDiscountInfo
} from 'optumflex-subscription-core';
// Process API response
const apiResponse = await fetch('/api/pricing').then(r => r.json());
const { subscriptionPlans } = processSubscriptionData(apiResponse);
// Calculate discount
const discountInfo = calculateDiscountInfo(plan, 'monthly');
console.log(`Save ${formatPrice(discountInfo.savings)}`);📚 API Reference
Core Functions
setApiKey(key: string, endpoint?: string)
Set the API key for package initialization.
processSubscriptionData(apiResponse: any)
Transform raw API response into structured subscription data.
calculateDiscountInfo(plan: PricingPackage, cycle: BillingCycle)
Calculate discount information for a plan and billing cycle.
formatPrice(price: number)
Format price with currency symbol.
React Hooks
useSubscriptionData(options?: UseSubscriptionDataOptions)
React hook for managing subscription data and state.
Options:
initialPlanType: Initial plan type ('subscriptionPlans' | 'modelPortfolios')initialSortBy: Initial sort orderonError: Error callback functiononSuccess: Success callback function
Returns:
subscriptionPlans: Array of subscription plansmodelPortfolios: Array of model portfoliosselectedCycles: Object mapping plan IDs to selected cyclessetSelectedCycle: Function to update selected cycleprocessApiResponse: Function to process API responsegetDisplayedPlans: Function to get filtered and sorted plansgetDiscountInfo: Function to get discount informationgetAvailableCycles: Function to get available cycles for a plan
Types
PricingPackage
interface PricingPackage {
id: string;
title: string;
description: string;
prices: { [key in BillingCycle]: number };
discounted: { [key in BillingCycle]: number };
features: string[];
}BillingCycle
type BillingCycle = 'weekly' | 'monthly' | 'quarterly' | 'halfyearly' | 'yearly';DiscountInfo
interface DiscountInfo {
originalPrice: number;
discountedPrice: number;
savings: number;
savingsPercentage: number;
isDiscounted: boolean;
}🔧 Configuration
API Key Validation
The package automatically validates your API key against your domain:
import { setApiKey, getPackageStatus } from 'optumflex-subscription-core';
// Set API key
setApiKey('your-api-key');
// Check status
const status = getPackageStatus();
console.log(status.isInitialized); // true/false
console.log(status.domain); // validated domainCustom Validation Endpoint
setApiKey('your-api-key', 'https://your-custom-endpoint.com/validate');🛠️ Development
Building
npm run buildDevelopment Mode
npm run devTesting
npm test📄 License
MIT License - see LICENSE file for details.
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
📞 Support
For support and questions, please open an issue on GitHub or contact the OptumFlex team.