@buildbase/sdk 0.0.27 → 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/dist/index.d.ts CHANGED
@@ -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 seats allowed. 0 = unlimited. */
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,37 @@ 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
- * @returns SeatStatus computed seat information
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, availableSeats, billableSeats } = useSeatStatus(workspace);
2778
+ * const { isAtMax, canInvite, inviteBlockMessage, availableSeats } = useSeatStatus(workspace);
2654
2779
  *
2655
- * if (isAtMax) {
2656
- * return <UpgradeBanner />;
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): SeatStatus;
2788
+ } | null, options?: {
2789
+ settingsMaxUsers?: number | null;
2790
+ }): SeatStatus;
2664
2791
 
2665
2792
  interface PushNotificationState {
2666
2793
  /** Browser's Notification.permission: 'default' | 'granted' | 'denied' */
@@ -2846,73 +2973,6 @@ declare function getQuotaUnitLabelFromName(nameOrSlug: string): string;
2846
2973
  */
2847
2974
  declare function formatQuotaIncludedOverage(included: number | undefined, overageCents: number | undefined, unitLabel: string, currency: string, unitSize?: number): string;
2848
2975
 
2849
- /**
2850
- * Helpers for multi-currency plan version pricing (pricingVariants).
2851
- */
2852
-
2853
- /** Get the pricing variant for a currency, or null if not available. */
2854
- declare function getPricingVariant(planVersion: IPlanVersion, currency: string): IPricingVariant | null;
2855
- /**
2856
- * Get base price in cents for a plan version and currency/interval.
2857
- */
2858
- declare function getBasePriceCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval): number | null;
2859
- /**
2860
- * Get Stripe price ID for the given plan version, currency, and interval.
2861
- */
2862
- declare function getStripePriceIdForInterval(planVersion: IPlanVersion, currency: string, interval: BillingInterval): string | null;
2863
- /**
2864
- * Get overage amount in cents for a quota in a given currency and interval.
2865
- * Returns undefined if not defined in the pricing variant.
2866
- */
2867
- declare function getQuotaOverageCents(planVersion: IPlanVersion, currency: string, quotaSlug: string, interval: BillingInterval): number | undefined;
2868
- /**
2869
- * Get display currency for a plan version when using a given currency.
2870
- * Returns the requested currency if the variant exists; otherwise plan.currency or null.
2871
- */
2872
- declare function getDisplayCurrency(planVersion: IPlanVersionWithPlan, currency: string): string;
2873
- /** Minimal shape for extracting currencies (IPlanVersionWithPlan or IPublicPlanVersion). */
2874
- type PlanVersionWithPricingVariants = {
2875
- pricingVariants?: IPricingVariant[];
2876
- };
2877
- /**
2878
- * Collect all unique currency codes from plan versions (from their pricingVariants).
2879
- * Use for currency selector. Accepts IPlanVersionWithPlan[] or IPublicPlanVersion[].
2880
- */
2881
- declare function getAvailableCurrenciesFromPlans(planVersions: PlanVersionWithPricingVariants[]): string[];
2882
- /**
2883
- * Quota display shape: included count and optional overage (cents) and unitSize from plan + variant.
2884
- */
2885
- type QuotaDisplayWithOverage = {
2886
- included: number;
2887
- overage?: number;
2888
- unitSize?: number;
2889
- } | null;
2890
- /**
2891
- * Get quota display value for a slug/interval, merging plan version quotas (included, unitSize)
2892
- * with pricing variant overage (cents) when available.
2893
- */
2894
- declare function getQuotaDisplayWithVariant(planVersion: IPlanVersion, currency: string, quotaSlug: string, interval: BillingInterval): QuotaDisplayWithOverage;
2895
- /**
2896
- * Resolve billing interval and currency from a Stripe price ID by checking all plan versions' pricingVariants.
2897
- */
2898
- declare function getBillingIntervalAndCurrencyFromPriceId(priceId: string | null | undefined, planVersions: IPlanVersionWithPlan[]): {
2899
- interval: BillingInterval;
2900
- currency: string;
2901
- } | null;
2902
- /** Get per-seat pricing config for a plan version and currency. Null if not enabled. */
2903
- declare function getSeatPricing(planVersion: IPlanVersion, currency: string): IPricingVariant['seatPricing'] | null;
2904
- /** Get per-seat price in cents for a billing interval. Null if seat pricing not enabled. */
2905
- declare function getPerSeatPriceCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval): number | null;
2906
- /** Calculate billable seats: max(0, currentSeats - includedSeats). */
2907
- declare function calculateBillableSeats(currentSeatCount: number, includedSeats: number): number;
2908
- /** Calculate total seat overage cost in cents. Null if seat pricing not enabled. */
2909
- declare function calculateSeatOverageCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval, currentSeatCount: number): number | null;
2910
- /**
2911
- * Calculate total subscription price in cents: base + seat overage (if enabled).
2912
- * Does not include metered usage (billed at period end).
2913
- */
2914
- declare function calculateTotalSubscriptionCents(planVersion: IPlanVersion, currency: string, interval: BillingInterval, currentSeatCount?: number): number | null;
2915
-
2916
2976
  type QuotaDisplayValue = {
2917
2977
  included: number;
2918
2978
  overage?: number;
@@ -2937,5 +2997,5 @@ interface FormatQuotaWithPriceOptions {
2937
2997
  */
2938
2998
  declare function formatQuotaWithPrice(value: QuotaDisplayValue, unitName: string, options?: FormatQuotaWithPriceOptions): string;
2939
2999
 
2940
- 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, 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 };
2941
- 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 };