@buildbase/sdk 0.0.44 → 0.0.45
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/css/styles.css +1 -1
- package/dist/index.d.ts +313 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/react/index.d.ts +908 -2
- package/dist/react/index.js +5 -5
- package/dist/react/index.mjs +5 -5
- package/package.json +1 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -79,12 +79,14 @@ declare const InvoiceStatuses: {
|
|
|
79
79
|
readonly Uncollectible: "uncollectible";
|
|
80
80
|
readonly Void: "void";
|
|
81
81
|
};
|
|
82
|
+
type InvoiceStatusType = (typeof InvoiceStatuses)[keyof typeof InvoiceStatuses];
|
|
82
83
|
/** Subscription item type constants */
|
|
83
84
|
declare const SubscriptionItemType: {
|
|
84
85
|
readonly Feature: "feature";
|
|
85
86
|
readonly Limit: "limit";
|
|
86
87
|
readonly Quota: "quota";
|
|
87
88
|
};
|
|
89
|
+
type SubscriptionItemTypeValue = (typeof SubscriptionItemType)[keyof typeof SubscriptionItemType];
|
|
88
90
|
/** Dunning state constants */
|
|
89
91
|
declare const DunningState: {
|
|
90
92
|
readonly None: "none";
|
|
@@ -93,11 +95,14 @@ declare const DunningState: {
|
|
|
93
95
|
readonly Final: "final";
|
|
94
96
|
readonly Suspended: "suspended";
|
|
95
97
|
};
|
|
98
|
+
type DunningStateType = (typeof DunningState)[keyof typeof DunningState];
|
|
96
99
|
interface ISubscription {
|
|
97
100
|
_id: string;
|
|
98
101
|
subscriptionStatus: SubscriptionStatusType;
|
|
99
102
|
stripePriceId?: string;
|
|
100
103
|
stripeCurrentPeriodEnd?: string;
|
|
104
|
+
/** When the current monthly usage period ends (quotas reset on this date). */
|
|
105
|
+
usageCurrentPeriodEnd?: string;
|
|
101
106
|
cancelAtPeriodEnd: boolean;
|
|
102
107
|
billingInterval?: BillingInterval;
|
|
103
108
|
/** Trial start date (ISO string). Set when subscription is in trial. */
|
|
@@ -217,6 +222,21 @@ interface IPlanVersion {
|
|
|
217
222
|
durationDays: number;
|
|
218
223
|
requireCard: boolean;
|
|
219
224
|
};
|
|
225
|
+
/** Credit grant configuration. When enabled, credits are granted to workspaces on this plan. */
|
|
226
|
+
creditGrant?: {
|
|
227
|
+
enabled: boolean;
|
|
228
|
+
/** Linked credit package (populated with name, slug, creditAmount). */
|
|
229
|
+
creditPackage?: {
|
|
230
|
+
_id: string;
|
|
231
|
+
name: string;
|
|
232
|
+
slug: string;
|
|
233
|
+
creditAmount: number;
|
|
234
|
+
} | string;
|
|
235
|
+
/** How unused plan credits are handled on renewal: 'reset' = expire old, 'topup' = add to existing. */
|
|
236
|
+
mode: 'reset' | 'topup';
|
|
237
|
+
/** true = credits given fresh every month, false = one-time lifetime grant (default). */
|
|
238
|
+
renewOnPeriod?: boolean;
|
|
239
|
+
};
|
|
220
240
|
isCurrent?: boolean;
|
|
221
241
|
isLegacy?: boolean;
|
|
222
242
|
archived?: boolean;
|
|
@@ -485,6 +505,15 @@ interface IPublicPlanVersion {
|
|
|
485
505
|
durationDays: number;
|
|
486
506
|
requireCard: boolean;
|
|
487
507
|
};
|
|
508
|
+
/** Credit grant config. Only present when the plan grants credits. */
|
|
509
|
+
creditGrant?: {
|
|
510
|
+
enabled: boolean;
|
|
511
|
+
creditAmount: number | null;
|
|
512
|
+
packageName: string | null;
|
|
513
|
+
mode: 'reset' | 'topup';
|
|
514
|
+
/** true = credits given fresh every month, false = one-time lifetime grant. */
|
|
515
|
+
renewOnPeriod: boolean;
|
|
516
|
+
};
|
|
488
517
|
}
|
|
489
518
|
interface IPublicPlansResponse {
|
|
490
519
|
items: IPublicPlanItem[];
|
|
@@ -580,6 +609,166 @@ interface IUsageLogsResponse {
|
|
|
580
609
|
hasNextPage: boolean;
|
|
581
610
|
hasPrevPage: boolean;
|
|
582
611
|
}
|
|
612
|
+
/** Credit bucket source (how credits entered the workspace) */
|
|
613
|
+
declare const CreditBucketSource: {
|
|
614
|
+
readonly PlanGrant: "plan_grant";
|
|
615
|
+
readonly CreditPackPurchase: "credit_pack_purchase";
|
|
616
|
+
readonly AdminGrant: "admin_grant";
|
|
617
|
+
readonly Refund: "refund";
|
|
618
|
+
};
|
|
619
|
+
type CreditBucketSourceType = (typeof CreditBucketSource)[keyof typeof CreditBucketSource];
|
|
620
|
+
/** Credit bucket status */
|
|
621
|
+
declare const CreditBucketStatus: {
|
|
622
|
+
readonly Pending: "pending";
|
|
623
|
+
readonly Active: "active";
|
|
624
|
+
readonly Expired: "expired";
|
|
625
|
+
readonly Consumed: "consumed";
|
|
626
|
+
};
|
|
627
|
+
type CreditBucketStatusType = (typeof CreditBucketStatus)[keyof typeof CreditBucketStatus];
|
|
628
|
+
/** Credit transaction type */
|
|
629
|
+
declare const CreditTransactionType: {
|
|
630
|
+
readonly PlanGrant: "plan_grant";
|
|
631
|
+
readonly PackPurchased: "pack_purchased";
|
|
632
|
+
readonly Consumed: "consumed";
|
|
633
|
+
readonly Expired: "expired";
|
|
634
|
+
readonly AdminGrant: "admin_grant";
|
|
635
|
+
readonly AdminRevoke: "admin_revoke";
|
|
636
|
+
readonly Refund: "refund";
|
|
637
|
+
};
|
|
638
|
+
type CreditTransactionTypeValue = (typeof CreditTransactionType)[keyof typeof CreditTransactionType];
|
|
639
|
+
/** Credit balance for a workspace */
|
|
640
|
+
interface ICreditBalance {
|
|
641
|
+
available: number;
|
|
642
|
+
totalGranted: number;
|
|
643
|
+
totalConsumed: number;
|
|
644
|
+
totalExpired: number;
|
|
645
|
+
totalRefunded: number;
|
|
646
|
+
}
|
|
647
|
+
/** Pricing variant for a credit package */
|
|
648
|
+
interface ICreditPackagePricingVariant {
|
|
649
|
+
currency: string;
|
|
650
|
+
/** Price in smallest currency unit (cents) */
|
|
651
|
+
amount: number;
|
|
652
|
+
stripePriceId?: string;
|
|
653
|
+
}
|
|
654
|
+
/** Admin-defined purchasable credit package */
|
|
655
|
+
interface ICreditPackage extends IDocument {
|
|
656
|
+
name: string;
|
|
657
|
+
slug: string;
|
|
658
|
+
description?: string;
|
|
659
|
+
creditAmount: number;
|
|
660
|
+
pricingVariants: ICreditPackagePricingVariant[];
|
|
661
|
+
validityDays?: number;
|
|
662
|
+
isActive: boolean;
|
|
663
|
+
sortOrder: number;
|
|
664
|
+
archived: boolean;
|
|
665
|
+
}
|
|
666
|
+
/** A single credit transaction (user-facing event history) */
|
|
667
|
+
interface ICreditTransaction extends IDocument {
|
|
668
|
+
workspace: string;
|
|
669
|
+
type: CreditTransactionTypeValue;
|
|
670
|
+
/** Positive for grants, negative for consume/expire/revoke */
|
|
671
|
+
amount: number;
|
|
672
|
+
balanceAfter: number;
|
|
673
|
+
description?: string;
|
|
674
|
+
bucket?: string;
|
|
675
|
+
creditPackage?: string;
|
|
676
|
+
actor?: string;
|
|
677
|
+
metadata?: Record<string, any>;
|
|
678
|
+
}
|
|
679
|
+
/** A credit bucket (per-grant allocation with expiry) */
|
|
680
|
+
interface ICreditBucket extends IDocument {
|
|
681
|
+
workspace: string;
|
|
682
|
+
source: CreditBucketSourceType;
|
|
683
|
+
status: CreditBucketStatusType;
|
|
684
|
+
creditAmount: number;
|
|
685
|
+
remaining: number;
|
|
686
|
+
expiresAt?: string;
|
|
687
|
+
activatedAt?: string;
|
|
688
|
+
creditPackage?: string | ICreditPackage;
|
|
689
|
+
grantedBy?: string;
|
|
690
|
+
metadata?: Record<string, any>;
|
|
691
|
+
}
|
|
692
|
+
/** Request body for POST .../credits/consume */
|
|
693
|
+
interface IConsumeCreditsRequest {
|
|
694
|
+
amount: number;
|
|
695
|
+
description?: string;
|
|
696
|
+
idempotencyKey?: string;
|
|
697
|
+
metadata?: Record<string, any>;
|
|
698
|
+
}
|
|
699
|
+
/** Response from POST .../credits/consume */
|
|
700
|
+
interface IConsumeCreditsResponse {
|
|
701
|
+
success: boolean;
|
|
702
|
+
consumed: number;
|
|
703
|
+
balanceAfter: number;
|
|
704
|
+
}
|
|
705
|
+
/** Request body for POST .../credits/purchase */
|
|
706
|
+
interface ICreditPurchaseRequest {
|
|
707
|
+
creditPackageId: string;
|
|
708
|
+
currency?: string;
|
|
709
|
+
successUrl: string;
|
|
710
|
+
cancelUrl: string;
|
|
711
|
+
}
|
|
712
|
+
/** Response from POST .../credits/purchase */
|
|
713
|
+
interface ICreditPurchaseResponse {
|
|
714
|
+
sessionId: string;
|
|
715
|
+
url: string;
|
|
716
|
+
}
|
|
717
|
+
/** Query params for GET .../credits/transactions */
|
|
718
|
+
interface ICreditTransactionsQuery {
|
|
719
|
+
type?: CreditTransactionTypeValue;
|
|
720
|
+
page?: number;
|
|
721
|
+
limit?: number;
|
|
722
|
+
}
|
|
723
|
+
/** Paginated response from GET .../credits/transactions */
|
|
724
|
+
interface ICreditTransactionsResponse {
|
|
725
|
+
docs: ICreditTransaction[];
|
|
726
|
+
totalDocs: number;
|
|
727
|
+
limit: number;
|
|
728
|
+
page: number;
|
|
729
|
+
totalPages: number;
|
|
730
|
+
hasNextPage: boolean;
|
|
731
|
+
hasPrevPage: boolean;
|
|
732
|
+
}
|
|
733
|
+
/** Query params for GET .../credits/buckets */
|
|
734
|
+
interface ICreditBucketsQuery {
|
|
735
|
+
status?: CreditBucketStatusType;
|
|
736
|
+
source?: CreditBucketSourceType;
|
|
737
|
+
page?: number;
|
|
738
|
+
limit?: number;
|
|
739
|
+
}
|
|
740
|
+
/** Paginated response from GET .../credits/buckets */
|
|
741
|
+
interface ICreditBucketsResponse {
|
|
742
|
+
docs: ICreditBucket[];
|
|
743
|
+
totalDocs: number;
|
|
744
|
+
limit: number;
|
|
745
|
+
page: number;
|
|
746
|
+
totalPages: number;
|
|
747
|
+
hasNextPage: boolean;
|
|
748
|
+
hasPrevPage: boolean;
|
|
749
|
+
}
|
|
750
|
+
/** Response from GET .../credits/expiring */
|
|
751
|
+
interface IExpiringCreditsResponse {
|
|
752
|
+
days: number;
|
|
753
|
+
expiringCredits: number;
|
|
754
|
+
buckets: ICreditBucket[];
|
|
755
|
+
}
|
|
756
|
+
/** Public credit package (from public endpoint, no auth) */
|
|
757
|
+
interface IPublicCreditPackage {
|
|
758
|
+
_id: string;
|
|
759
|
+
name: string;
|
|
760
|
+
slug: string;
|
|
761
|
+
description: string;
|
|
762
|
+
creditAmount: number;
|
|
763
|
+
pricingVariants: ICreditPackagePricingVariant[];
|
|
764
|
+
validityDays: number | null;
|
|
765
|
+
sortOrder: number;
|
|
766
|
+
}
|
|
767
|
+
/** Response from GET /:orgId/credit-packages (public, no auth) */
|
|
768
|
+
interface IPublicCreditPackagesResponse {
|
|
769
|
+
packages: IPublicCreditPackage[];
|
|
770
|
+
notes?: string;
|
|
771
|
+
}
|
|
583
772
|
|
|
584
773
|
interface IWorkspace {
|
|
585
774
|
_id: string;
|
|
@@ -1184,6 +1373,14 @@ declare class WorkspaceApi extends BaseApi {
|
|
|
1184
1373
|
* @returns Plan group versions response with currentVersion and availableVersions
|
|
1185
1374
|
*/
|
|
1186
1375
|
getPublicPlans(slug: string): Promise<IPublicPlansResponse>;
|
|
1376
|
+
/**
|
|
1377
|
+
* Get credit packages (public, no auth required).
|
|
1378
|
+
* Returns active credit packages for the org with pricing info.
|
|
1379
|
+
* Use this for public credit store pages.
|
|
1380
|
+
*
|
|
1381
|
+
* @returns Credit packages with pricing variants
|
|
1382
|
+
*/
|
|
1383
|
+
getPublicCreditPackages(): Promise<IPublicCreditPackagesResponse>;
|
|
1187
1384
|
/**
|
|
1188
1385
|
* Get plan group version details by ID (public, no auth required).
|
|
1189
1386
|
* Returns the full plan group version with populated plan versions.
|
|
@@ -1343,6 +1540,56 @@ declare class WorkspaceApi extends BaseApi {
|
|
|
1343
1540
|
email?: boolean;
|
|
1344
1541
|
push?: boolean;
|
|
1345
1542
|
}>>;
|
|
1543
|
+
/**
|
|
1544
|
+
* Get credit balance for a workspace.
|
|
1545
|
+
* @param workspaceId - The workspace ID
|
|
1546
|
+
* @returns Credit balance with available, totalGranted, totalConsumed, totalExpired, totalRefunded
|
|
1547
|
+
*/
|
|
1548
|
+
getCreditBalance(workspaceId: string): Promise<ICreditBalance>;
|
|
1549
|
+
/**
|
|
1550
|
+
* Consume credits from a workspace balance.
|
|
1551
|
+
* Throws an error with `code: 'INSUFFICIENT_CREDITS'` and `available`/`requested` fields on 402.
|
|
1552
|
+
* @param workspaceId - The workspace ID
|
|
1553
|
+
* @param request - Consume request with amount, optional description, idempotencyKey, metadata
|
|
1554
|
+
* @returns Consume result with consumed amount and balanceAfter
|
|
1555
|
+
*/
|
|
1556
|
+
consumeCredits(workspaceId: string, request: IConsumeCreditsRequest): Promise<IConsumeCreditsResponse>;
|
|
1557
|
+
/**
|
|
1558
|
+
* Create a Stripe checkout session for purchasing a credit package.
|
|
1559
|
+
* Returns a checkout URL to redirect the user to.
|
|
1560
|
+
* @param workspaceId - The workspace ID
|
|
1561
|
+
* @param request - Purchase request with creditPackageId, successUrl, cancelUrl, optional currency
|
|
1562
|
+
* @returns Checkout session ID and URL
|
|
1563
|
+
*/
|
|
1564
|
+
purchaseCredits(workspaceId: string, request: ICreditPurchaseRequest): Promise<ICreditPurchaseResponse>;
|
|
1565
|
+
/**
|
|
1566
|
+
* List available credit packages for purchase.
|
|
1567
|
+
* Returns active, non-archived packages sorted by sortOrder then creditAmount.
|
|
1568
|
+
* @param workspaceId - The workspace ID
|
|
1569
|
+
* @returns Array of credit packages
|
|
1570
|
+
*/
|
|
1571
|
+
getCreditPackages(workspaceId: string): Promise<ICreditPackage[]>;
|
|
1572
|
+
/**
|
|
1573
|
+
* Get paginated credit transaction history.
|
|
1574
|
+
* @param workspaceId - The workspace ID
|
|
1575
|
+
* @param query - Optional filters: type, page, limit
|
|
1576
|
+
* @returns Paginated credit transactions
|
|
1577
|
+
*/
|
|
1578
|
+
getCreditTransactions(workspaceId: string, query?: ICreditTransactionsQuery): Promise<ICreditTransactionsResponse>;
|
|
1579
|
+
/**
|
|
1580
|
+
* Get paginated credit buckets.
|
|
1581
|
+
* @param workspaceId - The workspace ID
|
|
1582
|
+
* @param query - Optional filters: status, source, page, limit
|
|
1583
|
+
* @returns Paginated credit buckets
|
|
1584
|
+
*/
|
|
1585
|
+
getCreditBuckets(workspaceId: string, query?: ICreditBucketsQuery): Promise<ICreditBucketsResponse>;
|
|
1586
|
+
/**
|
|
1587
|
+
* Get credits expiring within N days.
|
|
1588
|
+
* @param workspaceId - The workspace ID
|
|
1589
|
+
* @param days - Look-ahead window in days (1-90, default 7)
|
|
1590
|
+
* @returns Expiring credits summary with bucket list
|
|
1591
|
+
*/
|
|
1592
|
+
getExpiringCredits(workspaceId: string, days?: number): Promise<IExpiringCreditsResponse>;
|
|
1346
1593
|
}
|
|
1347
1594
|
|
|
1348
1595
|
/**
|
|
@@ -1424,6 +1671,12 @@ declare class EventEmitter {
|
|
|
1424
1671
|
}
|
|
1425
1672
|
declare const eventEmitter: EventEmitter;
|
|
1426
1673
|
|
|
1674
|
+
/**
|
|
1675
|
+
* Notify all subscribers to refetch credit balance (e.g. after consume or purchase).
|
|
1676
|
+
* Called internally by useConsumeCredits, usePurchaseCredits on success.
|
|
1677
|
+
*/
|
|
1678
|
+
declare function invalidateCreditBalance(): void;
|
|
1679
|
+
|
|
1427
1680
|
/**
|
|
1428
1681
|
* Notify all subscribers to refetch quota usage (e.g. after recording usage).
|
|
1429
1682
|
* Called internally by useRecordUsage on success.
|
|
@@ -1468,6 +1721,37 @@ declare function invalidateSubscription(): void;
|
|
|
1468
1721
|
*/
|
|
1469
1722
|
/** The single URL param name used by the SDK */
|
|
1470
1723
|
declare const BB_PARAM = "bb";
|
|
1724
|
+
/** BB param action values */
|
|
1725
|
+
declare const BBAction: {
|
|
1726
|
+
readonly Checkout: "checkout";
|
|
1727
|
+
readonly Billing: "billing";
|
|
1728
|
+
readonly SelectPlan: "selectPlan";
|
|
1729
|
+
readonly CreditPurchase: "creditPurchase";
|
|
1730
|
+
readonly OpenCreditStore: "openCreditStore";
|
|
1731
|
+
readonly Invite: "invite";
|
|
1732
|
+
};
|
|
1733
|
+
type BBActionType = (typeof BBAction)[keyof typeof BBAction];
|
|
1734
|
+
/** BB param status values */
|
|
1735
|
+
declare const BBStatus: {
|
|
1736
|
+
readonly Success: "success";
|
|
1737
|
+
readonly Cancel: "cancel";
|
|
1738
|
+
readonly Error: "error";
|
|
1739
|
+
};
|
|
1740
|
+
type BBStatusType = (typeof BBStatus)[keyof typeof BBStatus];
|
|
1741
|
+
/** BB param screen values (mirrors SettingsScreen but avoids cross-layer import) */
|
|
1742
|
+
declare const BBScreen: {
|
|
1743
|
+
readonly Subscription: "subscription";
|
|
1744
|
+
readonly Credits: "credits";
|
|
1745
|
+
readonly Usage: "usage";
|
|
1746
|
+
readonly Users: "users";
|
|
1747
|
+
readonly Profile: "profile";
|
|
1748
|
+
readonly General: "general";
|
|
1749
|
+
readonly Features: "features";
|
|
1750
|
+
readonly Notifications: "notifications";
|
|
1751
|
+
readonly Permissions: "permissions";
|
|
1752
|
+
readonly Danger: "danger";
|
|
1753
|
+
};
|
|
1754
|
+
type BBScreenType = (typeof BBScreen)[keyof typeof BBScreen];
|
|
1471
1755
|
/**
|
|
1472
1756
|
* Build a URL with BuildBase params.
|
|
1473
1757
|
*
|
|
@@ -1495,6 +1779,14 @@ declare function createCheckoutRedirectUrls(workspaceId: string, baseUrl?: strin
|
|
|
1495
1779
|
successUrl: string;
|
|
1496
1780
|
cancelUrl: string;
|
|
1497
1781
|
};
|
|
1782
|
+
/**
|
|
1783
|
+
* Build success + cancel URL pair for credit purchase checkout redirects.
|
|
1784
|
+
* Both include the workspace ID and screen:credits.
|
|
1785
|
+
*/
|
|
1786
|
+
declare function createCreditPurchaseRedirectUrls(workspaceId: string, baseUrl?: string): {
|
|
1787
|
+
successUrl: string;
|
|
1788
|
+
cancelUrl: string;
|
|
1789
|
+
};
|
|
1498
1790
|
/**
|
|
1499
1791
|
* Read the `bb` param from the current URL.
|
|
1500
1792
|
* Returns null if no `bb` param is present.
|
|
@@ -1879,6 +2171,7 @@ interface SDKMessages {
|
|
|
1879
2171
|
users: string;
|
|
1880
2172
|
subscription: string;
|
|
1881
2173
|
usage: string;
|
|
2174
|
+
credits: string;
|
|
1882
2175
|
features: string;
|
|
1883
2176
|
notifications: string;
|
|
1884
2177
|
permissions: string;
|
|
@@ -1892,6 +2185,7 @@ interface SDKMessages {
|
|
|
1892
2185
|
users: string;
|
|
1893
2186
|
subscription: string;
|
|
1894
2187
|
usage: string;
|
|
2188
|
+
credits: string;
|
|
1895
2189
|
features: string;
|
|
1896
2190
|
notifications: string;
|
|
1897
2191
|
permissions: string;
|
|
@@ -1992,6 +2286,17 @@ interface SDKMessages {
|
|
|
1992
2286
|
features: string;
|
|
1993
2287
|
limits: string;
|
|
1994
2288
|
quotas: string;
|
|
2289
|
+
credits: string;
|
|
2290
|
+
creditsPerMonth: string;
|
|
2291
|
+
creditsOneTime: string;
|
|
2292
|
+
creditRenewal: string;
|
|
2293
|
+
creditModeReset: string;
|
|
2294
|
+
creditModeTopup: string;
|
|
2295
|
+
creditModeLifetime: string;
|
|
2296
|
+
/** @deprecated */
|
|
2297
|
+
creditsPerPeriod: string;
|
|
2298
|
+
/** @deprecated */
|
|
2299
|
+
creditRollover: string;
|
|
1995
2300
|
};
|
|
1996
2301
|
checkout: {
|
|
1997
2302
|
upgrade: string;
|
|
@@ -2357,6 +2662,50 @@ interface SDKMessages {
|
|
|
2357
2662
|
saving: string;
|
|
2358
2663
|
saveSuccess: string;
|
|
2359
2664
|
};
|
|
2665
|
+
credits: {
|
|
2666
|
+
title: string;
|
|
2667
|
+
description: string;
|
|
2668
|
+
balance: string;
|
|
2669
|
+
available: string;
|
|
2670
|
+
totalGranted: string;
|
|
2671
|
+
totalConsumed: string;
|
|
2672
|
+
totalExpired: string;
|
|
2673
|
+
noCredits: string;
|
|
2674
|
+
noCreditsHint: string;
|
|
2675
|
+
buyCredits: string;
|
|
2676
|
+
buyAmount: string;
|
|
2677
|
+
purchasing: string;
|
|
2678
|
+
packages: string;
|
|
2679
|
+
noPackages: string;
|
|
2680
|
+
creditsAmount: string;
|
|
2681
|
+
validityDays: string;
|
|
2682
|
+
validityUnlimited: string;
|
|
2683
|
+
transactions: string;
|
|
2684
|
+
noTransactions: string;
|
|
2685
|
+
loadMore: string;
|
|
2686
|
+
viewAll: string;
|
|
2687
|
+
expiringSoon: string;
|
|
2688
|
+
expiringInDays: string;
|
|
2689
|
+
noExpiring: string;
|
|
2690
|
+
type: {
|
|
2691
|
+
plan_grant: string;
|
|
2692
|
+
pack_purchased: string;
|
|
2693
|
+
consumed: string;
|
|
2694
|
+
expired: string;
|
|
2695
|
+
admin_grant: string;
|
|
2696
|
+
admin_revoke: string;
|
|
2697
|
+
refund: string;
|
|
2698
|
+
};
|
|
2699
|
+
dialogTitle: string;
|
|
2700
|
+
dialogDescription: string;
|
|
2701
|
+
dialogDescriptionWorkspace: string;
|
|
2702
|
+
perCredit: string;
|
|
2703
|
+
purchaseSuccess: string;
|
|
2704
|
+
purchaseCanceled: string;
|
|
2705
|
+
purchaseFailed: string;
|
|
2706
|
+
errorLoading: string;
|
|
2707
|
+
insufficientCredits: string;
|
|
2708
|
+
};
|
|
2360
2709
|
errors: {
|
|
2361
2710
|
networkError: string;
|
|
2362
2711
|
unauthorized: string;
|
|
@@ -2378,6 +2727,12 @@ interface SDKMessages {
|
|
|
2378
2727
|
fetchQuotaUsage: string;
|
|
2379
2728
|
fetchAllQuotaUsage: string;
|
|
2380
2729
|
fetchUsageLogs: string;
|
|
2730
|
+
fetchCreditBalance: string;
|
|
2731
|
+
consumeCredits: string;
|
|
2732
|
+
purchaseCredits: string;
|
|
2733
|
+
fetchCreditPackages: string;
|
|
2734
|
+
fetchCreditTransactions: string;
|
|
2735
|
+
fetchExpiringCredits: string;
|
|
2381
2736
|
};
|
|
2382
2737
|
}
|
|
2383
2738
|
/** Supported locale codes */
|
|
@@ -2566,6 +2921,7 @@ declare const SettingsScreen: {
|
|
|
2566
2921
|
readonly Users: "users";
|
|
2567
2922
|
readonly Subscription: "subscription";
|
|
2568
2923
|
readonly Usage: "usage";
|
|
2924
|
+
readonly Credits: "credits";
|
|
2569
2925
|
readonly Features: "features";
|
|
2570
2926
|
readonly Notifications: "notifications";
|
|
2571
2927
|
readonly Permissions: "permissions";
|
|
@@ -2579,6 +2935,8 @@ declare function useSaaSAuth(): {
|
|
|
2579
2935
|
signIn: (returnUrl?: string) => Promise<void>;
|
|
2580
2936
|
signOut: () => Promise<void>;
|
|
2581
2937
|
openWorkspaceSettings: (section?: WorkspaceSettingsSection) => void;
|
|
2938
|
+
openCreditStore: () => void;
|
|
2939
|
+
openPlanPicker: () => void;
|
|
2582
2940
|
isAuthenticated: boolean;
|
|
2583
2941
|
isLoading: boolean;
|
|
2584
2942
|
isRedirecting: boolean;
|
|
@@ -3172,6 +3530,292 @@ declare const WhenQuotaThreshold: {
|
|
|
3172
3530
|
displayName: string;
|
|
3173
3531
|
};
|
|
3174
3532
|
|
|
3533
|
+
interface CreditActionsDetails {
|
|
3534
|
+
/** Current credit balance. Null while loading. */
|
|
3535
|
+
balance: ICreditBalance | null;
|
|
3536
|
+
/** Whether balance is loading. */
|
|
3537
|
+
loading: boolean;
|
|
3538
|
+
/** Available credit packages for purchase. */
|
|
3539
|
+
packages: ICreditPackage[];
|
|
3540
|
+
/** Whether packages are loading. */
|
|
3541
|
+
packagesLoading: boolean;
|
|
3542
|
+
/**
|
|
3543
|
+
* Consume credits from the workspace balance.
|
|
3544
|
+
* Throws with `code: 'INSUFFICIENT_CREDITS'` if balance is too low.
|
|
3545
|
+
*
|
|
3546
|
+
* @example
|
|
3547
|
+
* ```ts
|
|
3548
|
+
* try {
|
|
3549
|
+
* const result = await consume({ amount: 10, description: 'AI generation' });
|
|
3550
|
+
* console.log(`Balance: ${result.balanceAfter}`);
|
|
3551
|
+
* } catch (err) {
|
|
3552
|
+
* if (err.code === 'INSUFFICIENT_CREDITS') showUpgradePrompt();
|
|
3553
|
+
* }
|
|
3554
|
+
* ```
|
|
3555
|
+
*/
|
|
3556
|
+
consume: (request: IConsumeCreditsRequest) => Promise<IConsumeCreditsResponse>;
|
|
3557
|
+
/** Whether a consume operation is in progress. */
|
|
3558
|
+
consuming: boolean;
|
|
3559
|
+
/**
|
|
3560
|
+
* Purchase a credit package. Redirects to Stripe Checkout.
|
|
3561
|
+
* On success, user returns to the app with the credits screen open.
|
|
3562
|
+
*
|
|
3563
|
+
* @example
|
|
3564
|
+
* ```ts
|
|
3565
|
+
* await purchase(packages[0]); // Redirects to Stripe
|
|
3566
|
+
* ```
|
|
3567
|
+
*/
|
|
3568
|
+
purchase: (pkg: ICreditPackage) => Promise<void>;
|
|
3569
|
+
/** Whether a purchase redirect is in progress. */
|
|
3570
|
+
purchasing: boolean;
|
|
3571
|
+
/** Refetch the balance. */
|
|
3572
|
+
refetch: () => Promise<void>;
|
|
3573
|
+
/** Error from the last consume or purchase operation. */
|
|
3574
|
+
error: string | null;
|
|
3575
|
+
}
|
|
3576
|
+
interface CreditActionsProviderProps {
|
|
3577
|
+
/** Render prop receiving credit actions — build your own UI. */
|
|
3578
|
+
children: (details: CreditActionsDetails) => React.ReactNode;
|
|
3579
|
+
}
|
|
3580
|
+
/**
|
|
3581
|
+
* Provides credit balance, packages, and action functions (consume, purchase) via render prop.
|
|
3582
|
+
* Must be inside SaaSOSProvider. Handles Stripe redirect URLs automatically.
|
|
3583
|
+
*
|
|
3584
|
+
* @example
|
|
3585
|
+
* ```tsx
|
|
3586
|
+
* <CreditActionsProvider>
|
|
3587
|
+
* {({ balance, packages, consume, purchase, consuming, purchasing }) => (
|
|
3588
|
+
* <div>
|
|
3589
|
+
* <p>{balance?.available ?? 0} credits</p>
|
|
3590
|
+
*
|
|
3591
|
+
* <button onClick={() => consume({ amount: 5 })} disabled={consuming}>
|
|
3592
|
+
* Use 5 Credits
|
|
3593
|
+
* </button>
|
|
3594
|
+
*
|
|
3595
|
+
* {packages.map(pkg => (
|
|
3596
|
+
* <button key={pkg._id} onClick={() => purchase(pkg)} disabled={purchasing}>
|
|
3597
|
+
* Buy {pkg.creditAmount} for ${pkg.pricingVariants[0]?.amount / 100}
|
|
3598
|
+
* </button>
|
|
3599
|
+
* ))}
|
|
3600
|
+
* </div>
|
|
3601
|
+
* )}
|
|
3602
|
+
* </CreditActionsProvider>
|
|
3603
|
+
* ```
|
|
3604
|
+
*/
|
|
3605
|
+
declare const CreditActionsProvider: {
|
|
3606
|
+
({ children }: CreditActionsProviderProps): react.ReactNode;
|
|
3607
|
+
displayName: string;
|
|
3608
|
+
};
|
|
3609
|
+
|
|
3610
|
+
interface CreditBalanceDetails {
|
|
3611
|
+
/** Credit balance data. Null while loading or if no workspace. */
|
|
3612
|
+
balance: ICreditBalance | null;
|
|
3613
|
+
/** Whether data is being fetched. */
|
|
3614
|
+
loading: boolean;
|
|
3615
|
+
/** Error message if fetch failed. */
|
|
3616
|
+
error: string | null;
|
|
3617
|
+
/** Manually refresh the balance. */
|
|
3618
|
+
refetch: () => Promise<void>;
|
|
3619
|
+
}
|
|
3620
|
+
interface CreditBalanceProps {
|
|
3621
|
+
/** Render prop receiving balance details — build your own UI. */
|
|
3622
|
+
children: (details: CreditBalanceDetails) => React.ReactNode;
|
|
3623
|
+
}
|
|
3624
|
+
/**
|
|
3625
|
+
* Provides credit balance data for the current workspace via render prop.
|
|
3626
|
+
* Must be inside SaaSOSProvider. Balance auto-updates after consume/purchase.
|
|
3627
|
+
*
|
|
3628
|
+
* @example
|
|
3629
|
+
* ```tsx
|
|
3630
|
+
* <CreditBalance>
|
|
3631
|
+
* {({ balance, loading }) => {
|
|
3632
|
+
* if (loading) return <Skeleton />;
|
|
3633
|
+
* return <span>{balance?.available ?? 0} credits</span>;
|
|
3634
|
+
* }}
|
|
3635
|
+
* </CreditBalance>
|
|
3636
|
+
* ```
|
|
3637
|
+
*
|
|
3638
|
+
* @example
|
|
3639
|
+
* ```tsx
|
|
3640
|
+
* // Navbar credit indicator
|
|
3641
|
+
* <CreditBalance>
|
|
3642
|
+
* {({ balance, loading, refetch }) => (
|
|
3643
|
+
* <button onClick={refetch} disabled={loading}>
|
|
3644
|
+
* <CoinIcon />
|
|
3645
|
+
* {loading ? '...' : balance?.available ?? 0}
|
|
3646
|
+
* </button>
|
|
3647
|
+
* )}
|
|
3648
|
+
* </CreditBalance>
|
|
3649
|
+
* ```
|
|
3650
|
+
*/
|
|
3651
|
+
declare const CreditBalance: {
|
|
3652
|
+
({ children }: CreditBalanceProps): react.ReactNode;
|
|
3653
|
+
displayName: string;
|
|
3654
|
+
};
|
|
3655
|
+
|
|
3656
|
+
interface CreditStorePageDetails {
|
|
3657
|
+
/** Whether package data is being fetched */
|
|
3658
|
+
loading: boolean;
|
|
3659
|
+
/** Error message if fetch failed */
|
|
3660
|
+
error: string | null;
|
|
3661
|
+
/** Available credit packages with pricing */
|
|
3662
|
+
packages: IPublicCreditPackage[];
|
|
3663
|
+
/** Optional note from API (e.g. "Pricing is in cents.") */
|
|
3664
|
+
notes?: string;
|
|
3665
|
+
/** Refetch package data */
|
|
3666
|
+
refetch: () => Promise<void>;
|
|
3667
|
+
/**
|
|
3668
|
+
* Select a package to purchase. Handles everything automatically:
|
|
3669
|
+
* - If authenticated → opens the workspace settings Credits tab
|
|
3670
|
+
* - If not authenticated → saves a redirect URL and triggers sign-in
|
|
3671
|
+
*
|
|
3672
|
+
* @example
|
|
3673
|
+
* ```tsx
|
|
3674
|
+
* <button onClick={() => selectPackage(pkg._id)}>
|
|
3675
|
+
* Buy {pkg.creditAmount} Credits
|
|
3676
|
+
* </button>
|
|
3677
|
+
* ```
|
|
3678
|
+
*/
|
|
3679
|
+
selectPackage: (packageId: string) => void;
|
|
3680
|
+
}
|
|
3681
|
+
interface CreditStorePageProps {
|
|
3682
|
+
/** Render prop receiving package details — build your own credit store UI */
|
|
3683
|
+
children: (details: CreditStorePageDetails) => ReactNode;
|
|
3684
|
+
/** Custom loading UI. Defaults to skeleton. */
|
|
3685
|
+
loadingFallback?: ReactNode;
|
|
3686
|
+
/** Custom error UI. Receives error message. */
|
|
3687
|
+
errorFallback?: (error: string) => ReactNode;
|
|
3688
|
+
/**
|
|
3689
|
+
* Base URL for post-login redirects (e.g. `"https://app.com/dashboard"`).
|
|
3690
|
+
* When set, `selectPackage()` can redirect unauthenticated users through login
|
|
3691
|
+
* and back to the dashboard with the credits screen open.
|
|
3692
|
+
*/
|
|
3693
|
+
redirectBaseUrl?: string;
|
|
3694
|
+
}
|
|
3695
|
+
/**
|
|
3696
|
+
* Fetches and provides credit package details for public credit store pages (no login required).
|
|
3697
|
+
* Returns packages with pricing — the consumer constructs the layout.
|
|
3698
|
+
* Similar to `<PricingPage>` but for credit packages.
|
|
3699
|
+
*
|
|
3700
|
+
* @example
|
|
3701
|
+
* ```tsx
|
|
3702
|
+
* <CreditStorePage redirectBaseUrl="https://app.com/dashboard">
|
|
3703
|
+
* {({ loading, error, packages, selectPackage }) => {
|
|
3704
|
+
* if (loading) return <Loading />;
|
|
3705
|
+
* if (error) return <Error message={error} />;
|
|
3706
|
+
*
|
|
3707
|
+
* return (
|
|
3708
|
+
* <div className="grid grid-cols-3 gap-4">
|
|
3709
|
+
* {packages.map(pkg => (
|
|
3710
|
+
* <div key={pkg._id}>
|
|
3711
|
+
* <h3>{pkg.name}</h3>
|
|
3712
|
+
* <p>{pkg.creditAmount} credits</p>
|
|
3713
|
+
* <p>${(pkg.pricingVariants[0]?.amount / 100).toFixed(2)}</p>
|
|
3714
|
+
* <button onClick={() => selectPackage(pkg._id)}>Buy</button>
|
|
3715
|
+
* </div>
|
|
3716
|
+
* ))}
|
|
3717
|
+
* </div>
|
|
3718
|
+
* );
|
|
3719
|
+
* }}
|
|
3720
|
+
* </CreditStorePage>
|
|
3721
|
+
* ```
|
|
3722
|
+
*/
|
|
3723
|
+
declare function CreditStorePage({ children, loadingFallback, errorFallback, redirectBaseUrl, }: CreditStorePageProps): react_jsx_runtime.JSX.Element;
|
|
3724
|
+
|
|
3725
|
+
interface IWhenCreditsProps {
|
|
3726
|
+
/** Content to render when the condition is met. */
|
|
3727
|
+
children: React.ReactNode;
|
|
3728
|
+
/** Optional component/element to show while credit balance is loading (e.g. <Skeleton />). */
|
|
3729
|
+
loadingComponent?: React.ReactNode;
|
|
3730
|
+
/** Optional component/element to show when condition is not met (e.g. <BuyCreditsPrompt />). */
|
|
3731
|
+
fallbackComponent?: React.ReactNode;
|
|
3732
|
+
}
|
|
3733
|
+
interface IWhenCreditsAvailableProps extends IWhenCreditsProps {
|
|
3734
|
+
/** Minimum credits required to render children. Default: 1 */
|
|
3735
|
+
min?: number;
|
|
3736
|
+
}
|
|
3737
|
+
interface IWhenCreditsLowProps extends IWhenCreditsProps {
|
|
3738
|
+
/** Credits threshold. Children render when available <= threshold. */
|
|
3739
|
+
threshold: number;
|
|
3740
|
+
}
|
|
3741
|
+
/**
|
|
3742
|
+
* Renders children only when the workspace has at least `min` credits available.
|
|
3743
|
+
* Must be used within CreditBalanceContextProvider (included in SaaSOSProvider by default).
|
|
3744
|
+
*
|
|
3745
|
+
* @example
|
|
3746
|
+
* ```tsx
|
|
3747
|
+
* <WhenCreditsAvailable min={10}>
|
|
3748
|
+
* <GenerateButton />
|
|
3749
|
+
* </WhenCreditsAvailable>
|
|
3750
|
+
* ```
|
|
3751
|
+
*
|
|
3752
|
+
* @example
|
|
3753
|
+
* ```tsx
|
|
3754
|
+
* <WhenCreditsAvailable
|
|
3755
|
+
* min={5}
|
|
3756
|
+
* loadingComponent={<Skeleton />}
|
|
3757
|
+
* fallbackComponent={<p>Not enough credits. <BuyCreditsLink /></p>}
|
|
3758
|
+
* >
|
|
3759
|
+
* <AIFeature />
|
|
3760
|
+
* </WhenCreditsAvailable>
|
|
3761
|
+
* ```
|
|
3762
|
+
*/
|
|
3763
|
+
declare const WhenCreditsAvailable: {
|
|
3764
|
+
(props: IWhenCreditsAvailableProps): react.ReactNode;
|
|
3765
|
+
displayName: string;
|
|
3766
|
+
};
|
|
3767
|
+
/**
|
|
3768
|
+
* Renders children only when the workspace has zero credits available.
|
|
3769
|
+
* Must be used within CreditBalanceContextProvider (included in SaaSOSProvider by default).
|
|
3770
|
+
*
|
|
3771
|
+
* @example
|
|
3772
|
+
* ```tsx
|
|
3773
|
+
* <WhenCreditsExhausted>
|
|
3774
|
+
* <BuyCreditsPrompt message="You're out of credits!" />
|
|
3775
|
+
* </WhenCreditsExhausted>
|
|
3776
|
+
* ```
|
|
3777
|
+
*
|
|
3778
|
+
* @example
|
|
3779
|
+
* ```tsx
|
|
3780
|
+
* <WhenCreditsExhausted
|
|
3781
|
+
* loadingComponent={<Spinner />}
|
|
3782
|
+
* fallbackComponent={null}
|
|
3783
|
+
* >
|
|
3784
|
+
* <NoCreditsOverlay />
|
|
3785
|
+
* </WhenCreditsExhausted>
|
|
3786
|
+
* ```
|
|
3787
|
+
*/
|
|
3788
|
+
declare const WhenCreditsExhausted: {
|
|
3789
|
+
(props: IWhenCreditsProps): react.ReactNode;
|
|
3790
|
+
displayName: string;
|
|
3791
|
+
};
|
|
3792
|
+
/**
|
|
3793
|
+
* Renders children when credits are at or below a threshold.
|
|
3794
|
+
* Must be used within CreditBalanceContextProvider (included in SaaSOSProvider by default).
|
|
3795
|
+
*
|
|
3796
|
+
* @example
|
|
3797
|
+
* ```tsx
|
|
3798
|
+
* <WhenCreditsLow threshold={50}>
|
|
3799
|
+
* <p>Running low on credits! Consider buying more.</p>
|
|
3800
|
+
* </WhenCreditsLow>
|
|
3801
|
+
* ```
|
|
3802
|
+
*
|
|
3803
|
+
* @example
|
|
3804
|
+
* ```tsx
|
|
3805
|
+
* <WhenCreditsLow
|
|
3806
|
+
* threshold={10}
|
|
3807
|
+
* loadingComponent={<Skeleton />}
|
|
3808
|
+
* fallbackComponent={null}
|
|
3809
|
+
* >
|
|
3810
|
+
* <LowCreditsBanner />
|
|
3811
|
+
* </WhenCreditsLow>
|
|
3812
|
+
* ```
|
|
3813
|
+
*/
|
|
3814
|
+
declare const WhenCreditsLow: {
|
|
3815
|
+
(props: IWhenCreditsLowProps): react.ReactNode;
|
|
3816
|
+
displayName: string;
|
|
3817
|
+
};
|
|
3818
|
+
|
|
3175
3819
|
/**
|
|
3176
3820
|
* Value provided by SubscriptionContext and returned by useSubscriptionContext.
|
|
3177
3821
|
*/
|
|
@@ -3242,6 +3886,35 @@ declare const QuotaUsageContextProvider: react__default.FC<{
|
|
|
3242
3886
|
*/
|
|
3243
3887
|
declare function useQuotaUsageContext(): QuotaUsageContextValue;
|
|
3244
3888
|
|
|
3889
|
+
interface CreditBalanceContextValue {
|
|
3890
|
+
/** Credit balance for the current workspace. Null if not loaded or no workspace. */
|
|
3891
|
+
balance: ICreditBalance | null;
|
|
3892
|
+
/** Whether the balance is being fetched. */
|
|
3893
|
+
loading: boolean;
|
|
3894
|
+
/** Error message if the fetch failed. */
|
|
3895
|
+
error: string | null;
|
|
3896
|
+
/** Manually refetch the credit balance. */
|
|
3897
|
+
refetch: () => Promise<void>;
|
|
3898
|
+
}
|
|
3899
|
+
|
|
3900
|
+
/**
|
|
3901
|
+
* Provides credit balance data for the current workspace to credit gate components.
|
|
3902
|
+
* Fetches when workspace changes; refetches when credit balance is invalidated
|
|
3903
|
+
* (e.g. after consume or purchase).
|
|
3904
|
+
* Included in SaaSOSProvider by default.
|
|
3905
|
+
*/
|
|
3906
|
+
declare const CreditBalanceContextProvider: react__default.FC<{
|
|
3907
|
+
children: ReactNode;
|
|
3908
|
+
}>;
|
|
3909
|
+
/**
|
|
3910
|
+
* Returns credit balance data for the current workspace.
|
|
3911
|
+
* Must be used within CreditBalanceContextProvider (included in SaaSOSProvider by default).
|
|
3912
|
+
*
|
|
3913
|
+
* @returns CreditBalanceContextValue - { balance, loading, error, refetch }
|
|
3914
|
+
* @throws Error if used outside CreditBalanceContextProvider
|
|
3915
|
+
*/
|
|
3916
|
+
declare function useCreditBalanceContext(): CreditBalanceContextValue;
|
|
3917
|
+
|
|
3245
3918
|
/**
|
|
3246
3919
|
* Hook to access OS (organization) state (serverUrl, version, orgId, auth, settings).
|
|
3247
3920
|
* Prefer useSaaSSettings() when you only need settings.
|
|
@@ -4157,6 +4830,239 @@ declare const useUsageLogs: (workspaceId: string | null | undefined, quotaSlug?:
|
|
|
4157
4830
|
refetch: () => Promise<void>;
|
|
4158
4831
|
};
|
|
4159
4832
|
|
|
4833
|
+
/**
|
|
4834
|
+
* Hook to get the credit balance for a workspace.
|
|
4835
|
+
* Automatically fetches when workspaceId changes.
|
|
4836
|
+
*
|
|
4837
|
+
* @param workspaceId - The workspace ID. Can be null/undefined to disable fetching.
|
|
4838
|
+
* @returns { balance, loading, error, refetch }
|
|
4839
|
+
*
|
|
4840
|
+
* @example
|
|
4841
|
+
* ```tsx
|
|
4842
|
+
* function CreditDisplay() {
|
|
4843
|
+
* const { currentWorkspace } = useSaaSWorkspaces();
|
|
4844
|
+
* const { balance, loading } = useCreditBalance(currentWorkspace?._id);
|
|
4845
|
+
*
|
|
4846
|
+
* if (loading) return <Loading />;
|
|
4847
|
+
* if (!balance) return null;
|
|
4848
|
+
*
|
|
4849
|
+
* return <p>{balance.available} credits available</p>;
|
|
4850
|
+
* }
|
|
4851
|
+
* ```
|
|
4852
|
+
*/
|
|
4853
|
+
declare const useCreditBalance: (workspaceId: string | null | undefined) => {
|
|
4854
|
+
balance: ICreditBalance | null;
|
|
4855
|
+
loading: boolean;
|
|
4856
|
+
error: string | null;
|
|
4857
|
+
refetch: () => Promise<void>;
|
|
4858
|
+
};
|
|
4859
|
+
/**
|
|
4860
|
+
* Hook to consume credits from a workspace balance.
|
|
4861
|
+
* Returns a mutation function. Throws with `code: 'INSUFFICIENT_CREDITS'` on 402.
|
|
4862
|
+
*
|
|
4863
|
+
* @param workspaceId - The workspace ID. Can be null/undefined.
|
|
4864
|
+
* @returns { consumeCredits, loading, error }
|
|
4865
|
+
*
|
|
4866
|
+
* @example
|
|
4867
|
+
* ```tsx
|
|
4868
|
+
* function GenerateButton() {
|
|
4869
|
+
* const { currentWorkspace } = useSaaSWorkspaces();
|
|
4870
|
+
* const { consumeCredits, loading } = useConsumeCredits(currentWorkspace?._id);
|
|
4871
|
+
*
|
|
4872
|
+
* const handleGenerate = async () => {
|
|
4873
|
+
* try {
|
|
4874
|
+
* const result = await consumeCredits({
|
|
4875
|
+
* amount: 10,
|
|
4876
|
+
* description: 'AI image generation',
|
|
4877
|
+
* idempotencyKey: `gen-${crypto.randomUUID()}`,
|
|
4878
|
+
* });
|
|
4879
|
+
* console.log(`Balance after: ${result.balanceAfter}`);
|
|
4880
|
+
* } catch (err: any) {
|
|
4881
|
+
* if (err.code === 'INSUFFICIENT_CREDITS') {
|
|
4882
|
+
* alert(`Not enough credits. Available: ${err.available}`);
|
|
4883
|
+
* }
|
|
4884
|
+
* }
|
|
4885
|
+
* };
|
|
4886
|
+
*
|
|
4887
|
+
* return <button onClick={handleGenerate} disabled={loading}>Generate</button>;
|
|
4888
|
+
* }
|
|
4889
|
+
* ```
|
|
4890
|
+
*/
|
|
4891
|
+
declare const useConsumeCredits: (workspaceId: string | null | undefined) => {
|
|
4892
|
+
consumeCredits: (request: IConsumeCreditsRequest) => Promise<IConsumeCreditsResponse>;
|
|
4893
|
+
loading: boolean;
|
|
4894
|
+
error: string | null;
|
|
4895
|
+
};
|
|
4896
|
+
/**
|
|
4897
|
+
* Hook to create a Stripe checkout session for purchasing a credit package.
|
|
4898
|
+
* Returns a mutation function that resolves with { sessionId, url }.
|
|
4899
|
+
*
|
|
4900
|
+
* @param workspaceId - The workspace ID. Can be null/undefined.
|
|
4901
|
+
* @returns { purchaseCredits, loading, error }
|
|
4902
|
+
*
|
|
4903
|
+
* @example
|
|
4904
|
+
* ```tsx
|
|
4905
|
+
* function BuyCreditsButton({ packageId }) {
|
|
4906
|
+
* const { currentWorkspace } = useSaaSWorkspaces();
|
|
4907
|
+
* const { purchaseCredits, loading } = usePurchaseCredits(currentWorkspace?._id);
|
|
4908
|
+
*
|
|
4909
|
+
* const handleBuy = async () => {
|
|
4910
|
+
* const result = await purchaseCredits({
|
|
4911
|
+
* creditPackageId: packageId,
|
|
4912
|
+
* successUrl: `${window.location.origin}/credits/success`,
|
|
4913
|
+
* cancelUrl: `${window.location.origin}/credits`,
|
|
4914
|
+
* });
|
|
4915
|
+
* window.location.href = result.url;
|
|
4916
|
+
* };
|
|
4917
|
+
*
|
|
4918
|
+
* return <button onClick={handleBuy} disabled={loading}>Buy Credits</button>;
|
|
4919
|
+
* }
|
|
4920
|
+
* ```
|
|
4921
|
+
*/
|
|
4922
|
+
declare const usePurchaseCredits: (workspaceId: string | null | undefined) => {
|
|
4923
|
+
purchaseCredits: (request: ICreditPurchaseRequest) => Promise<ICreditPurchaseResponse>;
|
|
4924
|
+
loading: boolean;
|
|
4925
|
+
error: string | null;
|
|
4926
|
+
};
|
|
4927
|
+
/**
|
|
4928
|
+
* Hook to list available credit packages for purchase.
|
|
4929
|
+
* Automatically fetches when workspaceId changes.
|
|
4930
|
+
*
|
|
4931
|
+
* @param workspaceId - The workspace ID. Can be null/undefined to disable fetching.
|
|
4932
|
+
* @returns { packages, loading, error, refetch }
|
|
4933
|
+
*
|
|
4934
|
+
* @example
|
|
4935
|
+
* ```tsx
|
|
4936
|
+
* function CreditStore() {
|
|
4937
|
+
* const { currentWorkspace } = useSaaSWorkspaces();
|
|
4938
|
+
* const { packages, loading } = useCreditPackages(currentWorkspace?._id);
|
|
4939
|
+
*
|
|
4940
|
+
* if (loading) return <Loading />;
|
|
4941
|
+
*
|
|
4942
|
+
* return (
|
|
4943
|
+
* <div>
|
|
4944
|
+
* {packages.map(pkg => (
|
|
4945
|
+
* <div key={pkg._id}>
|
|
4946
|
+
* <h3>{pkg.name}</h3>
|
|
4947
|
+
* <p>{pkg.creditAmount} credits</p>
|
|
4948
|
+
* </div>
|
|
4949
|
+
* ))}
|
|
4950
|
+
* </div>
|
|
4951
|
+
* );
|
|
4952
|
+
* }
|
|
4953
|
+
* ```
|
|
4954
|
+
*/
|
|
4955
|
+
declare const useCreditPackages: (workspaceId: string | null | undefined) => {
|
|
4956
|
+
packages: ICreditPackage[];
|
|
4957
|
+
loading: boolean;
|
|
4958
|
+
error: string | null;
|
|
4959
|
+
refetch: () => Promise<void>;
|
|
4960
|
+
};
|
|
4961
|
+
/**
|
|
4962
|
+
* Hook to get paginated credit transaction history.
|
|
4963
|
+
* Automatically fetches when workspaceId or query params change.
|
|
4964
|
+
*
|
|
4965
|
+
* @param workspaceId - The workspace ID. Can be null/undefined to disable fetching.
|
|
4966
|
+
* @param query - Optional filters: type, page, limit
|
|
4967
|
+
* @returns { transactions, totalDocs, totalPages, page, hasNextPage, hasPrevPage, loading, error, refetch }
|
|
4968
|
+
*
|
|
4969
|
+
* @example
|
|
4970
|
+
* ```tsx
|
|
4971
|
+
* function TransactionHistory() {
|
|
4972
|
+
* const { currentWorkspace } = useSaaSWorkspaces();
|
|
4973
|
+
* const { transactions, totalPages, page, loading } = useCreditTransactions(
|
|
4974
|
+
* currentWorkspace?._id,
|
|
4975
|
+
* { limit: 20 }
|
|
4976
|
+
* );
|
|
4977
|
+
*
|
|
4978
|
+
* if (loading) return <Loading />;
|
|
4979
|
+
*
|
|
4980
|
+
* return (
|
|
4981
|
+
* <div>
|
|
4982
|
+
* {transactions.map(tx => (
|
|
4983
|
+
* <div key={tx._id}>
|
|
4984
|
+
* {tx.type}: {tx.amount} (balance: {tx.balanceAfter})
|
|
4985
|
+
* </div>
|
|
4986
|
+
* ))}
|
|
4987
|
+
* <p>Page {page} of {totalPages}</p>
|
|
4988
|
+
* </div>
|
|
4989
|
+
* );
|
|
4990
|
+
* }
|
|
4991
|
+
* ```
|
|
4992
|
+
*/
|
|
4993
|
+
declare const useCreditTransactions: (workspaceId: string | null | undefined, query?: ICreditTransactionsQuery) => {
|
|
4994
|
+
transactions: ICreditTransaction[];
|
|
4995
|
+
totalDocs: number;
|
|
4996
|
+
totalPages: number;
|
|
4997
|
+
page: number;
|
|
4998
|
+
hasNextPage: boolean;
|
|
4999
|
+
hasPrevPage: boolean;
|
|
5000
|
+
loading: boolean;
|
|
5001
|
+
error: string | null;
|
|
5002
|
+
refetch: () => Promise<void>;
|
|
5003
|
+
};
|
|
5004
|
+
/**
|
|
5005
|
+
* Hook to get credits expiring within N days.
|
|
5006
|
+
* Automatically fetches when workspaceId or days changes.
|
|
5007
|
+
*
|
|
5008
|
+
* @param workspaceId - The workspace ID. Can be null/undefined to disable fetching.
|
|
5009
|
+
* @param days - Look-ahead window in days (1-90, default 7)
|
|
5010
|
+
* @returns { expiringCredits, buckets, days, loading, error, refetch }
|
|
5011
|
+
*
|
|
5012
|
+
* @example
|
|
5013
|
+
* ```tsx
|
|
5014
|
+
* function ExpiringCreditsWarning() {
|
|
5015
|
+
* const { currentWorkspace } = useSaaSWorkspaces();
|
|
5016
|
+
* const { expiringCredits, loading } = useExpiringCredits(currentWorkspace?._id, 7);
|
|
5017
|
+
*
|
|
5018
|
+
* if (loading || expiringCredits === 0) return null;
|
|
5019
|
+
*
|
|
5020
|
+
* return <p>Warning: {expiringCredits} credits expire within 7 days</p>;
|
|
5021
|
+
* }
|
|
5022
|
+
* ```
|
|
5023
|
+
*/
|
|
5024
|
+
declare const useExpiringCredits: (workspaceId: string | null | undefined, days?: number) => {
|
|
5025
|
+
expiringCredits: number;
|
|
5026
|
+
buckets: ICreditBucket[];
|
|
5027
|
+
days: number;
|
|
5028
|
+
loading: boolean;
|
|
5029
|
+
error: string | null;
|
|
5030
|
+
refetch: () => Promise<void>;
|
|
5031
|
+
};
|
|
5032
|
+
/**
|
|
5033
|
+
* Hook to fetch credit packages publicly (no auth required).
|
|
5034
|
+
* Uses orgId from SaaSOSProvider — must be inside the provider.
|
|
5035
|
+
*
|
|
5036
|
+
* @returns { packages, notes, loading, error, refetch }
|
|
5037
|
+
*
|
|
5038
|
+
* @example
|
|
5039
|
+
* ```tsx
|
|
5040
|
+
* function CreditStore() {
|
|
5041
|
+
* const { packages, loading } = usePublicCreditPackages();
|
|
5042
|
+
*
|
|
5043
|
+
* if (loading) return <Loading />;
|
|
5044
|
+
*
|
|
5045
|
+
* return (
|
|
5046
|
+
* <div>
|
|
5047
|
+
* {packages.map(pkg => (
|
|
5048
|
+
* <div key={pkg._id}>
|
|
5049
|
+
* <h3>{pkg.name}</h3>
|
|
5050
|
+
* <p>{pkg.creditAmount} credits</p>
|
|
5051
|
+
* </div>
|
|
5052
|
+
* ))}
|
|
5053
|
+
* </div>
|
|
5054
|
+
* );
|
|
5055
|
+
* }
|
|
5056
|
+
* ```
|
|
5057
|
+
*/
|
|
5058
|
+
declare const usePublicCreditPackages: () => {
|
|
5059
|
+
packages: IPublicCreditPackage[];
|
|
5060
|
+
notes: string | undefined;
|
|
5061
|
+
loading: boolean;
|
|
5062
|
+
error: string | null;
|
|
5063
|
+
refetch: () => Promise<void>;
|
|
5064
|
+
};
|
|
5065
|
+
|
|
4160
5066
|
interface TrialStatus {
|
|
4161
5067
|
/** Whether the current subscription is in trial. */
|
|
4162
5068
|
isTrialing: boolean;
|
|
@@ -4368,5 +5274,5 @@ declare const PushNotificationProvider: react__default.FC<PushNotificationProvid
|
|
|
4368
5274
|
*/
|
|
4369
5275
|
declare function usePushNotifications(): PushNotificationContextValue;
|
|
4370
5276
|
|
|
4371
|
-
export { ApiVersion, AuthApi, AuthStatus, BB_PARAM, BaseApi, BetaForm, BillingIntervals, CURRENCY_DISPLAY, CURRENCY_FLAG, DEFAULT_ROLE_PERMISSIONS, DunningState, EventEmitter, InvoiceStatuses, PLAN_CURRENCY_CODES, PLAN_CURRENCY_OPTIONS, PUSH_SERVICE_WORKER_SCRIPT, Permission, PricingPage, PushApi, PushNotificationProvider, QuotaUsageContextProvider, SDKEvent, SETTINGS_SCREENS, SUPPORTED_LOCALES, SaaSOSProvider, SettingsApi, SettingsScreen, SubscriptionContextProvider, SubscriptionItemType, SubscriptionStatus, UserApi, WhenAuthenticated, WhenNoSubscription, WhenNotTrialing, WhenPermission, WhenQuotaAvailable, WhenQuotaExhausted, WhenQuotaOverage, WhenQuotaThreshold, WhenRoles, WhenSubscription, WhenSubscriptionToPlans, WhenTrialEnding, WhenTrialing, WhenUnauthenticated, WhenUserFeatureDisabled, WhenUserFeatureEnabled, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceApi, WorkspaceSwitcher, calculateBillableSeats, calculateSeatOverageCents, calculateTotalSubscriptionCents, cleanBBParams, clearAuthIntent, consumeAuthIntent, createBBUrl, createCheckoutRedirectUrls, eventEmitter, formatCents, formatOverageRate, formatOverageRateWithLabel, formatQuotaIncludedOverage, formatQuotaWithPrice, getAvailableCurrenciesFromPlans, getBasePriceCents, getBillingIntervalAndCurrencyFromPriceId, getCurrencyFlag, getCurrencySymbol, getDisplayCurrency, getPerSeatPriceCents, getPricingVariant, getQuotaDisplayValue, getQuotaDisplayWithVariant, getQuotaOverageCents, getQuotaUnitLabelFromName, getSeatPricing, getStripePriceIdForInterval, hasPermission, invalidateQuotaUsage, invalidateSubscription, readBBParams, resolveMaxUsers, resolvePermissions, safeRedirect, saveAuthIntent, useAllQuotaUsage, useBillingPortal, useCancelSubscription, useCreateCheckoutSession, useInvoice, useInvoices, usePermissions, usePlanGroup, usePlanGroupVersions, usePublicPlanGroupVersion, usePublicPlans, usePushNotifications, useQuotaUsageContext, useQuotaUsageStatus, useRecordUsage, useResumeSubscription, useSaaSAuth, useSaaSOs, useSaaSSettings, useSaaSWorkspaces, useSeatStatus, useSubscription, useSubscriptionContext, useSubscriptionManagement, useTranslation, useTrialStatus, useUpdateSubscription, useUsageLogs, useUserAttributes, useUserFeatures, validateInvite, validateRedirectUrl };
|
|
4372
|
-
export type { BetaFormData, BetaFormResponse, BillingInterval, CheckoutResult, EventData, EventType, 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, InvoiceStatus, MaxUsersConfig, NotificationData, NotificationEvent, NotificationResult, OnWorkspaceChangeParams, PermissionContext, PermissionKey, PlanVersionWithPricingVariants, PricingPageDetails, PricingPageProps, QuotaDisplayValue, QuotaDisplayWithOverage, QuotaUsageContextValue, RolePermissionMap, SDKLocale, SDKMessages, SaaSOSProviderProps, SeatStatus, SubscriptionContextValue, SubscriptionStatusType, TrialStatus, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceSettingsSection, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };
|
|
5277
|
+
export { ApiVersion, AuthApi, AuthStatus, BBAction, BBScreen, BBStatus, BB_PARAM, BaseApi, BetaForm, BillingIntervals, CURRENCY_DISPLAY, CURRENCY_FLAG, CreditActionsProvider, CreditBalance, CreditBalanceContextProvider, CreditBucketSource, CreditBucketStatus, CreditStorePage, CreditTransactionType, DEFAULT_ROLE_PERMISSIONS, DunningState, EventEmitter, InvoiceStatuses, PLAN_CURRENCY_CODES, PLAN_CURRENCY_OPTIONS, PUSH_SERVICE_WORKER_SCRIPT, Permission, PricingPage, PushApi, PushNotificationProvider, QuotaUsageContextProvider, SDKEvent, SETTINGS_SCREENS, SUPPORTED_LOCALES, SaaSOSProvider, SettingsApi, SettingsScreen, SubscriptionContextProvider, SubscriptionItemType, SubscriptionStatus, UserApi, WhenAuthenticated, WhenCreditsAvailable, WhenCreditsExhausted, WhenCreditsLow, WhenNoSubscription, WhenNotTrialing, WhenPermission, WhenQuotaAvailable, WhenQuotaExhausted, WhenQuotaOverage, WhenQuotaThreshold, WhenRoles, WhenSubscription, WhenSubscriptionToPlans, WhenTrialEnding, WhenTrialing, WhenUnauthenticated, WhenUserFeatureDisabled, WhenUserFeatureEnabled, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceApi, WorkspaceSwitcher, calculateBillableSeats, calculateSeatOverageCents, calculateTotalSubscriptionCents, cleanBBParams, clearAuthIntent, consumeAuthIntent, createBBUrl, createCheckoutRedirectUrls, createCreditPurchaseRedirectUrls, eventEmitter, formatCents, formatOverageRate, formatOverageRateWithLabel, formatQuotaIncludedOverage, formatQuotaWithPrice, getAvailableCurrenciesFromPlans, getBasePriceCents, getBillingIntervalAndCurrencyFromPriceId, getCurrencyFlag, getCurrencySymbol, getDisplayCurrency, getPerSeatPriceCents, getPricingVariant, getQuotaDisplayValue, getQuotaDisplayWithVariant, getQuotaOverageCents, getQuotaUnitLabelFromName, getSeatPricing, getStripePriceIdForInterval, hasPermission, invalidateCreditBalance, invalidateQuotaUsage, invalidateSubscription, readBBParams, resolveMaxUsers, resolvePermissions, safeRedirect, saveAuthIntent, useAllQuotaUsage, useBillingPortal, useCancelSubscription, useConsumeCredits, useCreateCheckoutSession, useCreditBalance, useCreditBalanceContext, useCreditPackages, useCreditTransactions, useExpiringCredits, useInvoice, useInvoices, usePermissions, usePlanGroup, usePlanGroupVersions, usePublicCreditPackages, usePublicPlanGroupVersion, usePublicPlans, usePurchaseCredits, usePushNotifications, useQuotaUsageContext, useQuotaUsageStatus, useRecordUsage, useResumeSubscription, useSaaSAuth, useSaaSOs, useSaaSSettings, useSaaSWorkspaces, useSeatStatus, useSubscription, useSubscriptionContext, useSubscriptionManagement, useTranslation, useTrialStatus, useUpdateSubscription, useUsageLogs, useUserAttributes, useUserFeatures, validateInvite, validateRedirectUrl };
|
|
5278
|
+
export type { BBActionType, BBScreenType, BBStatusType, BetaFormData, BetaFormResponse, BillingInterval, CheckoutResult, CreditActionsDetails, CreditBalanceContextValue, CreditBalanceDetails, CreditBucketSourceType, CreditBucketStatusType, CreditStorePageDetails, CreditTransactionTypeValue, DunningStateType, EventData, EventType, 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, InvoiceStatus, InvoiceStatusType, MaxUsersConfig, NotificationData, NotificationEvent, NotificationResult, OnWorkspaceChangeParams, PermissionContext, PermissionKey, PlanVersionWithPricingVariants, PricingPageDetails, PricingPageProps, QuotaDisplayValue, QuotaDisplayWithOverage, QuotaUsageContextValue, RolePermissionMap, SDKLocale, SDKMessages, SaaSOSProviderProps, SeatStatus, SubscriptionContextValue, SubscriptionItemTypeValue, SubscriptionStatusType, TrialStatus, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceSettingsSection, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };
|