@stigmer/react 3.39.1-dev.20260928194002 → 3.40.0

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 (180) hide show
  1. package/billing/AutoRechargeCard.js +1 -1
  2. package/billing/AutoRechargeCard.js.map +1 -1
  3. package/billing/BillingSection.d.ts +18 -1
  4. package/billing/BillingSection.d.ts.map +1 -1
  5. package/billing/BillingSection.js +21 -11
  6. package/billing/BillingSection.js.map +1 -1
  7. package/billing/ChangePlanDialog.d.ts +46 -0
  8. package/billing/ChangePlanDialog.d.ts.map +1 -0
  9. package/billing/ChangePlanDialog.js +90 -0
  10. package/billing/ChangePlanDialog.js.map +1 -0
  11. package/billing/CreditPackGrid.d.ts +1 -1
  12. package/billing/CreditPackGrid.js +1 -1
  13. package/billing/LowBalanceBanner.js +1 -1
  14. package/billing/LowBalanceBanner.js.map +1 -1
  15. package/billing/PaymentMethodCard.d.ts +9 -1
  16. package/billing/PaymentMethodCard.d.ts.map +1 -1
  17. package/billing/PaymentMethodCard.js +2 -2
  18. package/billing/PaymentMethodCard.js.map +1 -1
  19. package/billing/PlanCard.d.ts +27 -0
  20. package/billing/PlanCard.d.ts.map +1 -0
  21. package/billing/PlanCard.js +68 -0
  22. package/billing/PlanCard.js.map +1 -0
  23. package/billing/PlanPicker.d.ts +34 -0
  24. package/billing/PlanPicker.d.ts.map +1 -0
  25. package/billing/PlanPicker.js +46 -0
  26. package/billing/PlanPicker.js.map +1 -0
  27. package/billing/PlanSection.d.ts +45 -0
  28. package/billing/PlanSection.d.ts.map +1 -0
  29. package/billing/PlanSection.js +136 -0
  30. package/billing/PlanSection.js.map +1 -0
  31. package/billing/UpgradeNotice.d.ts +47 -0
  32. package/billing/UpgradeNotice.d.ts.map +1 -0
  33. package/billing/UpgradeNotice.js +49 -0
  34. package/billing/UpgradeNotice.js.map +1 -0
  35. package/billing/credit-packs.d.ts.map +1 -1
  36. package/billing/credit-packs.js +4 -1
  37. package/billing/credit-packs.js.map +1 -1
  38. package/billing/index.d.ts +26 -1
  39. package/billing/index.d.ts.map +1 -1
  40. package/billing/index.js +12 -0
  41. package/billing/index.js.map +1 -1
  42. package/billing/plan-features.d.ts +60 -0
  43. package/billing/plan-features.d.ts.map +1 -0
  44. package/billing/plan-features.js +128 -0
  45. package/billing/plan-features.js.map +1 -0
  46. package/billing/plan-state.d.ts +43 -0
  47. package/billing/plan-state.d.ts.map +1 -0
  48. package/billing/plan-state.js +69 -0
  49. package/billing/plan-state.js.map +1 -0
  50. package/billing/redirect.d.ts +31 -0
  51. package/billing/redirect.d.ts.map +1 -0
  52. package/billing/redirect.js +30 -0
  53. package/billing/redirect.js.map +1 -0
  54. package/billing/useBillingAccount.d.ts +10 -1
  55. package/billing/useBillingAccount.d.ts.map +1 -1
  56. package/billing/useBillingAccount.js +2 -2
  57. package/billing/useBillingAccount.js.map +1 -1
  58. package/billing/useChangePlan.d.ts +51 -0
  59. package/billing/useChangePlan.d.ts.map +1 -0
  60. package/billing/useChangePlan.js +61 -0
  61. package/billing/useChangePlan.js.map +1 -0
  62. package/billing/useCreateBillingPortalSession.d.ts +6 -3
  63. package/billing/useCreateBillingPortalSession.d.ts.map +1 -1
  64. package/billing/useCreateBillingPortalSession.js +11 -4
  65. package/billing/useCreateBillingPortalSession.js.map +1 -1
  66. package/billing/useCreateCheckoutSession.d.ts +7 -5
  67. package/billing/useCreateCheckoutSession.d.ts.map +1 -1
  68. package/billing/useCreateCheckoutSession.js +5 -3
  69. package/billing/useCreateCheckoutSession.js.map +1 -1
  70. package/billing/useCreatePaymentMethodSetupSession.d.ts +28 -0
  71. package/billing/useCreatePaymentMethodSetupSession.d.ts.map +1 -0
  72. package/billing/useCreatePaymentMethodSetupSession.js +50 -0
  73. package/billing/useCreatePaymentMethodSetupSession.js.map +1 -0
  74. package/billing/useEntitlements.d.ts +46 -0
  75. package/billing/useEntitlements.d.ts.map +1 -0
  76. package/billing/useEntitlements.js +37 -0
  77. package/billing/useEntitlements.js.map +1 -0
  78. package/billing/usePeriodEstimate.d.ts +35 -0
  79. package/billing/usePeriodEstimate.d.ts.map +1 -0
  80. package/billing/usePeriodEstimate.js +29 -0
  81. package/billing/usePeriodEstimate.js.map +1 -0
  82. package/billing/usePlans.d.ts +38 -0
  83. package/billing/usePlans.d.ts.map +1 -0
  84. package/billing/usePlans.js +33 -0
  85. package/billing/usePlans.js.map +1 -0
  86. package/billing/useSubscription.d.ts +39 -0
  87. package/billing/useSubscription.d.ts.map +1 -0
  88. package/billing/useSubscription.js +40 -0
  89. package/billing/useSubscription.js.map +1 -0
  90. package/index.d.ts +4 -2
  91. package/index.d.ts.map +1 -1
  92. package/index.js +4 -1
  93. package/index.js.map +1 -1
  94. package/internal/features.d.ts +11 -0
  95. package/internal/features.d.ts.map +1 -0
  96. package/internal/features.js +42 -0
  97. package/internal/features.js.map +1 -0
  98. package/licenses/license-format.d.ts +5 -3
  99. package/licenses/license-format.d.ts.map +1 -1
  100. package/licenses/license-format.js +10 -19
  101. package/licenses/license-format.js.map +1 -1
  102. package/package.json +5 -5
  103. package/plan-catalog/PlanCatalogConsole.d.ts +22 -0
  104. package/plan-catalog/PlanCatalogConsole.d.ts.map +1 -0
  105. package/plan-catalog/PlanCatalogConsole.js +90 -0
  106. package/plan-catalog/PlanCatalogConsole.js.map +1 -0
  107. package/plan-catalog/PlanCreateForm.d.ts +17 -0
  108. package/plan-catalog/PlanCreateForm.d.ts.map +1 -0
  109. package/plan-catalog/PlanCreateForm.js +52 -0
  110. package/plan-catalog/PlanCreateForm.js.map +1 -0
  111. package/plan-catalog/PlansAccessNotice.d.ts +10 -0
  112. package/plan-catalog/PlansAccessNotice.d.ts.map +1 -0
  113. package/plan-catalog/PlansAccessNotice.js +13 -0
  114. package/plan-catalog/PlansAccessNotice.js.map +1 -0
  115. package/plan-catalog/index.d.ts +8 -0
  116. package/plan-catalog/index.d.ts.map +1 -0
  117. package/plan-catalog/index.js +10 -0
  118. package/plan-catalog/index.js.map +1 -0
  119. package/plan-catalog/plan-draft.d.ts +30 -0
  120. package/plan-catalog/plan-draft.d.ts.map +1 -0
  121. package/plan-catalog/plan-draft.js +91 -0
  122. package/plan-catalog/plan-draft.js.map +1 -0
  123. package/plan-catalog/usePlanMutations.d.ts +42 -0
  124. package/plan-catalog/usePlanMutations.d.ts.map +1 -0
  125. package/plan-catalog/usePlanMutations.js +57 -0
  126. package/plan-catalog/usePlanMutations.js.map +1 -0
  127. package/settings/TeamsSection.d.ts.map +1 -1
  128. package/settings/TeamsSection.js +19 -2
  129. package/settings/TeamsSection.js.map +1 -1
  130. package/settings/settings-nav.d.ts.map +1 -1
  131. package/settings/settings-nav.js +7 -1
  132. package/settings/settings-nav.js.map +1 -1
  133. package/settings/useSettingsNavGroups.d.ts.map +1 -1
  134. package/settings/useSettingsNavGroups.js +4 -1
  135. package/settings/useSettingsNavGroups.js.map +1 -1
  136. package/src/billing/AutoRechargeCard.tsx +2 -2
  137. package/src/billing/BillingSection.tsx +68 -11
  138. package/src/billing/ChangePlanDialog.tsx +221 -0
  139. package/src/billing/CreditPackGrid.tsx +1 -1
  140. package/src/billing/LowBalanceBanner.tsx +1 -1
  141. package/src/billing/PaymentMethodCard.tsx +28 -2
  142. package/src/billing/PlanCard.tsx +171 -0
  143. package/src/billing/PlanPicker.tsx +178 -0
  144. package/src/billing/PlanSection.tsx +234 -0
  145. package/src/billing/UpgradeNotice.tsx +95 -0
  146. package/src/billing/credit-packs.ts +4 -1
  147. package/src/billing/index.ts +26 -1
  148. package/src/billing/plan-features.ts +162 -0
  149. package/src/billing/plan-state.ts +92 -0
  150. package/src/billing/redirect.ts +45 -0
  151. package/src/billing/useBillingAccount.ts +12 -0
  152. package/src/billing/useChangePlan.ts +115 -0
  153. package/src/billing/useCreateBillingPortalSession.ts +17 -6
  154. package/src/billing/useCreateCheckoutSession.ts +12 -7
  155. package/src/billing/useCreatePaymentMethodSetupSession.ts +77 -0
  156. package/src/billing/useEntitlements.ts +80 -0
  157. package/src/billing/usePeriodEstimate.ts +59 -0
  158. package/src/billing/usePlans.ts +65 -0
  159. package/src/billing/useSubscription.ts +70 -0
  160. package/src/index.ts +54 -0
  161. package/src/internal/features.ts +49 -0
  162. package/src/licenses/license-format.ts +10 -19
  163. package/src/plan-catalog/PlanCatalogConsole.tsx +197 -0
  164. package/src/plan-catalog/PlanCreateForm.tsx +167 -0
  165. package/src/plan-catalog/PlansAccessNotice.tsx +20 -0
  166. package/src/plan-catalog/index.ts +14 -0
  167. package/src/plan-catalog/plan-draft.ts +116 -0
  168. package/src/plan-catalog/usePlanMutations.ts +94 -0
  169. package/src/settings/TeamsSection.tsx +20 -2
  170. package/src/settings/settings-nav.ts +7 -0
  171. package/src/settings/useSettingsNavGroups.ts +8 -1
  172. package/src/team/CreateTeamForm.tsx +12 -3
  173. package/src/team/TeamMembersPanel.tsx +6 -2
  174. package/team/CreateTeamForm.d.ts +6 -1
  175. package/team/CreateTeamForm.d.ts.map +1 -1
  176. package/team/CreateTeamForm.js +4 -2
  177. package/team/CreateTeamForm.js.map +1 -1
  178. package/team/TeamMembersPanel.d.ts.map +1 -1
  179. package/team/TeamMembersPanel.js +3 -1
  180. package/team/TeamMembersPanel.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"useCreateCheckoutSession.d.ts","sourceRoot":"","sources":["../src/billing/useCreateCheckoutSession.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,6CAA6C,CAAC;AAIvG,kFAAkF;AAClF,MAAM,WAAW,0BAA0B;IACzC,uCAAuC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,mEAAmE;IACnE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,mDAAmD;IACnD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,wDAAwD;AACxD,MAAM,WAAW,8BA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AM,IAAI,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,CAAC,EAAE,eAAe,GACzB,8BAA8B,CAuChC"}
@@ -2,6 +2,7 @@
2
2
  import { useCallback, useState } from "react";
3
3
  import { useStigmer } from "../hooks.js";
4
4
  import { toError } from "../internal/toError.js";
5
+ import { leaveForStripe } from "./redirect.js";
5
6
  /**
6
7
  * Behavior hook that creates a Stripe Checkout Session for credit
7
8
  * pack purchases.
@@ -25,8 +26,9 @@ import { toError } from "../internal/toError.js";
25
26
  * };
26
27
  * ```
27
28
  */
28
- export function useCreateCheckoutSession() {
29
+ export function useCreateCheckoutSession(redirect) {
29
30
  const stigmer = useStigmer();
31
+ const openUrl = redirect?.openUrl;
30
32
  const [isSubmitting, setIsSubmitting] = useState(false);
31
33
  const [error, setError] = useState(null);
32
34
  const clearError = useCallback(() => setError(null), []);
@@ -41,7 +43,7 @@ export function useCreateCheckoutSession() {
41
43
  cancelUrl: input.cancelUrl,
42
44
  });
43
45
  if (response.checkoutUrl) {
44
- window.location.href = response.checkoutUrl;
46
+ await leaveForStripe(response.checkoutUrl, { openUrl });
45
47
  }
46
48
  return response;
47
49
  }
@@ -52,7 +54,7 @@ export function useCreateCheckoutSession() {
52
54
  finally {
53
55
  setIsSubmitting(false);
54
56
  }
55
- }, [stigmer]);
57
+ }, [stigmer, openUrl]);
56
58
  return { createSession, isSubmitting, error, clearError };
57
59
  }
58
60
  //# sourceMappingURL=useCreateCheckoutSession.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCreateCheckoutSession.js","sourceRoot":"","sources":["../src/billing/useCreateCheckoutSession.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB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AAc,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;YAC1D,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;YACvB,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,eAAe,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,EACD,CAAC,OAAO,EAAE,OAAO,CAAC,CACnB,CAAC;IAEF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { type BillingRedirect } from "./redirect.js";
2
+ /** Return value of {@link useCreatePaymentMethodSetupSession}. */
3
+ export interface UseCreatePaymentMethodSetupSessionReturn {
4
+ /**
5
+ * Leave for Stripe's hosted page to save a card, with no charge. Stripe
6
+ * returns to the billing page with `?setup=success` (and `&plan=<id>`
7
+ * when `planId` names the plan the person was subscribing to, so the
8
+ * page can reopen that choice), or without a query when they leave.
9
+ * The saved card becomes the organization's default for every invoice.
10
+ */
11
+ readonly addPaymentMethod: (orgId: string, planId?: string) => Promise<void>;
12
+ /** `true` while the setup session is being created. */
13
+ readonly isSubmitting: boolean;
14
+ /** Error from the last failed attempt, or `null` when healthy. */
15
+ readonly error: Error | null;
16
+ /** Reset `error` to `null`. */
17
+ readonly clearError: () => void;
18
+ }
19
+ /**
20
+ * Behaviour hook that saves a payment method through a Stripe-hosted setup
21
+ * page: the card door every subscription needs before its first period.
22
+ *
23
+ * The caller needs `can_manage_billing` on the organization. Pass the
24
+ * host's {@link BillingRedirect} where the window cannot host Stripe's
25
+ * page itself.
26
+ */
27
+ export declare function useCreatePaymentMethodSetupSession(redirect?: BillingRedirect): UseCreatePaymentMethodSetupSessionReturn;
28
+ //# sourceMappingURL=useCreatePaymentMethodSetupSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCreatePaymentMethodSetupSession.d.ts","sourceRoot":"","sources":["../src/billing/useCreatePaymentMethodSetupSession.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoC,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAEvF,kEAAkE;AAClE,MAAM,WAAW,wCAAwC;IACvD;;;;;;OAMG;IACH,QAAQ,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7E,uDAAuD;IACvD,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC7B,+BAA+B;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC;CACjC;AAED;;;;;;;GAOG;AACH,wBAAgB,kCAAkC,CAChD,QAAQ,CAAC,EAAE,eAAe,GACzB,wCAAwC,CAyC1C"}
@@ -0,0 +1,50 @@
1
+ "use client";
2
+ import { useCallback, useMemo, useState } from "react";
3
+ import { useStigmer } from "../hooks.js";
4
+ import { toError } from "../internal/toError.js";
5
+ import { billingReturnUrl, leaveForStripe } from "./redirect.js";
6
+ /**
7
+ * Behaviour hook that saves a payment method through a Stripe-hosted setup
8
+ * page: the card door every subscription needs before its first period.
9
+ *
10
+ * The caller needs `can_manage_billing` on the organization. Pass the
11
+ * host's {@link BillingRedirect} where the window cannot host Stripe's
12
+ * page itself.
13
+ */
14
+ export function useCreatePaymentMethodSetupSession(redirect) {
15
+ const stigmer = useStigmer();
16
+ const openUrl = redirect?.openUrl;
17
+ const returnUrl = redirect?.returnUrl;
18
+ const [isSubmitting, setIsSubmitting] = useState(false);
19
+ const [error, setError] = useState(null);
20
+ const addPaymentMethod = useCallback(async (orgId, planId) => {
21
+ setIsSubmitting(true);
22
+ setError(null);
23
+ try {
24
+ const billingPage = billingReturnUrl({ returnUrl });
25
+ const success = new URLSearchParams({ setup: "success" });
26
+ if (planId !== undefined && planId !== "") {
27
+ success.set("plan", planId);
28
+ }
29
+ const response = await stigmer.billing.createPaymentMethodSetupSession({
30
+ orgId,
31
+ successUrl: `${billingPage}?${success.toString()}`,
32
+ cancelUrl: billingPage,
33
+ });
34
+ if (response.setupUrl) {
35
+ await leaveForStripe(response.setupUrl, { openUrl });
36
+ }
37
+ }
38
+ catch (e) {
39
+ const err = toError(e);
40
+ setError(err);
41
+ throw err;
42
+ }
43
+ finally {
44
+ setIsSubmitting(false);
45
+ }
46
+ }, [stigmer.billing, openUrl, returnUrl]);
47
+ const clearError = useCallback(() => setError(null), []);
48
+ return useMemo(() => ({ addPaymentMethod, isSubmitting, error, clearError }), [addPaymentMethod, isSubmitting, error, clearError]);
49
+ }
50
+ //# sourceMappingURL=useCreatePaymentMethodSetupSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCreatePaymentMethodSetupSession.js","sourceRoot":"","sources":["../src/billing/useCreatePaymentMethodSetupSession.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAwB,MAAM,eAAe,CAAC;AAoBvF;;;;;;;GAOG;AACH,MAAM,UAAU,kCAAkC,CAChD,QAA0B;IAE1B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,OAAO,GAAG,QAAQ,EAAE,OAAO,CAAC;IAClC,MAAM,SAAS,GAAG,QAAQ,EAAE,SAAS,CAAC;IACtC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxD,MAA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AQ,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAEzD,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC,EAAE,gBAAgB,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAC7D,CAAC,gBAAgB,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,CAAC,CACpD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { type GetEntitlementsOutput } from "@stigmer/protos/ai/stigmer/billing/subscription/v1/io_pb";
2
+ import type { Feature } from "@stigmer/protos/ai/stigmer/platform/v1/entitlement_pb";
3
+ /** Options for {@link useEntitlements}. */
4
+ export interface UseEntitlementsOptions {
5
+ /** Skip fetching while `false` (stable no-op). Default `true`. */
6
+ readonly enabled?: boolean;
7
+ }
8
+ /** Return value of {@link useEntitlements}. */
9
+ export interface UseEntitlementsReturn {
10
+ /**
11
+ * What the organization may do right now and the plan that permits it
12
+ * (`planId` empty on Free), or `null` before the first successful fetch.
13
+ */
14
+ readonly entitlements: GetEntitlementsOutput | null;
15
+ /**
16
+ * Whether the organization's plan includes `feature` right now; `null`
17
+ * until the entitlements have loaded, so a caller never refuses on a
18
+ * guess.
19
+ */
20
+ readonly allows: (feature: Feature) => boolean | null;
21
+ /** `true` while the initial fetch is in flight. */
22
+ readonly isLoading: boolean;
23
+ /** Error from the last failed request, or `null` when healthy. */
24
+ readonly error: Error | null;
25
+ /** Discard cached data and re-fetch from the server. */
26
+ readonly refetch: () => void;
27
+ }
28
+ /**
29
+ * Data hook that resolves what an organization's plan permits right now.
30
+ *
31
+ * The answer is derived by the server on every read: the live
32
+ * subscription's plan, else Free's. A platform-managed organization
33
+ * resolves through its integrator's plan. Every member may read it
34
+ * (`can_view_billing` is granted to viewers).
35
+ *
36
+ * Cloud-only. Self-hosted editions answer from their license, not a plan,
37
+ * so callers gate on the edition before reading (see `UpgradeNotice`).
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * const { allows } = useEntitlements(orgId);
42
+ * if (allows(Feature.teams) === false) return <UpgradeNotice feature={Feature.teams} />;
43
+ * ```
44
+ */
45
+ export declare function useEntitlements(orgId: string | null, options?: UseEntitlementsOptions): UseEntitlementsReturn;
46
+ //# sourceMappingURL=useEntitlements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEntitlements.d.ts","sourceRoot":"","sources":["../src/billing/useEntitlements.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,0DAA0D,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uDAAuD,CAAC;AAIrF,2CAA2C;AAC3C,MAAM,WAAW,sBAAsB;IACrC,kEAAkE;IAClE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,+CAA+C;AAC/C,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,QAAQ,CAAC,YAAY,EAAE,qBAAqB,GAAG,IAAI,CAAC;IACpD;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,GAAG,IAAI,CAAC;IACtD,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC7B,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,qBAAqB,CAoBvB"}
@@ -0,0 +1,37 @@
1
+ "use client";
2
+ import { useMemo } from "react";
3
+ import { create } from "@bufbuild/protobuf";
4
+ import { GetEntitlementsInputSchema, } from "@stigmer/protos/ai/stigmer/billing/subscription/v1/io_pb";
5
+ import { useStigmer } from "../hooks.js";
6
+ import { useFetch } from "../internal/useFetch.js";
7
+ /**
8
+ * Data hook that resolves what an organization's plan permits right now.
9
+ *
10
+ * The answer is derived by the server on every read: the live
11
+ * subscription's plan, else Free's. A platform-managed organization
12
+ * resolves through its integrator's plan. Every member may read it
13
+ * (`can_view_billing` is granted to viewers).
14
+ *
15
+ * Cloud-only. Self-hosted editions answer from their license, not a plan,
16
+ * so callers gate on the edition before reading (see `UpgradeNotice`).
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * const { allows } = useEntitlements(orgId);
21
+ * if (allows(Feature.teams) === false) return <UpgradeNotice feature={Feature.teams} />;
22
+ * ```
23
+ */
24
+ export function useEntitlements(orgId, options) {
25
+ const stigmer = useStigmer();
26
+ const enabled = (options?.enabled ?? true) && orgId !== null && orgId !== "";
27
+ const { data: entitlements, isLoading, error, refetch } = useFetch(enabled && orgId ? () => stigmer.subscription.getEntitlements(create(GetEntitlementsInputSchema, { orgId })) : null, [enabled, orgId, stigmer], null, { refetchOnWindowFocus: true });
28
+ const features = entitlements?.entitlements?.features;
29
+ return useMemo(() => ({
30
+ entitlements,
31
+ allows: (feature) => (features === undefined ? null : features.includes(feature)),
32
+ isLoading,
33
+ error,
34
+ refetch,
35
+ }), [entitlements, features, isLoading, error, refetch]);
36
+ }
37
+ //# sourceMappingURL=useEntitlements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEntitlements.js","sourceRoot":"","sources":["../src/billing/useEntitlements.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EACL,0BAA0B,GAE3B,MAAM,0DAA0D,CAAC;AAElE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AA6BnD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,eAAe,CAC7B,KAAoB,EACpB,OAAgC;IAEhC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;IAC7E,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,QAAQ,CAChE,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,MAAM,CAAC,0BAA0B,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EACnH,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,EACzB,IAAoC,EACpC,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAC/B,CAAC;IACF,MAAM,QAAQ,GAAG,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAC;IACtD,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,YAAY;QACZ,MAAM,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC1F,SAAS;QACT,KAAK;QACL,OAAO;KACR,CAAC,EACF,CAAC,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,CACpD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { type PeriodEstimate } from "@stigmer/protos/ai/stigmer/billing/subscription/v1/io_pb";
2
+ /** Options for {@link usePeriodEstimate}. */
3
+ export interface UsePeriodEstimateOptions {
4
+ /** Skip fetching while `false`: read only while a subscription is live. Default `true`. */
5
+ readonly enabled?: boolean;
6
+ }
7
+ /** Return value of {@link usePeriodEstimate}. */
8
+ export interface UsePeriodEstimateReturn {
9
+ /** The current period's estimated invoice, or `null` before the first successful fetch. */
10
+ readonly estimate: PeriodEstimate | null;
11
+ /** `true` while the initial fetch is in flight. */
12
+ readonly isLoading: boolean;
13
+ /** Error from the last failed request, or `null` when healthy. */
14
+ readonly error: Error | null;
15
+ /** Discard cached data and re-fetch from the server. */
16
+ readonly refetch: () => void;
17
+ }
18
+ /**
19
+ * Data hook that estimates what an organization's current subscription
20
+ * period will be invoiced.
21
+ *
22
+ * The estimate is the invoice the period would close with if no further
23
+ * usage occurred: the plan's minimum for the whole period (or its share of
24
+ * the period's provider cost, whichever is greater), less the commission
25
+ * already collected on tokens, plus managed organizations beyond those
26
+ * included. The server rates it by the same rule the monthly close
27
+ * invoices by, so it agrees with the invoice to the cent.
28
+ *
29
+ * The server answers NOT_FOUND when nothing is live to invoice (Free, or a
30
+ * managed organization), so enable it only while a subscription is live.
31
+ *
32
+ * Cloud-only; the caller needs `can_view_billing` on the organization.
33
+ */
34
+ export declare function usePeriodEstimate(orgId: string | null, options?: UsePeriodEstimateOptions): UsePeriodEstimateReturn;
35
+ //# sourceMappingURL=usePeriodEstimate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePeriodEstimate.d.ts","sourceRoot":"","sources":["../src/billing/usePeriodEstimate.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,0DAA0D,CAAC;AAIlE,6CAA6C;AAC7C,MAAM,WAAW,wBAAwB;IACvC,2FAA2F;IAC3F,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,iDAAiD;AACjD,MAAM,WAAW,uBAAuB;IACtC,2FAA2F;IAC3F,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAC;IACzC,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC7B,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,OAAO,CAAC,EAAE,wBAAwB,GACjC,uBAAuB,CAUzB"}
@@ -0,0 +1,29 @@
1
+ "use client";
2
+ import { useMemo } from "react";
3
+ import { create } from "@bufbuild/protobuf";
4
+ import { GetPeriodEstimateInputSchema, } from "@stigmer/protos/ai/stigmer/billing/subscription/v1/io_pb";
5
+ import { useStigmer } from "../hooks.js";
6
+ import { useFetch } from "../internal/useFetch.js";
7
+ /**
8
+ * Data hook that estimates what an organization's current subscription
9
+ * period will be invoiced.
10
+ *
11
+ * The estimate is the invoice the period would close with if no further
12
+ * usage occurred: the plan's minimum for the whole period (or its share of
13
+ * the period's provider cost, whichever is greater), less the commission
14
+ * already collected on tokens, plus managed organizations beyond those
15
+ * included. The server rates it by the same rule the monthly close
16
+ * invoices by, so it agrees with the invoice to the cent.
17
+ *
18
+ * The server answers NOT_FOUND when nothing is live to invoice (Free, or a
19
+ * managed organization), so enable it only while a subscription is live.
20
+ *
21
+ * Cloud-only; the caller needs `can_view_billing` on the organization.
22
+ */
23
+ export function usePeriodEstimate(orgId, options) {
24
+ const stigmer = useStigmer();
25
+ const enabled = (options?.enabled ?? true) && orgId !== null && orgId !== "";
26
+ const { data: estimate, isLoading, error, refetch } = useFetch(enabled && orgId ? () => stigmer.subscription.getPeriodEstimate(create(GetPeriodEstimateInputSchema, { orgId })) : null, [enabled, orgId, stigmer], null, { refetchOnWindowFocus: true });
27
+ return useMemo(() => ({ estimate, isLoading, error, refetch }), [estimate, isLoading, error, refetch]);
28
+ }
29
+ //# sourceMappingURL=usePeriodEstimate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePeriodEstimate.js","sourceRoot":"","sources":["../src/billing/usePeri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interface UsePlansOptions {
4
+ /** Include retired plans beside the ones that can still be bought. Default `false`. */
5
+ readonly includeRetired?: boolean;
6
+ /** Skip fetching while `false` (stable no-op). Default `true`. */
7
+ readonly enabled?: boolean;
8
+ }
9
+ /** Return value of {@link usePlans}. */
10
+ export interface UsePlansReturn {
11
+ /** The catalog's plans, or `null` before the first successful fetch. */
12
+ readonly plans: readonly Plan[] | null;
13
+ /** `true` while the initial fetch is in flight. */
14
+ readonly isLoading: boolean;
15
+ /** `true` while a background refetch is in flight and stale data is shown. */
16
+ readonly isRefetching: boolean;
17
+ /** Error from the last failed request, or `null` when healthy. */
18
+ readonly error: Error | null;
19
+ /** Discard cached data and re-fetch from the server. */
20
+ readonly refetch: () => void;
21
+ }
22
+ /**
23
+ * Data hook that lists the Stigmer Cloud plan catalog.
24
+ *
25
+ * Every signed-in caller may read it. By default it lists only the plans
26
+ * that can still be bought; `includeRetired` adds the retired rows an
27
+ * operator audits. Free is not a row: an organization with no live
28
+ * subscription is on Free.
29
+ *
30
+ * Cloud-only: other editions serve no plans.
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * const { plans } = usePlans();
35
+ * ```
36
+ */
37
+ export declare function usePlans(options?: UsePlansOptions): UsePlansReturn;
38
+ //# sourceMappingURL=usePlans.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePlans.d.ts","sourceRoot":"","sources":["../src/billing/usePlans.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mDAAmD,CAAC;AAK9E,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B,uFAAuF;IACvF,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAClC,kEAAkE;IAClE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,wCAAwC;AACxC,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,IAAI,CAAC;IACvC,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,8EAA8E;IAC9E,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC7B,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,cAAc,CAkBlE"}
@@ -0,0 +1,33 @@
1
+ "use client";
2
+ import { useMemo } from "react";
3
+ import { create } from "@bufbuild/protobuf";
4
+ import { ListPlansInputSchema } from "@stigmer/protos/ai/stigmer/billing/plan/v1/io_pb";
5
+ import { useStigmer } from "../hooks.js";
6
+ import { useFetch } from "../internal/useFetch.js";
7
+ /**
8
+ * Data hook that lists the Stigmer Cloud plan catalog.
9
+ *
10
+ * Every signed-in caller may read it. By default it lists only the plans
11
+ * that can still be bought; `includeRetired` adds the retired rows an
12
+ * operator audits. Free is not a row: an organization with no live
13
+ * subscription is on Free.
14
+ *
15
+ * Cloud-only: other editions serve no plans.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * const { plans } = usePlans();
20
+ * ```
21
+ */
22
+ export function usePlans(options) {
23
+ const stigmer = useStigmer();
24
+ const enabled = options?.enabled ?? true;
25
+ const includeRetired = options?.includeRetired ?? false;
26
+ const { data: plans, isLoading, isRefetching, error, refetch } = useFetch(enabled
27
+ ? () => stigmer.plan
28
+ .list(create(ListPlansInputSchema, { includeRetired }))
29
+ .then((result) => result.entries)
30
+ : null, [enabled, includeRetired, stigmer], null);
31
+ return useMemo(() => ({ plans, isLoading, isRefetching, error, refetch }), [plans, isLoading, isRefetching, error, refetch]);
32
+ }
33
+ //# sourceMappingURL=usePlans.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePlans.js","sourceRoot":"","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/v1/api_pb";
2
+ /** Return value of {@link useSubscription}. */
3
+ export interface UseSubscriptionReturn {
4
+ /**
5
+ * The organization's subscription as stored; `null` when it never
6
+ * subscribed (it is on Free) or before the first successful fetch.
7
+ * A subscription that ended reads `canceled` with its period in the
8
+ * past; {@link useEntitlements} says what the organization may do now.
9
+ */
10
+ readonly subscription: Subscription | null;
11
+ /** `true` while the initial fetch is in flight. */
12
+ readonly isLoading: boolean;
13
+ /** `true` while a background refetch is in flight and stale data is shown. */
14
+ readonly isRefetching: boolean;
15
+ /** Error from the last failed request, or `null` when healthy. Never NOT_FOUND. */
16
+ readonly error: Error | null;
17
+ /** Discard cached data and re-fetch from the server. */
18
+ readonly refetch: () => void;
19
+ }
20
+ /**
21
+ * Data hook that reads an organization's subscription.
22
+ *
23
+ * The server answers NOT_FOUND for an organization that never subscribed;
24
+ * this hook reads that as `null`, because never subscribed is a state (the
25
+ * Free plan), not a failure.
26
+ *
27
+ * Pass `null` as `orgId` to skip fetching. Refetches when the window
28
+ * regains focus, so a plan changed in another window, or a card saved in
29
+ * the system browser, shows on return.
30
+ *
31
+ * Cloud-only; the caller needs `can_view_billing` on the organization.
32
+ *
33
+ * @example
34
+ * ```tsx
35
+ * const { subscription } = useSubscription(orgId);
36
+ * ```
37
+ */
38
+ export declare function useSubscription(orgId: string | null): UseSubscriptionReturn;
39
+ //# sourceMappingURL=useSubscription.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSubscription.d.ts","sourceRoot":"","sources":["../src/billing/useSubscription.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2DAA2D,CAAC;AAK9F,+CAA+C;AAC/C,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAC3C,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,8EAA8E;IAC9E,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,mFAAmF;IACnF,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAC7B,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,qBAAqB,CAsB3E"}
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { useMemo } from "react";
3
+ import { create } from "@bufbuild/protobuf";
4
+ import { isNotFound } from "@stigmer/sdk";
5
+ import { GetSubscriptionForOrganizationInputSchema } from "@stigmer/protos/ai/stigmer/billing/subscription/v1/io_pb";
6
+ import { useStigmer } from "../hooks.js";
7
+ import { useFetch } from "../internal/useFetch.js";
8
+ /**
9
+ * Data hook that reads an organization's subscription.
10
+ *
11
+ * The server answers NOT_FOUND for an organization that never subscribed;
12
+ * this hook reads that as `null`, because never subscribed is a state (the
13
+ * Free plan), not a failure.
14
+ *
15
+ * Pass `null` as `orgId` to skip fetching. Refetches when the window
16
+ * regains focus, so a plan changed in another window, or a card saved in
17
+ * the system browser, shows on return.
18
+ *
19
+ * Cloud-only; the caller needs `can_view_billing` on the organization.
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * const { subscription } = useSubscription(orgId);
24
+ * ```
25
+ */
26
+ export function useSubscription(orgId) {
27
+ const stigmer = useStigmer();
28
+ const { data: subscription, isLoading, isRefetching, error, refetch } = useFetch(orgId
29
+ ? () => stigmer.subscription
30
+ .getForOrganization(create(GetSubscriptionForOrganizationInputSchema, { orgId }))
31
+ .catch((err) => {
32
+ if (isNotFound(err)) {
33
+ return null;
34
+ }
35
+ throw err;
36
+ })
37
+ : null, [orgId, stigmer], null, { refetchOnWindowFocus: true });
38
+ return useMemo(() => ({ subscription, isLoading, isRefetching, error, refetch }), [subscription, isLoading, isRefetching, error, refetch]);
39
+ }
40
+ //# sourceMappingURL=useSub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EAAE,KAAK,EAAE,OAAO,CAAC,CACxD,CAAC;AACJ,CAAC"}
package/index.d.ts CHANGED
@@ -58,8 +58,8 @@ export { ManageAccessDialog, ManageAccessButton, useManageAccess, } from "./acce
58
58
  export type { ManageAccessDialogProps, ManageAccessButtonProps, UseManageAccessArgs, UseManageAccessReturn, AccessResource, AccessVisibility, AccessExtraSection, } from "./access/index.js";
59
59
  export { OrgProvider, useOrg, useActiveOrgSlug, useActiveOrgId, useOrgGate, useOrganization, useCreateOrganization, useUpdateOrganization, CreateOrganizationForm, OrgProfilePanel, OrgPreferencesPanel, OrgSwitcher, } from "./organization/index.js";
60
60
  export type { OrgContextValue, UseOrgGateOptions, OrgGateState, UseOrgGateReturn, UseOrganizationReturn, UseCreateOrganizationReturn, UseUpdateOrganizationReturn, CreateOrganizationFormProps, OrgProfilePanelProps, OrgPreferencesPanelProps, OrgSwitcherProps, } from "./organization/index.js";
61
- export { useBillingAccount, useCreditLedger, useBillingUsageReport, useCustomerModelPricing, useCreateCheckoutSession, useCreateBillingPortalSession, useSetAutoRechargeConfig, BillingSection, CreditBalanceCard, PaymentMethodCard, AutoRechargeCard, CreditPackGrid, CreditLedgerTable, LowBalanceBanner, CREDIT_PACKS, formatPackPrice, formatCreditCount, formatCreditBalance, formatLedgerAmount, ledgerEntryLabel, isCredit, isHold, formatLedgerDate, } from "./billing/index.js";
62
- export type { UseBillingAccountReturn, UseCreditLedgerReturn, UseCreditLedgerOptions, UseBillingUsageReportReturn, UseCustomerModelPricingReturn, CreateCheckoutSessionInput, UseCreateCheckoutSessionReturn, UseCreateBillingPortalSessionReturn, SetAutoRechargeConfigInput, UseSetAutoRechargeConfigReturn, BillingSectionProps, CreditBalanceCardProps, PaymentMethodCardProps, AutoRechargeCardProps, CreditPackGridProps, CreditLedgerTableProps, LowBalanceBannerProps, CreditPackInfo, } from "./billing/index.js";
61
+ export { useBillingAccount, useCreditLedger, useBillingUsageReport, useCustomerModelPricing, useCreateCheckoutSession, useCreateBillingPortalSession, useSetAutoRechargeConfig, usePlans, useSubscription, useEntitlements, usePeriodEstimate, useChangePlan, useCancelSubscription, useCreatePaymentMethodSetupSession, planStanding, planMove, PlanSection, PlanCard, PlanPicker, ENTERPRISE_CONTACT_URL, ChangePlanDialog, PAYMENT_METHOD_REQUIRED, UpgradeNotice, planUpgradeFeature, PLAN_UPGRADE_REQUIRED, DEFAULT_BILLING_HREF, BillingSection, CreditBalanceCard, PaymentMethodCard, AutoRechargeCard, CreditPackGrid, CreditLedgerTable, LowBalanceBanner, CREDIT_PACKS, formatPackPrice, formatCreditCount, formatCreditBalance, formatLedgerAmount, ledgerEntryLabel, isCredit, isHold, formatLedgerDate, } from "./billing/index.js";
62
+ export type { UseBillingAccountOptions, UseBillingAccountReturn, UsePlansOptions, UsePlansReturn, UseSubscriptionReturn, UseEntitlementsOptions, UseEntitlementsReturn, UsePeriodEstimateOptions, UsePeriodEstimateReturn, UseChangePlanReturn, UseCancelSubscriptionReturn, UseCreatePaymentMethodSetupSessionReturn, BillingRedirect, PlanStanding, PlanMove, PlanSectionProps, PlanCardProps, PlanPickerProps, ChangePlanDialogProps, UpgradeNoticeProps, UseCreditLedgerReturn, UseCreditLedgerOptions, UseBillingUsageReportReturn, UseCustomerModelPricingReturn, CreateCheckoutSessionInput, UseCreateCheckoutSessionReturn, UseCreateBillingPortalSessionReturn, SetAutoRechargeConfigInput, UseSetAutoRechargeConfigReturn, BillingSectionProps, CreditBalanceCardProps, PaymentMethodCardProps, AutoRechargeCardProps, CreditPackGridProps, CreditLedgerTableProps, LowBalanceBannerProps, CreditPackInfo, } from "./billing/index.js";
63
63
  export { usePricingGovernance, useModelPricingBaselines, useModelGovernanceView, useDecidePricingOverride, useUpsertModelPricingBaseline, useRetireModelPricingBaseline, PricingGovernancePanel, ModelCatalogPanel, PricingGovernanceConsole, } from "./pricing-governance/index.js";
64
64
  export type { UsePricingGovernanceReturn, UseModelPricingBaselinesOptions, UseModelPricingBaselinesReturn, GovernanceFlow, ModelGovernanceRow, UseModelGovernanceViewReturn, DecidePricingOverrideInput, UseDecidePricingOverrideReturn, UpsertModelPricingBaselineInput, UseUpsertModelPricingBaselineReturn, RetireModelPricingBaselineInput, UseRetireModelPricingBaselineReturn, PricingGovernancePanelProps, ModelCatalogPanelProps, PricingGovernanceConsoleProps, PricingGovernanceTab, } from "./pricing-governance/index.js";
65
65
  export { useCursorAccounts, useCursorAccountView, useUpsertCursorAccount, useDeleteCursorAccount, useCursorMemberKeyActions, useSyncCursorAccount, CursorAccountsConsole, CursorAccountEditor, CursorAccountsAccessNotice, } from "./cursor-accounts/index.js";
@@ -68,6 +68,8 @@ export { useProviderStanding, ProviderStandingConsole, ProviderStandingAccessNot
68
68
  export type { UseProviderStandingReturn, ProviderStandingConsoleProps, } from "./provider-standing/index.js";
69
69
  export { useLicenses, useLicense, useIssueLicense, LicensesConsole, LicensesAccessNotice, } from "./licenses/index.js";
70
70
  export type { UseLicensesReturn, UseLicenseReturn, UseIssueLicenseReturn, LicensesConsoleProps, } from "./licenses/index.js";
71
+ export { useCreatePlan, useRetirePlan, PlanCatalogConsole, PlanCreateForm, PlansAccessNotice, } from "./plan-catalog/index.js";
72
+ export type { UseCreatePlanReturn, UseRetirePlanReturn, PlanCatalogConsoleProps, PlanCreateFormProps, } from "./plan-catalog/index.js";
71
73
  export { SETTINGS_NAV_GROUPS, PLATFORM_SETTINGS_NAV_GROUP, useSettingsNavGroups, } from "./settings/index.js";
72
74
  export type { SettingsNavItem, SettingsNavGroup } from "./settings/index.js";
73
75
  export { ApiKeysSection } from "./settings/index.js";