@buildbase/sdk 0.0.14 → 0.0.16

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 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
  - [User Management](#-user-management)
14
14
  - [Workspace Management](#-complete-workspace-management)
15
+ - [Public Pricing (No Login)](#-public-pricing-no-login)
15
16
  - [Beta Form Component](#-beta-form-component)
16
17
  - [Event System](#-event-system)
17
18
  - [Error Handling](#️-error-handling)
@@ -406,6 +407,71 @@ function WorkspaceManager() {
406
407
  }
407
408
  ```
408
409
 
410
+ ## 💰 Public Pricing (No Login)
411
+
412
+ Display subscription plans and pricing on public pages (e.g. marketing site, pricing page) without requiring users to log in.
413
+
414
+ ### usePublicPlans
415
+
416
+ Fetches public plans by slug. Returns `items` (features, limits, quotas) and `plans` (with pricing). You construct the layout from this data:
417
+
418
+ ```tsx
419
+ import { usePublicPlans } from '@buildbase/sdk';
420
+
421
+ function PublicPricingPage() {
422
+ const { items, plans, loading, error } = usePublicPlans('main-pricing');
423
+
424
+ if (loading) return <Loading />;
425
+ if (error) return <Error message={error} />;
426
+
427
+ return (
428
+ <div>
429
+ {plans.map(plan => (
430
+ <PlanCard key={plan._id} plan={plan} items={items} />
431
+ ))}
432
+ </div>
433
+ );
434
+ }
435
+ ```
436
+
437
+ ### PricingPage Component
438
+
439
+ Use the `PricingPage` component with a render-prop pattern:
440
+
441
+ ```tsx
442
+ import { PricingPage } from '@buildbase/sdk';
443
+
444
+ function PublicPricingPage() {
445
+ return (
446
+ <PricingPage slug="main-pricing">
447
+ {({ loading, error, items, plans, refetch }) => {
448
+ if (loading) return <Loading />;
449
+ if (error) return <Error message={error} />;
450
+
451
+ return (
452
+ <div>
453
+ {plans.map(plan => (
454
+ <PlanCard key={plan._id} plan={plan} items={items} />
455
+ ))}
456
+ </div>
457
+ );
458
+ }}
459
+ </PricingPage>
460
+ );
461
+ }
462
+ ```
463
+
464
+ | Prop | Type | Description |
465
+ |------|------|-------------|
466
+ | `slug` | `string` | Plan group slug (e.g. 'main-pricing', 'enterprise') |
467
+ | `children` | `(details) => ReactNode` | Render prop receiving `{ loading, error, items, plans, refetch }` |
468
+ | `loadingFallback` | `ReactNode` | Custom loading UI (defaults to skeleton) |
469
+ | `errorFallback` | `(error: string) => ReactNode` | Custom error UI |
470
+
471
+ **Response shape**: `items` = subscription item definitions (features, limits, quotas with category); `plans` = plan versions with `pricing`, `quotas`, `features`, `limits`.
472
+
473
+ **Backend requirement**: `GET /api/v1/public/{orgId}/plans/{groupSlug}` must be implemented and allow unauthenticated access.
474
+
409
475
  ## 📝 Beta Form Component
410
476
 
411
477
  Use the pre-built `BetaForm` component for signup/waitlist forms:
package/dist/index.d.ts CHANGED
@@ -21,9 +21,12 @@ interface IUser extends IDocument {
21
21
  currency: string;
22
22
  attributes?: Record<string, string | number | boolean>;
23
23
  }
24
+ type BillingInterval = 'monthly' | 'yearly' | 'quarterly';
24
25
  interface ISubscription {
25
26
  _id: string;
26
27
  subscriptionStatus: 'active' | 'trialing' | 'canceled' | 'past_due';
28
+ stripePriceId?: string;
29
+ stripeCurrentPeriodEnd?: string;
27
30
  cancelAtPeriodEnd: boolean;
28
31
  createdAt: string;
29
32
  updatedAt: string;
@@ -175,7 +178,6 @@ interface IPlanGroupVersionsResponse {
175
178
  currentVersion: IPlanGroupVersionWithPlans;
176
179
  availableVersions: IPlanGroupVersionWithPlans[];
177
180
  }
178
- type BillingInterval = 'monthly' | 'yearly' | 'quarterly';
179
181
  interface ICheckoutSessionRequest {
180
182
  planVersionId: string;
181
183
  billingInterval?: BillingInterval;
@@ -211,6 +213,42 @@ interface ISubscriptionUpdateResponse {
211
213
  createdAt: string;
212
214
  updatedAt: string;
213
215
  }
216
+ interface IPublicPlanItemCategory {
217
+ name: string;
218
+ slug: string;
219
+ }
220
+ interface IPublicPlanItem {
221
+ _id: string;
222
+ name: string;
223
+ slug: string;
224
+ description: string;
225
+ type: 'feature' | 'limit' | 'quota';
226
+ category: IPublicPlanItemCategory;
227
+ }
228
+ interface IPublicPlanPricing {
229
+ monthly: number;
230
+ yearly: number;
231
+ quarterly: number;
232
+ }
233
+ interface IPublicPlanQuotaValue {
234
+ included: number;
235
+ overage: number;
236
+ stripePriceId?: string;
237
+ }
238
+ interface IPublicPlanVersion {
239
+ _id: string;
240
+ name: string;
241
+ version: number;
242
+ status: 'draft' | 'published';
243
+ pricing: IPublicPlanPricing;
244
+ quotas: Record<string, IPublicPlanQuotaValue>;
245
+ features: Record<string, boolean>;
246
+ limits: Record<string, number>;
247
+ }
248
+ interface IPublicPlansResponse {
249
+ items: IPublicPlanItem[];
250
+ plans: IPublicPlanVersion[];
251
+ }
214
252
  type InvoiceStatus = 'draft' | 'open' | 'paid' | 'uncollectible' | 'void';
215
253
  interface IInvoice {
216
254
  id: string;
@@ -430,6 +468,52 @@ interface BetaFormProps {
430
468
  }
431
469
  declare const BetaForm: react__default.FC<BetaFormProps>;
432
470
 
471
+ interface PricingPageDetails {
472
+ /** Whether plan data is being fetched */
473
+ loading: boolean;
474
+ /** Error message if fetch failed */
475
+ error: string | null;
476
+ /** Subscription items (features, limits, quotas) */
477
+ items: IPublicPlanItem[];
478
+ /** Plan versions with pricing, features, limits, quotas */
479
+ plans: IPublicPlanVersion[];
480
+ /** Refetch plan data */
481
+ refetch: () => Promise<void>;
482
+ }
483
+ interface PricingPageProps {
484
+ /** Plan group slug (e.g. 'main-pricing', 'enterprise') */
485
+ slug: string;
486
+ /** Render prop receiving plan details - construct layout from items and plans */
487
+ children: (details: PricingPageDetails) => ReactNode;
488
+ /** Custom loading UI. Defaults to skeleton. */
489
+ loadingFallback?: ReactNode;
490
+ /** Custom error UI. Receives error message. */
491
+ errorFallback?: (error: string) => ReactNode;
492
+ }
493
+ /**
494
+ * Fetches and provides plan/pricing details for public pricing pages (no login required).
495
+ * Returns items (features, limits, quotas) and plans (with pricing) - user constructs layout.
496
+ *
497
+ * @example
498
+ * ```tsx
499
+ * <PricingPage slug="main-pricing">
500
+ * {({ loading, error, items, plans, refetch }) => {
501
+ * if (loading) return <Loading />;
502
+ * if (error) return <Error message={error} />;
503
+ *
504
+ * return (
505
+ * <div>
506
+ * {plans.map(plan => (
507
+ * <PlanCard key={plan._id} plan={plan} items={items} />
508
+ * ))}
509
+ * </div>
510
+ * );
511
+ * }}
512
+ * </PricingPage>
513
+ * ```
514
+ */
515
+ declare function PricingPage({ slug, children, loadingFallback, errorFallback, }: PricingPageProps): react_jsx_runtime.JSX.Element;
516
+
433
517
  interface IProps$2 {
434
518
  children: React.ReactNode;
435
519
  }
@@ -1060,6 +1144,59 @@ declare function WorkspaceSwitcher(props: {
1060
1144
  trigger: (isLoading: boolean, currentWorkspace: IWorkspace | null) => ReactNode;
1061
1145
  }): react_jsx_runtime.JSX.Element;
1062
1146
 
1147
+ /**
1148
+ * Hook to get public plans by slug (no auth required).
1149
+ * Returns items (features, limits, quotas) and plans (with pricing).
1150
+ * Uses orgId from SaaSOSProvider - must be inside provider.
1151
+ *
1152
+ * @param slug - Plan group slug (e.g. 'main-pricing', 'enterprise')
1153
+ * @returns { items, plans, loading, error, refetch }
1154
+ */
1155
+ declare const usePublicPlans: (slug: string) => {
1156
+ items: IPublicPlanItem[];
1157
+ plans: IPublicPlanVersion[];
1158
+ loading: boolean;
1159
+ error: string | null;
1160
+ refetch: () => Promise<void>;
1161
+ };
1162
+ /**
1163
+ * Hook to get a single plan group version by ID (no auth required).
1164
+ * Use this for public pricing pages when you have the groupVersionId (e.g. from config or URL).
1165
+ *
1166
+ * @param groupVersionId - The plan group version ID to fetch. Pass null/undefined to disable fetching.
1167
+ * @returns An object containing:
1168
+ * - `planGroupVersion`: Plan group version data (null if not loaded)
1169
+ * - `loading`: Boolean indicating if data is being fetched
1170
+ * - `error`: Error message string (null if no error)
1171
+ * - `refetch()`: Function to manually refetch
1172
+ *
1173
+ * @example
1174
+ * ```tsx
1175
+ * function PublicPricingPage() {
1176
+ * const groupVersionId = 'your-plan-group-version-id'; // from config or URL
1177
+ * const { planGroupVersion, loading } = usePublicPlanGroupVersion(groupVersionId);
1178
+ *
1179
+ * if (loading) return <Loading />;
1180
+ * if (!planGroupVersion) return null;
1181
+ *
1182
+ * const plans = Array.isArray(planGroupVersion.planVersionIds)
1183
+ * ? planGroupVersion.planVersionIds.filter((p): p is IPlanVersionWithPlan => typeof p !== 'string')
1184
+ * : [];
1185
+ *
1186
+ * return (
1187
+ * <div>
1188
+ * {plans.map(plan => <PlanCard key={plan._id} plan={plan} />)}
1189
+ * </div>
1190
+ * );
1191
+ * }
1192
+ * ```
1193
+ */
1194
+ declare const usePublicPlanGroupVersion: (groupVersionId: string | null | undefined) => {
1195
+ planGroupVersion: IPlanGroupVersion | null;
1196
+ loading: boolean;
1197
+ error: string | null;
1198
+ refetch: () => Promise<void>;
1199
+ };
1063
1200
  /**
1064
1201
  * Hook to get and manage the current subscription for a workspace.
1065
1202
  * Automatically fetches subscription when workspaceId changes.
@@ -1568,5 +1705,5 @@ declare class EventEmitter {
1568
1705
  }
1569
1706
  declare const eventEmitter: EventEmitter;
1570
1707
 
1571
- export { ApiVersion, AuthStatus, BetaForm, SaaSOSProvider, WhenAuthenticated, WhenRoles, WhenUnauthenticated, WhenUserFeatureDisabled, WhenUserFeatureEnabled, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceSwitcher, eventEmitter, useCreateCheckoutSession, useInvoice, useInvoices, usePlanGroup, usePlanGroupVersions, useSaaSAuth, useSaaSSettings, useSaaSWorkspaces, useSubscription, useSubscriptionManagement, useUpdateSubscription, useUserAttributes, useUserFeatures };
1572
- export type { BillingInterval, EventData, EventType, IBasePricing, ICheckoutSessionRequest, ICheckoutSessionResponse, IEventCallbacks, IInvoice, IInvoiceListResponse, IInvoiceResponse, IPlan, IPlanGroup, IPlanGroupLatestVersion, IPlanGroupResponse, IPlanGroupVersion, IPlanGroupVersionWithPlans, IPlanGroupVersionsResponse, IPlanVersion, IPlanVersionWithPlan, IQuotaValue, ISubscription, ISubscriptionItem, ISubscriptionResponse, ISubscriptionUpdateRequest, ISubscriptionUpdateResponse, InvoiceStatus, OnWorkspaceChangeParams, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };
1708
+ export { ApiVersion, AuthStatus, BetaForm, PricingPage, SaaSOSProvider, WhenAuthenticated, WhenRoles, WhenUnauthenticated, WhenUserFeatureDisabled, WhenUserFeatureEnabled, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceSwitcher, eventEmitter, useCreateCheckoutSession, useInvoice, useInvoices, usePlanGroup, usePlanGroupVersions, usePublicPlanGroupVersion, usePublicPlans, useSaaSAuth, useSaaSSettings, useSaaSWorkspaces, useSubscription, useSubscriptionManagement, useUpdateSubscription, useUserAttributes, useUserFeatures };
1709
+ export type { BillingInterval, EventData, EventType, IBasePricing, ICheckoutSessionRequest, ICheckoutSessionResponse, IEventCallbacks, IInvoice, IInvoiceListResponse, IInvoiceResponse, IPlan, IPlanGroup, IPlanGroupLatestVersion, IPlanGroupResponse, IPlanGroupVersion, IPlanGroupVersionWithPlans, IPlanGroupVersionsResponse, IPlanVersion, IPlanVersionWithPlan, IPublicPlanItem, IPublicPlanItemCategory, IPublicPlanPricing, IPublicPlanQuotaValue, IPublicPlanVersion, IPublicPlansResponse, IQuotaValue, ISubscription, ISubscriptionItem, ISubscriptionResponse, ISubscriptionUpdateRequest, ISubscriptionUpdateResponse, InvoiceStatus, OnWorkspaceChangeParams, PricingPageDetails, PricingPageProps, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };