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
@@ -414,6 +414,8 @@ declare const CheckoutParamsSchema: z.ZodObject<{
414
414
  feature_id: z.ZodString;
415
415
  quantity: z.ZodNumber;
416
416
  }, z.core.$strip>>>;
417
+ force_checkout: z.ZodOptional<z.ZodBoolean>;
418
+ invoice: z.ZodOptional<z.ZodBoolean>;
417
419
  success_url: z.ZodOptional<z.ZodString>;
418
420
  customer_data: z.ZodOptional<z.ZodObject<{
419
421
  name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -454,52 +456,16 @@ declare enum FeatureType {
454
456
  declare const FeatureSchema: z$1.ZodObject<{
455
457
  id: z$1.ZodString;
456
458
  name: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
457
- type: z$1.ZodNativeEnum<typeof FeatureType>;
459
+ type: z$1.ZodEnum<typeof FeatureType>;
458
460
  display: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodObject<{
459
461
  singular: z$1.ZodString;
460
462
  plural: z$1.ZodString;
461
- }, "strip", z$1.ZodTypeAny, {
462
- singular: string;
463
- plural: string;
464
- }, {
465
- singular: string;
466
- plural: string;
467
- }>>>;
463
+ }, z$1.core.$strip>>>;
468
464
  credit_schema: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodArray<z$1.ZodObject<{
469
465
  metered_feature_id: z$1.ZodString;
470
466
  credit_cost: z$1.ZodNumber;
471
- }, "strip", z$1.ZodTypeAny, {
472
- metered_feature_id: string;
473
- credit_cost: number;
474
- }, {
475
- metered_feature_id: string;
476
- credit_cost: number;
477
- }>, "many">>>;
478
- }, "strip", z$1.ZodTypeAny, {
479
- id: string;
480
- type: FeatureType;
481
- credit_schema?: {
482
- metered_feature_id: string;
483
- credit_cost: number;
484
- }[] | null | undefined;
485
- name?: string | null | undefined;
486
- display?: {
487
- singular: string;
488
- plural: string;
489
- } | null | undefined;
490
- }, {
491
- id: string;
492
- type: FeatureType;
493
- credit_schema?: {
494
- metered_feature_id: string;
495
- credit_cost: number;
496
- }[] | null | undefined;
497
- name?: string | null | undefined;
498
- display?: {
499
- singular: string;
500
- plural: string;
501
- } | null | undefined;
502
- }>;
467
+ }, z$1.core.$strip>>>>;
468
+ }, z$1.core.$strip>;
503
469
  type Feature = z$1.infer<typeof FeatureSchema>;
504
470
 
505
471
  declare class Autumn {
@@ -579,9 +545,63 @@ declare class Autumn {
579
545
  list: Feature[];
580
546
  }, AutumnError>>;
581
547
  };
582
- static checkout: (params: CheckoutParams) => Promise<Result<CheckoutResult, AutumnError>>;
548
+ /**
549
+ * Initiates a checkout flow for a product purchase.
550
+ *
551
+ * The checkout function handles the purchase process for products with pricing.
552
+ * It determines whether to show a dialog for user input or redirect directly
553
+ * to Stripe based on the customer's state and product requirements.
554
+ *
555
+ * @param params - Checkout parameters including product ID, customer data, and options
556
+ * @returns Promise resolving to checkout details including pricing, prorations, and URLs
557
+ *
558
+ * @example
559
+ * ```typescript
560
+ * const result = await autumn.checkout({
561
+ * customer_id: "user_123",
562
+ * product_id: "pro",
563
+ * success_url: "https://myapp.com/success"
564
+ * });
565
+ *
566
+ * if (result.url) {
567
+ * // Redirect to Stripe checkout
568
+ * window.location.href = result.url;
569
+ * }
570
+ * ```
571
+ */
583
572
  checkout(params: CheckoutParams): Promise<Result<CheckoutResult, AutumnError>>;
584
- static attach: (params: AttachParams) => Promise<Result<{
573
+ static checkout: (params: CheckoutParams) => Promise<Result<CheckoutResult, AutumnError>>;
574
+ static usage: (params: UsageParams) => Promise<Result<UsageResult, AutumnError>>;
575
+ /**
576
+ * Attaches a product to a customer, enabling access and handling billing.
577
+ *
578
+ * The attach function activates a product for a customer and applies all product items.
579
+ * When you attach a product:
580
+ * - The customer gains access to all features in the product
581
+ * - If the product has prices, the customer will be billed accordingly
582
+ * - If there's no existing payment method, a checkout URL will be generated
583
+ *
584
+ * @param params - Attach parameters including customer ID, product ID, and options
585
+ * @returns Promise resolving to attachment result with checkout URL if needed
586
+ *
587
+ * @example
588
+ * ```typescript
589
+ * const result = await autumn.attach({
590
+ * customer_id: "user_123",
591
+ * product_id: "pro",
592
+ * success_url: "https://myapp.com/success"
593
+ * });
594
+ *
595
+ * if (result.checkout_url) {
596
+ * // Payment required - redirect to checkout
597
+ * window.location.href = result.checkout_url;
598
+ * } else {
599
+ * // Product successfully attached
600
+ * console.log("Access granted:", result.message);
601
+ * }
602
+ * ```
603
+ */
604
+ attach(params: AttachParams): Promise<Result<{
585
605
  customer_id: string;
586
606
  product_ids: string[];
587
607
  code: string;
@@ -596,8 +616,7 @@ declare class Autumn {
596
616
  currency: string;
597
617
  } | undefined;
598
618
  }, AutumnError>>;
599
- static usage: (params: UsageParams) => Promise<Result<UsageResult, AutumnError>>;
600
- attach(params: AttachParams): Promise<Result<{
619
+ static attach: (params: AttachParams) => Promise<Result<{
601
620
  customer_id: string;
602
621
  product_ids: string[];
603
622
  code: string;
@@ -613,18 +632,76 @@ declare class Autumn {
613
632
  } | undefined;
614
633
  }, AutumnError>>;
615
634
  static setupPayment: (params: SetupPaymentParams) => Promise<Result<SetupPaymentResult, AutumnError>>;
635
+ /**
636
+ * Sets up a payment method for a customer.
637
+ *
638
+ * This method allows you to set up payment methods for customers without
639
+ * immediately charging them. Useful for collecting payment information
640
+ * before product attachment or for updating existing payment methods.
641
+ *
642
+ * @param params - Setup payment parameters including customer information
643
+ * @returns Promise resolving to setup payment result
644
+ *
645
+ * @example
646
+ * ```typescript
647
+ * const result = await autumn.setupPayment({
648
+ * customer_id: "user_123"
649
+ * });
650
+ * ```
651
+ */
616
652
  setupPayment(params: SetupPaymentParams): Promise<Result<SetupPaymentResult, AutumnError>>;
617
653
  static cancel: (params: CancelParams) => Promise<Result<{
618
654
  success: boolean;
619
655
  customer_id: string;
620
656
  product_id: string;
621
657
  }, AutumnError>>;
658
+ /**
659
+ * Cancels a customer's subscription or product attachment.
660
+ *
661
+ * This method allows you to cancel a customer's subscription to a specific product.
662
+ * You can choose to cancel immediately or at the end of the billing cycle.
663
+ *
664
+ * @param params - Cancel parameters including customer ID and product ID
665
+ * @returns Promise resolving to cancellation result
666
+ *
667
+ * @example
668
+ * ```typescript
669
+ * const result = await autumn.cancel({
670
+ * customer_id: "user_123",
671
+ * product_id: "pro",
672
+ * cancel_immediately: false // Cancel at end of billing cycle
673
+ * });
674
+ * ```
675
+ */
622
676
  cancel(params: CancelParams): Promise<Result<{
623
677
  success: boolean;
624
678
  customer_id: string;
625
679
  product_id: string;
626
680
  }, AutumnError>>;
627
681
  static check: (params: CheckParams) => Promise<Result<CheckResult, AutumnError>>;
682
+ /**
683
+ * Checks if a customer has access to a specific feature.
684
+ *
685
+ * This method verifies whether a customer has permission to use a feature
686
+ * and checks their remaining balance/usage limits. It can be used to gate
687
+ * features and determine when to show upgrade prompts.
688
+ *
689
+ * @param params - Check parameters including customer ID and feature ID
690
+ * @returns Promise resolving to access check result with allowed status and balance info
691
+ *
692
+ * @example
693
+ * ```typescript
694
+ * const result = await autumn.check({
695
+ * customer_id: "user_123",
696
+ * feature_id: "messages",
697
+ * required_balance: 1
698
+ * });
699
+ *
700
+ * if (!result.allowed) {
701
+ * console.log("Feature access denied - upgrade required");
702
+ * }
703
+ * ```
704
+ */
628
705
  check(params: CheckParams): Promise<Result<CheckResult, AutumnError>>;
629
706
  static track: (params: TrackParams) => Promise<Result<{
630
707
  id: string;
@@ -633,6 +710,25 @@ declare class Autumn {
633
710
  feature_id?: string | undefined;
634
711
  event_name?: string | undefined;
635
712
  }, AutumnError>>;
713
+ /**
714
+ * Tracks usage events for features or analytics.
715
+ *
716
+ * This method records usage events for metered features, updating the customer's
717
+ * balance and usage statistics. It's typically used server-side to ensure
718
+ * accurate tracking that cannot be manipulated by users.
719
+ *
720
+ * @param params - Track parameters including customer ID, feature ID, and usage value
721
+ * @returns Promise resolving to tracking result
722
+ *
723
+ * @example
724
+ * ```typescript
725
+ * const result = await autumn.track({
726
+ * customer_id: "user_123",
727
+ * feature_id: "messages",
728
+ * value: 1 // Track 1 message sent
729
+ * });
730
+ * ```
731
+ */
636
732
  track(params: TrackParams): Promise<Result<{
637
733
  id: string;
638
734
  code: string;
@@ -640,8 +736,46 @@ declare class Autumn {
640
736
  feature_id?: string | undefined;
641
737
  event_name?: string | undefined;
642
738
  }, AutumnError>>;
739
+ /**
740
+ * Retrieves usage statistics and analytics for a customer.
741
+ *
742
+ * This method fetches detailed usage information for a customer's features,
743
+ * including current balances, usage history, and analytics data. Useful
744
+ * for displaying usage dashboards or generating reports.
745
+ *
746
+ * @param params - Usage parameters including customer ID and optional filters
747
+ * @returns Promise resolving to usage statistics and analytics data
748
+ *
749
+ * @example
750
+ * ```typescript
751
+ * const result = await autumn.usage({
752
+ * customer_id: "user_123",
753
+ * feature_id: "messages"
754
+ * value: 20 // Usage value
755
+ * });
756
+ * ```
757
+ */
643
758
  usage(params: UsageParams): Promise<Result<UsageResult, AutumnError>>;
644
759
  static query: (params: QueryParams) => Promise<Result<QueryResult, AutumnError>>;
760
+ /**
761
+ * Performs advanced queries on customer data and analytics.
762
+ *
763
+ * This method allows you to run complex queries against customer data,
764
+ * usage patterns, and billing information. Useful for generating reports,
765
+ * analytics, and custom data insights.
766
+ *
767
+ * @param params - Query parameters including customer ID and query specifications
768
+ * @returns Promise resolving to query results with requested data
769
+ *
770
+ * @example
771
+ * ```typescript
772
+ * const result = await autumn.query({
773
+ * customer_id: "user_123",
774
+ * feature_id: "messages" // feature id to fetch for query, can also be an array
775
+ * });
776
+ *
777
+ * ```
778
+ */
645
779
  query(params: QueryParams): Promise<Result<QueryResult, AutumnError>>;
646
780
  }
647
781
 
@@ -414,6 +414,8 @@ declare const CheckoutParamsSchema: z.ZodObject<{
414
414
  feature_id: z.ZodString;
415
415
  quantity: z.ZodNumber;
416
416
  }, z.core.$strip>>>;
417
+ force_checkout: z.ZodOptional<z.ZodBoolean>;
418
+ invoice: z.ZodOptional<z.ZodBoolean>;
417
419
  success_url: z.ZodOptional<z.ZodString>;
418
420
  customer_data: z.ZodOptional<z.ZodObject<{
419
421
  name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -454,52 +456,16 @@ declare enum FeatureType {
454
456
  declare const FeatureSchema: z$1.ZodObject<{
455
457
  id: z$1.ZodString;
456
458
  name: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
457
- type: z$1.ZodNativeEnum<typeof FeatureType>;
459
+ type: z$1.ZodEnum<typeof FeatureType>;
458
460
  display: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodObject<{
459
461
  singular: z$1.ZodString;
460
462
  plural: z$1.ZodString;
461
- }, "strip", z$1.ZodTypeAny, {
462
- singular: string;
463
- plural: string;
464
- }, {
465
- singular: string;
466
- plural: string;
467
- }>>>;
463
+ }, z$1.core.$strip>>>;
468
464
  credit_schema: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodArray<z$1.ZodObject<{
469
465
  metered_feature_id: z$1.ZodString;
470
466
  credit_cost: z$1.ZodNumber;
471
- }, "strip", z$1.ZodTypeAny, {
472
- metered_feature_id: string;
473
- credit_cost: number;
474
- }, {
475
- metered_feature_id: string;
476
- credit_cost: number;
477
- }>, "many">>>;
478
- }, "strip", z$1.ZodTypeAny, {
479
- id: string;
480
- type: FeatureType;
481
- credit_schema?: {
482
- metered_feature_id: string;
483
- credit_cost: number;
484
- }[] | null | undefined;
485
- name?: string | null | undefined;
486
- display?: {
487
- singular: string;
488
- plural: string;
489
- } | null | undefined;
490
- }, {
491
- id: string;
492
- type: FeatureType;
493
- credit_schema?: {
494
- metered_feature_id: string;
495
- credit_cost: number;
496
- }[] | null | undefined;
497
- name?: string | null | undefined;
498
- display?: {
499
- singular: string;
500
- plural: string;
501
- } | null | undefined;
502
- }>;
467
+ }, z$1.core.$strip>>>>;
468
+ }, z$1.core.$strip>;
503
469
  type Feature = z$1.infer<typeof FeatureSchema>;
504
470
 
505
471
  declare class Autumn {
@@ -579,9 +545,63 @@ declare class Autumn {
579
545
  list: Feature[];
580
546
  }, AutumnError>>;
581
547
  };
582
- static checkout: (params: CheckoutParams) => Promise<Result<CheckoutResult, AutumnError>>;
548
+ /**
549
+ * Initiates a checkout flow for a product purchase.
550
+ *
551
+ * The checkout function handles the purchase process for products with pricing.
552
+ * It determines whether to show a dialog for user input or redirect directly
553
+ * to Stripe based on the customer's state and product requirements.
554
+ *
555
+ * @param params - Checkout parameters including product ID, customer data, and options
556
+ * @returns Promise resolving to checkout details including pricing, prorations, and URLs
557
+ *
558
+ * @example
559
+ * ```typescript
560
+ * const result = await autumn.checkout({
561
+ * customer_id: "user_123",
562
+ * product_id: "pro",
563
+ * success_url: "https://myapp.com/success"
564
+ * });
565
+ *
566
+ * if (result.url) {
567
+ * // Redirect to Stripe checkout
568
+ * window.location.href = result.url;
569
+ * }
570
+ * ```
571
+ */
583
572
  checkout(params: CheckoutParams): Promise<Result<CheckoutResult, AutumnError>>;
584
- static attach: (params: AttachParams) => Promise<Result<{
573
+ static checkout: (params: CheckoutParams) => Promise<Result<CheckoutResult, AutumnError>>;
574
+ static usage: (params: UsageParams) => Promise<Result<UsageResult, AutumnError>>;
575
+ /**
576
+ * Attaches a product to a customer, enabling access and handling billing.
577
+ *
578
+ * The attach function activates a product for a customer and applies all product items.
579
+ * When you attach a product:
580
+ * - The customer gains access to all features in the product
581
+ * - If the product has prices, the customer will be billed accordingly
582
+ * - If there's no existing payment method, a checkout URL will be generated
583
+ *
584
+ * @param params - Attach parameters including customer ID, product ID, and options
585
+ * @returns Promise resolving to attachment result with checkout URL if needed
586
+ *
587
+ * @example
588
+ * ```typescript
589
+ * const result = await autumn.attach({
590
+ * customer_id: "user_123",
591
+ * product_id: "pro",
592
+ * success_url: "https://myapp.com/success"
593
+ * });
594
+ *
595
+ * if (result.checkout_url) {
596
+ * // Payment required - redirect to checkout
597
+ * window.location.href = result.checkout_url;
598
+ * } else {
599
+ * // Product successfully attached
600
+ * console.log("Access granted:", result.message);
601
+ * }
602
+ * ```
603
+ */
604
+ attach(params: AttachParams): Promise<Result<{
585
605
  customer_id: string;
586
606
  product_ids: string[];
587
607
  code: string;
@@ -596,8 +616,7 @@ declare class Autumn {
596
616
  currency: string;
597
617
  } | undefined;
598
618
  }, AutumnError>>;
599
- static usage: (params: UsageParams) => Promise<Result<UsageResult, AutumnError>>;
600
- attach(params: AttachParams): Promise<Result<{
619
+ static attach: (params: AttachParams) => Promise<Result<{
601
620
  customer_id: string;
602
621
  product_ids: string[];
603
622
  code: string;
@@ -613,18 +632,76 @@ declare class Autumn {
613
632
  } | undefined;
614
633
  }, AutumnError>>;
615
634
  static setupPayment: (params: SetupPaymentParams) => Promise<Result<SetupPaymentResult, AutumnError>>;
635
+ /**
636
+ * Sets up a payment method for a customer.
637
+ *
638
+ * This method allows you to set up payment methods for customers without
639
+ * immediately charging them. Useful for collecting payment information
640
+ * before product attachment or for updating existing payment methods.
641
+ *
642
+ * @param params - Setup payment parameters including customer information
643
+ * @returns Promise resolving to setup payment result
644
+ *
645
+ * @example
646
+ * ```typescript
647
+ * const result = await autumn.setupPayment({
648
+ * customer_id: "user_123"
649
+ * });
650
+ * ```
651
+ */
616
652
  setupPayment(params: SetupPaymentParams): Promise<Result<SetupPaymentResult, AutumnError>>;
617
653
  static cancel: (params: CancelParams) => Promise<Result<{
618
654
  success: boolean;
619
655
  customer_id: string;
620
656
  product_id: string;
621
657
  }, AutumnError>>;
658
+ /**
659
+ * Cancels a customer's subscription or product attachment.
660
+ *
661
+ * This method allows you to cancel a customer's subscription to a specific product.
662
+ * You can choose to cancel immediately or at the end of the billing cycle.
663
+ *
664
+ * @param params - Cancel parameters including customer ID and product ID
665
+ * @returns Promise resolving to cancellation result
666
+ *
667
+ * @example
668
+ * ```typescript
669
+ * const result = await autumn.cancel({
670
+ * customer_id: "user_123",
671
+ * product_id: "pro",
672
+ * cancel_immediately: false // Cancel at end of billing cycle
673
+ * });
674
+ * ```
675
+ */
622
676
  cancel(params: CancelParams): Promise<Result<{
623
677
  success: boolean;
624
678
  customer_id: string;
625
679
  product_id: string;
626
680
  }, AutumnError>>;
627
681
  static check: (params: CheckParams) => Promise<Result<CheckResult, AutumnError>>;
682
+ /**
683
+ * Checks if a customer has access to a specific feature.
684
+ *
685
+ * This method verifies whether a customer has permission to use a feature
686
+ * and checks their remaining balance/usage limits. It can be used to gate
687
+ * features and determine when to show upgrade prompts.
688
+ *
689
+ * @param params - Check parameters including customer ID and feature ID
690
+ * @returns Promise resolving to access check result with allowed status and balance info
691
+ *
692
+ * @example
693
+ * ```typescript
694
+ * const result = await autumn.check({
695
+ * customer_id: "user_123",
696
+ * feature_id: "messages",
697
+ * required_balance: 1
698
+ * });
699
+ *
700
+ * if (!result.allowed) {
701
+ * console.log("Feature access denied - upgrade required");
702
+ * }
703
+ * ```
704
+ */
628
705
  check(params: CheckParams): Promise<Result<CheckResult, AutumnError>>;
629
706
  static track: (params: TrackParams) => Promise<Result<{
630
707
  id: string;
@@ -633,6 +710,25 @@ declare class Autumn {
633
710
  feature_id?: string | undefined;
634
711
  event_name?: string | undefined;
635
712
  }, AutumnError>>;
713
+ /**
714
+ * Tracks usage events for features or analytics.
715
+ *
716
+ * This method records usage events for metered features, updating the customer's
717
+ * balance and usage statistics. It's typically used server-side to ensure
718
+ * accurate tracking that cannot be manipulated by users.
719
+ *
720
+ * @param params - Track parameters including customer ID, feature ID, and usage value
721
+ * @returns Promise resolving to tracking result
722
+ *
723
+ * @example
724
+ * ```typescript
725
+ * const result = await autumn.track({
726
+ * customer_id: "user_123",
727
+ * feature_id: "messages",
728
+ * value: 1 // Track 1 message sent
729
+ * });
730
+ * ```
731
+ */
636
732
  track(params: TrackParams): Promise<Result<{
637
733
  id: string;
638
734
  code: string;
@@ -640,8 +736,46 @@ declare class Autumn {
640
736
  feature_id?: string | undefined;
641
737
  event_name?: string | undefined;
642
738
  }, AutumnError>>;
739
+ /**
740
+ * Retrieves usage statistics and analytics for a customer.
741
+ *
742
+ * This method fetches detailed usage information for a customer's features,
743
+ * including current balances, usage history, and analytics data. Useful
744
+ * for displaying usage dashboards or generating reports.
745
+ *
746
+ * @param params - Usage parameters including customer ID and optional filters
747
+ * @returns Promise resolving to usage statistics and analytics data
748
+ *
749
+ * @example
750
+ * ```typescript
751
+ * const result = await autumn.usage({
752
+ * customer_id: "user_123",
753
+ * feature_id: "messages"
754
+ * value: 20 // Usage value
755
+ * });
756
+ * ```
757
+ */
643
758
  usage(params: UsageParams): Promise<Result<UsageResult, AutumnError>>;
644
759
  static query: (params: QueryParams) => Promise<Result<QueryResult, AutumnError>>;
760
+ /**
761
+ * Performs advanced queries on customer data and analytics.
762
+ *
763
+ * This method allows you to run complex queries against customer data,
764
+ * usage patterns, and billing information. Useful for generating reports,
765
+ * analytics, and custom data insights.
766
+ *
767
+ * @param params - Query parameters including customer ID and query specifications
768
+ * @returns Promise resolving to query results with requested data
769
+ *
770
+ * @example
771
+ * ```typescript
772
+ * const result = await autumn.query({
773
+ * customer_id: "user_123",
774
+ * feature_id: "messages" // feature id to fetch for query, can also be an array
775
+ * });
776
+ *
777
+ * ```
778
+ */
645
779
  query(params: QueryParams): Promise<Result<QueryResult, AutumnError>>;
646
780
  }
647
781