@buildbase/sdk 0.0.26 → 0.0.28
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.
- package/README.md +37 -0
- package/dist/index.d.ts +188 -78
- package/dist/index.esm.js +5 -5
- package/dist/index.js +5 -5
- package/dist/saas-os.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ A React SDK for [BuildBase](https://www.buildbase.app/) that provides essential
|
|
|
12
12
|
- [Feature Flags](#️-feature-flags)
|
|
13
13
|
- [Subscription Gates](#-subscription-gates)
|
|
14
14
|
- [Trial Gates](#-trial-gates)
|
|
15
|
+
- [Push Notifications](#-push-notifications)
|
|
15
16
|
- [User Management](#-user-management)
|
|
16
17
|
- [Workspace Management](#-complete-workspace-management)
|
|
17
18
|
- [Public Pricing (No Login)](#-public-pricing-no-login)
|
|
@@ -37,6 +38,7 @@ A React SDK for [BuildBase](https://www.buildbase.app/) that provides essential
|
|
|
37
38
|
- **🎯 Feature Flags** - Workspace-level and user-level feature toggles
|
|
38
39
|
- **📋 Subscription Gates** - Show or hide UI based on current workspace subscription (plan)
|
|
39
40
|
- **⏳ Trial Gates** - `WhenTrialing`, `WhenNotTrialing`, `WhenTrialEnding` components + `useTrialStatus` hook
|
|
41
|
+
- **🔔 Push Notifications** - Browser push notifications with `usePushNotifications` hook, auto-triggers for billing events, and campaign management
|
|
40
42
|
- **💺 Seat-Based Pricing** - Per-seat billing with included seats, billable seat tracking, and seat limit enforcement
|
|
41
43
|
- **💱 Multi-Currency** - Per-currency pricing variants with workspace billing currency lock
|
|
42
44
|
- **📊 Quota Usage Tracking** - Record and monitor metered usage (API calls, storage, etc.) with real-time status
|
|
@@ -514,6 +516,40 @@ function TrialInfo() {
|
|
|
514
516
|
| `trialStartedAt`| `Date \| null` | Trial start date |
|
|
515
517
|
| `isTrialEnding` | `boolean` | True when 3 or fewer days remaining |
|
|
516
518
|
|
|
519
|
+
## 🔔 Push Notifications
|
|
520
|
+
|
|
521
|
+
Browser push notifications — built into the SDK. Users can enable/disable from the **Notifications** tab in workspace settings. Billing events (payment failed, trial ending) auto-send push notifications.
|
|
522
|
+
|
|
523
|
+
**Only setup required:** Create `public/push-sw.js` in your app:
|
|
524
|
+
|
|
525
|
+
```js
|
|
526
|
+
self.addEventListener('push', function(event) {
|
|
527
|
+
if (!event.data) return;
|
|
528
|
+
try {
|
|
529
|
+
var payload = event.data.json();
|
|
530
|
+
event.waitUntil(self.registration.showNotification(payload.title || 'Notification', {
|
|
531
|
+
body: payload.body || '',
|
|
532
|
+
icon: payload.icon || undefined,
|
|
533
|
+
badge: payload.icon || undefined,
|
|
534
|
+
data: { url: payload.url, ...(payload.data || {}) },
|
|
535
|
+
}));
|
|
536
|
+
} catch (e) { console.error('[PushSW]', e); }
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
self.addEventListener('notificationclick', function(event) {
|
|
540
|
+
event.notification.close();
|
|
541
|
+
var url = event.notification.data && event.notification.data.url;
|
|
542
|
+
if (url) {
|
|
543
|
+
event.waitUntil(clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function(list) {
|
|
544
|
+
for (var i = 0; i < list.length; i++) { if (list[i].url === url && 'focus' in list[i]) return list[i].focus(); }
|
|
545
|
+
if (clients.openWindow) return clients.openWindow(url);
|
|
546
|
+
}));
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
Everything else is built-in — permission handling, subscribe/unsubscribe, settings UI, billing auto-triggers, and browser-specific unblock instructions.
|
|
552
|
+
|
|
517
553
|
## 👤 User Management
|
|
518
554
|
|
|
519
555
|
### User Attributes
|
|
@@ -1285,6 +1321,7 @@ Prefer these SDK hooks for state and operations instead of `useAppSelector`:
|
|
|
1285
1321
|
| `useUserFeatures()` | User feature flags |
|
|
1286
1322
|
| `useSubscriptionContext()` | Subscription for current workspace (response, loading, refetch); use inside SubscriptionContextProvider |
|
|
1287
1323
|
| `useTrialStatus()` | Trial state: `isTrialing`, `daysRemaining`, `trialEndsAt`, `isTrialEnding` |
|
|
1324
|
+
| `usePushNotifications()` | Push notification state and actions: `isSubscribed`, `subscribe()`, `unsubscribe()` |
|
|
1288
1325
|
| Subscription hooks | `usePublicPlans`, `useSubscription`, `useSubscriptionManagement`, `usePlanGroup`, `usePlanGroupVersions`, `usePublicPlanGroupVersion`, `useCreateCheckoutSession`, `useUpdateSubscription`, `useCancelSubscription`, `useResumeSubscription`, `useInvoices`, `useInvoice` |
|
|
1289
1326
|
| `useQuotaUsageContext()` | Quota usage for current workspace (quotas, loading, refetch); use inside QuotaUsageContextProvider |
|
|
1290
1327
|
| Quota usage hooks | `useRecordUsage`, `useQuotaUsageStatus`, `useAllQuotaUsage`, `useUsageLogs` |
|
package/dist/index.d.ts
CHANGED
|
@@ -1406,7 +1406,7 @@ declare function useQuotaUsageContext(): QuotaUsageContextValue;
|
|
|
1406
1406
|
*/
|
|
1407
1407
|
declare function invalidateQuotaUsage(): void;
|
|
1408
1408
|
|
|
1409
|
-
type WorkspaceSettingsSection = 'profile' | 'general' | 'users' | 'subscription' | 'usage' | 'features' | 'danger';
|
|
1409
|
+
type WorkspaceSettingsSection = 'profile' | 'general' | 'users' | 'subscription' | 'usage' | 'features' | 'notifications' | 'danger';
|
|
1410
1410
|
|
|
1411
1411
|
declare function useSaaSAuth(): {
|
|
1412
1412
|
signIn: () => Promise<void>;
|
|
@@ -2619,6 +2619,116 @@ interface TrialStatus {
|
|
|
2619
2619
|
*/
|
|
2620
2620
|
declare function useTrialStatus(): TrialStatus;
|
|
2621
2621
|
|
|
2622
|
+
/**
|
|
2623
|
+
* Helpers for multi-currency plan version pricing (pricingVariants).
|
|
2624
|
+
*/
|
|
2625
|
+
|
|
2626
|
+
/** Get the pricing variant for a currency, or null if not available. */
|
|
2627
|
+
declare function getPricingVariant(planVersion: IPlanVersion, currency: string): IPricingVariant | null;
|
|
2628
|
+
/**
|
|
2629
|
+
* Get base price in cents for a plan version and currency/interval.
|
|
2630
|
+
*/
|
|
2631
|
+
declare function getBasePriceCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval): number | null;
|
|
2632
|
+
/**
|
|
2633
|
+
* Get Stripe price ID for the given plan version, currency, and interval.
|
|
2634
|
+
*/
|
|
2635
|
+
declare function getStripePriceIdForInterval(planVersion: IPlanVersion, currency: string, interval: BillingInterval): string | null;
|
|
2636
|
+
/**
|
|
2637
|
+
* Get overage amount in cents for a quota in a given currency and interval.
|
|
2638
|
+
* Returns undefined if not defined in the pricing variant.
|
|
2639
|
+
*/
|
|
2640
|
+
declare function getQuotaOverageCents(planVersion: IPlanVersion, currency: string, quotaSlug: string, interval: BillingInterval): number | undefined;
|
|
2641
|
+
/**
|
|
2642
|
+
* Get display currency for a plan version when using a given currency.
|
|
2643
|
+
* Returns the requested currency if the variant exists; otherwise plan.currency or null.
|
|
2644
|
+
*/
|
|
2645
|
+
declare function getDisplayCurrency(planVersion: IPlanVersionWithPlan, currency: string): string;
|
|
2646
|
+
/** Minimal shape for extracting currencies (IPlanVersionWithPlan or IPublicPlanVersion). */
|
|
2647
|
+
type PlanVersionWithPricingVariants = {
|
|
2648
|
+
pricingVariants?: IPricingVariant[];
|
|
2649
|
+
};
|
|
2650
|
+
/**
|
|
2651
|
+
* Collect all unique currency codes from plan versions (from their pricingVariants).
|
|
2652
|
+
* Use for currency selector. Accepts IPlanVersionWithPlan[] or IPublicPlanVersion[].
|
|
2653
|
+
*/
|
|
2654
|
+
declare function getAvailableCurrenciesFromPlans(planVersions: PlanVersionWithPricingVariants[]): string[];
|
|
2655
|
+
/**
|
|
2656
|
+
* Quota display shape: included count and optional overage (cents) and unitSize from plan + variant.
|
|
2657
|
+
*/
|
|
2658
|
+
type QuotaDisplayWithOverage = {
|
|
2659
|
+
included: number;
|
|
2660
|
+
overage?: number;
|
|
2661
|
+
unitSize?: number;
|
|
2662
|
+
} | null;
|
|
2663
|
+
/**
|
|
2664
|
+
* Get quota display value for a slug/interval, merging plan version quotas (included, unitSize)
|
|
2665
|
+
* with pricing variant overage (cents) when available.
|
|
2666
|
+
*/
|
|
2667
|
+
declare function getQuotaDisplayWithVariant(planVersion: IPlanVersion, currency: string, quotaSlug: string, interval: BillingInterval): QuotaDisplayWithOverage;
|
|
2668
|
+
/**
|
|
2669
|
+
* Resolve billing interval and currency from a Stripe price ID by checking all plan versions' pricingVariants.
|
|
2670
|
+
*/
|
|
2671
|
+
declare function getBillingIntervalAndCurrencyFromPriceId(priceId: string | null | undefined, planVersions: IPlanVersionWithPlan[]): {
|
|
2672
|
+
interval: BillingInterval;
|
|
2673
|
+
currency: string;
|
|
2674
|
+
} | null;
|
|
2675
|
+
/** Get per-seat pricing config for a plan version and currency. Null if not enabled. */
|
|
2676
|
+
declare function getSeatPricing(planVersion: IPlanVersion, currency: string): IPricingVariant['seatPricing'] | null;
|
|
2677
|
+
/** Get per-seat price in cents for a billing interval. Null if seat pricing not enabled. */
|
|
2678
|
+
declare function getPerSeatPriceCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval): number | null;
|
|
2679
|
+
/** Calculate billable seats: max(0, currentSeats - includedSeats). */
|
|
2680
|
+
declare function calculateBillableSeats(currentSeatCount: number, includedSeats: number): number;
|
|
2681
|
+
/** Calculate total seat overage cost in cents. Null if seat pricing not enabled. */
|
|
2682
|
+
declare function calculateSeatOverageCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval, currentSeatCount: number): number | null;
|
|
2683
|
+
/**
|
|
2684
|
+
* Calculate total subscription price in cents: base + seat overage (if enabled).
|
|
2685
|
+
* Does not include metered usage (billed at period end).
|
|
2686
|
+
*/
|
|
2687
|
+
declare function calculateTotalSubscriptionCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval, currentSeatCount?: number): number | null;
|
|
2688
|
+
interface MaxUsersConfig {
|
|
2689
|
+
/** The resolved maximum number of users allowed. 0 = unlimited. */
|
|
2690
|
+
maxUsers: number;
|
|
2691
|
+
/** Where the limit comes from. */
|
|
2692
|
+
source: 'seat_pricing' | 'settings' | 'none';
|
|
2693
|
+
/** Seats included in the base plan price (0 if no seat pricing). */
|
|
2694
|
+
includedSeats: number;
|
|
2695
|
+
/** Whether seat-based pricing is active. */
|
|
2696
|
+
hasSeatPricing: boolean;
|
|
2697
|
+
}
|
|
2698
|
+
/**
|
|
2699
|
+
* Resolve the effective max users limit from the plan's seat pricing config,
|
|
2700
|
+
* falling back to settings when no seat pricing is configured.
|
|
2701
|
+
*
|
|
2702
|
+
* Priority:
|
|
2703
|
+
* 1. Seat pricing `maxSeats` (from plan version's pricing variant) — the plan controls the limit
|
|
2704
|
+
* 2. Settings fallback (`workspace.maxWorkspaceUsers`) — for workspaces without a subscription
|
|
2705
|
+
*
|
|
2706
|
+
* Returns 0 if no limit is set (unlimited).
|
|
2707
|
+
*/
|
|
2708
|
+
declare function resolveMaxUsers(opts: {
|
|
2709
|
+
planVersion?: IPlanVersion | null;
|
|
2710
|
+
currency?: string;
|
|
2711
|
+
settingsMaxUsers?: number | null;
|
|
2712
|
+
}): MaxUsersConfig;
|
|
2713
|
+
type InviteBlockReason = 'seat_limit_reached' | 'settings_user_limit_reached' | 'no_subscription' | null;
|
|
2714
|
+
interface InviteValidation {
|
|
2715
|
+
/** Whether a new user can be invited. */
|
|
2716
|
+
canInvite: boolean;
|
|
2717
|
+
/** Reason the invite is blocked, or null if allowed. */
|
|
2718
|
+
blockReason: InviteBlockReason;
|
|
2719
|
+
/** Human-readable message for the block reason. */
|
|
2720
|
+
blockMessage: string | null;
|
|
2721
|
+
}
|
|
2722
|
+
/**
|
|
2723
|
+
* Validate whether a new member can be invited given current seat/user limits.
|
|
2724
|
+
*/
|
|
2725
|
+
declare function validateInvite(opts: {
|
|
2726
|
+
memberCount: number;
|
|
2727
|
+
maxUsersConfig: MaxUsersConfig;
|
|
2728
|
+
hasSubscription?: boolean;
|
|
2729
|
+
requireSubscription?: boolean;
|
|
2730
|
+
}): InviteValidation;
|
|
2731
|
+
|
|
2622
2732
|
interface SeatStatus {
|
|
2623
2733
|
/** Whether the current plan uses seat-based pricing. */
|
|
2624
2734
|
hasSeatPricing: boolean;
|
|
@@ -2626,13 +2736,20 @@ interface SeatStatus {
|
|
|
2626
2736
|
memberCount: number;
|
|
2627
2737
|
/** Seats included in the base price (free). */
|
|
2628
2738
|
includedSeats: number;
|
|
2629
|
-
/** Maximum
|
|
2739
|
+
/** Maximum users allowed (resolved from seat pricing, plan limits, or settings). 0 = unlimited. */
|
|
2740
|
+
maxUsers: number;
|
|
2741
|
+
/**
|
|
2742
|
+
* Maximum seats allowed from seat pricing config. 0 = unlimited.
|
|
2743
|
+
* @deprecated Use `maxUsers` for the unified limit.
|
|
2744
|
+
*/
|
|
2630
2745
|
maxSeats: number;
|
|
2746
|
+
/** Where the max user limit comes from. */
|
|
2747
|
+
limitSource: MaxUsersConfig['source'];
|
|
2631
2748
|
/** Seats beyond included that are being billed. */
|
|
2632
2749
|
billableSeats: number;
|
|
2633
2750
|
/** Remaining seats before hitting max. Infinity if unlimited. */
|
|
2634
2751
|
availableSeats: number;
|
|
2635
|
-
/** Whether workspace is at max seat capacity. */
|
|
2752
|
+
/** Whether workspace is at max seat/user capacity. */
|
|
2636
2753
|
isAtMax: boolean;
|
|
2637
2754
|
/** Whether workspace is near max (>= 80% used). */
|
|
2638
2755
|
isNearMax: boolean;
|
|
@@ -2640,27 +2757,87 @@ interface SeatStatus {
|
|
|
2640
2757
|
perSeatPriceCents: number | null;
|
|
2641
2758
|
/** Billing currency. */
|
|
2642
2759
|
currency: string;
|
|
2760
|
+
/** Whether a new member can be invited. */
|
|
2761
|
+
canInvite: boolean;
|
|
2762
|
+
/** Reason the invite is blocked, or null if allowed. */
|
|
2763
|
+
inviteBlockReason: InviteBlockReason;
|
|
2764
|
+
/** Human-readable message for why invite is blocked. */
|
|
2765
|
+
inviteBlockMessage: string | null;
|
|
2643
2766
|
}
|
|
2644
2767
|
/**
|
|
2645
2768
|
* Hook that computes seat status from subscription context and workspace data.
|
|
2769
|
+
* Resolves max user limits from seat pricing, plan limits, and settings in priority order.
|
|
2646
2770
|
* Must be used within SubscriptionContextProvider.
|
|
2647
2771
|
*
|
|
2648
|
-
* @param workspace - The current workspace (needs users array)
|
|
2649
|
-
* @
|
|
2772
|
+
* @param workspace - The current workspace (needs users array, limits, billingCurrency)
|
|
2773
|
+
* @param options - Optional overrides (e.g. settingsMaxUsers fallback)
|
|
2774
|
+
* @returns SeatStatus — computed seat and invite information
|
|
2650
2775
|
*
|
|
2651
2776
|
* @example
|
|
2652
2777
|
* ```tsx
|
|
2653
|
-
* const { isAtMax,
|
|
2778
|
+
* const { isAtMax, canInvite, inviteBlockMessage, availableSeats } = useSeatStatus(workspace);
|
|
2654
2779
|
*
|
|
2655
|
-
* if (
|
|
2656
|
-
* return <
|
|
2780
|
+
* if (!canInvite) {
|
|
2781
|
+
* return <div>{inviteBlockMessage}</div>;
|
|
2657
2782
|
* }
|
|
2658
2783
|
* ```
|
|
2659
2784
|
*/
|
|
2660
2785
|
declare function useSeatStatus(workspace: {
|
|
2661
2786
|
users?: any[];
|
|
2662
2787
|
billingCurrency?: string | null;
|
|
2663
|
-
} | null
|
|
2788
|
+
} | null, options?: {
|
|
2789
|
+
settingsMaxUsers?: number | null;
|
|
2790
|
+
}): SeatStatus;
|
|
2791
|
+
|
|
2792
|
+
interface PushNotificationState {
|
|
2793
|
+
/** Browser's Notification.permission: 'default' | 'granted' | 'denied' */
|
|
2794
|
+
permission: NotificationPermission;
|
|
2795
|
+
/** Whether this device is subscribed to push notifications */
|
|
2796
|
+
isSubscribed: boolean;
|
|
2797
|
+
/** Whether the browser supports push notifications */
|
|
2798
|
+
isSupported: boolean;
|
|
2799
|
+
/** Loading state for subscribe/unsubscribe operations */
|
|
2800
|
+
loading: boolean;
|
|
2801
|
+
/** Error message from the last operation */
|
|
2802
|
+
error: string | null;
|
|
2803
|
+
}
|
|
2804
|
+
interface PushNotificationContextValue extends PushNotificationState {
|
|
2805
|
+
/** Request notification permission from the browser. Returns true if granted. */
|
|
2806
|
+
requestPermission: () => Promise<boolean>;
|
|
2807
|
+
/** Subscribe this device to push notifications (requests permission if needed). */
|
|
2808
|
+
subscribe: () => Promise<void>;
|
|
2809
|
+
/** Unsubscribe this device from push notifications. */
|
|
2810
|
+
unsubscribe: () => Promise<void>;
|
|
2811
|
+
}
|
|
2812
|
+
interface PushNotificationProviderProps {
|
|
2813
|
+
children: react__default.ReactNode;
|
|
2814
|
+
/** Path to the service worker file (default: '/push-sw.js') */
|
|
2815
|
+
serviceWorkerPath?: string;
|
|
2816
|
+
/** Automatically subscribe after permission is granted on login (default: false) */
|
|
2817
|
+
autoSubscribe?: boolean;
|
|
2818
|
+
}
|
|
2819
|
+
declare const PushNotificationProvider: react__default.FC<PushNotificationProviderProps>;
|
|
2820
|
+
/**
|
|
2821
|
+
* Hook to access push notification state and actions.
|
|
2822
|
+
* Must be used within PushNotificationProvider (included in SaaSOSProvider when push config is provided).
|
|
2823
|
+
*/
|
|
2824
|
+
declare function usePushNotifications(): PushNotificationContextValue;
|
|
2825
|
+
|
|
2826
|
+
/**
|
|
2827
|
+
* Push notification service worker source code.
|
|
2828
|
+
* Export this string and write it to a file in your app's `public/` directory.
|
|
2829
|
+
*
|
|
2830
|
+
* @example
|
|
2831
|
+
* ```ts
|
|
2832
|
+
* // scripts/generate-sw.ts
|
|
2833
|
+
* import { PUSH_SERVICE_WORKER_SCRIPT } from '@buildbase/sdk';
|
|
2834
|
+
* import fs from 'fs';
|
|
2835
|
+
* fs.writeFileSync('public/push-sw.js', PUSH_SERVICE_WORKER_SCRIPT);
|
|
2836
|
+
* ```
|
|
2837
|
+
*
|
|
2838
|
+
* Or manually create `public/push-sw.js` with this content.
|
|
2839
|
+
*/
|
|
2840
|
+
declare const PUSH_SERVICE_WORKER_SCRIPT = "\n// BuildBase Push Notification Service Worker\n// Place this file in your app's public directory (e.g. public/push-sw.js)\n\nself.addEventListener('push', function(event) {\n if (!event.data) return;\n\n try {\n var payload = event.data.json();\n var title = payload.title || 'Notification';\n var options = {\n body: payload.body || '',\n icon: payload.icon || undefined,\n badge: payload.icon || undefined,\n data: { url: payload.url, ...(payload.data || {}) },\n tag: 'buildbase-push-' + Date.now(),\n };\n\n event.waitUntil(\n self.registration.showNotification(title, options)\n );\n } catch (e) {\n console.error('[PushSW] Failed to show notification:', e);\n }\n});\n\nself.addEventListener('notificationclick', function(event) {\n event.notification.close();\n\n var url = event.notification.data && event.notification.data.url;\n if (url) {\n event.waitUntil(\n clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function(clientList) {\n for (var i = 0; i < clientList.length; i++) {\n var client = clientList[i];\n if (client.url === url && 'focus' in client) {\n return client.focus();\n }\n }\n if (clients.openWindow) {\n return clients.openWindow(url);\n }\n })\n );\n }\n});\n";
|
|
2664
2841
|
|
|
2665
2842
|
/**
|
|
2666
2843
|
* EventEmitter class to handle and trigger event callbacks
|
|
@@ -2796,73 +2973,6 @@ declare function getQuotaUnitLabelFromName(nameOrSlug: string): string;
|
|
|
2796
2973
|
*/
|
|
2797
2974
|
declare function formatQuotaIncludedOverage(included: number | undefined, overageCents: number | undefined, unitLabel: string, currency: string, unitSize?: number): string;
|
|
2798
2975
|
|
|
2799
|
-
/**
|
|
2800
|
-
* Helpers for multi-currency plan version pricing (pricingVariants).
|
|
2801
|
-
*/
|
|
2802
|
-
|
|
2803
|
-
/** Get the pricing variant for a currency, or null if not available. */
|
|
2804
|
-
declare function getPricingVariant(planVersion: IPlanVersion, currency: string): IPricingVariant | null;
|
|
2805
|
-
/**
|
|
2806
|
-
* Get base price in cents for a plan version and currency/interval.
|
|
2807
|
-
*/
|
|
2808
|
-
declare function getBasePriceCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval): number | null;
|
|
2809
|
-
/**
|
|
2810
|
-
* Get Stripe price ID for the given plan version, currency, and interval.
|
|
2811
|
-
*/
|
|
2812
|
-
declare function getStripePriceIdForInterval(planVersion: IPlanVersion, currency: string, interval: BillingInterval): string | null;
|
|
2813
|
-
/**
|
|
2814
|
-
* Get overage amount in cents for a quota in a given currency and interval.
|
|
2815
|
-
* Returns undefined if not defined in the pricing variant.
|
|
2816
|
-
*/
|
|
2817
|
-
declare function getQuotaOverageCents(planVersion: IPlanVersion, currency: string, quotaSlug: string, interval: BillingInterval): number | undefined;
|
|
2818
|
-
/**
|
|
2819
|
-
* Get display currency for a plan version when using a given currency.
|
|
2820
|
-
* Returns the requested currency if the variant exists; otherwise plan.currency or null.
|
|
2821
|
-
*/
|
|
2822
|
-
declare function getDisplayCurrency(planVersion: IPlanVersionWithPlan, currency: string): string;
|
|
2823
|
-
/** Minimal shape for extracting currencies (IPlanVersionWithPlan or IPublicPlanVersion). */
|
|
2824
|
-
type PlanVersionWithPricingVariants = {
|
|
2825
|
-
pricingVariants?: IPricingVariant[];
|
|
2826
|
-
};
|
|
2827
|
-
/**
|
|
2828
|
-
* Collect all unique currency codes from plan versions (from their pricingVariants).
|
|
2829
|
-
* Use for currency selector. Accepts IPlanVersionWithPlan[] or IPublicPlanVersion[].
|
|
2830
|
-
*/
|
|
2831
|
-
declare function getAvailableCurrenciesFromPlans(planVersions: PlanVersionWithPricingVariants[]): string[];
|
|
2832
|
-
/**
|
|
2833
|
-
* Quota display shape: included count and optional overage (cents) and unitSize from plan + variant.
|
|
2834
|
-
*/
|
|
2835
|
-
type QuotaDisplayWithOverage = {
|
|
2836
|
-
included: number;
|
|
2837
|
-
overage?: number;
|
|
2838
|
-
unitSize?: number;
|
|
2839
|
-
} | null;
|
|
2840
|
-
/**
|
|
2841
|
-
* Get quota display value for a slug/interval, merging plan version quotas (included, unitSize)
|
|
2842
|
-
* with pricing variant overage (cents) when available.
|
|
2843
|
-
*/
|
|
2844
|
-
declare function getQuotaDisplayWithVariant(planVersion: IPlanVersion, currency: string, quotaSlug: string, interval: BillingInterval): QuotaDisplayWithOverage;
|
|
2845
|
-
/**
|
|
2846
|
-
* Resolve billing interval and currency from a Stripe price ID by checking all plan versions' pricingVariants.
|
|
2847
|
-
*/
|
|
2848
|
-
declare function getBillingIntervalAndCurrencyFromPriceId(priceId: string | null | undefined, planVersions: IPlanVersionWithPlan[]): {
|
|
2849
|
-
interval: BillingInterval;
|
|
2850
|
-
currency: string;
|
|
2851
|
-
} | null;
|
|
2852
|
-
/** Get per-seat pricing config for a plan version and currency. Null if not enabled. */
|
|
2853
|
-
declare function getSeatPricing(planVersion: IPlanVersion, currency: string): IPricingVariant['seatPricing'] | null;
|
|
2854
|
-
/** Get per-seat price in cents for a billing interval. Null if seat pricing not enabled. */
|
|
2855
|
-
declare function getPerSeatPriceCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval): number | null;
|
|
2856
|
-
/** Calculate billable seats: max(0, currentSeats - includedSeats). */
|
|
2857
|
-
declare function calculateBillableSeats(currentSeatCount: number, includedSeats: number): number;
|
|
2858
|
-
/** Calculate total seat overage cost in cents. Null if seat pricing not enabled. */
|
|
2859
|
-
declare function calculateSeatOverageCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval, currentSeatCount: number): number | null;
|
|
2860
|
-
/**
|
|
2861
|
-
* Calculate total subscription price in cents: base + seat overage (if enabled).
|
|
2862
|
-
* Does not include metered usage (billed at period end).
|
|
2863
|
-
*/
|
|
2864
|
-
declare function calculateTotalSubscriptionCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval, currentSeatCount?: number): number | null;
|
|
2865
|
-
|
|
2866
2976
|
type QuotaDisplayValue = {
|
|
2867
2977
|
included: number;
|
|
2868
2978
|
overage?: number;
|
|
@@ -2887,5 +2997,5 @@ interface FormatQuotaWithPriceOptions {
|
|
|
2887
2997
|
*/
|
|
2888
2998
|
declare function formatQuotaWithPrice(value: QuotaDisplayValue, unitName: string, options?: FormatQuotaWithPriceOptions): string;
|
|
2889
2999
|
|
|
2890
|
-
export { ApiVersion, AuthStatus, BaseApi, BetaForm, CURRENCY_DISPLAY, CURRENCY_FLAG, PLAN_CURRENCY_CODES, PLAN_CURRENCY_OPTIONS, PricingPage, QuotaUsageContextProvider, SaaSOSProvider, SettingsApi, SubscriptionContextProvider, UserApi, WhenAuthenticated, WhenNoSubscription, WhenNotTrialing, WhenQuotaAvailable, WhenQuotaExhausted, WhenQuotaOverage, WhenQuotaThreshold, WhenRoles, WhenSubscription, WhenSubscriptionToPlans, WhenTrialEnding, WhenTrialing, WhenUnauthenticated, WhenUserFeatureDisabled, WhenUserFeatureEnabled, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceApi, WorkspaceSwitcher, calculateBillableSeats, calculateSeatOverageCents, calculateTotalSubscriptionCents, eventEmitter, formatCents, formatOverageRate, formatOverageRateWithLabel, formatQuotaIncludedOverage, formatQuotaWithPrice, getAvailableCurrenciesFromPlans, getBasePriceCents, getBillingIntervalAndCurrencyFromPriceId, getCurrencyFlag, getCurrencySymbol, getDisplayCurrency, getPerSeatPriceCents, getPricingVariant, getQuotaDisplayValue, getQuotaDisplayWithVariant, getQuotaOverageCents, getQuotaUnitLabelFromName, getSeatPricing, getStripePriceIdForInterval, invalidateQuotaUsage, invalidateSubscription, useAllQuotaUsage, useBillingPortal, useCancelSubscription, useCreateCheckoutSession, useInvoice, useInvoices, usePlanGroup, usePlanGroupVersions, usePublicPlanGroupVersion, usePublicPlans, useQuotaUsageContext, useQuotaUsageStatus, useRecordUsage, useResumeSubscription, useSaaSAuth, useSaaSOs, useSaaSSettings, useSaaSWorkspaces, useSeatStatus, useSubscription, useSubscriptionContext, useSubscriptionManagement, useTrialStatus, useUpdateSubscription, useUsageLogs, useUserAttributes, useUserFeatures };
|
|
2891
|
-
export type { BillingInterval, CheckoutResult, EventData, EventType, FormatQuotaWithPriceOptions, IAllQuotaUsageResponse, IBaseApiConfig, IBasePricing, ICheckoutSessionRequest, ICheckoutSessionResponse, IEventCallbacks, IInvoice, IInvoiceListResponse, IInvoiceResponse, IPlan, IPlanGroup, IPlanGroupInfo, IPlanGroupLatestVersion, IPlanGroupResponse, IPlanGroupVersion, IPlanGroupVersionWithPlans, IPlanGroupVersionsResponse, IPlanVersion, IPlanVersionSummary, IPlanVersionWithPlan, IPricingVariant, IPublicPlanItem, IPublicPlanItemCategory, IPublicPlanVersion, IPublicPlansResponse, IQuotaByInterval, IQuotaIntervalValue, IQuotaOveragePriceIdsByInterval, IQuotaOveragesByInterval, IQuotaUsageStatus, IQuotaUsageStatusResponse, IRecordUsageRequest, IRecordUsageResponse, IStripePricesByInterval, ISubscription, ISubscriptionItem, ISubscriptionResponse, ISubscriptionUpdateRequest, ISubscriptionUpdateResponse, IUsageLogEntry, IUsageLogsQuery, IUsageLogsResponse, InvoiceStatus, OnWorkspaceChangeParams, PlanVersionWithPricingVariants, PricingPageDetails, PricingPageProps, QuotaDisplayValue, QuotaDisplayWithOverage, QuotaUsageContextValue, SeatStatus, SubscriptionContextValue, TrialStatus, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };
|
|
3000
|
+
export { ApiVersion, AuthStatus, BaseApi, BetaForm, CURRENCY_DISPLAY, CURRENCY_FLAG, PLAN_CURRENCY_CODES, PLAN_CURRENCY_OPTIONS, PUSH_SERVICE_WORKER_SCRIPT, PricingPage, PushNotificationProvider, QuotaUsageContextProvider, SaaSOSProvider, SettingsApi, SubscriptionContextProvider, UserApi, WhenAuthenticated, WhenNoSubscription, WhenNotTrialing, WhenQuotaAvailable, WhenQuotaExhausted, WhenQuotaOverage, WhenQuotaThreshold, WhenRoles, WhenSubscription, WhenSubscriptionToPlans, WhenTrialEnding, WhenTrialing, WhenUnauthenticated, WhenUserFeatureDisabled, WhenUserFeatureEnabled, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceApi, WorkspaceSwitcher, calculateBillableSeats, calculateSeatOverageCents, calculateTotalSubscriptionCents, eventEmitter, formatCents, formatOverageRate, formatOverageRateWithLabel, formatQuotaIncludedOverage, formatQuotaWithPrice, getAvailableCurrenciesFromPlans, getBasePriceCents, getBillingIntervalAndCurrencyFromPriceId, getCurrencyFlag, getCurrencySymbol, getDisplayCurrency, getPerSeatPriceCents, getPricingVariant, getQuotaDisplayValue, getQuotaDisplayWithVariant, getQuotaOverageCents, getQuotaUnitLabelFromName, getSeatPricing, getStripePriceIdForInterval, invalidateQuotaUsage, invalidateSubscription, resolveMaxUsers, useAllQuotaUsage, useBillingPortal, useCancelSubscription, useCreateCheckoutSession, useInvoice, useInvoices, usePlanGroup, usePlanGroupVersions, usePublicPlanGroupVersion, usePublicPlans, usePushNotifications, useQuotaUsageContext, useQuotaUsageStatus, useRecordUsage, useResumeSubscription, useSaaSAuth, useSaaSOs, useSaaSSettings, useSaaSWorkspaces, useSeatStatus, useSubscription, useSubscriptionContext, useSubscriptionManagement, useTrialStatus, useUpdateSubscription, useUsageLogs, useUserAttributes, useUserFeatures, validateInvite };
|
|
3001
|
+
export type { BillingInterval, CheckoutResult, EventData, EventType, FormatQuotaWithPriceOptions, IAllQuotaUsageResponse, IBaseApiConfig, IBasePricing, ICheckoutSessionRequest, ICheckoutSessionResponse, IEventCallbacks, IInvoice, IInvoiceListResponse, IInvoiceResponse, IPlan, IPlanGroup, IPlanGroupInfo, IPlanGroupLatestVersion, IPlanGroupResponse, IPlanGroupVersion, IPlanGroupVersionWithPlans, IPlanGroupVersionsResponse, IPlanVersion, IPlanVersionSummary, IPlanVersionWithPlan, IPricingVariant, IPublicPlanItem, IPublicPlanItemCategory, IPublicPlanVersion, IPublicPlansResponse, IQuotaByInterval, IQuotaIntervalValue, IQuotaOveragePriceIdsByInterval, IQuotaOveragesByInterval, IQuotaUsageStatus, IQuotaUsageStatusResponse, IRecordUsageRequest, IRecordUsageResponse, IStripePricesByInterval, ISubscription, ISubscriptionItem, ISubscriptionResponse, ISubscriptionUpdateRequest, ISubscriptionUpdateResponse, IUsageLogEntry, IUsageLogsQuery, IUsageLogsResponse, InviteBlockReason, InviteValidation, InvoiceStatus, MaxUsersConfig, OnWorkspaceChangeParams, PlanVersionWithPricingVariants, PricingPageDetails, PricingPageProps, QuotaDisplayValue, QuotaDisplayWithOverage, QuotaUsageContextValue, SeatStatus, SubscriptionContextValue, TrialStatus, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };
|