autumn-js 0.1.11 → 0.1.13

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 (136) hide show
  1. package/dist/libraries/backend/better-auth.d.mts +4 -0
  2. package/dist/libraries/backend/better-auth.d.ts +4 -0
  3. package/dist/libraries/backend/better-auth.js +172 -2
  4. package/dist/libraries/backend/better-auth.mjs +7 -7
  5. package/dist/libraries/backend/{chunk-EW2R7722.mjs → chunk-2DWGCQCF.mjs} +1 -1
  6. package/dist/libraries/backend/{chunk-VNJ3MFJE.mjs → chunk-56RGUNOT.mjs} +1 -1
  7. package/dist/libraries/backend/{chunk-P3ARLB2M.mjs → chunk-6JI6MF4S.mjs} +1 -1
  8. package/dist/libraries/backend/{chunk-5DDCZMDB.mjs → chunk-FA5Z2MOT.mjs} +1 -1
  9. package/dist/libraries/backend/{chunk-RAHKKJED.mjs → chunk-NWPFUFXX.mjs} +6 -6
  10. package/dist/libraries/backend/{chunk-NAP2URIW.mjs → chunk-Q7SD535L.mjs} +172 -2
  11. package/dist/libraries/backend/{chunk-7K3RATTK.mjs → chunk-SDL7BFTH.mjs} +1 -1
  12. package/dist/libraries/backend/convex.js +172 -2
  13. package/dist/libraries/backend/convex.mjs +7 -7
  14. package/dist/libraries/backend/elysia.js +172 -2
  15. package/dist/libraries/backend/elysia.mjs +7 -7
  16. package/dist/libraries/backend/express.d.mts +1 -1
  17. package/dist/libraries/backend/express.d.ts +1 -1
  18. package/dist/libraries/backend/express.js +172 -2
  19. package/dist/libraries/backend/express.mjs +7 -7
  20. package/dist/libraries/backend/fastify.js +172 -2
  21. package/dist/libraries/backend/fastify.mjs +7 -7
  22. package/dist/libraries/backend/hono.js +172 -2
  23. package/dist/libraries/backend/hono.mjs +7 -7
  24. package/dist/libraries/backend/index.d.mts +1 -1
  25. package/dist/libraries/backend/index.d.ts +1 -1
  26. package/dist/libraries/backend/index.js +172 -2
  27. package/dist/libraries/backend/index.mjs +7 -7
  28. package/dist/libraries/backend/next.js +172 -2
  29. package/dist/libraries/backend/next.mjs +7 -7
  30. package/dist/libraries/backend/react-router.js +172 -2
  31. package/dist/libraries/backend/react-router.mjs +7 -7
  32. package/dist/libraries/backend/{referralTypes-C1eZ8cjO.d.mts → referralTypes-DSv2hpmP.d.mts} +178 -44
  33. package/dist/libraries/backend/{referralTypes-FlI0fYwz.d.ts → referralTypes-DdKvvqSK.d.ts} +178 -44
  34. package/dist/libraries/backend/remix_dep.js +172 -2
  35. package/dist/libraries/backend/remix_dep.mjs +7 -7
  36. package/dist/libraries/backend/routes/backendRouter.js +172 -2
  37. package/dist/libraries/backend/routes/backendRouter.mjs +7 -7
  38. package/dist/libraries/backend/routes/entityRoutes.js +172 -2
  39. package/dist/libraries/backend/routes/entityRoutes.mjs +3 -3
  40. package/dist/libraries/backend/routes/genRoutes.js +172 -2
  41. package/dist/libraries/backend/routes/genRoutes.mjs +3 -3
  42. package/dist/libraries/backend/routes/productRoutes.js +172 -2
  43. package/dist/libraries/backend/routes/productRoutes.mjs +3 -3
  44. package/dist/libraries/backend/routes/referralRoutes.js +172 -2
  45. package/dist/libraries/backend/routes/referralRoutes.mjs +3 -3
  46. package/dist/libraries/backend/supabase.js +172 -2
  47. package/dist/libraries/backend/supabase.mjs +7 -7
  48. package/dist/libraries/backend/tanstack.js +172 -2
  49. package/dist/libraries/backend/tanstack.mjs +7 -7
  50. package/dist/libraries/backend/utils/backendRes.js +172 -2
  51. package/dist/libraries/backend/utils/backendRes.mjs +1 -1
  52. package/dist/libraries/backend/utils/withAuth.d.mts +1 -1
  53. package/dist/libraries/backend/utils/withAuth.d.ts +1 -1
  54. package/dist/libraries/backend/utils/withAuth.js +172 -2
  55. package/dist/libraries/backend/utils/withAuth.mjs +2 -2
  56. package/dist/libraries/react/AutumnContext.js +176 -4
  57. package/dist/libraries/react/AutumnContext.mjs +4 -4
  58. package/dist/libraries/react/BaseAutumnProvider.js +176 -15
  59. package/dist/libraries/react/BaseAutumnProvider.mjs +9 -9
  60. package/dist/libraries/react/ReactAutumnProvider.js +176 -15
  61. package/dist/libraries/react/ReactAutumnProvider.mjs +10 -10
  62. package/dist/libraries/react/{chunk-2ENHPIYQ.mjs → chunk-52HVA7E4.mjs} +3 -3
  63. package/dist/libraries/react/{chunk-WYQMHQUE.mjs → chunk-5O3IHYFF.mjs} +172 -2
  64. package/dist/libraries/react/{chunk-JHFJKAXG.mjs → chunk-5YM6QT7V.mjs} +33 -33
  65. package/dist/libraries/react/{chunk-KP2Q65Y3.mjs → chunk-643J45JV.mjs} +2 -2
  66. package/dist/libraries/react/{chunk-YHT2JUXO.mjs → chunk-7HRCOEUW.mjs} +1 -1
  67. package/dist/libraries/react/{chunk-OMJJLT2Q.mjs → chunk-7JU3XHKL.mjs} +1 -1
  68. package/dist/libraries/react/{chunk-XK3AXQED.mjs → chunk-BT5OY2CA.mjs} +3 -13
  69. package/dist/libraries/react/{chunk-KMYL54B4.mjs → chunk-DKOF357C.mjs} +1 -1
  70. package/dist/libraries/react/{chunk-4NZ7ML7V.mjs → chunk-M3SON3SH.mjs} +2 -2
  71. package/dist/libraries/react/{chunk-67RWFVWN.mjs → chunk-OSYZMMQC.mjs} +2 -2
  72. package/dist/libraries/react/{chunk-6D6TYTTO.mjs → chunk-P6CAHZVT.mjs} +1 -2
  73. package/dist/libraries/react/{chunk-VZY225C6.mjs → chunk-RP56DI4O.mjs} +2 -2
  74. package/dist/libraries/react/{chunk-FDNQ6GRK.mjs → chunk-SWVRRNIW.mjs} +1 -1
  75. package/dist/libraries/react/{chunk-U3OQJXCW.mjs → chunk-TOAZUTY6.mjs} +8 -6
  76. package/dist/libraries/react/{chunk-3MF54MDU.mjs → chunk-WBBWID5F.mjs} +1 -1
  77. package/dist/libraries/react/{chunk-TTLL63A4.mjs → chunk-Z7REFVM4.mjs} +3 -3
  78. package/dist/libraries/react/client/ReactAutumnClient.js +176 -4
  79. package/dist/libraries/react/client/ReactAutumnClient.mjs +3 -3
  80. package/dist/libraries/react/client/types/clientGenTypes.js +172 -2
  81. package/dist/libraries/react/client/types/clientGenTypes.mjs +1 -1
  82. package/dist/libraries/react/components/checkout-dialog/checkout-dialog-synced.css +3 -0
  83. package/dist/libraries/react/components/checkout-dialog/checkout-dialog-synced.js +181 -20
  84. package/dist/libraries/react/components/checkout-dialog/checkout-dialog-synced.mjs +26 -26
  85. package/dist/libraries/react/components/paywall-dialog/paywall-dialog-synced.css +3 -0
  86. package/dist/libraries/react/components/paywall-dialog/paywall-dialog-synced.js +176 -4
  87. package/dist/libraries/react/components/paywall-dialog/paywall-dialog-synced.mjs +26 -26
  88. package/dist/libraries/react/components/pricing-table/pricing-table-synced.css +3 -0
  89. package/dist/libraries/react/components/pricing-table/pricing-table-synced.js +181 -20
  90. package/dist/libraries/react/components/pricing-table/pricing-table-synced.mjs +26 -26
  91. package/dist/libraries/react/components/ui/button.d.mts +2 -2
  92. package/dist/libraries/react/components/ui/button.d.ts +2 -2
  93. package/dist/libraries/react/components/ui/dialog.mjs +2 -2
  94. package/dist/libraries/react/components/ui/popover.mjs +2 -2
  95. package/dist/libraries/react/hooks/helpers/handleCheck.js +172 -2
  96. package/dist/libraries/react/hooks/helpers/handleCheck.mjs +2 -2
  97. package/dist/libraries/react/hooks/helpers/useAutumnBase.js +172 -3
  98. package/dist/libraries/react/hooks/helpers/useAutumnBase.mjs +3 -3
  99. package/dist/libraries/react/hooks/useAnalytics.js +176 -4
  100. package/dist/libraries/react/hooks/useAnalytics.mjs +5 -5
  101. package/dist/libraries/react/hooks/useCustomer.d.mts +60 -2
  102. package/dist/libraries/react/hooks/useCustomer.d.ts +60 -2
  103. package/dist/libraries/react/hooks/useCustomer.js +176 -15
  104. package/dist/libraries/react/hooks/useCustomer.mjs +9 -9
  105. package/dist/libraries/react/hooks/useCustomerBase.d.mts +44 -3
  106. package/dist/libraries/react/hooks/useCustomerBase.d.ts +44 -3
  107. package/dist/libraries/react/hooks/useCustomerBase.js +176 -15
  108. package/dist/libraries/react/hooks/useCustomerBase.mjs +8 -8
  109. package/dist/libraries/react/hooks/useEntity.js +176 -5
  110. package/dist/libraries/react/hooks/useEntity.mjs +9 -9
  111. package/dist/libraries/react/hooks/useEntityBase.js +176 -5
  112. package/dist/libraries/react/hooks/useEntityBase.mjs +8 -8
  113. package/dist/libraries/react/hooks/usePaywall.js +176 -4
  114. package/dist/libraries/react/hooks/usePaywall.mjs +5 -5
  115. package/dist/libraries/react/hooks/usePricingTable.js +176 -4
  116. package/dist/libraries/react/hooks/usePricingTable.mjs +6 -6
  117. package/dist/libraries/react/hooks/usePricingTableBase.js +172 -2
  118. package/dist/libraries/react/hooks/usePricingTableBase.mjs +2 -2
  119. package/dist/libraries/react/index.d.mts +104 -7
  120. package/dist/libraries/react/index.d.ts +104 -7
  121. package/dist/libraries/react/index.js +182 -21
  122. package/dist/libraries/react/index.mjs +182 -21
  123. package/dist/next/client/hooks/useCustomer.d.mts +44 -7
  124. package/dist/next/client/hooks/useCustomer.d.ts +44 -7
  125. package/dist/next/server/cusActions.d.mts +178 -44
  126. package/dist/next/server/cusActions.d.ts +178 -44
  127. package/dist/sdk/index.d.mts +178 -44
  128. package/dist/sdk/index.d.ts +178 -44
  129. package/dist/sdk/index.js +171 -1
  130. package/dist/sdk/index.mjs +171 -1
  131. package/dist/styles/global.css +3 -0
  132. package/dist/utils/encryptUtils.js +172 -2
  133. package/dist/utils/encryptUtils.mjs +172 -2
  134. package/package.json +1 -1
  135. package/dist/libraries/react/{chunk-7JNU5ABT.mjs → chunk-FJWZPMWU.mjs} +3 -3
  136. package/dist/libraries/react/{chunk-LCWL3TIT.mjs → chunk-OTZ65PCT.mjs} +3 -3
@@ -487,6 +487,8 @@ declare const CheckoutParamsSchema: z.ZodObject<{
487
487
  feature_id: z.ZodString;
488
488
  quantity: z.ZodNumber;
489
489
  }, z.core.$strip>>>;
490
+ force_checkout: z.ZodOptional<z.ZodBoolean>;
491
+ invoice: z.ZodOptional<z.ZodBoolean>;
490
492
  success_url: z.ZodOptional<z.ZodString>;
491
493
  customer_data: z.ZodOptional<z.ZodObject<{
492
494
  name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -527,52 +529,16 @@ declare enum FeatureType {
527
529
  declare const FeatureSchema: z$1.ZodObject<{
528
530
  id: z$1.ZodString;
529
531
  name: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
530
- type: z$1.ZodNativeEnum<typeof FeatureType>;
532
+ type: z$1.ZodEnum<typeof FeatureType>;
531
533
  display: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodObject<{
532
534
  singular: z$1.ZodString;
533
535
  plural: z$1.ZodString;
534
- }, "strip", z$1.ZodTypeAny, {
535
- singular: string;
536
- plural: string;
537
- }, {
538
- singular: string;
539
- plural: string;
540
- }>>>;
536
+ }, z$1.core.$strip>>>;
541
537
  credit_schema: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodArray<z$1.ZodObject<{
542
538
  metered_feature_id: z$1.ZodString;
543
539
  credit_cost: z$1.ZodNumber;
544
- }, "strip", z$1.ZodTypeAny, {
545
- metered_feature_id: string;
546
- credit_cost: number;
547
- }, {
548
- metered_feature_id: string;
549
- credit_cost: number;
550
- }>, "many">>>;
551
- }, "strip", z$1.ZodTypeAny, {
552
- id: string;
553
- type: FeatureType;
554
- credit_schema?: {
555
- metered_feature_id: string;
556
- credit_cost: number;
557
- }[] | null | undefined;
558
- name?: string | null | undefined;
559
- display?: {
560
- singular: string;
561
- plural: string;
562
- } | null | undefined;
563
- }, {
564
- id: string;
565
- type: FeatureType;
566
- credit_schema?: {
567
- metered_feature_id: string;
568
- credit_cost: number;
569
- }[] | null | undefined;
570
- name?: string | null | undefined;
571
- display?: {
572
- singular: string;
573
- plural: string;
574
- } | null | undefined;
575
- }>;
540
+ }, z$1.core.$strip>>>>;
541
+ }, z$1.core.$strip>;
576
542
  type Feature = z$1.infer<typeof FeatureSchema>;
577
543
 
578
544
  type Success<T> = {
@@ -670,9 +636,63 @@ declare class Autumn {
670
636
  list: Feature[];
671
637
  }, AutumnError>>;
672
638
  };
673
- static checkout: (params: CheckoutParams) => Promise<Result<CheckoutResult, AutumnError>>;
639
+ /**
640
+ * Initiates a checkout flow for a product purchase.
641
+ *
642
+ * The checkout function handles the purchase process for products with pricing.
643
+ * It determines whether to show a dialog for user input or redirect directly
644
+ * to Stripe based on the customer's state and product requirements.
645
+ *
646
+ * @param params - Checkout parameters including product ID, customer data, and options
647
+ * @returns Promise resolving to checkout details including pricing, prorations, and URLs
648
+ *
649
+ * @example
650
+ * ```typescript
651
+ * const result = await autumn.checkout({
652
+ * customer_id: "user_123",
653
+ * product_id: "pro",
654
+ * success_url: "https://myapp.com/success"
655
+ * });
656
+ *
657
+ * if (result.url) {
658
+ * // Redirect to Stripe checkout
659
+ * window.location.href = result.url;
660
+ * }
661
+ * ```
662
+ */
674
663
  checkout(params: CheckoutParams): Promise<Result<CheckoutResult, AutumnError>>;
675
- static attach: (params: AttachParams) => Promise<Result<{
664
+ static checkout: (params: CheckoutParams) => Promise<Result<CheckoutResult, AutumnError>>;
665
+ static usage: (params: UsageParams) => Promise<Result<UsageResult, AutumnError>>;
666
+ /**
667
+ * Attaches a product to a customer, enabling access and handling billing.
668
+ *
669
+ * The attach function activates a product for a customer and applies all product items.
670
+ * When you attach a product:
671
+ * - The customer gains access to all features in the product
672
+ * - If the product has prices, the customer will be billed accordingly
673
+ * - If there's no existing payment method, a checkout URL will be generated
674
+ *
675
+ * @param params - Attach parameters including customer ID, product ID, and options
676
+ * @returns Promise resolving to attachment result with checkout URL if needed
677
+ *
678
+ * @example
679
+ * ```typescript
680
+ * const result = await autumn.attach({
681
+ * customer_id: "user_123",
682
+ * product_id: "pro",
683
+ * success_url: "https://myapp.com/success"
684
+ * });
685
+ *
686
+ * if (result.checkout_url) {
687
+ * // Payment required - redirect to checkout
688
+ * window.location.href = result.checkout_url;
689
+ * } else {
690
+ * // Product successfully attached
691
+ * console.log("Access granted:", result.message);
692
+ * }
693
+ * ```
694
+ */
695
+ attach(params: AttachParams): Promise<Result<{
676
696
  customer_id: string;
677
697
  product_ids: string[];
678
698
  code: string;
@@ -687,8 +707,7 @@ declare class Autumn {
687
707
  currency: string;
688
708
  } | undefined;
689
709
  }, AutumnError>>;
690
- static usage: (params: UsageParams) => Promise<Result<UsageResult, AutumnError>>;
691
- attach(params: AttachParams): Promise<Result<{
710
+ static attach: (params: AttachParams) => Promise<Result<{
692
711
  customer_id: string;
693
712
  product_ids: string[];
694
713
  code: string;
@@ -704,18 +723,76 @@ declare class Autumn {
704
723
  } | undefined;
705
724
  }, AutumnError>>;
706
725
  static setupPayment: (params: SetupPaymentParams) => Promise<Result<SetupPaymentResult, AutumnError>>;
726
+ /**
727
+ * Sets up a payment method for a customer.
728
+ *
729
+ * This method allows you to set up payment methods for customers without
730
+ * immediately charging them. Useful for collecting payment information
731
+ * before product attachment or for updating existing payment methods.
732
+ *
733
+ * @param params - Setup payment parameters including customer information
734
+ * @returns Promise resolving to setup payment result
735
+ *
736
+ * @example
737
+ * ```typescript
738
+ * const result = await autumn.setupPayment({
739
+ * customer_id: "user_123"
740
+ * });
741
+ * ```
742
+ */
707
743
  setupPayment(params: SetupPaymentParams): Promise<Result<SetupPaymentResult, AutumnError>>;
708
744
  static cancel: (params: CancelParams) => Promise<Result<{
709
745
  success: boolean;
710
746
  customer_id: string;
711
747
  product_id: string;
712
748
  }, AutumnError>>;
749
+ /**
750
+ * Cancels a customer's subscription or product attachment.
751
+ *
752
+ * This method allows you to cancel a customer's subscription to a specific product.
753
+ * You can choose to cancel immediately or at the end of the billing cycle.
754
+ *
755
+ * @param params - Cancel parameters including customer ID and product ID
756
+ * @returns Promise resolving to cancellation result
757
+ *
758
+ * @example
759
+ * ```typescript
760
+ * const result = await autumn.cancel({
761
+ * customer_id: "user_123",
762
+ * product_id: "pro",
763
+ * cancel_immediately: false // Cancel at end of billing cycle
764
+ * });
765
+ * ```
766
+ */
713
767
  cancel(params: CancelParams): Promise<Result<{
714
768
  success: boolean;
715
769
  customer_id: string;
716
770
  product_id: string;
717
771
  }, AutumnError>>;
718
772
  static check: (params: CheckParams) => Promise<Result<CheckResult, AutumnError>>;
773
+ /**
774
+ * Checks if a customer has access to a specific feature.
775
+ *
776
+ * This method verifies whether a customer has permission to use a feature
777
+ * and checks their remaining balance/usage limits. It can be used to gate
778
+ * features and determine when to show upgrade prompts.
779
+ *
780
+ * @param params - Check parameters including customer ID and feature ID
781
+ * @returns Promise resolving to access check result with allowed status and balance info
782
+ *
783
+ * @example
784
+ * ```typescript
785
+ * const result = await autumn.check({
786
+ * customer_id: "user_123",
787
+ * feature_id: "messages",
788
+ * required_balance: 1
789
+ * });
790
+ *
791
+ * if (!result.allowed) {
792
+ * console.log("Feature access denied - upgrade required");
793
+ * }
794
+ * ```
795
+ */
719
796
  check(params: CheckParams): Promise<Result<CheckResult, AutumnError>>;
720
797
  static track: (params: TrackParams) => Promise<Result<{
721
798
  id: string;
@@ -724,6 +801,25 @@ declare class Autumn {
724
801
  feature_id?: string | undefined;
725
802
  event_name?: string | undefined;
726
803
  }, AutumnError>>;
804
+ /**
805
+ * Tracks usage events for features or analytics.
806
+ *
807
+ * This method records usage events for metered features, updating the customer's
808
+ * balance and usage statistics. It's typically used server-side to ensure
809
+ * accurate tracking that cannot be manipulated by users.
810
+ *
811
+ * @param params - Track parameters including customer ID, feature ID, and usage value
812
+ * @returns Promise resolving to tracking result
813
+ *
814
+ * @example
815
+ * ```typescript
816
+ * const result = await autumn.track({
817
+ * customer_id: "user_123",
818
+ * feature_id: "messages",
819
+ * value: 1 // Track 1 message sent
820
+ * });
821
+ * ```
822
+ */
727
823
  track(params: TrackParams): Promise<Result<{
728
824
  id: string;
729
825
  code: string;
@@ -731,8 +827,46 @@ declare class Autumn {
731
827
  feature_id?: string | undefined;
732
828
  event_name?: string | undefined;
733
829
  }, AutumnError>>;
830
+ /**
831
+ * Retrieves usage statistics and analytics for a customer.
832
+ *
833
+ * This method fetches detailed usage information for a customer's features,
834
+ * including current balances, usage history, and analytics data. Useful
835
+ * for displaying usage dashboards or generating reports.
836
+ *
837
+ * @param params - Usage parameters including customer ID and optional filters
838
+ * @returns Promise resolving to usage statistics and analytics data
839
+ *
840
+ * @example
841
+ * ```typescript
842
+ * const result = await autumn.usage({
843
+ * customer_id: "user_123",
844
+ * feature_id: "messages"
845
+ * value: 20 // Usage value
846
+ * });
847
+ * ```
848
+ */
734
849
  usage(params: UsageParams): Promise<Result<UsageResult, AutumnError>>;
735
850
  static query: (params: QueryParams) => Promise<Result<QueryResult, AutumnError>>;
851
+ /**
852
+ * Performs advanced queries on customer data and analytics.
853
+ *
854
+ * This method allows you to run complex queries against customer data,
855
+ * usage patterns, and billing information. Useful for generating reports,
856
+ * analytics, and custom data insights.
857
+ *
858
+ * @param params - Query parameters including customer ID and query specifications
859
+ * @returns Promise resolving to query results with requested data
860
+ *
861
+ * @example
862
+ * ```typescript
863
+ * const result = await autumn.query({
864
+ * customer_id: "user_123",
865
+ * feature_id: "messages" // feature id to fetch for query, can also be an array
866
+ * });
867
+ *
868
+ * ```
869
+ */
736
870
  query(params: QueryParams): Promise<Result<QueryResult, AutumnError>>;
737
871
  }
738
872
 
@@ -487,6 +487,8 @@ declare const CheckoutParamsSchema: z.ZodObject<{
487
487
  feature_id: z.ZodString;
488
488
  quantity: z.ZodNumber;
489
489
  }, z.core.$strip>>>;
490
+ force_checkout: z.ZodOptional<z.ZodBoolean>;
491
+ invoice: z.ZodOptional<z.ZodBoolean>;
490
492
  success_url: z.ZodOptional<z.ZodString>;
491
493
  customer_data: z.ZodOptional<z.ZodObject<{
492
494
  name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -527,52 +529,16 @@ declare enum FeatureType {
527
529
  declare const FeatureSchema: z$1.ZodObject<{
528
530
  id: z$1.ZodString;
529
531
  name: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
530
- type: z$1.ZodNativeEnum<typeof FeatureType>;
532
+ type: z$1.ZodEnum<typeof FeatureType>;
531
533
  display: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodObject<{
532
534
  singular: z$1.ZodString;
533
535
  plural: z$1.ZodString;
534
- }, "strip", z$1.ZodTypeAny, {
535
- singular: string;
536
- plural: string;
537
- }, {
538
- singular: string;
539
- plural: string;
540
- }>>>;
536
+ }, z$1.core.$strip>>>;
541
537
  credit_schema: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodArray<z$1.ZodObject<{
542
538
  metered_feature_id: z$1.ZodString;
543
539
  credit_cost: z$1.ZodNumber;
544
- }, "strip", z$1.ZodTypeAny, {
545
- metered_feature_id: string;
546
- credit_cost: number;
547
- }, {
548
- metered_feature_id: string;
549
- credit_cost: number;
550
- }>, "many">>>;
551
- }, "strip", z$1.ZodTypeAny, {
552
- id: string;
553
- type: FeatureType;
554
- credit_schema?: {
555
- metered_feature_id: string;
556
- credit_cost: number;
557
- }[] | null | undefined;
558
- name?: string | null | undefined;
559
- display?: {
560
- singular: string;
561
- plural: string;
562
- } | null | undefined;
563
- }, {
564
- id: string;
565
- type: FeatureType;
566
- credit_schema?: {
567
- metered_feature_id: string;
568
- credit_cost: number;
569
- }[] | null | undefined;
570
- name?: string | null | undefined;
571
- display?: {
572
- singular: string;
573
- plural: string;
574
- } | null | undefined;
575
- }>;
540
+ }, z$1.core.$strip>>>>;
541
+ }, z$1.core.$strip>;
576
542
  type Feature = z$1.infer<typeof FeatureSchema>;
577
543
 
578
544
  type Success<T> = {
@@ -670,9 +636,63 @@ declare class Autumn {
670
636
  list: Feature[];
671
637
  }, AutumnError>>;
672
638
  };
673
- static checkout: (params: CheckoutParams) => Promise<Result<CheckoutResult, AutumnError>>;
639
+ /**
640
+ * Initiates a checkout flow for a product purchase.
641
+ *
642
+ * The checkout function handles the purchase process for products with pricing.
643
+ * It determines whether to show a dialog for user input or redirect directly
644
+ * to Stripe based on the customer's state and product requirements.
645
+ *
646
+ * @param params - Checkout parameters including product ID, customer data, and options
647
+ * @returns Promise resolving to checkout details including pricing, prorations, and URLs
648
+ *
649
+ * @example
650
+ * ```typescript
651
+ * const result = await autumn.checkout({
652
+ * customer_id: "user_123",
653
+ * product_id: "pro",
654
+ * success_url: "https://myapp.com/success"
655
+ * });
656
+ *
657
+ * if (result.url) {
658
+ * // Redirect to Stripe checkout
659
+ * window.location.href = result.url;
660
+ * }
661
+ * ```
662
+ */
674
663
  checkout(params: CheckoutParams): Promise<Result<CheckoutResult, AutumnError>>;
675
- static attach: (params: AttachParams) => Promise<Result<{
664
+ static checkout: (params: CheckoutParams) => Promise<Result<CheckoutResult, AutumnError>>;
665
+ static usage: (params: UsageParams) => Promise<Result<UsageResult, AutumnError>>;
666
+ /**
667
+ * Attaches a product to a customer, enabling access and handling billing.
668
+ *
669
+ * The attach function activates a product for a customer and applies all product items.
670
+ * When you attach a product:
671
+ * - The customer gains access to all features in the product
672
+ * - If the product has prices, the customer will be billed accordingly
673
+ * - If there's no existing payment method, a checkout URL will be generated
674
+ *
675
+ * @param params - Attach parameters including customer ID, product ID, and options
676
+ * @returns Promise resolving to attachment result with checkout URL if needed
677
+ *
678
+ * @example
679
+ * ```typescript
680
+ * const result = await autumn.attach({
681
+ * customer_id: "user_123",
682
+ * product_id: "pro",
683
+ * success_url: "https://myapp.com/success"
684
+ * });
685
+ *
686
+ * if (result.checkout_url) {
687
+ * // Payment required - redirect to checkout
688
+ * window.location.href = result.checkout_url;
689
+ * } else {
690
+ * // Product successfully attached
691
+ * console.log("Access granted:", result.message);
692
+ * }
693
+ * ```
694
+ */
695
+ attach(params: AttachParams): Promise<Result<{
676
696
  customer_id: string;
677
697
  product_ids: string[];
678
698
  code: string;
@@ -687,8 +707,7 @@ declare class Autumn {
687
707
  currency: string;
688
708
  } | undefined;
689
709
  }, AutumnError>>;
690
- static usage: (params: UsageParams) => Promise<Result<UsageResult, AutumnError>>;
691
- attach(params: AttachParams): Promise<Result<{
710
+ static attach: (params: AttachParams) => Promise<Result<{
692
711
  customer_id: string;
693
712
  product_ids: string[];
694
713
  code: string;
@@ -704,18 +723,76 @@ declare class Autumn {
704
723
  } | undefined;
705
724
  }, AutumnError>>;
706
725
  static setupPayment: (params: SetupPaymentParams) => Promise<Result<SetupPaymentResult, AutumnError>>;
726
+ /**
727
+ * Sets up a payment method for a customer.
728
+ *
729
+ * This method allows you to set up payment methods for customers without
730
+ * immediately charging them. Useful for collecting payment information
731
+ * before product attachment or for updating existing payment methods.
732
+ *
733
+ * @param params - Setup payment parameters including customer information
734
+ * @returns Promise resolving to setup payment result
735
+ *
736
+ * @example
737
+ * ```typescript
738
+ * const result = await autumn.setupPayment({
739
+ * customer_id: "user_123"
740
+ * });
741
+ * ```
742
+ */
707
743
  setupPayment(params: SetupPaymentParams): Promise<Result<SetupPaymentResult, AutumnError>>;
708
744
  static cancel: (params: CancelParams) => Promise<Result<{
709
745
  success: boolean;
710
746
  customer_id: string;
711
747
  product_id: string;
712
748
  }, AutumnError>>;
749
+ /**
750
+ * Cancels a customer's subscription or product attachment.
751
+ *
752
+ * This method allows you to cancel a customer's subscription to a specific product.
753
+ * You can choose to cancel immediately or at the end of the billing cycle.
754
+ *
755
+ * @param params - Cancel parameters including customer ID and product ID
756
+ * @returns Promise resolving to cancellation result
757
+ *
758
+ * @example
759
+ * ```typescript
760
+ * const result = await autumn.cancel({
761
+ * customer_id: "user_123",
762
+ * product_id: "pro",
763
+ * cancel_immediately: false // Cancel at end of billing cycle
764
+ * });
765
+ * ```
766
+ */
713
767
  cancel(params: CancelParams): Promise<Result<{
714
768
  success: boolean;
715
769
  customer_id: string;
716
770
  product_id: string;
717
771
  }, AutumnError>>;
718
772
  static check: (params: CheckParams) => Promise<Result<CheckResult, AutumnError>>;
773
+ /**
774
+ * Checks if a customer has access to a specific feature.
775
+ *
776
+ * This method verifies whether a customer has permission to use a feature
777
+ * and checks their remaining balance/usage limits. It can be used to gate
778
+ * features and determine when to show upgrade prompts.
779
+ *
780
+ * @param params - Check parameters including customer ID and feature ID
781
+ * @returns Promise resolving to access check result with allowed status and balance info
782
+ *
783
+ * @example
784
+ * ```typescript
785
+ * const result = await autumn.check({
786
+ * customer_id: "user_123",
787
+ * feature_id: "messages",
788
+ * required_balance: 1
789
+ * });
790
+ *
791
+ * if (!result.allowed) {
792
+ * console.log("Feature access denied - upgrade required");
793
+ * }
794
+ * ```
795
+ */
719
796
  check(params: CheckParams): Promise<Result<CheckResult, AutumnError>>;
720
797
  static track: (params: TrackParams) => Promise<Result<{
721
798
  id: string;
@@ -724,6 +801,25 @@ declare class Autumn {
724
801
  feature_id?: string | undefined;
725
802
  event_name?: string | undefined;
726
803
  }, AutumnError>>;
804
+ /**
805
+ * Tracks usage events for features or analytics.
806
+ *
807
+ * This method records usage events for metered features, updating the customer's
808
+ * balance and usage statistics. It's typically used server-side to ensure
809
+ * accurate tracking that cannot be manipulated by users.
810
+ *
811
+ * @param params - Track parameters including customer ID, feature ID, and usage value
812
+ * @returns Promise resolving to tracking result
813
+ *
814
+ * @example
815
+ * ```typescript
816
+ * const result = await autumn.track({
817
+ * customer_id: "user_123",
818
+ * feature_id: "messages",
819
+ * value: 1 // Track 1 message sent
820
+ * });
821
+ * ```
822
+ */
727
823
  track(params: TrackParams): Promise<Result<{
728
824
  id: string;
729
825
  code: string;
@@ -731,8 +827,46 @@ declare class Autumn {
731
827
  feature_id?: string | undefined;
732
828
  event_name?: string | undefined;
733
829
  }, AutumnError>>;
830
+ /**
831
+ * Retrieves usage statistics and analytics for a customer.
832
+ *
833
+ * This method fetches detailed usage information for a customer's features,
834
+ * including current balances, usage history, and analytics data. Useful
835
+ * for displaying usage dashboards or generating reports.
836
+ *
837
+ * @param params - Usage parameters including customer ID and optional filters
838
+ * @returns Promise resolving to usage statistics and analytics data
839
+ *
840
+ * @example
841
+ * ```typescript
842
+ * const result = await autumn.usage({
843
+ * customer_id: "user_123",
844
+ * feature_id: "messages"
845
+ * value: 20 // Usage value
846
+ * });
847
+ * ```
848
+ */
734
849
  usage(params: UsageParams): Promise<Result<UsageResult, AutumnError>>;
735
850
  static query: (params: QueryParams) => Promise<Result<QueryResult, AutumnError>>;
851
+ /**
852
+ * Performs advanced queries on customer data and analytics.
853
+ *
854
+ * This method allows you to run complex queries against customer data,
855
+ * usage patterns, and billing information. Useful for generating reports,
856
+ * analytics, and custom data insights.
857
+ *
858
+ * @param params - Query parameters including customer ID and query specifications
859
+ * @returns Promise resolving to query results with requested data
860
+ *
861
+ * @example
862
+ * ```typescript
863
+ * const result = await autumn.query({
864
+ * customer_id: "user_123",
865
+ * feature_id: "messages" // feature id to fetch for query, can also be an array
866
+ * });
867
+ *
868
+ * ```
869
+ */
736
870
  query(params: QueryParams): Promise<Result<QueryResult, AutumnError>>;
737
871
  }
738
872