@kelviq/react-sdk 2.0.2-beta → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ import { ReactNode } from 'react';
2
+ import { RawPricingFeature, RawPricingPlan } from '../types/api.types';
3
+ export interface KQFeatureListProps {
4
+ /** The plan identifier to display features for. */
5
+ planIdentifier: string;
6
+ /** Render function called for each feature in the plan. */
7
+ children: (data: {
8
+ feature: RawPricingFeature;
9
+ plan: RawPricingPlan;
10
+ index: number;
11
+ }) => ReactNode;
12
+ /** Shown while pricing data is loading. */
13
+ loadingComponent?: ReactNode;
14
+ /** Shown when the plan is not found or has no features. */
15
+ fallback?: ReactNode;
16
+ /** Optional filter to show only specific feature types. */
17
+ featureType?: 'BOOLEAN' | 'METER';
18
+ }
19
+ export declare const KQFeatureList: React.FC<KQFeatureListProps>;
@@ -0,0 +1,29 @@
1
+ import { ReactNode } from 'react';
2
+ import { RawPricingPlan, RawPricingCharge } from '../types/api.types';
3
+ import { KQFormatPriceOptions } from '../utils/formatPrice';
4
+ export interface KQPriceProps {
5
+ /** The plan identifier to display pricing for. */
6
+ planIdentifier: string;
7
+ /** The billing period to show (e.g. "MONTHLY", "YEARLY", "ONE_TIME"). */
8
+ billingPeriod: string;
9
+ /** Options for the formattedPrice string. */
10
+ formatOptions?: KQFormatPriceOptions;
11
+ /** Render function receiving price data and currency info. */
12
+ children: (data: {
13
+ plan: RawPricingPlan;
14
+ charge: RawPricingCharge | null;
15
+ amount: number;
16
+ formattedPrice: string;
17
+ currencySymbol: string;
18
+ currencyCode: string;
19
+ pricingLocale: string;
20
+ isFree: boolean;
21
+ hasFreeTrial: boolean;
22
+ trialPeriod: number;
23
+ }) => ReactNode;
24
+ /** Shown while pricing data is loading. */
25
+ loadingComponent?: ReactNode;
26
+ /** Shown when the plan is not found or pricing data is unavailable. */
27
+ fallback?: ReactNode;
28
+ }
29
+ export declare const KQPrice: React.FC<KQPriceProps>;
@@ -1,6 +1,6 @@
1
1
  import { Entitlement, EntitlementMap, EntitlementsResponse } from '../types/sdk.types';
2
2
  import { AsyncState } from '../types';
3
- import { RawSubscriptionData, RawCustomerApiResponse } from '../types/api.types';
3
+ import { RawSubscriptionData, RawCustomerApiResponse, RawPricingApiResponse } from '../types/api.types';
4
4
  /** Defines the shape of the context value provided by KelviqProvider. */
5
5
  export interface KelviqContextValue {
6
6
  allEntitlements: AsyncState<EntitlementMap | null>;
@@ -23,9 +23,13 @@ export interface KelviqContextValue {
23
23
  customer: AsyncState<RawCustomerApiResponse | null>;
24
24
  /** Manually refresh customer data. */
25
25
  refreshCustomer: () => Promise<void>;
26
+ /** Pricing data with localized currency. Only populated when fetchPricingOnMount is true. */
27
+ pricing: AsyncState<RawPricingApiResponse | null>;
28
+ /** Manually refresh pricing data. */
29
+ refreshPricing: () => Promise<void>;
26
30
  isLoading: boolean;
27
31
  error: Error | null;
28
- customerId: string;
32
+ customerId?: string;
29
33
  environment: string;
30
34
  apiUrl: string;
31
35
  entitlementsPath: string;
@@ -6,11 +6,13 @@ interface KelviqProviderProps {
6
6
  apiUrl?: string;
7
7
  /** Path for fetching all entitlements (e.g., "/entitlements"). Required. */
8
8
  entitlementsPath?: string;
9
- /** The customer ID. Required. */
10
- customerId: string;
9
+ /** The customer ID. Required for entitlements, subscriptions, and customer data. Optional for pricing. */
10
+ customerId?: string;
11
11
  environment?: 'production' | 'sandbox';
12
12
  /** Optional: The static authentication token string for API requests. */
13
13
  accessToken: string | null;
14
+ /** Optional: Product identifier for fetching pricing data. Required when fetchPricingOnMount is true. */
15
+ productId?: string;
14
16
  /** Optional: Further configuration options for API behavior. */
15
17
  config?: KelviqApiBehaviorOptions;
16
18
  }
@@ -0,0 +1,9 @@
1
+ import { AsyncState } from '../types';
2
+ import { RawPricingApiResponse } from '../types/api.types';
3
+ /**
4
+ * Hook to get pricing and plan data with localized currency.
5
+ * Only populated when `fetchPricingOnMount` is enabled in the provider config,
6
+ * or after calling `refreshPricing()` from `useKelviq()`.
7
+ * @returns AsyncState containing the pricing data or null.
8
+ */
9
+ export declare const usePricing: () => AsyncState<RawPricingApiResponse | null>;
package/dist/index.d.ts CHANGED
@@ -11,3 +11,7 @@ export * from './hooks/useCustomizableEntitlement';
11
11
  export * from './hooks/useMeteredEntitlement';
12
12
  export * from './hooks/useSubscriptions';
13
13
  export * from './hooks/useCustomer';
14
+ export * from './hooks/usePricing';
15
+ export * from './components/KQPrice';
16
+ export * from './components/KQFeatureList';
17
+ export * from './utils/formatPrice';