@buildbase/sdk 0.0.19 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +521 -2
- package/dist/index.d.ts +564 -13
- package/dist/index.esm.js +5 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/types/api/types.d.ts +63 -0
- package/dist/types/components/features/index.d.ts +16 -4
- package/dist/types/components/quota/index.d.ts +121 -0
- package/dist/types/components/subscription/index.d.ts +12 -3
- package/dist/types/components/user/auth.d.ts +8 -2
- package/dist/types/components/user/role.d.ts +8 -2
- package/dist/types/contexts/QuotaUsageContext/QuotaUsageContext.d.ts +22 -0
- package/dist/types/contexts/QuotaUsageContext/index.d.ts +2 -0
- package/dist/types/contexts/QuotaUsageContext/quotaUsageInvalidation.d.ts +19 -0
- package/dist/types/contexts/QuotaUsageContext/types.d.ts +14 -0
- package/dist/types/contexts/SubscriptionContext/types.d.ts +2 -0
- package/dist/types/index.d.ts +7 -2
- package/dist/types/providers/workspace/api.d.ts +28 -1
- package/dist/types/providers/workspace/subscription-hooks.d.ts +179 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -255,6 +255,7 @@ interface IPlanGroupVersionsResponse {
|
|
|
255
255
|
interface ICheckoutSessionRequest {
|
|
256
256
|
planVersionId: string;
|
|
257
257
|
billingInterval?: BillingInterval;
|
|
258
|
+
currency?: string;
|
|
258
259
|
successUrl?: string;
|
|
259
260
|
cancelUrl?: string;
|
|
260
261
|
}
|
|
@@ -348,6 +349,68 @@ interface IInvoiceResponse {
|
|
|
348
349
|
success: boolean;
|
|
349
350
|
invoice: IInvoice;
|
|
350
351
|
}
|
|
352
|
+
/** Request body for POST .../workspaces/:id/subscription/usage */
|
|
353
|
+
interface IRecordUsageRequest {
|
|
354
|
+
quotaSlug: string;
|
|
355
|
+
quantity: number;
|
|
356
|
+
metadata?: Record<string, unknown>;
|
|
357
|
+
source?: string;
|
|
358
|
+
idempotencyKey?: string;
|
|
359
|
+
}
|
|
360
|
+
/** Response from POST .../workspaces/:id/subscription/usage */
|
|
361
|
+
interface IRecordUsageResponse {
|
|
362
|
+
used: number;
|
|
363
|
+
consumed: number;
|
|
364
|
+
included: number;
|
|
365
|
+
available: number;
|
|
366
|
+
overage: number;
|
|
367
|
+
billedAsync: boolean;
|
|
368
|
+
}
|
|
369
|
+
/** Single quota usage status (shared between status and all endpoints). */
|
|
370
|
+
interface IQuotaUsageStatus {
|
|
371
|
+
consumed: number;
|
|
372
|
+
included: number;
|
|
373
|
+
available: number;
|
|
374
|
+
overage: number;
|
|
375
|
+
hasOverage: boolean;
|
|
376
|
+
}
|
|
377
|
+
/** Response from GET .../workspaces/:id/subscription/usage/status?quotaSlug=X */
|
|
378
|
+
interface IQuotaUsageStatusResponse extends IQuotaUsageStatus {
|
|
379
|
+
quotaSlug: string;
|
|
380
|
+
}
|
|
381
|
+
/** Response from GET .../workspaces/:id/subscription/usage/all */
|
|
382
|
+
interface IAllQuotaUsageResponse {
|
|
383
|
+
quotas: Record<string, IQuotaUsageStatus>;
|
|
384
|
+
}
|
|
385
|
+
/** Single usage log entry from GET .../usage/logs */
|
|
386
|
+
interface IUsageLogEntry {
|
|
387
|
+
_id: string;
|
|
388
|
+
quotaSlug: string;
|
|
389
|
+
quantity: number;
|
|
390
|
+
source?: string;
|
|
391
|
+
workspace: string;
|
|
392
|
+
createdAt: string;
|
|
393
|
+
updatedAt: string;
|
|
394
|
+
}
|
|
395
|
+
/** Query parameters for GET .../workspaces/:id/subscription/usage/logs */
|
|
396
|
+
interface IUsageLogsQuery {
|
|
397
|
+
quotaSlug?: string;
|
|
398
|
+
from?: string;
|
|
399
|
+
to?: string;
|
|
400
|
+
source?: string;
|
|
401
|
+
page?: number;
|
|
402
|
+
limit?: number;
|
|
403
|
+
}
|
|
404
|
+
/** Paginated response from GET .../workspaces/:id/subscription/usage/logs */
|
|
405
|
+
interface IUsageLogsResponse {
|
|
406
|
+
docs: IUsageLogEntry[];
|
|
407
|
+
totalDocs: number;
|
|
408
|
+
limit: number;
|
|
409
|
+
page: number;
|
|
410
|
+
totalPages: number;
|
|
411
|
+
hasNextPage: boolean;
|
|
412
|
+
hasPrevPage: boolean;
|
|
413
|
+
}
|
|
351
414
|
|
|
352
415
|
interface IWorkspace {
|
|
353
416
|
_id: string;
|
|
@@ -634,7 +697,10 @@ interface IProps$2 {
|
|
|
634
697
|
* }
|
|
635
698
|
* ```
|
|
636
699
|
*/
|
|
637
|
-
declare const WhenAuthenticated:
|
|
700
|
+
declare const WhenAuthenticated: {
|
|
701
|
+
(props: IProps$2): react.ReactNode;
|
|
702
|
+
displayName: string;
|
|
703
|
+
};
|
|
638
704
|
/**
|
|
639
705
|
* Conditional component that renders children only when user is NOT authenticated.
|
|
640
706
|
* Returns null if user is authenticated.
|
|
@@ -676,7 +742,10 @@ declare const WhenAuthenticated: (props: IProps$2) => react.ReactNode;
|
|
|
676
742
|
* }
|
|
677
743
|
* ```
|
|
678
744
|
*/
|
|
679
|
-
declare const WhenUnauthenticated:
|
|
745
|
+
declare const WhenUnauthenticated: {
|
|
746
|
+
(props: IProps$2): react.ReactNode;
|
|
747
|
+
displayName: string;
|
|
748
|
+
};
|
|
680
749
|
|
|
681
750
|
interface IProps$1 {
|
|
682
751
|
roles: string[];
|
|
@@ -718,7 +787,10 @@ interface IProps$1 {
|
|
|
718
787
|
* }
|
|
719
788
|
* ```
|
|
720
789
|
*/
|
|
721
|
-
declare const WhenRoles:
|
|
790
|
+
declare const WhenRoles: {
|
|
791
|
+
(props: IProps$1): react.ReactNode;
|
|
792
|
+
displayName: string;
|
|
793
|
+
};
|
|
722
794
|
/**
|
|
723
795
|
* Conditional component that renders children only when user has one of the specified roles
|
|
724
796
|
* in the current workspace. Checks workspace-specific role, not global role.
|
|
@@ -754,7 +826,10 @@ declare const WhenRoles: (props: IProps$1) => react.ReactNode;
|
|
|
754
826
|
* }
|
|
755
827
|
* ```
|
|
756
828
|
*/
|
|
757
|
-
declare const WhenWorkspaceRoles:
|
|
829
|
+
declare const WhenWorkspaceRoles: {
|
|
830
|
+
(props: IProps$1): react.ReactNode;
|
|
831
|
+
displayName: string;
|
|
832
|
+
};
|
|
758
833
|
|
|
759
834
|
interface IProps {
|
|
760
835
|
slug: string;
|
|
@@ -796,7 +871,10 @@ interface IProps {
|
|
|
796
871
|
* }
|
|
797
872
|
* ```
|
|
798
873
|
*/
|
|
799
|
-
declare const WhenWorkspaceFeatureEnabled:
|
|
874
|
+
declare const WhenWorkspaceFeatureEnabled: {
|
|
875
|
+
(props: IProps): react.ReactNode;
|
|
876
|
+
displayName: string;
|
|
877
|
+
};
|
|
800
878
|
/**
|
|
801
879
|
* Conditional component that renders children only when the specified workspace feature is disabled.
|
|
802
880
|
* Checks feature flags at the workspace level.
|
|
@@ -816,7 +894,10 @@ declare const WhenWorkspaceFeatureEnabled: (props: IProps) => react.ReactNode;
|
|
|
816
894
|
* }
|
|
817
895
|
* ```
|
|
818
896
|
*/
|
|
819
|
-
declare const WhenWorkspaceFeatureDisabled:
|
|
897
|
+
declare const WhenWorkspaceFeatureDisabled: {
|
|
898
|
+
(props: IProps): react.ReactNode;
|
|
899
|
+
displayName: string;
|
|
900
|
+
};
|
|
820
901
|
/**
|
|
821
902
|
* Conditional component that renders children only when the specified user feature is enabled.
|
|
822
903
|
* Checks feature flags at the user level (from UserProvider).
|
|
@@ -852,7 +933,10 @@ declare const WhenWorkspaceFeatureDisabled: (props: IProps) => react.ReactNode;
|
|
|
852
933
|
* }
|
|
853
934
|
* ```
|
|
854
935
|
*/
|
|
855
|
-
declare const WhenUserFeatureEnabled:
|
|
936
|
+
declare const WhenUserFeatureEnabled: {
|
|
937
|
+
(props: IProps): react.ReactNode;
|
|
938
|
+
displayName: string;
|
|
939
|
+
};
|
|
856
940
|
/**
|
|
857
941
|
* Conditional component that renders children only when the specified user feature is disabled.
|
|
858
942
|
* Checks feature flags at the user level (from UserProvider).
|
|
@@ -872,7 +956,10 @@ declare const WhenUserFeatureEnabled: (props: IProps) => react.ReactNode;
|
|
|
872
956
|
* }
|
|
873
957
|
* ```
|
|
874
958
|
*/
|
|
875
|
-
declare const WhenUserFeatureDisabled:
|
|
959
|
+
declare const WhenUserFeatureDisabled: {
|
|
960
|
+
(props: IProps): react.ReactNode;
|
|
961
|
+
displayName: string;
|
|
962
|
+
};
|
|
876
963
|
|
|
877
964
|
interface IWhenSubscriptionProps {
|
|
878
965
|
/** Content to render when the condition is met (workspace has an active subscription). */
|
|
@@ -910,7 +997,10 @@ interface IWhenSubscriptionProps {
|
|
|
910
997
|
* </WhenSubscription>
|
|
911
998
|
* ```
|
|
912
999
|
*/
|
|
913
|
-
declare const WhenSubscription:
|
|
1000
|
+
declare const WhenSubscription: {
|
|
1001
|
+
(props: IWhenSubscriptionProps): react.ReactNode;
|
|
1002
|
+
displayName: string;
|
|
1003
|
+
};
|
|
914
1004
|
/**
|
|
915
1005
|
* Renders children only when the current workspace has no subscription (or no current workspace).
|
|
916
1006
|
* Optionally pass loadingComponent (while loading) or fallbackComponent (when already subscribed).
|
|
@@ -939,7 +1029,10 @@ declare const WhenSubscription: (props: IWhenSubscriptionProps) => react.ReactNo
|
|
|
939
1029
|
* </WhenNoSubscription>
|
|
940
1030
|
* ```
|
|
941
1031
|
*/
|
|
942
|
-
declare const WhenNoSubscription:
|
|
1032
|
+
declare const WhenNoSubscription: {
|
|
1033
|
+
(props: IWhenSubscriptionProps): react.ReactNode;
|
|
1034
|
+
displayName: string;
|
|
1035
|
+
};
|
|
943
1036
|
interface IWhenSubscriptionToPlansProps {
|
|
944
1037
|
/** Plan slugs to match (e.g. ['pro', 'enterprise']). Matching is case-insensitive. */
|
|
945
1038
|
plans: string[];
|
|
@@ -980,7 +1073,131 @@ interface IWhenSubscriptionToPlansProps {
|
|
|
980
1073
|
* </WhenSubscriptionToPlans>
|
|
981
1074
|
* ```
|
|
982
1075
|
*/
|
|
983
|
-
declare const WhenSubscriptionToPlans:
|
|
1076
|
+
declare const WhenSubscriptionToPlans: {
|
|
1077
|
+
(props: IWhenSubscriptionToPlansProps): react.ReactNode;
|
|
1078
|
+
displayName: string;
|
|
1079
|
+
};
|
|
1080
|
+
|
|
1081
|
+
interface IWhenQuotaProps {
|
|
1082
|
+
/** Quota slug to check (e.g. 'api_calls', 'emails', 'storage'). */
|
|
1083
|
+
slug: string;
|
|
1084
|
+
/** Content to render when the condition is met. */
|
|
1085
|
+
children: React.ReactNode;
|
|
1086
|
+
/** Optional component/element to show while quota usage is loading (e.g. <Skeleton />). */
|
|
1087
|
+
loadingComponent?: React.ReactNode;
|
|
1088
|
+
/** Optional component/element to show when condition is not met (e.g. <UpgradePrompt />). */
|
|
1089
|
+
fallbackComponent?: React.ReactNode;
|
|
1090
|
+
}
|
|
1091
|
+
interface IWhenQuotaThresholdProps extends IWhenQuotaProps {
|
|
1092
|
+
/** Usage percentage threshold (0-100). Children render when usage >= this percentage. */
|
|
1093
|
+
threshold: number;
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Renders children only when the specified quota has remaining units (available > 0).
|
|
1097
|
+
* Must be used within QuotaUsageContextProvider (included in SaaSOSProvider by default).
|
|
1098
|
+
*
|
|
1099
|
+
* @example
|
|
1100
|
+
* ```tsx
|
|
1101
|
+
* <WhenQuotaAvailable slug="api_calls">
|
|
1102
|
+
* <MakeApiCallButton />
|
|
1103
|
+
* </WhenQuotaAvailable>
|
|
1104
|
+
* ```
|
|
1105
|
+
*
|
|
1106
|
+
* @example
|
|
1107
|
+
* ```tsx
|
|
1108
|
+
* <WhenQuotaAvailable
|
|
1109
|
+
* slug="emails"
|
|
1110
|
+
* loadingComponent={<Skeleton />}
|
|
1111
|
+
* fallbackComponent={<p>Email quota exhausted. <UpgradeLink /></p>}
|
|
1112
|
+
* >
|
|
1113
|
+
* <SendEmailButton />
|
|
1114
|
+
* </WhenQuotaAvailable>
|
|
1115
|
+
* ```
|
|
1116
|
+
*/
|
|
1117
|
+
declare const WhenQuotaAvailable: {
|
|
1118
|
+
(props: IWhenQuotaProps): react.ReactNode;
|
|
1119
|
+
displayName: string;
|
|
1120
|
+
};
|
|
1121
|
+
/**
|
|
1122
|
+
* Renders children only when the specified quota is fully consumed (available <= 0).
|
|
1123
|
+
* Must be used within QuotaUsageContextProvider (included in SaaSOSProvider by default).
|
|
1124
|
+
*
|
|
1125
|
+
* @example
|
|
1126
|
+
* ```tsx
|
|
1127
|
+
* <WhenQuotaExhausted slug="api_calls">
|
|
1128
|
+
* <UpgradePrompt message="You've used all your API calls this month." />
|
|
1129
|
+
* </WhenQuotaExhausted>
|
|
1130
|
+
* ```
|
|
1131
|
+
*
|
|
1132
|
+
* @example
|
|
1133
|
+
* ```tsx
|
|
1134
|
+
* <WhenQuotaExhausted
|
|
1135
|
+
* slug="storage"
|
|
1136
|
+
* loadingComponent={<Spinner />}
|
|
1137
|
+
* fallbackComponent={null}
|
|
1138
|
+
* >
|
|
1139
|
+
* <StorageFullBanner />
|
|
1140
|
+
* </WhenQuotaExhausted>
|
|
1141
|
+
* ```
|
|
1142
|
+
*/
|
|
1143
|
+
declare const WhenQuotaExhausted: {
|
|
1144
|
+
(props: IWhenQuotaProps): react.ReactNode;
|
|
1145
|
+
displayName: string;
|
|
1146
|
+
};
|
|
1147
|
+
/**
|
|
1148
|
+
* Renders children only when the specified quota is in overage (consumed > included).
|
|
1149
|
+
* Must be used within QuotaUsageContextProvider (included in SaaSOSProvider by default).
|
|
1150
|
+
*
|
|
1151
|
+
* @example
|
|
1152
|
+
* ```tsx
|
|
1153
|
+
* <WhenQuotaOverage slug="api_calls">
|
|
1154
|
+
* <OverageBillingWarning />
|
|
1155
|
+
* </WhenQuotaOverage>
|
|
1156
|
+
* ```
|
|
1157
|
+
*
|
|
1158
|
+
* @example
|
|
1159
|
+
* ```tsx
|
|
1160
|
+
* <WhenQuotaOverage
|
|
1161
|
+
* slug="emails"
|
|
1162
|
+
* loadingComponent={<Skeleton />}
|
|
1163
|
+
* fallbackComponent={null}
|
|
1164
|
+
* >
|
|
1165
|
+
* <p>You are being billed for overage usage.</p>
|
|
1166
|
+
* </WhenQuotaOverage>
|
|
1167
|
+
* ```
|
|
1168
|
+
*/
|
|
1169
|
+
declare const WhenQuotaOverage: {
|
|
1170
|
+
(props: IWhenQuotaProps): react.ReactNode;
|
|
1171
|
+
displayName: string;
|
|
1172
|
+
};
|
|
1173
|
+
/**
|
|
1174
|
+
* Renders children when the specified quota's usage percentage reaches or exceeds the threshold.
|
|
1175
|
+
* Usage percentage = (consumed / included) * 100. If included is 0 and consumed > 0, treats as 100%.
|
|
1176
|
+
* Must be used within QuotaUsageContextProvider (included in SaaSOSProvider by default).
|
|
1177
|
+
*
|
|
1178
|
+
* @example
|
|
1179
|
+
* ```tsx
|
|
1180
|
+
* <WhenQuotaThreshold slug="api_calls" threshold={80}>
|
|
1181
|
+
* <p>Warning: You've used over 80% of your API calls.</p>
|
|
1182
|
+
* </WhenQuotaThreshold>
|
|
1183
|
+
* ```
|
|
1184
|
+
*
|
|
1185
|
+
* @example
|
|
1186
|
+
* ```tsx
|
|
1187
|
+
* <WhenQuotaThreshold
|
|
1188
|
+
* slug="storage"
|
|
1189
|
+
* threshold={90}
|
|
1190
|
+
* loadingComponent={<Spinner />}
|
|
1191
|
+
* fallbackComponent={null}
|
|
1192
|
+
* >
|
|
1193
|
+
* <StorageWarningBanner />
|
|
1194
|
+
* </WhenQuotaThreshold>
|
|
1195
|
+
* ```
|
|
1196
|
+
*/
|
|
1197
|
+
declare const WhenQuotaThreshold: {
|
|
1198
|
+
(props: IWhenQuotaThresholdProps): react.ReactNode;
|
|
1199
|
+
displayName: string;
|
|
1200
|
+
};
|
|
984
1201
|
|
|
985
1202
|
/**
|
|
986
1203
|
* Value provided by SubscriptionContext and returned by useSubscriptionContext.
|
|
@@ -990,6 +1207,8 @@ interface SubscriptionContextValue {
|
|
|
990
1207
|
response: ISubscriptionResponse | null;
|
|
991
1208
|
/** True while subscription is being fetched. */
|
|
992
1209
|
loading: boolean;
|
|
1210
|
+
/** Error message if the last fetch failed, or null. */
|
|
1211
|
+
error: string | null;
|
|
993
1212
|
/** Refetch subscription for the current workspace. Call after plan change (e.g. upgrade) or when subscription was updated elsewhere. */
|
|
994
1213
|
refetch: () => Promise<void>;
|
|
995
1214
|
}
|
|
@@ -1015,6 +1234,53 @@ declare const SubscriptionContextProvider: react__default.FC<{
|
|
|
1015
1234
|
*/
|
|
1016
1235
|
declare function useSubscriptionContext(): SubscriptionContextValue;
|
|
1017
1236
|
|
|
1237
|
+
/**
|
|
1238
|
+
* Notify all subscribers to refetch subscription (e.g. after update/cancel/resume).
|
|
1239
|
+
* Called internally by useUpdateSubscription, useCancelSubscription, useResumeSubscription on success.
|
|
1240
|
+
*/
|
|
1241
|
+
declare function invalidateSubscription(): void;
|
|
1242
|
+
|
|
1243
|
+
/**
|
|
1244
|
+
* Value provided by QuotaUsageContext and returned by useQuotaUsageContext.
|
|
1245
|
+
*/
|
|
1246
|
+
interface QuotaUsageContextValue {
|
|
1247
|
+
/** Current quota usage statuses keyed by slug, or null if not loaded. */
|
|
1248
|
+
quotas: Record<string, IQuotaUsageStatus> | null;
|
|
1249
|
+
/** True while quota usage is being fetched. */
|
|
1250
|
+
loading: boolean;
|
|
1251
|
+
/** Error message if the last fetch failed, or null. */
|
|
1252
|
+
error: string | null;
|
|
1253
|
+
/** Refetch all quota usage for the current workspace. Call after recording usage or when usage was updated elsewhere. */
|
|
1254
|
+
refetch: () => Promise<void>;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
/**
|
|
1258
|
+
* Provides quota usage data for the current workspace to quota gate components.
|
|
1259
|
+
* Fetches when workspace changes; refetches when quota usage is invalidated (e.g. after recording usage).
|
|
1260
|
+
* Must wrap (or be ancestor of) any component that uses WhenQuotaAvailable, WhenQuotaExhausted,
|
|
1261
|
+
* WhenQuotaOverage, WhenQuotaThreshold, or useQuotaUsageContext. Included in SaaSOSProvider by default.
|
|
1262
|
+
*
|
|
1263
|
+
* @param props - Component props
|
|
1264
|
+
* @param props.children - React tree that may use quota gates or useQuotaUsageContext
|
|
1265
|
+
* @returns Provider element that supplies quota usage context to descendants
|
|
1266
|
+
*/
|
|
1267
|
+
declare const QuotaUsageContextProvider: react__default.FC<{
|
|
1268
|
+
children: ReactNode;
|
|
1269
|
+
}>;
|
|
1270
|
+
/**
|
|
1271
|
+
* Returns quota usage data for the current workspace. Must be used within QuotaUsageContextProvider.
|
|
1272
|
+
*
|
|
1273
|
+
* @returns QuotaUsageContextValue - { quotas, loading, refetch }
|
|
1274
|
+
* @throws Error if used outside QuotaUsageContextProvider
|
|
1275
|
+
*/
|
|
1276
|
+
declare function useQuotaUsageContext(): QuotaUsageContextValue;
|
|
1277
|
+
|
|
1278
|
+
/**
|
|
1279
|
+
* Notify all subscribers to refetch quota usage (e.g. after recording usage).
|
|
1280
|
+
* Called internally by useRecordUsage on success.
|
|
1281
|
+
*/
|
|
1282
|
+
declare function invalidateQuotaUsage(): void;
|
|
1283
|
+
|
|
1018
1284
|
type WorkspaceSettingsSection = 'profile' | 'general' | 'users' | 'subscription' | 'features' | 'danger';
|
|
1019
1285
|
|
|
1020
1286
|
declare function useSaaSAuth(): {
|
|
@@ -1354,6 +1620,33 @@ declare class WorkspaceApi extends BaseApi {
|
|
|
1354
1620
|
* @returns Updated subscription with cancelAtPeriodEnd set to false
|
|
1355
1621
|
*/
|
|
1356
1622
|
resumeSubscription(workspaceId: string): Promise<ISubscriptionResponse>;
|
|
1623
|
+
/**
|
|
1624
|
+
* Record quota usage for a workspace
|
|
1625
|
+
* @param workspaceId - The workspace ID
|
|
1626
|
+
* @param request - Usage request with quotaSlug, quantity, and optional metadata/source
|
|
1627
|
+
* @returns Usage result with consumed/included/available/overage
|
|
1628
|
+
*/
|
|
1629
|
+
recordUsage(workspaceId: string, request: IRecordUsageRequest): Promise<IRecordUsageResponse>;
|
|
1630
|
+
/**
|
|
1631
|
+
* Get usage status for a single quota
|
|
1632
|
+
* @param workspaceId - The workspace ID
|
|
1633
|
+
* @param quotaSlug - The quota slug to check
|
|
1634
|
+
* @returns Quota usage status with consumed/included/available/overage/hasOverage
|
|
1635
|
+
*/
|
|
1636
|
+
getQuotaUsageStatus(workspaceId: string, quotaSlug: string): Promise<IQuotaUsageStatusResponse>;
|
|
1637
|
+
/**
|
|
1638
|
+
* Get usage status for all quotas in the workspace's current plan
|
|
1639
|
+
* @param workspaceId - The workspace ID
|
|
1640
|
+
* @returns All quota usage statuses keyed by quota slug
|
|
1641
|
+
*/
|
|
1642
|
+
getAllQuotaUsage(workspaceId: string): Promise<IAllQuotaUsageResponse>;
|
|
1643
|
+
/**
|
|
1644
|
+
* Get paginated usage logs for a workspace
|
|
1645
|
+
* @param workspaceId - The workspace ID
|
|
1646
|
+
* @param query - Optional filters: quotaSlug, from, to, source, page, limit
|
|
1647
|
+
* @returns Paginated usage log entries
|
|
1648
|
+
*/
|
|
1649
|
+
getUsageLogs(workspaceId: string, query?: IUsageLogsQuery): Promise<IUsageLogsResponse>;
|
|
1357
1650
|
}
|
|
1358
1651
|
|
|
1359
1652
|
declare const useSaaSWorkspaces: () => {
|
|
@@ -1888,6 +2181,264 @@ declare const useInvoice: (workspaceId: string | null | undefined, invoiceId: st
|
|
|
1888
2181
|
error: string | null;
|
|
1889
2182
|
refetch: () => Promise<void>;
|
|
1890
2183
|
};
|
|
2184
|
+
/**
|
|
2185
|
+
* Hook to cancel a subscription at the end of the current billing period.
|
|
2186
|
+
* Sets cancelAtPeriodEnd: true - subscription remains active until period ends.
|
|
2187
|
+
*
|
|
2188
|
+
* @param workspaceId - The workspace ID. Can be null/undefined.
|
|
2189
|
+
* @returns An object containing:
|
|
2190
|
+
* - `cancelSubscription()`: Function to cancel subscription at period end
|
|
2191
|
+
* - `loading`: Boolean indicating if cancellation is in progress
|
|
2192
|
+
* - `error`: Error message string (null if no error)
|
|
2193
|
+
*
|
|
2194
|
+
* @example
|
|
2195
|
+
* ```tsx
|
|
2196
|
+
* function CancelSubscriptionButton() {
|
|
2197
|
+
* const { currentWorkspace } = useSaaSWorkspaces();
|
|
2198
|
+
* const { cancelSubscription, loading } = useCancelSubscription(currentWorkspace?._id);
|
|
2199
|
+
* const { refetch } = useSubscription(currentWorkspace?._id);
|
|
2200
|
+
*
|
|
2201
|
+
* const handleCancel = async () => {
|
|
2202
|
+
* try {
|
|
2203
|
+
* await cancelSubscription();
|
|
2204
|
+
* await refetch(); // Refresh subscription data
|
|
2205
|
+
* alert('Subscription will be canceled at the end of the billing period');
|
|
2206
|
+
* } catch (error) {
|
|
2207
|
+
* console.error('Failed to cancel:', error);
|
|
2208
|
+
* }
|
|
2209
|
+
* };
|
|
2210
|
+
*
|
|
2211
|
+
* return (
|
|
2212
|
+
* <button onClick={handleCancel} disabled={loading}>
|
|
2213
|
+
* {loading ? 'Canceling...' : 'Cancel Subscription'}
|
|
2214
|
+
* </button>
|
|
2215
|
+
* );
|
|
2216
|
+
* }
|
|
2217
|
+
* ```
|
|
2218
|
+
*/
|
|
2219
|
+
declare const useCancelSubscription: (workspaceId: string | null | undefined) => {
|
|
2220
|
+
cancelSubscription: () => Promise<ISubscriptionResponse>;
|
|
2221
|
+
loading: boolean;
|
|
2222
|
+
error: string | null;
|
|
2223
|
+
};
|
|
2224
|
+
/**
|
|
2225
|
+
* Hook to resume a subscription that was scheduled for cancellation.
|
|
2226
|
+
* Sets cancelAtPeriodEnd: false - subscription will continue after period ends.
|
|
2227
|
+
*
|
|
2228
|
+
* @param workspaceId - The workspace ID. Can be null/undefined.
|
|
2229
|
+
* @returns An object containing:
|
|
2230
|
+
* - `resumeSubscription()`: Function to resume subscription
|
|
2231
|
+
* - `loading`: Boolean indicating if resume is in progress
|
|
2232
|
+
* - `error`: Error message string (null if no error)
|
|
2233
|
+
*
|
|
2234
|
+
* @example
|
|
2235
|
+
* ```tsx
|
|
2236
|
+
* function ResumeSubscriptionButton() {
|
|
2237
|
+
* const { currentWorkspace } = useSaaSWorkspaces();
|
|
2238
|
+
* const { resumeSubscription, loading } = useResumeSubscription(currentWorkspace?._id);
|
|
2239
|
+
* const { refetch } = useSubscription(currentWorkspace?._id);
|
|
2240
|
+
*
|
|
2241
|
+
* const handleResume = async () => {
|
|
2242
|
+
* try {
|
|
2243
|
+
* await resumeSubscription();
|
|
2244
|
+
* await refetch(); // Refresh subscription data
|
|
2245
|
+
* alert('Subscription has been resumed');
|
|
2246
|
+
* } catch (error) {
|
|
2247
|
+
* console.error('Failed to resume:', error);
|
|
2248
|
+
* }
|
|
2249
|
+
* };
|
|
2250
|
+
*
|
|
2251
|
+
* return (
|
|
2252
|
+
* <button onClick={handleResume} disabled={loading}>
|
|
2253
|
+
* {loading ? 'Resuming...' : 'Resume Subscription'}
|
|
2254
|
+
* </button>
|
|
2255
|
+
* );
|
|
2256
|
+
* }
|
|
2257
|
+
* ```
|
|
2258
|
+
*/
|
|
2259
|
+
declare const useResumeSubscription: (workspaceId: string | null | undefined) => {
|
|
2260
|
+
resumeSubscription: () => Promise<ISubscriptionResponse>;
|
|
2261
|
+
loading: boolean;
|
|
2262
|
+
error: string | null;
|
|
2263
|
+
};
|
|
2264
|
+
/**
|
|
2265
|
+
* Hook to record quota usage for a workspace.
|
|
2266
|
+
* Returns a function to record usage (mutation pattern).
|
|
2267
|
+
*
|
|
2268
|
+
* @param workspaceId - The workspace ID. Can be null/undefined.
|
|
2269
|
+
* @returns An object containing:
|
|
2270
|
+
* - `recordUsage(request)`: Function to record usage (throws if workspaceId is null)
|
|
2271
|
+
* - `loading`: Boolean indicating if recording is in progress
|
|
2272
|
+
* - `error`: Error message string (null if no error)
|
|
2273
|
+
*
|
|
2274
|
+
* @example
|
|
2275
|
+
* ```tsx
|
|
2276
|
+
* function RecordUsageButton() {
|
|
2277
|
+
* const { currentWorkspace } = useSaaSWorkspaces();
|
|
2278
|
+
* const { recordUsage, loading } = useRecordUsage(currentWorkspace?._id);
|
|
2279
|
+
*
|
|
2280
|
+
* const handleRecord = async () => {
|
|
2281
|
+
* try {
|
|
2282
|
+
* const result = await recordUsage({
|
|
2283
|
+
* quotaSlug: 'api_calls',
|
|
2284
|
+
* quantity: 1,
|
|
2285
|
+
* source: 'web-app',
|
|
2286
|
+
* });
|
|
2287
|
+
* console.log(`Used: ${result.consumed}/${result.included}`);
|
|
2288
|
+
* } catch (error) {
|
|
2289
|
+
* console.error('Failed to record usage:', error);
|
|
2290
|
+
* }
|
|
2291
|
+
* };
|
|
2292
|
+
*
|
|
2293
|
+
* return (
|
|
2294
|
+
* <button onClick={handleRecord} disabled={loading}>
|
|
2295
|
+
* {loading ? 'Recording...' : 'Record Usage'}
|
|
2296
|
+
* </button>
|
|
2297
|
+
* );
|
|
2298
|
+
* }
|
|
2299
|
+
* ```
|
|
2300
|
+
*/
|
|
2301
|
+
declare const useRecordUsage: (workspaceId: string | null | undefined) => {
|
|
2302
|
+
recordUsage: (request: IRecordUsageRequest) => Promise<IRecordUsageResponse>;
|
|
2303
|
+
loading: boolean;
|
|
2304
|
+
error: string | null;
|
|
2305
|
+
};
|
|
2306
|
+
/**
|
|
2307
|
+
* Hook to get usage status for a single quota.
|
|
2308
|
+
* Automatically fetches when workspaceId or quotaSlug changes.
|
|
2309
|
+
*
|
|
2310
|
+
* @param workspaceId - The workspace ID. Can be null/undefined to disable fetching.
|
|
2311
|
+
* @param quotaSlug - The quota slug to check. Can be null/undefined to disable fetching.
|
|
2312
|
+
* @returns An object containing:
|
|
2313
|
+
* - `status`: Quota usage status (null if not loaded)
|
|
2314
|
+
* - `loading`: Boolean indicating if status is being fetched
|
|
2315
|
+
* - `error`: Error message string (null if no error)
|
|
2316
|
+
* - `refetch()`: Function to manually refetch the status
|
|
2317
|
+
*
|
|
2318
|
+
* @example
|
|
2319
|
+
* ```tsx
|
|
2320
|
+
* function QuotaStatusDisplay() {
|
|
2321
|
+
* const { currentWorkspace } = useSaaSWorkspaces();
|
|
2322
|
+
* const { status, loading } = useQuotaUsageStatus(currentWorkspace?._id, 'api_calls');
|
|
2323
|
+
*
|
|
2324
|
+
* if (loading) return <Loading />;
|
|
2325
|
+
* if (!status) return null;
|
|
2326
|
+
*
|
|
2327
|
+
* return (
|
|
2328
|
+
* <div>
|
|
2329
|
+
* <p>Used: {status.consumed} / {status.included}</p>
|
|
2330
|
+
* <p>Available: {status.available}</p>
|
|
2331
|
+
* {status.hasOverage && <p>Overage: {status.overage}</p>}
|
|
2332
|
+
* </div>
|
|
2333
|
+
* );
|
|
2334
|
+
* }
|
|
2335
|
+
* ```
|
|
2336
|
+
*/
|
|
2337
|
+
declare const useQuotaUsageStatus: (workspaceId: string | null | undefined, quotaSlug: string | null | undefined) => {
|
|
2338
|
+
status: IQuotaUsageStatusResponse | null;
|
|
2339
|
+
loading: boolean;
|
|
2340
|
+
error: string | null;
|
|
2341
|
+
refetch: () => Promise<void>;
|
|
2342
|
+
};
|
|
2343
|
+
/**
|
|
2344
|
+
* Hook to get usage status for all quotas in the workspace's current plan.
|
|
2345
|
+
* Automatically fetches when workspaceId changes.
|
|
2346
|
+
*
|
|
2347
|
+
* @param workspaceId - The workspace ID. Can be null/undefined to disable fetching.
|
|
2348
|
+
* @returns An object containing:
|
|
2349
|
+
* - `quotas`: Record of quota usage statuses keyed by slug (null if not loaded)
|
|
2350
|
+
* - `loading`: Boolean indicating if statuses are being fetched
|
|
2351
|
+
* - `error`: Error message string (null if no error)
|
|
2352
|
+
* - `refetch()`: Function to manually refetch all statuses
|
|
2353
|
+
*
|
|
2354
|
+
* @example
|
|
2355
|
+
* ```tsx
|
|
2356
|
+
* function AllQuotasDisplay() {
|
|
2357
|
+
* const { currentWorkspace } = useSaaSWorkspaces();
|
|
2358
|
+
* const { quotas, loading } = useAllQuotaUsage(currentWorkspace?._id);
|
|
2359
|
+
*
|
|
2360
|
+
* if (loading) return <Loading />;
|
|
2361
|
+
* if (!quotas) return null;
|
|
2362
|
+
*
|
|
2363
|
+
* return (
|
|
2364
|
+
* <div>
|
|
2365
|
+
* {Object.entries(quotas).map(([slug, usage]) => (
|
|
2366
|
+
* <div key={slug}>
|
|
2367
|
+
* <p>{slug}: {usage.consumed}/{usage.included}</p>
|
|
2368
|
+
* {usage.hasOverage && <p>Overage: {usage.overage}</p>}
|
|
2369
|
+
* </div>
|
|
2370
|
+
* ))}
|
|
2371
|
+
* </div>
|
|
2372
|
+
* );
|
|
2373
|
+
* }
|
|
2374
|
+
* ```
|
|
2375
|
+
*/
|
|
2376
|
+
declare const useAllQuotaUsage: (workspaceId: string | null | undefined) => {
|
|
2377
|
+
quotas: Record<string, IQuotaUsageStatus> | null;
|
|
2378
|
+
loading: boolean;
|
|
2379
|
+
error: string | null;
|
|
2380
|
+
refetch: () => Promise<void>;
|
|
2381
|
+
};
|
|
2382
|
+
/**
|
|
2383
|
+
* Hook to get paginated usage logs for a workspace.
|
|
2384
|
+
* Automatically fetches when workspaceId or filter params change.
|
|
2385
|
+
*
|
|
2386
|
+
* @param workspaceId - The workspace ID. Can be null/undefined to disable fetching.
|
|
2387
|
+
* @param quotaSlug - Optional quota slug to filter logs by.
|
|
2388
|
+
* @param options - Optional filters: from, to, source, page, limit
|
|
2389
|
+
* @returns An object containing:
|
|
2390
|
+
* - `logs`: Array of usage log entries
|
|
2391
|
+
* - `totalDocs`: Total number of log entries matching the query
|
|
2392
|
+
* - `totalPages`: Total number of pages
|
|
2393
|
+
* - `page`: Current page number
|
|
2394
|
+
* - `hasNextPage`: Whether there are more pages after the current one
|
|
2395
|
+
* - `hasPrevPage`: Whether there are pages before the current one
|
|
2396
|
+
* - `loading`: Boolean indicating if logs are being fetched
|
|
2397
|
+
* - `error`: Error message string (null if no error)
|
|
2398
|
+
* - `refetch()`: Function to manually refetch logs
|
|
2399
|
+
*
|
|
2400
|
+
* @example
|
|
2401
|
+
* ```tsx
|
|
2402
|
+
* function UsageLogsTable() {
|
|
2403
|
+
* const { currentWorkspace } = useSaaSWorkspaces();
|
|
2404
|
+
* const { logs, totalPages, page, hasNextPage, loading } = useUsageLogs(
|
|
2405
|
+
* currentWorkspace?._id,
|
|
2406
|
+
* 'api_calls',
|
|
2407
|
+
* { limit: 20 }
|
|
2408
|
+
* );
|
|
2409
|
+
*
|
|
2410
|
+
* if (loading) return <Loading />;
|
|
2411
|
+
*
|
|
2412
|
+
* return (
|
|
2413
|
+
* <div>
|
|
2414
|
+
* {logs.map(log => (
|
|
2415
|
+
* <div key={log._id}>
|
|
2416
|
+
* {log.quotaSlug}: {log.quantity} ({log.createdAt})
|
|
2417
|
+
* </div>
|
|
2418
|
+
* ))}
|
|
2419
|
+
* <p>Page {page} of {totalPages}</p>
|
|
2420
|
+
* </div>
|
|
2421
|
+
* );
|
|
2422
|
+
* }
|
|
2423
|
+
* ```
|
|
2424
|
+
*/
|
|
2425
|
+
declare const useUsageLogs: (workspaceId: string | null | undefined, quotaSlug?: string, options?: {
|
|
2426
|
+
from?: string;
|
|
2427
|
+
to?: string;
|
|
2428
|
+
source?: string;
|
|
2429
|
+
page?: number;
|
|
2430
|
+
limit?: number;
|
|
2431
|
+
}) => {
|
|
2432
|
+
logs: IUsageLogEntry[];
|
|
2433
|
+
totalDocs: number;
|
|
2434
|
+
totalPages: number;
|
|
2435
|
+
page: number;
|
|
2436
|
+
hasNextPage: boolean;
|
|
2437
|
+
hasPrevPage: boolean;
|
|
2438
|
+
loading: boolean;
|
|
2439
|
+
error: string | null;
|
|
2440
|
+
refetch: () => Promise<void>;
|
|
2441
|
+
};
|
|
1891
2442
|
|
|
1892
2443
|
/**
|
|
1893
2444
|
* EventEmitter class to handle and trigger event callbacks
|
|
@@ -2101,5 +2652,5 @@ interface FormatQuotaWithPriceOptions {
|
|
|
2101
2652
|
*/
|
|
2102
2653
|
declare function formatQuotaWithPrice(value: QuotaDisplayValue, unitName: string, options?: FormatQuotaWithPriceOptions): string;
|
|
2103
2654
|
|
|
2104
|
-
export { ApiVersion, AuthStatus, BaseApi, BetaForm, CURRENCY_DISPLAY, CURRENCY_FLAG, PLAN_CURRENCY_CODES, PLAN_CURRENCY_OPTIONS, PricingPage, SaaSOSProvider, SettingsApi, SubscriptionContextProvider, UserApi, WhenAuthenticated, WhenNoSubscription, WhenRoles, WhenSubscription, WhenSubscriptionToPlans, WhenUnauthenticated, WhenUserFeatureDisabled, WhenUserFeatureEnabled, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceApi, WorkspaceSwitcher, eventEmitter, formatCents, formatOverageRate, formatOverageRateWithLabel, formatQuotaIncludedOverage, formatQuotaWithPrice, getAvailableCurrenciesFromPlans, getBasePriceCents, getBillingIntervalAndCurrencyFromPriceId, getCurrencyFlag, getCurrencySymbol, getDisplayCurrency, getPricingVariant, getQuotaDisplayValue, getQuotaDisplayWithVariant, getQuotaOverageCents, getQuotaUnitLabelFromName, getStripePriceIdForInterval, useCreateCheckoutSession, useInvoice, useInvoices, usePlanGroup, usePlanGroupVersions, usePublicPlanGroupVersion, usePublicPlans, useSaaSAuth, useSaaSOs, useSaaSSettings, useSaaSWorkspaces, useSubscription, useSubscriptionContext, useSubscriptionManagement, useUpdateSubscription, useUserAttributes, useUserFeatures };
|
|
2105
|
-
export type { BillingInterval, EventData, EventType, FormatQuotaWithPriceOptions, IBaseApiConfig, IBasePricing, ICheckoutSessionRequest, ICheckoutSessionResponse, IEventCallbacks, IInvoice, IInvoiceListResponse, IInvoiceResponse, IPlan, IPlanGroup, IPlanGroupInfo, IPlanGroupLatestVersion, IPlanGroupResponse, IPlanGroupVersion, IPlanGroupVersionWithPlans, IPlanGroupVersionsResponse, IPlanVersion, IPlanVersionSummary, IPlanVersionWithPlan, IPricingVariant, IPublicPlanItem, IPublicPlanItemCategory, IPublicPlanVersion, IPublicPlansResponse, IQuotaByInterval, IQuotaIntervalValue, IQuotaOveragePriceIdsByInterval, IQuotaOveragesByInterval, IStripePricesByInterval, ISubscription, ISubscriptionItem, ISubscriptionResponse, ISubscriptionUpdateRequest, ISubscriptionUpdateResponse, InvoiceStatus, OnWorkspaceChangeParams, PlanVersionWithPricingVariants, PricingPageDetails, PricingPageProps, QuotaDisplayValue, QuotaDisplayWithOverage, SubscriptionContextValue, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };
|
|
2655
|
+
export { ApiVersion, AuthStatus, BaseApi, BetaForm, CURRENCY_DISPLAY, CURRENCY_FLAG, PLAN_CURRENCY_CODES, PLAN_CURRENCY_OPTIONS, PricingPage, QuotaUsageContextProvider, SaaSOSProvider, SettingsApi, SubscriptionContextProvider, UserApi, WhenAuthenticated, WhenNoSubscription, WhenQuotaAvailable, WhenQuotaExhausted, WhenQuotaOverage, WhenQuotaThreshold, WhenRoles, WhenSubscription, WhenSubscriptionToPlans, WhenUnauthenticated, WhenUserFeatureDisabled, WhenUserFeatureEnabled, WhenWorkspaceFeatureDisabled, WhenWorkspaceFeatureEnabled, WhenWorkspaceRoles, WorkspaceApi, WorkspaceSwitcher, eventEmitter, formatCents, formatOverageRate, formatOverageRateWithLabel, formatQuotaIncludedOverage, formatQuotaWithPrice, getAvailableCurrenciesFromPlans, getBasePriceCents, getBillingIntervalAndCurrencyFromPriceId, getCurrencyFlag, getCurrencySymbol, getDisplayCurrency, getPricingVariant, getQuotaDisplayValue, getQuotaDisplayWithVariant, getQuotaOverageCents, getQuotaUnitLabelFromName, getStripePriceIdForInterval, invalidateQuotaUsage, invalidateSubscription, useAllQuotaUsage, useCancelSubscription, useCreateCheckoutSession, useInvoice, useInvoices, usePlanGroup, usePlanGroupVersions, usePublicPlanGroupVersion, usePublicPlans, useQuotaUsageContext, useQuotaUsageStatus, useRecordUsage, useResumeSubscription, useSaaSAuth, useSaaSOs, useSaaSSettings, useSaaSWorkspaces, useSubscription, useSubscriptionContext, useSubscriptionManagement, useUpdateSubscription, useUsageLogs, useUserAttributes, useUserFeatures };
|
|
2656
|
+
export type { BillingInterval, EventData, EventType, FormatQuotaWithPriceOptions, IAllQuotaUsageResponse, IBaseApiConfig, IBasePricing, ICheckoutSessionRequest, ICheckoutSessionResponse, IEventCallbacks, IInvoice, IInvoiceListResponse, IInvoiceResponse, 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, InvoiceStatus, OnWorkspaceChangeParams, PlanVersionWithPricingVariants, PricingPageDetails, PricingPageProps, QuotaDisplayValue, QuotaDisplayWithOverage, QuotaUsageContextValue, SubscriptionContextValue, UserCreatedEventData, UserUpdatedEventData, WorkspaceChangedEventData, WorkspaceCreatedEventData, WorkspaceDeletedEventData, WorkspaceUpdatedEventData, WorkspaceUserAddedEventData, WorkspaceUserRemovedEventData, WorkspaceUserRoleChangedEventData };
|