@buildbase/sdk 0.0.24 → 0.0.26

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.
Files changed (133) hide show
  1. package/README.md +82 -0
  2. package/dist/index.d.ts +26 -1
  3. package/dist/index.esm.js +5 -6
  4. package/dist/index.js +5 -6
  5. package/package.json +3 -2
  6. package/dist/index.esm.js.map +0 -1
  7. package/dist/index.js.map +0 -1
  8. package/dist/types/api/currency-utils.d.ts +0 -44
  9. package/dist/types/api/index.d.ts +0 -12
  10. package/dist/types/api/pricing-variant-utils.d.ts +0 -66
  11. package/dist/types/api/quota-utils.d.ts +0 -24
  12. package/dist/types/api/types.d.ts +0 -495
  13. package/dist/types/components/ErrorBoundary.d.ts +0 -81
  14. package/dist/types/components/beta/BetaForm.d.ts +0 -24
  15. package/dist/types/components/beta/api.d.ts +0 -48
  16. package/dist/types/components/beta/hooks.d.ts +0 -11
  17. package/dist/types/components/beta/schema.d.ts +0 -6
  18. package/dist/types/components/beta/types.d.ts +0 -8
  19. package/dist/types/components/dropdowns/country/countries.d.ts +0 -7
  20. package/dist/types/components/dropdowns/country/selectCountry.d.ts +0 -6
  21. package/dist/types/components/dropdowns/currency/currencies.d.ts +0 -6
  22. package/dist/types/components/dropdowns/currency/selectCurrency.d.ts +0 -6
  23. package/dist/types/components/dropdowns/language/languages.d.ts +0 -6
  24. package/dist/types/components/dropdowns/language/selectLanguage.d.ts +0 -6
  25. package/dist/types/components/dropdowns/timezone/selectTimeZone.d.ts +0 -6
  26. package/dist/types/components/dropdowns/timezone/timezones.d.ts +0 -8
  27. package/dist/types/components/features/index.d.ts +0 -130
  28. package/dist/types/components/pricing/PricingPage.d.ts +0 -49
  29. package/dist/types/components/pricing/index.d.ts +0 -2
  30. package/dist/types/components/quota/index.d.ts +0 -121
  31. package/dist/types/components/subscription/index.d.ts +0 -182
  32. package/dist/types/components/ui/alert-dialog.d.ts +0 -20
  33. package/dist/types/components/ui/avatar.d.ts +0 -6
  34. package/dist/types/components/ui/button.d.ts +0 -18
  35. package/dist/types/components/ui/command-select.d.ts +0 -13
  36. package/dist/types/components/ui/command.d.ts +0 -82
  37. package/dist/types/components/ui/dialog.d.ts +0 -19
  38. package/dist/types/components/ui/form.d.ts +0 -23
  39. package/dist/types/components/ui/input.d.ts +0 -5
  40. package/dist/types/components/ui/label.d.ts +0 -5
  41. package/dist/types/components/ui/popover.d.ts +0 -6
  42. package/dist/types/components/ui/radio-group.d.ts +0 -5
  43. package/dist/types/components/ui/scroll-area.d.ts +0 -5
  44. package/dist/types/components/ui/select.d.ts +0 -11
  45. package/dist/types/components/ui/separator.d.ts +0 -4
  46. package/dist/types/components/ui/skeleton.d.ts +0 -3
  47. package/dist/types/components/ui/switch.d.ts +0 -4
  48. package/dist/types/components/user/auth.d.ts +0 -76
  49. package/dist/types/components/user/role.d.ts +0 -84
  50. package/dist/types/contexts/AuthContext/AuthContext.d.ts +0 -9
  51. package/dist/types/contexts/AuthContext/actions.d.ts +0 -12
  52. package/dist/types/contexts/AuthContext/index.d.ts +0 -4
  53. package/dist/types/contexts/AuthContext/reducer.d.ts +0 -19
  54. package/dist/types/contexts/AuthContext/types.d.ts +0 -18
  55. package/dist/types/contexts/OSContext/OSContext.d.ts +0 -9
  56. package/dist/types/contexts/OSContext/actions.d.ts +0 -11
  57. package/dist/types/contexts/OSContext/index.d.ts +0 -4
  58. package/dist/types/contexts/OSContext/reducer.d.ts +0 -11
  59. package/dist/types/contexts/OSContext/types.d.ts +0 -16
  60. package/dist/types/contexts/QuotaUsageContext/QuotaUsageContext.d.ts +0 -22
  61. package/dist/types/contexts/QuotaUsageContext/index.d.ts +0 -2
  62. package/dist/types/contexts/QuotaUsageContext/quotaUsageInvalidation.d.ts +0 -21
  63. package/dist/types/contexts/QuotaUsageContext/types.d.ts +0 -14
  64. package/dist/types/contexts/SDKContext/SDKContextProvider.d.ts +0 -18
  65. package/dist/types/contexts/SDKContext/index.d.ts +0 -2
  66. package/dist/types/contexts/SDKContext/types.d.ts +0 -12
  67. package/dist/types/contexts/SubscriptionContext/SubscriptionContext.d.ts +0 -22
  68. package/dist/types/contexts/SubscriptionContext/index.d.ts +0 -2
  69. package/dist/types/contexts/SubscriptionContext/subscriptionInvalidation.d.ts +0 -21
  70. package/dist/types/contexts/SubscriptionContext/types.d.ts +0 -14
  71. package/dist/types/contexts/WorkspaceContext/WorkspaceContext.d.ts +0 -8
  72. package/dist/types/contexts/WorkspaceContext/actions.d.ts +0 -19
  73. package/dist/types/contexts/WorkspaceContext/index.d.ts +0 -4
  74. package/dist/types/contexts/WorkspaceContext/reducer.d.ts +0 -10
  75. package/dist/types/contexts/WorkspaceContext/types.d.ts +0 -52
  76. package/dist/types/contexts/index.d.ts +0 -14
  77. package/dist/types/contexts/shared/createContext.d.ts +0 -27
  78. package/dist/types/contexts/shared/types.d.ts +0 -21
  79. package/dist/types/contexts/shared/useAppDispatch.d.ts +0 -20
  80. package/dist/types/contexts/shared/useAppSelector.d.ts +0 -26
  81. package/dist/types/contexts/shared/useSelectWithEquality.d.ts +0 -10
  82. package/dist/types/contexts/shared/utils/reducerHelpers.d.ts +0 -11
  83. package/dist/types/contexts/shared/utils/storage.d.ts +0 -25
  84. package/dist/types/hooks/use-seat-status.d.ts +0 -42
  85. package/dist/types/hooks/use-trial-status.d.ts +0 -28
  86. package/dist/types/index.d.ts +0 -39
  87. package/dist/types/lib/api-base.d.ts +0 -49
  88. package/dist/types/lib/api-client.d.ts +0 -25
  89. package/dist/types/lib/api-utils.d.ts +0 -182
  90. package/dist/types/lib/error-handler.d.ts +0 -118
  91. package/dist/types/lib/logger.d.ts +0 -27
  92. package/dist/types/lib/useAsyncEffect.d.ts +0 -29
  93. package/dist/types/lib/utils.d.ts +0 -7
  94. package/dist/types/providers/ContextConfigProvider.d.ts +0 -15
  95. package/dist/types/providers/PortalContainer.d.ts +0 -9
  96. package/dist/types/providers/SaaSOSProvider.d.ts +0 -7
  97. package/dist/types/providers/auth/api.d.ts +0 -12
  98. package/dist/types/providers/auth/hooks.d.ts +0 -75
  99. package/dist/types/providers/auth/provider.d.ts +0 -13
  100. package/dist/types/providers/auth/types.d.ts +0 -62
  101. package/dist/types/providers/auth/utils.d.ts +0 -40
  102. package/dist/types/providers/constants.d.ts +0 -3
  103. package/dist/types/providers/events/EventEmitter.d.ts +0 -81
  104. package/dist/types/providers/events/index.d.ts +0 -2
  105. package/dist/types/providers/events/types.d.ts +0 -61
  106. package/dist/types/providers/os/api.d.ts +0 -11
  107. package/dist/types/providers/os/hooks.d.ts +0 -50
  108. package/dist/types/providers/os/types.d.ts +0 -19
  109. package/dist/types/providers/types.d.ts +0 -9
  110. package/dist/types/providers/user/api.d.ts +0 -16
  111. package/dist/types/providers/user/hooks.d.ts +0 -80
  112. package/dist/types/providers/user/provider.d.ts +0 -17
  113. package/dist/types/providers/workspace/WorkspaceSettingsProvider.d.ts +0 -9
  114. package/dist/types/providers/workspace/api.d.ts +0 -155
  115. package/dist/types/providers/workspace/hooks.d.ts +0 -161
  116. package/dist/types/providers/workspace/provider.d.ts +0 -8
  117. package/dist/types/providers/workspace/settings-manager.d.ts +0 -36
  118. package/dist/types/providers/workspace/subscription-hooks.d.ts +0 -741
  119. package/dist/types/providers/workspace/types.d.ts +0 -61
  120. package/dist/types/providers/workspace/ui/SettingsDanger.d.ts +0 -6
  121. package/dist/types/providers/workspace/ui/SettingsDialog.d.ts +0 -17
  122. package/dist/types/providers/workspace/ui/SettingsFeatures.d.ts +0 -5
  123. package/dist/types/providers/workspace/ui/SettingsGeneral.d.ts +0 -6
  124. package/dist/types/providers/workspace/ui/SettingsInvoices.d.ts +0 -12
  125. package/dist/types/providers/workspace/ui/SettingsProfile.d.ts +0 -6
  126. package/dist/types/providers/workspace/ui/SettingsSubscription.d.ts +0 -6
  127. package/dist/types/providers/workspace/ui/SettingsUsage.d.ts +0 -3
  128. package/dist/types/providers/workspace/ui/SettingsUsers.d.ts +0 -6
  129. package/dist/types/providers/workspace/ui/Sidebar.d.ts +0 -10
  130. package/dist/types/providers/workspace/ui/Skeleton.d.ts +0 -1
  131. package/dist/types/providers/workspace/ui/SubscriptionDialog.d.ts +0 -21
  132. package/dist/types/providers/workspace/ui/utils.d.ts +0 -2
  133. package/dist/types/providers/workspace/utils.d.ts +0 -28
@@ -1,741 +0,0 @@
1
- import { BillingInterval, CheckoutResult, ICheckoutSessionRequest, ICheckoutSessionResponse, IInvoice, IPlanGroupResponse, IPlanGroupVersion, IPlanGroupVersionsResponse, IQuotaUsageStatus, IQuotaUsageStatusResponse, IRecordUsageRequest, IRecordUsageResponse, ISubscriptionResponse, ISubscriptionUpdateResponse, IUsageLogEntry } from '../../api/types';
2
- /**
3
- * Hook to get public plans by slug (no auth required).
4
- * Returns items (features, limits, quotas) and plans (with pricing).
5
- * Uses orgId from SaaSOSProvider - must be inside provider.
6
- *
7
- * @param slug - Plan group slug (e.g. 'main-pricing', 'enterprise')
8
- * @returns { items, plans, loading, error, refetch }
9
- */
10
- export declare const usePublicPlans: (slug: string) => {
11
- items: import("../..").IPublicPlanItem[];
12
- plans: import("../..").IPublicPlanVersion[];
13
- notes: string | undefined;
14
- loading: boolean;
15
- error: string | null;
16
- refetch: () => Promise<void>;
17
- };
18
- /**
19
- * Hook to get a single plan group version by ID (no auth required).
20
- * Use this for public pricing pages when you have the groupVersionId (e.g. from config or URL).
21
- *
22
- * @param groupVersionId - The plan group version ID to fetch. Pass null/undefined to disable fetching.
23
- * @returns An object containing:
24
- * - `planGroupVersion`: Plan group version data (null if not loaded)
25
- * - `loading`: Boolean indicating if data is being fetched
26
- * - `error`: Error message string (null if no error)
27
- * - `refetch()`: Function to manually refetch
28
- *
29
- * @example
30
- * ```tsx
31
- * function PublicPricingPage() {
32
- * const groupVersionId = 'your-plan-group-version-id'; // from config or URL
33
- * const { planGroupVersion, loading } = usePublicPlanGroupVersion(groupVersionId);
34
- *
35
- * if (loading) return <Loading />;
36
- * if (!planGroupVersion) return null;
37
- *
38
- * const plans = Array.isArray(planGroupVersion.planVersionIds)
39
- * ? planGroupVersion.planVersionIds.filter((p): p is IPlanVersionWithPlan => typeof p !== 'string')
40
- * : [];
41
- *
42
- * return (
43
- * <div>
44
- * {plans.map(plan => <PlanCard key={plan._id} plan={plan} />)}
45
- * </div>
46
- * );
47
- * }
48
- * ```
49
- */
50
- export declare const usePublicPlanGroupVersion: (groupVersionId: string | null | undefined) => {
51
- planGroupVersion: IPlanGroupVersion | null;
52
- loading: boolean;
53
- error: string | null;
54
- refetch: () => Promise<void>;
55
- };
56
- /**
57
- * Hook to get and manage the current subscription for a workspace.
58
- * Automatically fetches subscription when workspaceId changes.
59
- *
60
- * @param workspaceId - The workspace ID to get subscription for. Can be null/undefined to disable fetching.
61
- * @returns An object containing:
62
- * - `subscription`: Current subscription data (null if no subscription or not loaded)
63
- * - `loading`: Boolean indicating if subscription is being fetched
64
- * - `error`: Error message string (null if no error)
65
- * - `refetch()`: Function to manually refetch the subscription
66
- *
67
- * @example
68
- * ```tsx
69
- * function SubscriptionStatus() {
70
- * const { currentWorkspace } = useSaaSWorkspaces();
71
- * const { subscription, loading, error } = useSubscription(currentWorkspace?._id);
72
- *
73
- * if (loading) return <Loading />;
74
- * if (error) return <Error message={error} />;
75
- * if (!subscription) return <p>No active subscription</p>;
76
- *
77
- * return <p>Plan: {subscription.plan.name}</p>;
78
- * }
79
- * ```
80
- *
81
- * @example
82
- * ```tsx
83
- * // Edge case: Workspace ID changes
84
- * function SubscriptionComponent({ workspaceId }) {
85
- * const { subscription, refetch } = useSubscription(workspaceId);
86
- *
87
- * // Subscription automatically refetches when workspaceId changes
88
- * // Use refetch() to manually refresh after mutations
89
- * return <SubscriptionDetails subscription={subscription} />;
90
- * }
91
- * ```
92
- */
93
- export declare const useSubscription: (workspaceId: string | null | undefined) => {
94
- subscription: ISubscriptionResponse | null;
95
- loading: boolean;
96
- error: string | null;
97
- refetch: () => Promise<void>;
98
- };
99
- /**
100
- * Hook to get the plan group for a workspace.
101
- * Returns the plan group containing the current plan if subscription exists,
102
- * otherwise returns the latest published group.
103
- * Automatically fetches when workspaceId or groupVersionId changes.
104
- *
105
- * @param workspaceId - The workspace ID to get plan group for. Can be null/undefined to disable fetching.
106
- * @param groupVersionId - Optional: specific group version ID to fetch (for viewing historical versions)
107
- * @returns An object containing:
108
- * - `planGroup`: Plan group data (null if not loaded)
109
- * - `loading`: Boolean indicating if plan group is being fetched
110
- * - `error`: Error message string (null if no error)
111
- * - `refetch()`: Function to manually refetch the plan group
112
- *
113
- * @example
114
- * ```tsx
115
- * function PlanGroupDisplay() {
116
- * const { currentWorkspace } = useSaaSWorkspaces();
117
- * const { planGroup, loading } = usePlanGroup(currentWorkspace?._id);
118
- *
119
- * if (loading) return <Loading />;
120
- * if (!planGroup) return <p>No plan group available</p>;
121
- *
122
- * return (
123
- * <div>
124
- * <h3>{planGroup.group.name}</h3>
125
- * {planGroup.plans.map(plan => (
126
- * <PlanCard key={plan._id} plan={plan} />
127
- * ))}
128
- * </div>
129
- * );
130
- * }
131
- * ```
132
- *
133
- * @example
134
- * ```tsx
135
- * // Fetch specific version for comparison
136
- * function PlanVersionComparison() {
137
- * const { currentWorkspace } = useSaaSWorkspaces();
138
- * const current = usePlanGroup(currentWorkspace?._id);
139
- * const previous = usePlanGroup(currentWorkspace?._id, 'previous-version-id');
140
- *
141
- * return <ComparePlans current={current.planGroup} previous={previous.planGroup} />;
142
- * }
143
- * ```
144
- */
145
- export declare const usePlanGroup: (workspaceId: string | null | undefined, groupVersionId?: string | null) => {
146
- planGroup: IPlanGroupResponse | null;
147
- loading: boolean;
148
- error: string | null;
149
- refetch: () => Promise<void>;
150
- };
151
- /**
152
- * Hook to get all available versions of a plan group for a workspace.
153
- * Shows current version and available newer versions for upgrade paths.
154
- * Automatically fetches when workspaceId changes.
155
- *
156
- * @param workspaceId - The workspace ID to get plan group versions for. Can be null/undefined to disable fetching.
157
- * @returns An object containing:
158
- * - `versions`: Plan group versions response with currentVersion and availableVersions
159
- * - `loading`: Boolean indicating if versions are being fetched
160
- * - `error`: Error message string (null if no error)
161
- * - `refetch()`: Function to manually refetch the versions
162
- *
163
- * @example
164
- * ```tsx
165
- * function UpgradeOptions() {
166
- * const { currentWorkspace } = useSaaSWorkspaces();
167
- * const { versions, loading } = usePlanGroupVersions(currentWorkspace?._id);
168
- *
169
- * if (loading) return <Loading />;
170
- *
171
- * return (
172
- * <div>
173
- * <p>Current: {versions?.currentVersion.name}</p>
174
- * <h4>Available Upgrades:</h4>
175
- * {versions?.availableVersions.map(version => (
176
- * <UpgradeCard key={version._id} version={version} />
177
- * ))}
178
- * </div>
179
- * );
180
- * }
181
- * ```
182
- */
183
- export declare const usePlanGroupVersions: (workspaceId: string | null | undefined) => {
184
- versions: IPlanGroupVersionsResponse | null;
185
- loading: boolean;
186
- error: string | null;
187
- refetch: () => Promise<void>;
188
- };
189
- /**
190
- * Hook to create a checkout session for a new subscription.
191
- * Returns a function to initiate the checkout process.
192
- *
193
- * @param workspaceId - The workspace ID to create checkout session for. Can be null/undefined.
194
- * @returns An object containing:
195
- * - `createCheckoutSession(request)`: Function to create checkout session (throws if workspaceId is null)
196
- * - `loading`: Boolean indicating if checkout session is being created
197
- * - `error`: Error message string (null if no error)
198
- *
199
- * @example
200
- * ```tsx
201
- * function SubscribeButton({ planVersionId }) {
202
- * const { currentWorkspace } = useSaaSWorkspaces();
203
- * const { createCheckoutSession, loading } = useCreateCheckoutSession(currentWorkspace?._id);
204
- *
205
- * const handleSubscribe = async () => {
206
- * try {
207
- * const result = await createCheckoutSession({
208
- * planVersionId,
209
- * successUrl: window.location.href,
210
- * cancelUrl: window.location.href,
211
- * });
212
- * // Redirect to checkout
213
- * window.location.href = result.checkoutUrl;
214
- * } catch (error) {
215
- * console.error('Failed to create checkout:', error);
216
- * }
217
- * };
218
- *
219
- * return (
220
- * <button onClick={handleSubscribe} disabled={loading}>
221
- * {loading ? 'Loading...' : 'Subscribe'}
222
- * </button>
223
- * );
224
- * }
225
- * ```
226
- *
227
- * @example
228
- * ```tsx
229
- * // Edge case: Workspace ID not available
230
- * function SubscribeButton() {
231
- * const { currentWorkspace } = useSaaSWorkspaces();
232
- * const { createCheckoutSession } = useCreateCheckoutSession(currentWorkspace?._id);
233
- *
234
- * const handleSubscribe = async () => {
235
- * try {
236
- * await createCheckoutSession({ planVersionId: 'plan-123' });
237
- * } catch (error) {
238
- * // Error: "Workspace ID is required"
239
- * alert('Please select a workspace first');
240
- * }
241
- * };
242
- *
243
- * return <button onClick={handleSubscribe}>Subscribe</button>;
244
- * }
245
- * ```
246
- */
247
- export declare const useCreateCheckoutSession: (workspaceId: string | null | undefined) => {
248
- createCheckoutSession: (request: ICheckoutSessionRequest) => Promise<CheckoutResult>;
249
- loading: boolean;
250
- error: string | null;
251
- };
252
- /**
253
- * Hook to update subscription (upgrade/downgrade).
254
- * Returns checkout session if payment is required, otherwise returns subscription update response.
255
- *
256
- * @param workspaceId - The workspace ID to update subscription for. Can be null/undefined.
257
- * @returns An object containing:
258
- * - `updateSubscription(planVersionId, options?)`: Function to update subscription (throws if workspaceId is null)
259
- * - `loading`: Boolean indicating if subscription is being updated
260
- * - `error`: Error message string (null if no error)
261
- *
262
- * @example
263
- * ```tsx
264
- * function UpgradeButton({ planVersionId }) {
265
- * const { currentWorkspace } = useSaaSWorkspaces();
266
- * const { updateSubscription, loading } = useUpdateSubscription(currentWorkspace?._id);
267
- *
268
- * const handleUpgrade = async () => {
269
- * try {
270
- * const result = await updateSubscription(planVersionId, {
271
- * billingInterval: 'monthly',
272
- * successUrl: window.location.href,
273
- * cancelUrl: window.location.href,
274
- * });
275
- *
276
- * // Check if payment is required
277
- * if ('checkoutUrl' in result) {
278
- * window.location.href = result.checkoutUrl;
279
- * } else {
280
- * // Subscription updated without payment
281
- * alert('Subscription updated successfully!');
282
- * }
283
- * } catch (error) {
284
- * console.error('Failed to update subscription:', error);
285
- * }
286
- * };
287
- *
288
- * return (
289
- * <button onClick={handleUpgrade} disabled={loading}>
290
- * {loading ? 'Upgrading...' : 'Upgrade'}
291
- * </button>
292
- * );
293
- * }
294
- * ```
295
- *
296
- * @example
297
- * ```tsx
298
- * // Handle both checkout and direct update responses
299
- * function SubscriptionUpdater({ planVersionId }) {
300
- * const { updateSubscription } = useUpdateSubscription(workspaceId);
301
- *
302
- * const handleUpdate = async () => {
303
- * const result = await updateSubscription(planVersionId);
304
- *
305
- * // Type guard to check response type
306
- * if ('checkoutUrl' in result) {
307
- * // Redirect to payment
308
- * window.location.href = result.checkoutUrl;
309
- * } else {
310
- * // Direct update successful
311
- * console.log('Updated subscription:', result.subscription);
312
- * }
313
- * };
314
- *
315
- * return <button onClick={handleUpdate}>Update</button>;
316
- * }
317
- * ```
318
- */
319
- export declare const useUpdateSubscription: (workspaceId: string | null | undefined) => {
320
- updateSubscription: (planVersionId: string, options?: {
321
- billingInterval?: BillingInterval;
322
- successUrl?: string;
323
- cancelUrl?: string;
324
- }) => Promise<ISubscriptionUpdateResponse | ICheckoutSessionResponse>;
325
- loading: boolean;
326
- error: string | null;
327
- };
328
- /**
329
- * Combined hook that provides both subscription and plan group data.
330
- * Useful for subscription management pages that need both pieces of data.
331
- * Combines useSubscription, usePlanGroup, and useUpdateSubscription.
332
- *
333
- * @param workspaceId - The workspace ID. Can be null/undefined to disable fetching.
334
- * @param groupVersionId - Optional: specific group version ID to fetch
335
- * @returns An object containing:
336
- * - `subscription`: Current subscription data (from useSubscription)
337
- * - `planGroup`: Plan group data (from usePlanGroup)
338
- * - `loading`: Boolean indicating if any operation is in progress
339
- * - `error`: Error message string (null if no error)
340
- * - `updateSubscription(planVersionId, options?)`: Function to update subscription
341
- * - `refetch()`: Function to refetch both subscription and plan group
342
- *
343
- * @example
344
- * ```tsx
345
- * function SubscriptionManagementPage() {
346
- * const { currentWorkspace } = useSaaSWorkspaces();
347
- * const {
348
- * subscription,
349
- * planGroup,
350
- * loading,
351
- * updateSubscription,
352
- * refetch,
353
- * } = useSubscriptionManagement(currentWorkspace?._id);
354
- *
355
- * if (loading) return <Loading />;
356
- *
357
- * return (
358
- * <div>
359
- * <CurrentPlan subscription={subscription} />
360
- * <AvailablePlans planGroup={planGroup} onSelect={updateSubscription} />
361
- * <button onClick={refetch}>Refresh</button>
362
- * </div>
363
- * );
364
- * }
365
- * ```
366
- */
367
- export declare const useSubscriptionManagement: (workspaceId: string | null | undefined, groupVersionId?: string | null) => {
368
- subscription: ISubscriptionResponse | null;
369
- planGroup: IPlanGroupResponse | null;
370
- loading: boolean;
371
- error: string | null;
372
- updateSubscription: (planVersionId: string, options?: {
373
- billingInterval?: BillingInterval;
374
- successUrl?: string;
375
- cancelUrl?: string;
376
- }) => Promise<ISubscriptionUpdateResponse | ICheckoutSessionResponse>;
377
- refetch: () => Promise<void>;
378
- };
379
- /**
380
- * Hook to list invoices for a workspace subscription with pagination support.
381
- * Automatically fetches when workspaceId, limit, or startingAfter changes.
382
- *
383
- * @param workspaceId - The workspace ID to get invoices for. Can be null/undefined to disable fetching.
384
- * @param limit - Number of invoices to return (default: 10)
385
- * @param startingAfter - Invoice ID to start after (for pagination)
386
- * @returns An object containing:
387
- * - `invoices`: Array of invoice objects
388
- * - `hasMore`: Boolean indicating if there are more invoices to load
389
- * - `loading`: Boolean indicating if invoices are being fetched
390
- * - `error`: Error message string (null if no error)
391
- * - `refetch()`: Function to manually refetch invoices
392
- *
393
- * @example
394
- * ```tsx
395
- * function InvoiceList() {
396
- * const { currentWorkspace } = useSaaSWorkspaces();
397
- * const { invoices, hasMore, loading, refetch } = useInvoices(currentWorkspace?._id, 10);
398
- *
399
- * if (loading) return <Loading />;
400
- *
401
- * return (
402
- * <div>
403
- * {invoices.map(invoice => (
404
- * <InvoiceCard key={invoice._id} invoice={invoice} />
405
- * ))}
406
- * {hasMore && <button onClick={() => refetch()}>Load More</button>}
407
- * </div>
408
- * );
409
- * }
410
- * ```
411
- *
412
- * @example
413
- * ```tsx
414
- * // Pagination example
415
- * function PaginatedInvoices() {
416
- * const [lastInvoiceId, setLastInvoiceId] = useState<string | undefined>();
417
- * const { currentWorkspace } = useSaaSWorkspaces();
418
- * const { invoices, hasMore, refetch } = useInvoices(
419
- * currentWorkspace?._id,
420
- * 10,
421
- * lastInvoiceId
422
- * );
423
- *
424
- * const loadMore = () => {
425
- * if (invoices.length > 0) {
426
- * setLastInvoiceId(invoices[invoices.length - 1]._id);
427
- * }
428
- * };
429
- *
430
- * return (
431
- * <div>
432
- * {invoices.map(invoice => <InvoiceCard key={invoice._id} invoice={invoice} />)}
433
- * {hasMore && <button onClick={loadMore}>Load More</button>}
434
- * </div>
435
- * );
436
- * }
437
- * ```
438
- */
439
- export declare const useInvoices: (workspaceId: string | null | undefined, limit?: number, startingAfter?: string) => {
440
- invoices: IInvoice[];
441
- hasMore: boolean;
442
- loading: boolean;
443
- error: string | null;
444
- refetch: () => Promise<void>;
445
- };
446
- /**
447
- * Hook to get a single invoice by ID.
448
- * Automatically fetches when workspaceId or invoiceId changes.
449
- *
450
- * @param workspaceId - The workspace ID. Can be null/undefined to disable fetching.
451
- * @param invoiceId - The invoice ID to fetch. Can be null/undefined to disable fetching.
452
- * @returns An object containing:
453
- * - `invoice`: Invoice data object (null if not loaded)
454
- * - `loading`: Boolean indicating if invoice is being fetched
455
- * - `error`: Error message string (null if no error)
456
- * - `refetch()`: Function to manually refetch the invoice
457
- *
458
- * @example
459
- * ```tsx
460
- * function InvoiceDetails({ invoiceId }) {
461
- * const { currentWorkspace } = useSaaSWorkspaces();
462
- * const { invoice, loading, error } = useInvoice(currentWorkspace?._id, invoiceId);
463
- *
464
- * if (loading) return <Loading />;
465
- * if (error) return <Error message={error} />;
466
- * if (!invoice) return <p>Invoice not found</p>;
467
- *
468
- * return (
469
- * <div>
470
- * <h2>Invoice #{invoice.invoiceNumber}</h2>
471
- * <p>Amount: ${invoice.amount}</p>
472
- * <p>Status: {invoice.status}</p>
473
- * </div>
474
- * );
475
- * }
476
- * ```
477
- */
478
- export declare const useInvoice: (workspaceId: string | null | undefined, invoiceId: string | null | undefined) => {
479
- invoice: IInvoice | null;
480
- loading: boolean;
481
- error: string | null;
482
- refetch: () => Promise<void>;
483
- };
484
- /**
485
- * Hook to cancel a subscription at the end of the current billing period.
486
- * Sets cancelAtPeriodEnd: true - subscription remains active until period ends.
487
- *
488
- * @param workspaceId - The workspace ID. Can be null/undefined.
489
- * @returns An object containing:
490
- * - `cancelSubscription()`: Function to cancel subscription at period end
491
- * - `loading`: Boolean indicating if cancellation is in progress
492
- * - `error`: Error message string (null if no error)
493
- *
494
- * @example
495
- * ```tsx
496
- * function CancelSubscriptionButton() {
497
- * const { currentWorkspace } = useSaaSWorkspaces();
498
- * const { cancelSubscription, loading } = useCancelSubscription(currentWorkspace?._id);
499
- * const { refetch } = useSubscription(currentWorkspace?._id);
500
- *
501
- * const handleCancel = async () => {
502
- * try {
503
- * await cancelSubscription();
504
- * await refetch(); // Refresh subscription data
505
- * alert('Subscription will be canceled at the end of the billing period');
506
- * } catch (error) {
507
- * console.error('Failed to cancel:', error);
508
- * }
509
- * };
510
- *
511
- * return (
512
- * <button onClick={handleCancel} disabled={loading}>
513
- * {loading ? 'Canceling...' : 'Cancel Subscription'}
514
- * </button>
515
- * );
516
- * }
517
- * ```
518
- */
519
- export declare const useCancelSubscription: (workspaceId: string | null | undefined) => {
520
- cancelSubscription: () => Promise<ISubscriptionResponse>;
521
- loading: boolean;
522
- error: string | null;
523
- };
524
- /**
525
- * Hook to resume a subscription that was scheduled for cancellation.
526
- * Sets cancelAtPeriodEnd: false - subscription will continue after period ends.
527
- *
528
- * @param workspaceId - The workspace ID. Can be null/undefined.
529
- * @returns An object containing:
530
- * - `resumeSubscription()`: Function to resume subscription
531
- * - `loading`: Boolean indicating if resume is in progress
532
- * - `error`: Error message string (null if no error)
533
- *
534
- * @example
535
- * ```tsx
536
- * function ResumeSubscriptionButton() {
537
- * const { currentWorkspace } = useSaaSWorkspaces();
538
- * const { resumeSubscription, loading } = useResumeSubscription(currentWorkspace?._id);
539
- * const { refetch } = useSubscription(currentWorkspace?._id);
540
- *
541
- * const handleResume = async () => {
542
- * try {
543
- * await resumeSubscription();
544
- * await refetch(); // Refresh subscription data
545
- * alert('Subscription has been resumed');
546
- * } catch (error) {
547
- * console.error('Failed to resume:', error);
548
- * }
549
- * };
550
- *
551
- * return (
552
- * <button onClick={handleResume} disabled={loading}>
553
- * {loading ? 'Resuming...' : 'Resume Subscription'}
554
- * </button>
555
- * );
556
- * }
557
- * ```
558
- */
559
- export declare const useResumeSubscription: (workspaceId: string | null | undefined) => {
560
- resumeSubscription: () => Promise<ISubscriptionResponse>;
561
- loading: boolean;
562
- error: string | null;
563
- };
564
- /**
565
- * Hook to record quota usage for a workspace.
566
- * Returns a function to record usage (mutation pattern).
567
- *
568
- * @param workspaceId - The workspace ID. Can be null/undefined.
569
- * @returns An object containing:
570
- * - `recordUsage(request)`: Function to record usage (throws if workspaceId is null)
571
- * - `loading`: Boolean indicating if recording is in progress
572
- * - `error`: Error message string (null if no error)
573
- *
574
- * @example
575
- * ```tsx
576
- * function RecordUsageButton() {
577
- * const { currentWorkspace } = useSaaSWorkspaces();
578
- * const { recordUsage, loading } = useRecordUsage(currentWorkspace?._id);
579
- *
580
- * const handleRecord = async () => {
581
- * try {
582
- * const result = await recordUsage({
583
- * quotaSlug: 'api_calls',
584
- * quantity: 1,
585
- * source: 'web-app',
586
- * });
587
- * console.log(`Used: ${result.consumed}/${result.included}`);
588
- * } catch (error) {
589
- * console.error('Failed to record usage:', error);
590
- * }
591
- * };
592
- *
593
- * return (
594
- * <button onClick={handleRecord} disabled={loading}>
595
- * {loading ? 'Recording...' : 'Record Usage'}
596
- * </button>
597
- * );
598
- * }
599
- * ```
600
- */
601
- export declare const useRecordUsage: (workspaceId: string | null | undefined) => {
602
- recordUsage: (request: IRecordUsageRequest) => Promise<IRecordUsageResponse>;
603
- loading: boolean;
604
- error: string | null;
605
- };
606
- /**
607
- * Hook to get usage status for a single quota.
608
- * Automatically fetches when workspaceId or quotaSlug changes.
609
- *
610
- * @param workspaceId - The workspace ID. Can be null/undefined to disable fetching.
611
- * @param quotaSlug - The quota slug to check. Can be null/undefined to disable fetching.
612
- * @returns An object containing:
613
- * - `status`: Quota usage status (null if not loaded)
614
- * - `loading`: Boolean indicating if status is being fetched
615
- * - `error`: Error message string (null if no error)
616
- * - `refetch()`: Function to manually refetch the status
617
- *
618
- * @example
619
- * ```tsx
620
- * function QuotaStatusDisplay() {
621
- * const { currentWorkspace } = useSaaSWorkspaces();
622
- * const { status, loading } = useQuotaUsageStatus(currentWorkspace?._id, 'api_calls');
623
- *
624
- * if (loading) return <Loading />;
625
- * if (!status) return null;
626
- *
627
- * return (
628
- * <div>
629
- * <p>Used: {status.consumed} / {status.included}</p>
630
- * <p>Available: {status.available}</p>
631
- * {status.hasOverage && <p>Overage: {status.overage}</p>}
632
- * </div>
633
- * );
634
- * }
635
- * ```
636
- */
637
- export declare const useQuotaUsageStatus: (workspaceId: string | null | undefined, quotaSlug: string | null | undefined) => {
638
- status: IQuotaUsageStatusResponse | null;
639
- loading: boolean;
640
- error: string | null;
641
- refetch: () => Promise<void>;
642
- };
643
- /**
644
- * Hook to get usage status for all quotas in the workspace's current plan.
645
- * Automatically fetches when workspaceId changes.
646
- *
647
- * @param workspaceId - The workspace ID. Can be null/undefined to disable fetching.
648
- * @returns An object containing:
649
- * - `quotas`: Record of quota usage statuses keyed by slug (null if not loaded)
650
- * - `loading`: Boolean indicating if statuses are being fetched
651
- * - `error`: Error message string (null if no error)
652
- * - `refetch()`: Function to manually refetch all statuses
653
- *
654
- * @example
655
- * ```tsx
656
- * function AllQuotasDisplay() {
657
- * const { currentWorkspace } = useSaaSWorkspaces();
658
- * const { quotas, loading } = useAllQuotaUsage(currentWorkspace?._id);
659
- *
660
- * if (loading) return <Loading />;
661
- * if (!quotas) return null;
662
- *
663
- * return (
664
- * <div>
665
- * {Object.entries(quotas).map(([slug, usage]) => (
666
- * <div key={slug}>
667
- * <p>{slug}: {usage.consumed}/{usage.included}</p>
668
- * {usage.hasOverage && <p>Overage: {usage.overage}</p>}
669
- * </div>
670
- * ))}
671
- * </div>
672
- * );
673
- * }
674
- * ```
675
- */
676
- export declare const useAllQuotaUsage: (workspaceId: string | null | undefined) => {
677
- quotas: Record<string, IQuotaUsageStatus> | null;
678
- loading: boolean;
679
- error: string | null;
680
- refetch: () => Promise<void>;
681
- };
682
- /**
683
- * Hook to get paginated usage logs for a workspace.
684
- * Automatically fetches when workspaceId or filter params change.
685
- *
686
- * @param workspaceId - The workspace ID. Can be null/undefined to disable fetching.
687
- * @param quotaSlug - Optional quota slug to filter logs by.
688
- * @param options - Optional filters: from, to, source, page, limit
689
- * @returns An object containing:
690
- * - `logs`: Array of usage log entries
691
- * - `totalDocs`: Total number of log entries matching the query
692
- * - `totalPages`: Total number of pages
693
- * - `page`: Current page number
694
- * - `hasNextPage`: Whether there are more pages after the current one
695
- * - `hasPrevPage`: Whether there are pages before the current one
696
- * - `loading`: Boolean indicating if logs are being fetched
697
- * - `error`: Error message string (null if no error)
698
- * - `refetch()`: Function to manually refetch logs
699
- *
700
- * @example
701
- * ```tsx
702
- * function UsageLogsTable() {
703
- * const { currentWorkspace } = useSaaSWorkspaces();
704
- * const { logs, totalPages, page, hasNextPage, loading } = useUsageLogs(
705
- * currentWorkspace?._id,
706
- * 'api_calls',
707
- * { limit: 20 }
708
- * );
709
- *
710
- * if (loading) return <Loading />;
711
- *
712
- * return (
713
- * <div>
714
- * {logs.map(log => (
715
- * <div key={log._id}>
716
- * {log.quotaSlug}: {log.quantity} ({log.createdAt})
717
- * </div>
718
- * ))}
719
- * <p>Page {page} of {totalPages}</p>
720
- * </div>
721
- * );
722
- * }
723
- * ```
724
- */
725
- export declare const useUsageLogs: (workspaceId: string | null | undefined, quotaSlug?: string, options?: {
726
- from?: string;
727
- to?: string;
728
- source?: string;
729
- page?: number;
730
- limit?: number;
731
- }) => {
732
- logs: IUsageLogEntry[];
733
- totalDocs: number;
734
- totalPages: number;
735
- page: number;
736
- hasNextPage: boolean;
737
- hasPrevPage: boolean;
738
- loading: boolean;
739
- error: string | null;
740
- refetch: () => Promise<void>;
741
- };