JSPM

optumflex-subscription-core

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q26907F
  • License MIT

Core logic and utilities for subscription management, pricing calculations, and data processing - framework agnostic

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 order
  • onError: Error callback function
  • onSuccess: Success callback function

Returns:

  • subscriptionPlans: Array of subscription plans
  • modelPortfolios: Array of model portfolios
  • selectedCycles: Object mapping plan IDs to selected cycles
  • setSelectedCycle: Function to update selected cycle
  • processApiResponse: Function to process API response
  • getDisplayedPlans: Function to get filtered and sorted plans
  • getDiscountInfo: Function to get discount information
  • getAvailableCycles: 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 domain

Custom Validation Endpoint

setApiKey('your-api-key', 'https://your-custom-endpoint.com/validate');

🛠️ Development

Building

npm run build

Development Mode

npm run dev

Testing

npm test

📄 License

MIT License - see LICENSE file for details.

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

📞 Support

For support and questions, please open an issue on GitHub or contact the OptumFlex team.