@buildbase/sdk 0.0.10 → 0.0.11
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 +2 -1
- package/dist/index.d.ts +154 -16
- package/dist/index.esm.js +6 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/saas-os.css +1 -1
- package/dist/types/api/types.d.ts +83 -4
- package/dist/types/contexts/AuthContext/actions.d.ts +1 -0
- package/dist/types/contexts/AuthContext/reducer.d.ts +9 -3
- package/dist/types/contexts/AuthContext/types.d.ts +2 -0
- package/dist/types/contexts/shared/useAppSelector.d.ts +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/providers/auth/hooks.d.ts +6 -6
- package/dist/types/providers/auth/types.d.ts +7 -3
- package/dist/types/providers/workspace/api.d.ts +42 -2
- package/dist/types/providers/workspace/subscription-hooks.d.ts +63 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -212,7 +212,7 @@ const {
|
|
|
212
212
|
isAuthenticated, // Boolean: true if user is authenticated
|
|
213
213
|
isLoading, // Boolean: true when checking authentication status
|
|
214
214
|
isRedirecting, // Boolean: true when redirecting for OAuth
|
|
215
|
-
status, //
|
|
215
|
+
status, // AuthStatus: 'loading' | 'redirecting' | 'authenticating' | 'authenticated' | 'unauthenticated' (use AuthStatus enum for type-safe checks)
|
|
216
216
|
signIn, // Function: initiates sign-in flow
|
|
217
217
|
signOut, // Function: signs out the user
|
|
218
218
|
openWorkspaceSettings, // Function: opens workspace settings dialog
|
|
@@ -529,6 +529,7 @@ function SettingsExample() {
|
|
|
529
529
|
### Enums
|
|
530
530
|
|
|
531
531
|
- `ApiVersion` - API version enum (currently only `V1`)
|
|
532
|
+
- `AuthStatus` - Auth status enum: `loading` \| `redirecting` \| `authenticating` \| `authenticated` \| `unauthenticated`. Use with `useSaaSAuth().status`; `isLoading`, `isAuthenticated`, and `isRedirecting` are derived from it.
|
|
532
533
|
|
|
533
534
|
### Types
|
|
534
535
|
|
package/dist/index.d.ts
CHANGED
|
@@ -38,7 +38,13 @@ interface ISubscriptionItem {
|
|
|
38
38
|
}
|
|
39
39
|
interface IQuotaValue {
|
|
40
40
|
included: number;
|
|
41
|
-
overage
|
|
41
|
+
overage?: number;
|
|
42
|
+
stripePriceId?: string;
|
|
43
|
+
}
|
|
44
|
+
interface IBasePricing {
|
|
45
|
+
monthly: number;
|
|
46
|
+
yearly: number;
|
|
47
|
+
quarterly: number;
|
|
42
48
|
}
|
|
43
49
|
interface IPlanVersion {
|
|
44
50
|
_id: string;
|
|
@@ -48,7 +54,11 @@ interface IPlanVersion {
|
|
|
48
54
|
features?: Record<string, boolean>;
|
|
49
55
|
limits?: Record<string, number>;
|
|
50
56
|
quotas?: Record<string, number | IQuotaValue>;
|
|
57
|
+
basePricing?: IBasePricing;
|
|
51
58
|
stripePrices?: {
|
|
59
|
+
monthlyPriceId?: string;
|
|
60
|
+
yearlyPriceId?: string;
|
|
61
|
+
quarterlyPriceId?: string;
|
|
52
62
|
monthly?: string;
|
|
53
63
|
yearly?: string;
|
|
54
64
|
};
|
|
@@ -129,13 +139,59 @@ interface ISubscriptionResponse {
|
|
|
129
139
|
interface IPlanVersionWithPlan extends IPlanVersion {
|
|
130
140
|
plan: IPlan;
|
|
131
141
|
}
|
|
132
|
-
interface
|
|
133
|
-
|
|
134
|
-
|
|
142
|
+
interface IPlanGroupVersionWithPlans {
|
|
143
|
+
_id: string;
|
|
144
|
+
version: number;
|
|
145
|
+
description?: string;
|
|
135
146
|
plans: IPlanVersionWithPlan[];
|
|
147
|
+
isCurrent?: boolean;
|
|
148
|
+
whatsNew?: {
|
|
149
|
+
newPlans: IPlanVersionWithPlan[];
|
|
150
|
+
updatedPlans: IPlanVersionWithPlan[];
|
|
151
|
+
removedPlans: IPlanVersionWithPlan[];
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
interface IPlanGroupResponse {
|
|
155
|
+
group: {
|
|
156
|
+
_id: string;
|
|
157
|
+
name: string;
|
|
158
|
+
slug: string;
|
|
159
|
+
};
|
|
160
|
+
currentVersion: IPlanGroupVersionWithPlans;
|
|
161
|
+
availableVersions: IPlanGroupVersionWithPlans[];
|
|
162
|
+
}
|
|
163
|
+
interface IPlanGroupVersionsResponse {
|
|
164
|
+
group: {
|
|
165
|
+
_id: string;
|
|
166
|
+
name: string;
|
|
167
|
+
slug: string;
|
|
168
|
+
};
|
|
169
|
+
currentVersion: IPlanGroupVersionWithPlans;
|
|
170
|
+
availableVersions: IPlanGroupVersionWithPlans[];
|
|
171
|
+
}
|
|
172
|
+
type BillingInterval = 'monthly' | 'yearly' | 'quarterly';
|
|
173
|
+
interface ICheckoutSessionRequest {
|
|
174
|
+
planVersionId: string;
|
|
175
|
+
billingInterval?: BillingInterval;
|
|
176
|
+
successUrl?: string;
|
|
177
|
+
cancelUrl?: string;
|
|
178
|
+
}
|
|
179
|
+
interface ICheckoutSessionResponse {
|
|
180
|
+
success: boolean;
|
|
181
|
+
checkoutUrl: string;
|
|
182
|
+
sessionId: string;
|
|
183
|
+
message: string;
|
|
184
|
+
planVersion?: {
|
|
185
|
+
_id: string;
|
|
186
|
+
version: number;
|
|
187
|
+
name: string;
|
|
188
|
+
};
|
|
136
189
|
}
|
|
137
190
|
interface ISubscriptionUpdateRequest {
|
|
138
191
|
planVersionId: string;
|
|
192
|
+
billingInterval?: BillingInterval;
|
|
193
|
+
successUrl?: string;
|
|
194
|
+
cancelUrl?: string;
|
|
139
195
|
}
|
|
140
196
|
interface ISubscriptionUpdateResponse {
|
|
141
197
|
_id: string;
|
|
@@ -149,6 +205,29 @@ interface ISubscriptionUpdateResponse {
|
|
|
149
205
|
createdAt: string;
|
|
150
206
|
updatedAt: string;
|
|
151
207
|
}
|
|
208
|
+
type InvoiceStatus = 'draft' | 'open' | 'paid' | 'uncollectible' | 'void';
|
|
209
|
+
interface IInvoice {
|
|
210
|
+
id: string;
|
|
211
|
+
amount_due: number;
|
|
212
|
+
amount_paid: number;
|
|
213
|
+
currency: string;
|
|
214
|
+
status: InvoiceStatus;
|
|
215
|
+
created: number;
|
|
216
|
+
due_date: number | null;
|
|
217
|
+
hosted_invoice_url: string;
|
|
218
|
+
invoice_pdf: string | null;
|
|
219
|
+
description: string | null;
|
|
220
|
+
subscription: string;
|
|
221
|
+
}
|
|
222
|
+
interface IInvoiceListResponse {
|
|
223
|
+
success: boolean;
|
|
224
|
+
invoices: IInvoice[];
|
|
225
|
+
has_more: boolean;
|
|
226
|
+
}
|
|
227
|
+
interface IInvoiceResponse {
|
|
228
|
+
success: boolean;
|
|
229
|
+
invoice: IInvoice;
|
|
230
|
+
}
|
|
152
231
|
|
|
153
232
|
interface IWorkspace {
|
|
154
233
|
_id: string;
|
|
@@ -240,6 +319,7 @@ interface IEventCallbacks {
|
|
|
240
319
|
|
|
241
320
|
declare enum AuthStatus {
|
|
242
321
|
loading = "loading",
|
|
322
|
+
redirecting = "redirecting",
|
|
243
323
|
authenticated = "authenticated",
|
|
244
324
|
unauthenticated = "unauthenticated",
|
|
245
325
|
authenticating = "authenticating"
|
|
@@ -355,15 +435,15 @@ declare const WhenUserFeatureEnabled: (props: IProps) => react.ReactNode;
|
|
|
355
435
|
declare const WhenUserFeatureDisabled: (props: IProps) => react.ReactNode;
|
|
356
436
|
|
|
357
437
|
declare function useSaaSAuth(): {
|
|
358
|
-
user: AuthUser | undefined;
|
|
359
|
-
session: AuthSession | null;
|
|
360
|
-
isLoading: boolean;
|
|
361
|
-
isAuthenticated: boolean;
|
|
362
|
-
isRedirecting: boolean;
|
|
363
|
-
status: AuthStatus;
|
|
364
438
|
signIn: () => Promise<void>;
|
|
365
439
|
signOut: () => Promise<void>;
|
|
366
440
|
openWorkspaceSettings: (section?: "profile" | "general" | "users" | "features" | "danger") => void;
|
|
441
|
+
isAuthenticated: boolean;
|
|
442
|
+
isLoading: boolean;
|
|
443
|
+
isRedirecting: boolean;
|
|
444
|
+
user: AuthUser | undefined;
|
|
445
|
+
session: AuthSession | null;
|
|
446
|
+
status: AuthStatus;
|
|
367
447
|
};
|
|
368
448
|
|
|
369
449
|
declare function useSaaSSettings(): {
|
|
@@ -453,21 +533,48 @@ declare const useSubscription: (workspaceId: string | null | undefined) => {
|
|
|
453
533
|
* Returns the plan group containing the current plan if subscription exists,
|
|
454
534
|
* otherwise returns the latest published group
|
|
455
535
|
* @param workspaceId - The workspace ID to get plan group for
|
|
536
|
+
* @param groupVersionId - Optional: specific group version ID to fetch
|
|
456
537
|
* @returns Plan group data and loading/error states
|
|
457
538
|
*/
|
|
458
|
-
declare const usePlanGroup: (workspaceId: string | null | undefined) => {
|
|
539
|
+
declare const usePlanGroup: (workspaceId: string | null | undefined, groupVersionId?: string | null) => {
|
|
459
540
|
planGroup: IPlanGroupResponse | null;
|
|
460
541
|
loading: boolean;
|
|
461
542
|
error: string | null;
|
|
462
543
|
refetch: () => Promise<void>;
|
|
463
544
|
};
|
|
545
|
+
/**
|
|
546
|
+
* Hook to get all available versions of a plan group for a workspace
|
|
547
|
+
* @param workspaceId - The workspace ID to get plan group versions for
|
|
548
|
+
* @returns Plan group versions data and loading/error states
|
|
549
|
+
*/
|
|
550
|
+
declare const usePlanGroupVersions: (workspaceId: string | null | undefined) => {
|
|
551
|
+
versions: IPlanGroupVersionsResponse | null;
|
|
552
|
+
loading: boolean;
|
|
553
|
+
error: string | null;
|
|
554
|
+
refetch: () => Promise<void>;
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* Hook to create checkout session for new subscription
|
|
558
|
+
* @param workspaceId - The workspace ID to create checkout session for
|
|
559
|
+
* @returns Create checkout function and loading/error states
|
|
560
|
+
*/
|
|
561
|
+
declare const useCreateCheckoutSession: (workspaceId: string | null | undefined) => {
|
|
562
|
+
createCheckoutSession: (request: ICheckoutSessionRequest) => Promise<ICheckoutSessionResponse>;
|
|
563
|
+
loading: boolean;
|
|
564
|
+
error: string | null;
|
|
565
|
+
};
|
|
464
566
|
/**
|
|
465
567
|
* Hook to update subscription (upgrade/downgrade)
|
|
568
|
+
* Returns checkout session if payment is required, otherwise returns subscription update response
|
|
466
569
|
* @param workspaceId - The workspace ID to update subscription for
|
|
467
570
|
* @returns Update function and loading/error states
|
|
468
571
|
*/
|
|
469
572
|
declare const useUpdateSubscription: (workspaceId: string | null | undefined) => {
|
|
470
|
-
updateSubscription: (planVersionId: string
|
|
573
|
+
updateSubscription: (planVersionId: string, options?: {
|
|
574
|
+
billingInterval?: BillingInterval;
|
|
575
|
+
successUrl?: string;
|
|
576
|
+
cancelUrl?: string;
|
|
577
|
+
}) => Promise<ISubscriptionUpdateResponse | ICheckoutSessionResponse>;
|
|
471
578
|
loading: boolean;
|
|
472
579
|
error: string | null;
|
|
473
580
|
};
|
|
@@ -475,14 +582,45 @@ declare const useUpdateSubscription: (workspaceId: string | null | undefined) =>
|
|
|
475
582
|
* Combined hook that provides both subscription and plan group data
|
|
476
583
|
* Useful for subscription management pages
|
|
477
584
|
* @param workspaceId - The workspace ID
|
|
585
|
+
* @param groupVersionId - Optional: specific group version ID to fetch
|
|
478
586
|
* @returns Combined subscription and plan group data with loading/error states
|
|
479
587
|
*/
|
|
480
|
-
declare const useSubscriptionManagement: (workspaceId: string | null | undefined) => {
|
|
588
|
+
declare const useSubscriptionManagement: (workspaceId: string | null | undefined, groupVersionId?: string | null) => {
|
|
481
589
|
subscription: ISubscriptionResponse | null;
|
|
482
590
|
planGroup: IPlanGroupResponse | null;
|
|
483
591
|
loading: boolean;
|
|
484
592
|
error: string | null;
|
|
485
|
-
updateSubscription: (planVersionId: string
|
|
593
|
+
updateSubscription: (planVersionId: string, options?: {
|
|
594
|
+
billingInterval?: BillingInterval;
|
|
595
|
+
successUrl?: string;
|
|
596
|
+
cancelUrl?: string;
|
|
597
|
+
}) => Promise<ISubscriptionUpdateResponse | ICheckoutSessionResponse>;
|
|
598
|
+
refetch: () => Promise<void>;
|
|
599
|
+
};
|
|
600
|
+
/**
|
|
601
|
+
* Hook to list invoices for a workspace subscription
|
|
602
|
+
* @param workspaceId - The workspace ID to get invoices for
|
|
603
|
+
* @param limit - Number of invoices to return (default: 10)
|
|
604
|
+
* @param startingAfter - Invoice ID to start after (for pagination)
|
|
605
|
+
* @returns Invoice list data and loading/error states
|
|
606
|
+
*/
|
|
607
|
+
declare const useInvoices: (workspaceId: string | null | undefined, limit?: number, startingAfter?: string) => {
|
|
608
|
+
invoices: IInvoice[];
|
|
609
|
+
hasMore: boolean;
|
|
610
|
+
loading: boolean;
|
|
611
|
+
error: string | null;
|
|
612
|
+
refetch: () => Promise<void>;
|
|
613
|
+
};
|
|
614
|
+
/**
|
|
615
|
+
* Hook to get a single invoice by ID
|
|
616
|
+
* @param workspaceId - The workspace ID
|
|
617
|
+
* @param invoiceId - The invoice ID to fetch
|
|
618
|
+
* @returns Invoice data and loading/error states
|
|
619
|
+
*/
|
|
620
|
+
declare const useInvoice: (workspaceId: string | null | undefined, invoiceId: string | null | undefined) => {
|
|
621
|
+
invoice: IInvoice | null;
|
|
622
|
+
loading: boolean;
|
|
623
|
+
error: string | null;
|
|
486
624
|
refetch: () => Promise<void>;
|
|
487
625
|
};
|
|
488
626
|
|
|
@@ -658,5 +796,5 @@ declare const errorHandler: ErrorHandler;
|
|
|
658
796
|
declare function handleError(error: Error | unknown, context?: SDKErrorContext): void;
|
|
659
797
|
declare function createSDKError(message: string, code?: string, context?: SDKErrorContext, originalError?: Error): SDKError;
|
|
660
798
|
|
|
661
|
-
export { ApiVersion, BetaForm, SDKErrorBoundary as ErrorBoundary, SDKError, SDKErrorBoundary, SaaSOSProvider, WhenAuthenticated, WhenRoles, WhenUnauthenticated, WhenUserFeatureDisabled, WhenUserFeatureEnabled, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceSwitcher, createSDKError, errorHandler, eventEmitter, handleError, usePlanGroup, useSaaSAuth, useSaaSSettings, useSaaSWorkspaces, useSubscription, useSubscriptionManagement, useUpdateSubscription, useUserAttributes, useUserFeatures };
|
|
662
|
-
export type { ErrorHandlerConfig, EventData, EventType, IEventCallbacks, IPlan, IPlanGroup, IPlanGroupLatestVersion, IPlanGroupResponse, IPlanGroupVersion, IPlanVersion, IPlanVersionWithPlan, IQuotaValue, ISubscription, ISubscriptionItem, ISubscriptionResponse, ISubscriptionUpdateRequest, ISubscriptionUpdateResponse, SDKErrorContext, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };
|
|
799
|
+
export { ApiVersion, AuthStatus, BetaForm, SDKErrorBoundary as ErrorBoundary, SDKError, SDKErrorBoundary, SaaSOSProvider, WhenAuthenticated, WhenRoles, WhenUnauthenticated, WhenUserFeatureDisabled, WhenUserFeatureEnabled, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceSwitcher, createSDKError, errorHandler, eventEmitter, handleError, useCreateCheckoutSession, useInvoice, useInvoices, usePlanGroup, usePlanGroupVersions, useSaaSAuth, useSaaSSettings, useSaaSWorkspaces, useSubscription, useSubscriptionManagement, useUpdateSubscription, useUserAttributes, useUserFeatures };
|
|
800
|
+
export type { BillingInterval, ErrorHandlerConfig, 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, SDKErrorContext, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };
|