@buildbase/sdk 0.0.44 → 0.0.46
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 +290 -48
- package/dist/css/styles.css +1 -1
- package/dist/index.d.ts +330 -16
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/react/index.d.ts +930 -18
- package/dist/react/index.js +5 -5
- package/dist/react/index.mjs +5 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -75,12 +75,14 @@ declare const InvoiceStatuses: {
|
|
|
75
75
|
readonly Uncollectible: "uncollectible";
|
|
76
76
|
readonly Void: "void";
|
|
77
77
|
};
|
|
78
|
+
type InvoiceStatusType = (typeof InvoiceStatuses)[keyof typeof InvoiceStatuses];
|
|
78
79
|
/** Subscription item type constants */
|
|
79
80
|
declare const SubscriptionItemType: {
|
|
80
81
|
readonly Feature: "feature";
|
|
81
82
|
readonly Limit: "limit";
|
|
82
83
|
readonly Quota: "quota";
|
|
83
84
|
};
|
|
85
|
+
type SubscriptionItemTypeValue = (typeof SubscriptionItemType)[keyof typeof SubscriptionItemType];
|
|
84
86
|
/** Dunning state constants */
|
|
85
87
|
declare const DunningState: {
|
|
86
88
|
readonly None: "none";
|
|
@@ -89,11 +91,16 @@ declare const DunningState: {
|
|
|
89
91
|
readonly Final: "final";
|
|
90
92
|
readonly Suspended: "suspended";
|
|
91
93
|
};
|
|
94
|
+
type DunningStateType = (typeof DunningState)[keyof typeof DunningState];
|
|
92
95
|
interface ISubscription {
|
|
93
96
|
_id: string;
|
|
94
97
|
subscriptionStatus: SubscriptionStatusType;
|
|
98
|
+
/** Stripe Subscription ID (e.g. 'sub_...'). Present when linked to Stripe. */
|
|
99
|
+
subscriptionId?: string;
|
|
95
100
|
stripePriceId?: string;
|
|
96
101
|
stripeCurrentPeriodEnd?: string;
|
|
102
|
+
/** When the current monthly usage period ends (quotas reset on this date). */
|
|
103
|
+
usageCurrentPeriodEnd?: string;
|
|
97
104
|
cancelAtPeriodEnd: boolean;
|
|
98
105
|
billingInterval?: BillingInterval;
|
|
99
106
|
/** Trial start date (ISO string). Set when subscription is in trial. */
|
|
@@ -213,6 +220,21 @@ interface IPlanVersion {
|
|
|
213
220
|
durationDays: number;
|
|
214
221
|
requireCard: boolean;
|
|
215
222
|
};
|
|
223
|
+
/** Credit grant configuration. When enabled, credits are granted to workspaces on this plan. */
|
|
224
|
+
creditGrant?: {
|
|
225
|
+
enabled: boolean;
|
|
226
|
+
/** Linked credit package (populated with name, slug, creditAmount). */
|
|
227
|
+
creditPackage?: {
|
|
228
|
+
_id: string;
|
|
229
|
+
name: string;
|
|
230
|
+
slug: string;
|
|
231
|
+
creditAmount: number;
|
|
232
|
+
} | string;
|
|
233
|
+
/** How unused plan credits are handled on renewal: 'reset' = expire old, 'topup' = add to existing. */
|
|
234
|
+
mode: 'reset' | 'topup';
|
|
235
|
+
/** true = credits given fresh every month, false = one-time lifetime grant (default). */
|
|
236
|
+
renewOnPeriod?: boolean;
|
|
237
|
+
};
|
|
216
238
|
isCurrent?: boolean;
|
|
217
239
|
isLegacy?: boolean;
|
|
218
240
|
archived?: boolean;
|
|
@@ -481,6 +503,15 @@ interface IPublicPlanVersion {
|
|
|
481
503
|
durationDays: number;
|
|
482
504
|
requireCard: boolean;
|
|
483
505
|
};
|
|
506
|
+
/** Credit grant config. Only present when the plan grants credits. */
|
|
507
|
+
creditGrant?: {
|
|
508
|
+
enabled: boolean;
|
|
509
|
+
creditAmount: number | null;
|
|
510
|
+
packageName: string | null;
|
|
511
|
+
mode: 'reset' | 'topup';
|
|
512
|
+
/** true = credits given fresh every month, false = one-time lifetime grant. */
|
|
513
|
+
renewOnPeriod: boolean;
|
|
514
|
+
};
|
|
484
515
|
}
|
|
485
516
|
interface IPublicPlansResponse {
|
|
486
517
|
items: IPublicPlanItem[];
|
|
@@ -504,12 +535,10 @@ interface IInvoice {
|
|
|
504
535
|
subscription: string;
|
|
505
536
|
}
|
|
506
537
|
interface IInvoiceListResponse {
|
|
507
|
-
success: boolean;
|
|
508
538
|
invoices: IInvoice[];
|
|
509
539
|
has_more: boolean;
|
|
510
540
|
}
|
|
511
541
|
interface IInvoiceResponse {
|
|
512
|
-
success: boolean;
|
|
513
542
|
invoice: IInvoice;
|
|
514
543
|
}
|
|
515
544
|
/** Request body for POST .../workspaces/:id/subscription/usage */
|
|
@@ -576,6 +605,166 @@ interface IUsageLogsResponse {
|
|
|
576
605
|
hasNextPage: boolean;
|
|
577
606
|
hasPrevPage: boolean;
|
|
578
607
|
}
|
|
608
|
+
/** Credit bucket source (how credits entered the workspace) */
|
|
609
|
+
declare const CreditBucketSource: {
|
|
610
|
+
readonly PlanGrant: "plan_grant";
|
|
611
|
+
readonly CreditPackPurchase: "credit_pack_purchase";
|
|
612
|
+
readonly AdminGrant: "admin_grant";
|
|
613
|
+
readonly Refund: "refund";
|
|
614
|
+
};
|
|
615
|
+
type CreditBucketSourceType = (typeof CreditBucketSource)[keyof typeof CreditBucketSource];
|
|
616
|
+
/** Credit bucket status */
|
|
617
|
+
declare const CreditBucketStatus: {
|
|
618
|
+
readonly Pending: "pending";
|
|
619
|
+
readonly Active: "active";
|
|
620
|
+
readonly Expired: "expired";
|
|
621
|
+
readonly Consumed: "consumed";
|
|
622
|
+
};
|
|
623
|
+
type CreditBucketStatusType = (typeof CreditBucketStatus)[keyof typeof CreditBucketStatus];
|
|
624
|
+
/** Credit transaction type */
|
|
625
|
+
declare const CreditTransactionType: {
|
|
626
|
+
readonly PlanGrant: "plan_grant";
|
|
627
|
+
readonly PackPurchased: "pack_purchased";
|
|
628
|
+
readonly Consumed: "consumed";
|
|
629
|
+
readonly Expired: "expired";
|
|
630
|
+
readonly AdminGrant: "admin_grant";
|
|
631
|
+
readonly AdminRevoke: "admin_revoke";
|
|
632
|
+
readonly Refund: "refund";
|
|
633
|
+
};
|
|
634
|
+
type CreditTransactionTypeValue = (typeof CreditTransactionType)[keyof typeof CreditTransactionType];
|
|
635
|
+
/** Credit balance for a workspace */
|
|
636
|
+
interface ICreditBalance {
|
|
637
|
+
available: number;
|
|
638
|
+
totalGranted: number;
|
|
639
|
+
totalConsumed: number;
|
|
640
|
+
totalExpired: number;
|
|
641
|
+
totalRefunded: number;
|
|
642
|
+
}
|
|
643
|
+
/** Pricing variant for a credit package */
|
|
644
|
+
interface ICreditPackagePricingVariant {
|
|
645
|
+
currency: string;
|
|
646
|
+
/** Price in smallest currency unit (cents) */
|
|
647
|
+
amount: number;
|
|
648
|
+
stripePriceId?: string;
|
|
649
|
+
}
|
|
650
|
+
/** Admin-defined purchasable credit package */
|
|
651
|
+
interface ICreditPackage extends IDocument {
|
|
652
|
+
name: string;
|
|
653
|
+
slug: string;
|
|
654
|
+
description?: string;
|
|
655
|
+
creditAmount: number;
|
|
656
|
+
pricingVariants: ICreditPackagePricingVariant[];
|
|
657
|
+
validityDays?: number;
|
|
658
|
+
isActive: boolean;
|
|
659
|
+
sortOrder: number;
|
|
660
|
+
archived: boolean;
|
|
661
|
+
}
|
|
662
|
+
/** A single credit transaction (user-facing event history) */
|
|
663
|
+
interface ICreditTransaction extends IDocument {
|
|
664
|
+
workspace: string;
|
|
665
|
+
type: CreditTransactionTypeValue;
|
|
666
|
+
/** Positive for grants, negative for consume/expire/revoke */
|
|
667
|
+
amount: number;
|
|
668
|
+
balanceAfter: number;
|
|
669
|
+
description?: string;
|
|
670
|
+
bucket?: string;
|
|
671
|
+
creditPackage?: string;
|
|
672
|
+
actor?: string;
|
|
673
|
+
metadata?: Record<string, any>;
|
|
674
|
+
}
|
|
675
|
+
/** A credit bucket (per-grant allocation with expiry) */
|
|
676
|
+
interface ICreditBucket extends IDocument {
|
|
677
|
+
workspace: string;
|
|
678
|
+
source: CreditBucketSourceType;
|
|
679
|
+
status: CreditBucketStatusType;
|
|
680
|
+
creditAmount: number;
|
|
681
|
+
remaining: number;
|
|
682
|
+
expiresAt?: string;
|
|
683
|
+
activatedAt?: string;
|
|
684
|
+
creditPackage?: string | ICreditPackage;
|
|
685
|
+
grantedBy?: string;
|
|
686
|
+
metadata?: Record<string, any>;
|
|
687
|
+
}
|
|
688
|
+
/** Request body for POST .../credits/consume */
|
|
689
|
+
interface IConsumeCreditsRequest {
|
|
690
|
+
amount: number;
|
|
691
|
+
description?: string;
|
|
692
|
+
idempotencyKey?: string;
|
|
693
|
+
metadata?: Record<string, any>;
|
|
694
|
+
}
|
|
695
|
+
/** Response from POST .../credits/consume */
|
|
696
|
+
interface IConsumeCreditsResponse {
|
|
697
|
+
success: boolean;
|
|
698
|
+
consumed: number;
|
|
699
|
+
balanceAfter: number;
|
|
700
|
+
}
|
|
701
|
+
/** Request body for POST .../credits/purchase */
|
|
702
|
+
interface ICreditPurchaseRequest {
|
|
703
|
+
creditPackageId: string;
|
|
704
|
+
currency?: string;
|
|
705
|
+
successUrl: string;
|
|
706
|
+
cancelUrl: string;
|
|
707
|
+
}
|
|
708
|
+
/** Response from POST .../credits/purchase */
|
|
709
|
+
interface ICreditPurchaseResponse {
|
|
710
|
+
sessionId: string;
|
|
711
|
+
url: string;
|
|
712
|
+
}
|
|
713
|
+
/** Query params for GET .../credits/transactions */
|
|
714
|
+
interface ICreditTransactionsQuery {
|
|
715
|
+
type?: CreditTransactionTypeValue;
|
|
716
|
+
page?: number;
|
|
717
|
+
limit?: number;
|
|
718
|
+
}
|
|
719
|
+
/** Paginated response from GET .../credits/transactions */
|
|
720
|
+
interface ICreditTransactionsResponse {
|
|
721
|
+
docs: ICreditTransaction[];
|
|
722
|
+
totalDocs: number;
|
|
723
|
+
limit: number;
|
|
724
|
+
page: number;
|
|
725
|
+
totalPages: number;
|
|
726
|
+
hasNextPage: boolean;
|
|
727
|
+
hasPrevPage: boolean;
|
|
728
|
+
}
|
|
729
|
+
/** Query params for GET .../credits/buckets */
|
|
730
|
+
interface ICreditBucketsQuery {
|
|
731
|
+
status?: CreditBucketStatusType;
|
|
732
|
+
source?: CreditBucketSourceType;
|
|
733
|
+
page?: number;
|
|
734
|
+
limit?: number;
|
|
735
|
+
}
|
|
736
|
+
/** Paginated response from GET .../credits/buckets */
|
|
737
|
+
interface ICreditBucketsResponse {
|
|
738
|
+
docs: ICreditBucket[];
|
|
739
|
+
totalDocs: number;
|
|
740
|
+
limit: number;
|
|
741
|
+
page: number;
|
|
742
|
+
totalPages: number;
|
|
743
|
+
hasNextPage: boolean;
|
|
744
|
+
hasPrevPage: boolean;
|
|
745
|
+
}
|
|
746
|
+
/** Response from GET .../credits/expiring */
|
|
747
|
+
interface IExpiringCreditsResponse {
|
|
748
|
+
days: number;
|
|
749
|
+
expiringCredits: number;
|
|
750
|
+
buckets: ICreditBucket[];
|
|
751
|
+
}
|
|
752
|
+
/** Public credit package (from public endpoint, no auth) */
|
|
753
|
+
interface IPublicCreditPackage {
|
|
754
|
+
_id: string;
|
|
755
|
+
name: string;
|
|
756
|
+
slug: string;
|
|
757
|
+
description: string;
|
|
758
|
+
creditAmount: number;
|
|
759
|
+
pricingVariants: ICreditPackagePricingVariant[];
|
|
760
|
+
validityDays: number | null;
|
|
761
|
+
sortOrder: number;
|
|
762
|
+
}
|
|
763
|
+
/** Response from GET /:orgId/credit-packages (public, no auth) */
|
|
764
|
+
interface IPublicCreditPackagesResponse {
|
|
765
|
+
packages: IPublicCreditPackage[];
|
|
766
|
+
notes?: string;
|
|
767
|
+
}
|
|
579
768
|
|
|
580
769
|
interface IWorkspace {
|
|
581
770
|
_id: string;
|
|
@@ -868,6 +1057,8 @@ interface IBaseApiConfig {
|
|
|
868
1057
|
method: string;
|
|
869
1058
|
path: string;
|
|
870
1059
|
}) => void;
|
|
1060
|
+
/** Called when any request receives a 401 response (session expired mid-use). */
|
|
1061
|
+
onUnauthorized?: () => void;
|
|
871
1062
|
/** Custom fetch implementation. */
|
|
872
1063
|
fetch?: typeof globalThis.fetch;
|
|
873
1064
|
}
|
|
@@ -891,6 +1082,7 @@ declare abstract class BaseApi {
|
|
|
891
1082
|
private readonly _debug;
|
|
892
1083
|
private readonly _customHeaders;
|
|
893
1084
|
private readonly _onError?;
|
|
1085
|
+
private readonly _onUnauthorized?;
|
|
894
1086
|
private readonly _fetch;
|
|
895
1087
|
constructor(config: IBaseApiConfig);
|
|
896
1088
|
/** Throws if config is not ready for API calls. Called automatically by fetchJson/fetchResponse. */
|
|
@@ -919,6 +1111,16 @@ declare abstract class BaseApi {
|
|
|
919
1111
|
* Caller is responsible for checking response.ok and parsing body.
|
|
920
1112
|
*/
|
|
921
1113
|
protected fetchResponse(path: string, init?: RequestInit): Promise<Response>;
|
|
1114
|
+
/**
|
|
1115
|
+
* Throw an error from a failed response.
|
|
1116
|
+
* Tries to parse JSON error body; falls back to status-based message.
|
|
1117
|
+
*/
|
|
1118
|
+
protected throwResponseError(response: Response, defaultMsg: string): Promise<never>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Parse JSON and unwrap `{ success, data }` envelope if present.
|
|
1121
|
+
* Throws if `success` is explicitly `false`.
|
|
1122
|
+
*/
|
|
1123
|
+
protected unwrapResponse<T>(response: Response, defaultMsg: string): Promise<T>;
|
|
922
1124
|
}
|
|
923
1125
|
|
|
924
1126
|
/**
|
|
@@ -947,7 +1149,8 @@ declare class AuthApi extends BaseApi {
|
|
|
947
1149
|
});
|
|
948
1150
|
/**
|
|
949
1151
|
* Initiate OAuth sign-in flow. Returns redirect URL to the auth provider.
|
|
950
|
-
* Uses /api/v1/auth/request
|
|
1152
|
+
* Uses /api/v1/auth/request — auth endpoints sit outside the /public basePath,
|
|
1153
|
+
* so we build the URL directly instead of using fetchResponse.
|
|
951
1154
|
*/
|
|
952
1155
|
requestAuth(params: AuthRequestParams): Promise<AuthRequestResponse>;
|
|
953
1156
|
/** Fetch user profile with the given session ID (used after OAuth redirect or from storage). */
|
|
@@ -1127,6 +1330,7 @@ interface NotificationEvent {
|
|
|
1127
1330
|
declare class WorkspaceApi extends BaseApi {
|
|
1128
1331
|
constructor(config: IOsConfig & {
|
|
1129
1332
|
sessionId?: string;
|
|
1333
|
+
onUnauthorized?: () => void;
|
|
1130
1334
|
});
|
|
1131
1335
|
getWorkspaces(): Promise<IWorkspace[]>;
|
|
1132
1336
|
createWorkspace(data: {
|
|
@@ -1202,6 +1406,14 @@ declare class WorkspaceApi extends BaseApi {
|
|
|
1202
1406
|
* @returns Plan group versions response with currentVersion and availableVersions
|
|
1203
1407
|
*/
|
|
1204
1408
|
getPublicPlans(slug: string): Promise<IPublicPlansResponse>;
|
|
1409
|
+
/**
|
|
1410
|
+
* Get credit packages (public, no auth required).
|
|
1411
|
+
* Returns active credit packages for the org with pricing info.
|
|
1412
|
+
* Use this for public credit store pages.
|
|
1413
|
+
*
|
|
1414
|
+
* @returns Credit packages with pricing variants
|
|
1415
|
+
*/
|
|
1416
|
+
getPublicCreditPackages(): Promise<IPublicCreditPackagesResponse>;
|
|
1205
1417
|
/**
|
|
1206
1418
|
* Get plan group version details by ID (public, no auth required).
|
|
1207
1419
|
* Returns the full plan group version with populated plan versions.
|
|
@@ -1361,6 +1573,56 @@ declare class WorkspaceApi extends BaseApi {
|
|
|
1361
1573
|
email?: boolean;
|
|
1362
1574
|
push?: boolean;
|
|
1363
1575
|
}>>;
|
|
1576
|
+
/**
|
|
1577
|
+
* Get credit balance for a workspace.
|
|
1578
|
+
* @param workspaceId - The workspace ID
|
|
1579
|
+
* @returns Credit balance with available, totalGranted, totalConsumed, totalExpired, totalRefunded
|
|
1580
|
+
*/
|
|
1581
|
+
getCreditBalance(workspaceId: string): Promise<ICreditBalance>;
|
|
1582
|
+
/**
|
|
1583
|
+
* Consume credits from a workspace balance.
|
|
1584
|
+
* Throws an error with `code: 'INSUFFICIENT_CREDITS'` and `available`/`requested` fields on 402.
|
|
1585
|
+
* @param workspaceId - The workspace ID
|
|
1586
|
+
* @param request - Consume request with amount, optional description, idempotencyKey, metadata
|
|
1587
|
+
* @returns Consume result with consumed amount and balanceAfter
|
|
1588
|
+
*/
|
|
1589
|
+
consumeCredits(workspaceId: string, request: IConsumeCreditsRequest): Promise<IConsumeCreditsResponse>;
|
|
1590
|
+
/**
|
|
1591
|
+
* Create a Stripe checkout session for purchasing a credit package.
|
|
1592
|
+
* Returns a checkout URL to redirect the user to.
|
|
1593
|
+
* @param workspaceId - The workspace ID
|
|
1594
|
+
* @param request - Purchase request with creditPackageId, successUrl, cancelUrl, optional currency
|
|
1595
|
+
* @returns Checkout session ID and URL
|
|
1596
|
+
*/
|
|
1597
|
+
purchaseCredits(workspaceId: string, request: ICreditPurchaseRequest): Promise<ICreditPurchaseResponse>;
|
|
1598
|
+
/**
|
|
1599
|
+
* List available credit packages for purchase.
|
|
1600
|
+
* Returns active, non-archived packages sorted by sortOrder then creditAmount.
|
|
1601
|
+
* @param workspaceId - The workspace ID
|
|
1602
|
+
* @returns Array of credit packages
|
|
1603
|
+
*/
|
|
1604
|
+
getCreditPackages(workspaceId: string): Promise<ICreditPackage[]>;
|
|
1605
|
+
/**
|
|
1606
|
+
* Get paginated credit transaction history.
|
|
1607
|
+
* @param workspaceId - The workspace ID
|
|
1608
|
+
* @param query - Optional filters: type, page, limit
|
|
1609
|
+
* @returns Paginated credit transactions
|
|
1610
|
+
*/
|
|
1611
|
+
getCreditTransactions(workspaceId: string, query?: ICreditTransactionsQuery): Promise<ICreditTransactionsResponse>;
|
|
1612
|
+
/**
|
|
1613
|
+
* Get paginated credit buckets.
|
|
1614
|
+
* @param workspaceId - The workspace ID
|
|
1615
|
+
* @param query - Optional filters: status, source, page, limit
|
|
1616
|
+
* @returns Paginated credit buckets
|
|
1617
|
+
*/
|
|
1618
|
+
getCreditBuckets(workspaceId: string, query?: ICreditBucketsQuery): Promise<ICreditBucketsResponse>;
|
|
1619
|
+
/**
|
|
1620
|
+
* Get credits expiring within N days.
|
|
1621
|
+
* @param workspaceId - The workspace ID
|
|
1622
|
+
* @param days - Look-ahead window in days (1-90, default 7)
|
|
1623
|
+
* @returns Expiring credits summary with bucket list
|
|
1624
|
+
*/
|
|
1625
|
+
getExpiringCredits(workspaceId: string, days?: number): Promise<IExpiringCreditsResponse>;
|
|
1364
1626
|
}
|
|
1365
1627
|
|
|
1366
1628
|
/**
|
|
@@ -1442,17 +1704,11 @@ declare class EventEmitter {
|
|
|
1442
1704
|
}
|
|
1443
1705
|
declare const eventEmitter: EventEmitter;
|
|
1444
1706
|
|
|
1445
|
-
|
|
1446
|
-
* Notify all subscribers to refetch quota usage (e.g. after recording usage).
|
|
1447
|
-
* Called internally by useRecordUsage on success.
|
|
1448
|
-
*/
|
|
1449
|
-
declare function invalidateQuotaUsage(): void;
|
|
1707
|
+
declare const invalidateCreditBalance: () => void;
|
|
1450
1708
|
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
*/
|
|
1455
|
-
declare function invalidateSubscription(): void;
|
|
1709
|
+
declare const invalidateQuotaUsage: () => void;
|
|
1710
|
+
|
|
1711
|
+
declare const invalidateSubscription: () => void;
|
|
1456
1712
|
|
|
1457
1713
|
/**
|
|
1458
1714
|
* BuildBase URL parameter utilities.
|
|
@@ -1486,6 +1742,37 @@ declare function invalidateSubscription(): void;
|
|
|
1486
1742
|
*/
|
|
1487
1743
|
/** The single URL param name used by the SDK */
|
|
1488
1744
|
declare const BB_PARAM = "bb";
|
|
1745
|
+
/** BB param action values */
|
|
1746
|
+
declare const BBAction: {
|
|
1747
|
+
readonly Checkout: "checkout";
|
|
1748
|
+
readonly Billing: "billing";
|
|
1749
|
+
readonly SelectPlan: "selectPlan";
|
|
1750
|
+
readonly CreditPurchase: "creditPurchase";
|
|
1751
|
+
readonly OpenCreditStore: "openCreditStore";
|
|
1752
|
+
readonly Invite: "invite";
|
|
1753
|
+
};
|
|
1754
|
+
type BBActionType = (typeof BBAction)[keyof typeof BBAction];
|
|
1755
|
+
/** BB param status values */
|
|
1756
|
+
declare const BBStatus: {
|
|
1757
|
+
readonly Success: "success";
|
|
1758
|
+
readonly Cancel: "cancel";
|
|
1759
|
+
readonly Error: "error";
|
|
1760
|
+
};
|
|
1761
|
+
type BBStatusType = (typeof BBStatus)[keyof typeof BBStatus];
|
|
1762
|
+
/** BB param screen values (mirrors SettingsScreen but avoids cross-layer import) */
|
|
1763
|
+
declare const BBScreen: {
|
|
1764
|
+
readonly Subscription: "subscription";
|
|
1765
|
+
readonly Credits: "credits";
|
|
1766
|
+
readonly Usage: "usage";
|
|
1767
|
+
readonly Users: "users";
|
|
1768
|
+
readonly Profile: "profile";
|
|
1769
|
+
readonly General: "general";
|
|
1770
|
+
readonly Features: "features";
|
|
1771
|
+
readonly Notifications: "notifications";
|
|
1772
|
+
readonly Permissions: "permissions";
|
|
1773
|
+
readonly Danger: "danger";
|
|
1774
|
+
};
|
|
1775
|
+
type BBScreenType = (typeof BBScreen)[keyof typeof BBScreen];
|
|
1489
1776
|
/**
|
|
1490
1777
|
* Build a URL with BuildBase params.
|
|
1491
1778
|
*
|
|
@@ -1513,6 +1800,14 @@ declare function createCheckoutRedirectUrls(workspaceId: string, baseUrl?: strin
|
|
|
1513
1800
|
successUrl: string;
|
|
1514
1801
|
cancelUrl: string;
|
|
1515
1802
|
};
|
|
1803
|
+
/**
|
|
1804
|
+
* Build success + cancel URL pair for credit purchase checkout redirects.
|
|
1805
|
+
* Both include the workspace ID and screen:credits.
|
|
1806
|
+
*/
|
|
1807
|
+
declare function createCreditPurchaseRedirectUrls(workspaceId: string, baseUrl?: string): {
|
|
1808
|
+
successUrl: string;
|
|
1809
|
+
cancelUrl: string;
|
|
1810
|
+
};
|
|
1516
1811
|
/**
|
|
1517
1812
|
* Read the `bb` param from the current URL.
|
|
1518
1813
|
* Returns null if no `bb` param is present.
|
|
@@ -1874,7 +2169,7 @@ declare function hasPermission(permission: string | string[], ctx: PermissionCon
|
|
|
1874
2169
|
*
|
|
1875
2170
|
* Or manually create `public/push-sw.js` with this content.
|
|
1876
2171
|
*/
|
|
1877
|
-
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
|
|
2172
|
+
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 const payload = event.data.json();\n const title = payload.title || 'Notification';\n const 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 const 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 (let i = 0; i < clientList.length; i++) {\n const 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";
|
|
1878
2173
|
|
|
1879
2174
|
interface BetaFormData {
|
|
1880
2175
|
name?: string;
|
|
@@ -2170,6 +2465,24 @@ interface NotificationActions {
|
|
|
2170
2465
|
*/
|
|
2171
2466
|
send(workspaceId: string, event: string, userId?: string, data?: NotificationData): Promise<NotificationResult>;
|
|
2172
2467
|
}
|
|
2468
|
+
interface CreditActions {
|
|
2469
|
+
/** Get workspace credit balance */
|
|
2470
|
+
getBalance(workspaceId: string): Promise<ICreditBalance>;
|
|
2471
|
+
/** Consume credits from workspace. Throws with code 'INSUFFICIENT_CREDITS' on 402. */
|
|
2472
|
+
consume(workspaceId: string, request: IConsumeCreditsRequest): Promise<IConsumeCreditsResponse>;
|
|
2473
|
+
/** Create Stripe checkout session for purchasing a credit package */
|
|
2474
|
+
purchase(workspaceId: string, request: ICreditPurchaseRequest): Promise<ICreditPurchaseResponse>;
|
|
2475
|
+
/** List available credit packages for purchase */
|
|
2476
|
+
getPackages(workspaceId: string): Promise<ICreditPackage[]>;
|
|
2477
|
+
/** Get paginated credit transaction history */
|
|
2478
|
+
getTransactions(workspaceId: string, query?: ICreditTransactionsQuery): Promise<ICreditTransactionsResponse>;
|
|
2479
|
+
/** Get paginated credit buckets */
|
|
2480
|
+
getBuckets(workspaceId: string, query?: ICreditBucketsQuery): Promise<ICreditBucketsResponse>;
|
|
2481
|
+
/** Get credits expiring within N days (default 7) */
|
|
2482
|
+
getExpiring(workspaceId: string, days?: number): Promise<IExpiringCreditsResponse>;
|
|
2483
|
+
/** Get credit packages publicly (no auth required) */
|
|
2484
|
+
getPublicPackages(): Promise<IPublicCreditPackagesResponse>;
|
|
2485
|
+
}
|
|
2173
2486
|
/** All action modules bound to a specific session. Returned by `withSession()`. */
|
|
2174
2487
|
interface ScopedActions {
|
|
2175
2488
|
workspace: WorkspaceActions;
|
|
@@ -2182,6 +2495,7 @@ interface ScopedActions {
|
|
|
2182
2495
|
features: FeatureActions;
|
|
2183
2496
|
permissions: PermissionActions;
|
|
2184
2497
|
notification: NotificationActions;
|
|
2498
|
+
credits: CreditActions;
|
|
2185
2499
|
}
|
|
2186
2500
|
interface BuildBaseResult extends ScopedActions {
|
|
2187
2501
|
/**
|
|
@@ -2230,5 +2544,5 @@ interface BuildBaseResult extends ScopedActions {
|
|
|
2230
2544
|
}
|
|
2231
2545
|
declare function BuildBase(config: BuildBaseConfig): BuildBaseResult;
|
|
2232
2546
|
|
|
2233
|
-
export { ApiVersion, AuthApi, AuthStatus, BB_PARAM, BaseApi, BetaForm, BillingIntervals, BuildBase, CURRENCY_DISPLAY, CURRENCY_FLAG, DEFAULT_ROLE_PERMISSIONS, DunningState, EventEmitter, InvoiceStatuses, PLAN_CURRENCY_CODES, PLAN_CURRENCY_OPTIONS, PUSH_SERVICE_WORKER_SCRIPT, Permission, PushApi, SDKEvent, SettingsApi, SubscriptionItemType, SubscriptionStatus, UserApi, WorkspaceApi, calculateBillableSeats, calculateSeatOverageCents, calculateTotalSubscriptionCents, cleanBBParams, clearAuthIntent, consumeAuthIntent, createBBUrl, createCheckoutRedirectUrls, BuildBase as default, eventEmitter, formatCents, formatOverageRate, formatOverageRateWithLabel, formatQuotaIncludedOverage, formatQuotaWithPrice, getAvailableCurrenciesFromPlans, getBasePriceCents, getBillingIntervalAndCurrencyFromPriceId, getCurrencyFlag, getCurrencySymbol, getDisplayCurrency, getPerSeatPriceCents, getPricingVariant, getQuotaDisplayValue, getQuotaDisplayWithVariant, getQuotaOverageCents, getQuotaUnitLabelFromName, getSeatPricing, getStripePriceIdForInterval, hasPermission, invalidateQuotaUsage, invalidateSubscription, parseWebhookEvent, readBBParams, resolveMaxUsers, resolvePermissions, safeRedirect, saveAuthIntent, validateInvite, validateRedirectUrl, verifyWebhookSignature };
|
|
2234
|
-
export type { BetaFormData, BetaFormResponse, BillingInterval, BuildBaseConfig, BuildBaseResult, BuildBaseSession, CheckoutResult, EventData, EventType, FeatureActions, FormatQuotaWithPriceOptions, GetCheckoutStripeParams, IAllQuotaUsageResponse, IBaseApiConfig, IBasePricing, IBetaConfig, ICheckoutSessionRequest, ICheckoutSessionResponse, ICheckoutStripeOptions, IEventCallbacks, IInvoice, IInvoiceListResponse, IInvoiceResponse, IOsConfig, IOsState, 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, InvoiceActions, InvoiceStatus, MaxUsersConfig, NotificationData, NotificationEvent, NotificationResult, OnWorkspaceChangeParams, PermissionActions, PermissionContext, PermissionKey, PlanActions, PlanVersionWithPricingVariants, QuotaDisplayValue, QuotaDisplayWithOverage, RolePermissionMap, ScopedActions, SettingsActions, SubscriptionActions, SubscriptionStatusType, UsageActions, UserActions, UserCreatedEventData, UserUpdatedEventData, WorkspaceActions, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };
|
|
2547
|
+
export { ApiVersion, AuthApi, AuthStatus, BBAction, BBScreen, BBStatus, BB_PARAM, BaseApi, BetaForm, BillingIntervals, BuildBase, CURRENCY_DISPLAY, CURRENCY_FLAG, CreditBucketSource, CreditBucketStatus, CreditTransactionType, DEFAULT_ROLE_PERMISSIONS, DunningState, EventEmitter, InvoiceStatuses, PLAN_CURRENCY_CODES, PLAN_CURRENCY_OPTIONS, PUSH_SERVICE_WORKER_SCRIPT, Permission, PushApi, SDKEvent, SettingsApi, SubscriptionItemType, SubscriptionStatus, UserApi, WorkspaceApi, calculateBillableSeats, calculateSeatOverageCents, calculateTotalSubscriptionCents, cleanBBParams, clearAuthIntent, consumeAuthIntent, createBBUrl, createCheckoutRedirectUrls, createCreditPurchaseRedirectUrls, BuildBase as default, eventEmitter, formatCents, formatOverageRate, formatOverageRateWithLabel, formatQuotaIncludedOverage, formatQuotaWithPrice, getAvailableCurrenciesFromPlans, getBasePriceCents, getBillingIntervalAndCurrencyFromPriceId, getCurrencyFlag, getCurrencySymbol, getDisplayCurrency, getPerSeatPriceCents, getPricingVariant, getQuotaDisplayValue, getQuotaDisplayWithVariant, getQuotaOverageCents, getQuotaUnitLabelFromName, getSeatPricing, getStripePriceIdForInterval, hasPermission, invalidateCreditBalance, invalidateQuotaUsage, invalidateSubscription, parseWebhookEvent, readBBParams, resolveMaxUsers, resolvePermissions, safeRedirect, saveAuthIntent, validateInvite, validateRedirectUrl, verifyWebhookSignature };
|
|
2548
|
+
export type { BBActionType, BBScreenType, BBStatusType, BetaFormData, BetaFormResponse, BillingInterval, BuildBaseConfig, BuildBaseResult, BuildBaseSession, CheckoutResult, CreditActions, CreditBucketSourceType, CreditBucketStatusType, CreditTransactionTypeValue, DunningStateType, EventData, EventType, FeatureActions, FormatQuotaWithPriceOptions, GetCheckoutStripeParams, IAllQuotaUsageResponse, IBaseApiConfig, IBasePricing, IBetaConfig, ICheckoutSessionRequest, ICheckoutSessionResponse, ICheckoutStripeOptions, IConsumeCreditsRequest, IConsumeCreditsResponse, ICreditBalance, ICreditBucket, ICreditBucketsQuery, ICreditBucketsResponse, ICreditPackage, ICreditPackagePricingVariant, ICreditPurchaseRequest, ICreditPurchaseResponse, ICreditTransaction, ICreditTransactionsQuery, ICreditTransactionsResponse, IEventCallbacks, IExpiringCreditsResponse, IInvoice, IInvoiceListResponse, IInvoiceResponse, IOsConfig, IOsState, IPlan, IPlanGroup, IPlanGroupInfo, IPlanGroupLatestVersion, IPlanGroupResponse, IPlanGroupVersion, IPlanGroupVersionWithPlans, IPlanGroupVersionsResponse, IPlanVersion, IPlanVersionSummary, IPlanVersionWithPlan, IPricingVariant, IPublicCreditPackage, IPublicCreditPackagesResponse, IPublicPlanItem, IPublicPlanItemCategory, IPublicPlanVersion, IPublicPlansResponse, IQuotaByInterval, IQuotaIntervalValue, IQuotaOveragePriceIdsByInterval, IQuotaOveragesByInterval, IQuotaUsageStatus, IQuotaUsageStatusResponse, IRecordUsageRequest, IRecordUsageResponse, IStripePricesByInterval, ISubscription, ISubscriptionItem, ISubscriptionResponse, ISubscriptionUpdateRequest, ISubscriptionUpdateResponse, IUsageLogEntry, IUsageLogsQuery, IUsageLogsResponse, InviteBlockReason, InviteValidation, InvoiceActions, InvoiceStatus, InvoiceStatusType, MaxUsersConfig, NotificationData, NotificationEvent, NotificationResult, OnWorkspaceChangeParams, PermissionActions, PermissionContext, PermissionKey, PlanActions, PlanVersionWithPricingVariants, QuotaDisplayValue, QuotaDisplayWithOverage, RolePermissionMap, ScopedActions, SettingsActions, SubscriptionActions, SubscriptionItemTypeValue, SubscriptionStatusType, UsageActions, UserActions, UserCreatedEventData, UserUpdatedEventData, WorkspaceActions, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };
|