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.
- package/dist/libraries/backend/better-auth.d.mts +4 -0
- package/dist/libraries/backend/better-auth.d.ts +4 -0
- package/dist/libraries/backend/better-auth.js +172 -2
- package/dist/libraries/backend/better-auth.mjs +7 -7
- package/dist/libraries/backend/{chunk-EW2R7722.mjs → chunk-2DWGCQCF.mjs} +1 -1
- package/dist/libraries/backend/{chunk-VNJ3MFJE.mjs → chunk-56RGUNOT.mjs} +1 -1
- package/dist/libraries/backend/{chunk-P3ARLB2M.mjs → chunk-6JI6MF4S.mjs} +1 -1
- package/dist/libraries/backend/{chunk-5DDCZMDB.mjs → chunk-FA5Z2MOT.mjs} +1 -1
- package/dist/libraries/backend/{chunk-RAHKKJED.mjs → chunk-NWPFUFXX.mjs} +6 -6
- package/dist/libraries/backend/{chunk-NAP2URIW.mjs → chunk-Q7SD535L.mjs} +172 -2
- package/dist/libraries/backend/{chunk-7K3RATTK.mjs → chunk-SDL7BFTH.mjs} +1 -1
- package/dist/libraries/backend/convex.js +172 -2
- package/dist/libraries/backend/convex.mjs +7 -7
- package/dist/libraries/backend/elysia.js +172 -2
- package/dist/libraries/backend/elysia.mjs +7 -7
- package/dist/libraries/backend/express.d.mts +1 -1
- package/dist/libraries/backend/express.d.ts +1 -1
- package/dist/libraries/backend/express.js +172 -2
- package/dist/libraries/backend/express.mjs +7 -7
- package/dist/libraries/backend/fastify.js +172 -2
- package/dist/libraries/backend/fastify.mjs +7 -7
- package/dist/libraries/backend/hono.js +172 -2
- package/dist/libraries/backend/hono.mjs +7 -7
- package/dist/libraries/backend/index.d.mts +1 -1
- package/dist/libraries/backend/index.d.ts +1 -1
- package/dist/libraries/backend/index.js +172 -2
- package/dist/libraries/backend/index.mjs +7 -7
- package/dist/libraries/backend/next.js +172 -2
- package/dist/libraries/backend/next.mjs +7 -7
- package/dist/libraries/backend/react-router.js +172 -2
- package/dist/libraries/backend/react-router.mjs +7 -7
- package/dist/libraries/backend/{referralTypes-C1eZ8cjO.d.mts → referralTypes-DSv2hpmP.d.mts} +178 -44
- package/dist/libraries/backend/{referralTypes-FlI0fYwz.d.ts → referralTypes-DdKvvqSK.d.ts} +178 -44
- package/dist/libraries/backend/remix_dep.js +172 -2
- package/dist/libraries/backend/remix_dep.mjs +7 -7
- package/dist/libraries/backend/routes/backendRouter.js +172 -2
- package/dist/libraries/backend/routes/backendRouter.mjs +7 -7
- package/dist/libraries/backend/routes/entityRoutes.js +172 -2
- package/dist/libraries/backend/routes/entityRoutes.mjs +3 -3
- package/dist/libraries/backend/routes/genRoutes.js +172 -2
- package/dist/libraries/backend/routes/genRoutes.mjs +3 -3
- package/dist/libraries/backend/routes/productRoutes.js +172 -2
- package/dist/libraries/backend/routes/productRoutes.mjs +3 -3
- package/dist/libraries/backend/routes/referralRoutes.js +172 -2
- package/dist/libraries/backend/routes/referralRoutes.mjs +3 -3
- package/dist/libraries/backend/supabase.js +172 -2
- package/dist/libraries/backend/supabase.mjs +7 -7
- package/dist/libraries/backend/tanstack.js +172 -2
- package/dist/libraries/backend/tanstack.mjs +7 -7
- package/dist/libraries/backend/utils/backendRes.js +172 -2
- package/dist/libraries/backend/utils/backendRes.mjs +1 -1
- package/dist/libraries/backend/utils/withAuth.d.mts +1 -1
- package/dist/libraries/backend/utils/withAuth.d.ts +1 -1
- package/dist/libraries/backend/utils/withAuth.js +172 -2
- package/dist/libraries/backend/utils/withAuth.mjs +2 -2
- package/dist/libraries/react/AutumnContext.js +176 -4
- package/dist/libraries/react/AutumnContext.mjs +4 -4
- package/dist/libraries/react/BaseAutumnProvider.js +176 -15
- package/dist/libraries/react/BaseAutumnProvider.mjs +9 -9
- package/dist/libraries/react/ReactAutumnProvider.js +176 -15
- package/dist/libraries/react/ReactAutumnProvider.mjs +10 -10
- package/dist/libraries/react/{chunk-2ENHPIYQ.mjs → chunk-52HVA7E4.mjs} +3 -3
- package/dist/libraries/react/{chunk-WYQMHQUE.mjs → chunk-5O3IHYFF.mjs} +172 -2
- package/dist/libraries/react/{chunk-JHFJKAXG.mjs → chunk-5YM6QT7V.mjs} +33 -33
- package/dist/libraries/react/{chunk-KP2Q65Y3.mjs → chunk-643J45JV.mjs} +2 -2
- package/dist/libraries/react/{chunk-YHT2JUXO.mjs → chunk-7HRCOEUW.mjs} +1 -1
- package/dist/libraries/react/{chunk-OMJJLT2Q.mjs → chunk-7JU3XHKL.mjs} +1 -1
- package/dist/libraries/react/{chunk-XK3AXQED.mjs → chunk-BT5OY2CA.mjs} +3 -13
- package/dist/libraries/react/{chunk-KMYL54B4.mjs → chunk-DKOF357C.mjs} +1 -1
- package/dist/libraries/react/{chunk-4NZ7ML7V.mjs → chunk-M3SON3SH.mjs} +2 -2
- package/dist/libraries/react/{chunk-67RWFVWN.mjs → chunk-OSYZMMQC.mjs} +2 -2
- package/dist/libraries/react/{chunk-6D6TYTTO.mjs → chunk-P6CAHZVT.mjs} +1 -2
- package/dist/libraries/react/{chunk-VZY225C6.mjs → chunk-RP56DI4O.mjs} +2 -2
- package/dist/libraries/react/{chunk-FDNQ6GRK.mjs → chunk-SWVRRNIW.mjs} +1 -1
- package/dist/libraries/react/{chunk-U3OQJXCW.mjs → chunk-TOAZUTY6.mjs} +8 -6
- package/dist/libraries/react/{chunk-3MF54MDU.mjs → chunk-WBBWID5F.mjs} +1 -1
- package/dist/libraries/react/{chunk-TTLL63A4.mjs → chunk-Z7REFVM4.mjs} +3 -3
- package/dist/libraries/react/client/ReactAutumnClient.js +176 -4
- package/dist/libraries/react/client/ReactAutumnClient.mjs +3 -3
- package/dist/libraries/react/client/types/clientGenTypes.js +172 -2
- package/dist/libraries/react/client/types/clientGenTypes.mjs +1 -1
- package/dist/libraries/react/components/checkout-dialog/checkout-dialog-synced.css +3 -0
- package/dist/libraries/react/components/checkout-dialog/checkout-dialog-synced.js +181 -20
- package/dist/libraries/react/components/checkout-dialog/checkout-dialog-synced.mjs +26 -26
- package/dist/libraries/react/components/paywall-dialog/paywall-dialog-synced.css +3 -0
- package/dist/libraries/react/components/paywall-dialog/paywall-dialog-synced.js +176 -4
- package/dist/libraries/react/components/paywall-dialog/paywall-dialog-synced.mjs +26 -26
- package/dist/libraries/react/components/pricing-table/pricing-table-synced.css +3 -0
- package/dist/libraries/react/components/pricing-table/pricing-table-synced.js +181 -20
- package/dist/libraries/react/components/pricing-table/pricing-table-synced.mjs +26 -26
- package/dist/libraries/react/components/ui/button.d.mts +2 -2
- package/dist/libraries/react/components/ui/button.d.ts +2 -2
- package/dist/libraries/react/components/ui/dialog.mjs +2 -2
- package/dist/libraries/react/components/ui/popover.mjs +2 -2
- package/dist/libraries/react/hooks/helpers/handleCheck.js +172 -2
- package/dist/libraries/react/hooks/helpers/handleCheck.mjs +2 -2
- package/dist/libraries/react/hooks/helpers/useAutumnBase.js +172 -3
- package/dist/libraries/react/hooks/helpers/useAutumnBase.mjs +3 -3
- package/dist/libraries/react/hooks/useAnalytics.js +176 -4
- package/dist/libraries/react/hooks/useAnalytics.mjs +5 -5
- package/dist/libraries/react/hooks/useCustomer.d.mts +60 -2
- package/dist/libraries/react/hooks/useCustomer.d.ts +60 -2
- package/dist/libraries/react/hooks/useCustomer.js +176 -15
- package/dist/libraries/react/hooks/useCustomer.mjs +9 -9
- package/dist/libraries/react/hooks/useCustomerBase.d.mts +44 -3
- package/dist/libraries/react/hooks/useCustomerBase.d.ts +44 -3
- package/dist/libraries/react/hooks/useCustomerBase.js +176 -15
- package/dist/libraries/react/hooks/useCustomerBase.mjs +8 -8
- package/dist/libraries/react/hooks/useEntity.js +176 -5
- package/dist/libraries/react/hooks/useEntity.mjs +9 -9
- package/dist/libraries/react/hooks/useEntityBase.js +176 -5
- package/dist/libraries/react/hooks/useEntityBase.mjs +8 -8
- package/dist/libraries/react/hooks/usePaywall.js +176 -4
- package/dist/libraries/react/hooks/usePaywall.mjs +5 -5
- package/dist/libraries/react/hooks/usePricingTable.js +176 -4
- package/dist/libraries/react/hooks/usePricingTable.mjs +6 -6
- package/dist/libraries/react/hooks/usePricingTableBase.js +172 -2
- package/dist/libraries/react/hooks/usePricingTableBase.mjs +2 -2
- package/dist/libraries/react/index.d.mts +104 -7
- package/dist/libraries/react/index.d.ts +104 -7
- package/dist/libraries/react/index.js +182 -21
- package/dist/libraries/react/index.mjs +182 -21
- package/dist/next/client/hooks/useCustomer.d.mts +44 -7
- package/dist/next/client/hooks/useCustomer.d.ts +44 -7
- package/dist/next/server/cusActions.d.mts +178 -44
- package/dist/next/server/cusActions.d.ts +178 -44
- package/dist/sdk/index.d.mts +178 -44
- package/dist/sdk/index.d.ts +178 -44
- package/dist/sdk/index.js +171 -1
- package/dist/sdk/index.mjs +171 -1
- package/dist/styles/global.css +3 -0
- package/dist/utils/encryptUtils.js +172 -2
- package/dist/utils/encryptUtils.mjs +172 -2
- package/package.json +1 -1
- package/dist/libraries/react/{chunk-7JNU5ABT.mjs → chunk-FJWZPMWU.mjs} +3 -3
- package/dist/libraries/react/{chunk-LCWL3TIT.mjs → chunk-OTZ65PCT.mjs} +3 -3
package/dist/sdk/index.d.mts
CHANGED
|
@@ -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.
|
|
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
|
-
},
|
|
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
|
-
},
|
|
545
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -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.
|
|
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
|
-
},
|
|
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
|
-
},
|
|
545
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|