@freemius/sdk 0.0.1 → 0.0.3

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/index.d.mts CHANGED
@@ -1,123 +1,13 @@
1
- import createClient from "openapi-fetch";
2
- import { CheckoutOptions, CheckoutPopupArbitraryParams, CheckoutPopupParams } from "@freemius/checkout";
1
+ import createClient, { QuerySerializerOptions } from "openapi-fetch";
2
+ import { CheckoutOptions, CheckoutPopupParams } from "@freemius/checkout";
3
+ import * as zod from "zod";
3
4
  import * as http0 from "http";
4
5
 
5
- //#region src/contracts/types.d.ts
6
- /**
7
- * This file holds all generic types used across the SDK, not specific to any contract.
8
- */
9
- declare enum BILLING_CYCLE {
10
- MONTHLY = "monthly",
11
- YEARLY = "yearly",
12
- ONEOFF = "oneoff",
13
- }
14
- interface PagingOptions {
15
- count?: number;
16
- offset?: number;
17
- }
18
- type ApiEntitiesFilter<T> = Omit<NonNullable<T>, 'count' | 'offset'>;
19
- declare enum CURRENCY {
20
- USD = "USD",
21
- EUR = "EUR",
22
- GBP = "GBP",
23
- }
24
- type PaymentMethod = 'card' | 'paypal' | 'ideal';
25
- //#endregion
26
- //#region src/contracts/purchase.d.ts
27
- interface PurchaseData {
28
- /**
29
- * Email address of the user associated with the license. This is unique to the user and is used for communication regarding the license.
30
- */
31
- email: string;
32
- /**
33
- * First name of the user associated with the license.
34
- */
35
- firstName: string;
36
- /**
37
- * Last name of the user associated with the license.
38
- */
39
- lastName: string;
40
- /**
41
- * ID of the Freemius user.
42
- */
43
- userId: string;
44
- /**
45
- * ID of the Freemius plan the license is associated with.
46
- */
47
- planId: string;
48
- /**
49
- * ID of the Freemius pricing of the plan (used to determine the quota of the purchase).
50
- */
51
- pricingId: string;
52
- /**
53
- * ID of the Freemius license.
54
- *
55
- * Use this ID to make additional API calls related to the license and associated subscriptions.
56
- */
57
- licenseId: string;
58
- /**
59
- * Expiration date of the license.
60
- *
61
- * If `null` then the license never expires (for one-off purchases).
62
- */
63
- expiration: Date | null;
64
- /**
65
- * Indicates if the license is canceled.
66
- */
67
- canceled: boolean;
68
- /**
69
- * Quota/Units associated with the license. If `null`, then it means the license has unlimited quota.
70
- */
71
- quota: number | null;
72
- /**
73
- * ID of the Freemius subscription associated with the license, if any.
74
- *
75
- * This is optional and may be `null` if the license is not associated with a subscription (for one-off purchases or if the subscription is cancelled already).
76
- */
77
- subscriptionId: string | null;
78
- /**
79
- * Billing cycle of the subscription, if applicable.
80
- *
81
- * This is optional and may be `null` if the license is not associated with a subscription.
82
- * The billing cycle could be `oneoff`, in case a subscription was created against a one-off trial.
83
- */
84
- billingCycle: BILLING_CYCLE | null;
85
- /**
86
- * Indicates if the license is currently active. Only relevant for subscriptions.
87
- */
88
- isActive: boolean;
89
- /**
90
- * Initial amount charged for the purchase, if applicable.
91
- */
92
- initialAmount: number | null;
93
- /**
94
- * Renewal amount for the subscription, if applicable.
95
- */
96
- renewalAmount: number | null;
97
- /**
98
- * Renewal date for the subscription, if applicable.
99
- */
100
- renewalDate: Date | null;
101
- /**
102
- * Currency of the purchase, if applicable.
103
- */
104
- currency: CURRENCY | null;
105
- /**
106
- * Payment method used for the purchase, if applicable.
107
- */
108
- paymentMethod: PaymentMethod | null;
109
- /**
110
- * Date when the purchase was created. This reflects the created date of the license. The subscription however can get cancelled or updated durign the life-cycle and shouldn't be used to determine the purchase date.
111
- */
112
- created: Date;
113
- }
114
- //#endregion
115
6
  //#region src/api/schema.d.ts
116
7
  /**
117
8
  * This file was auto-generated by openapi-typescript.
118
9
  * Do not make direct changes to the file.
119
10
  */
120
-
121
11
  interface paths {
122
12
  '/developers/{developer_id}/bank_account/{bank_account_id}.json': {
123
13
  parameters: {
@@ -1623,7 +1513,7 @@ interface paths {
1623
1513
  post?: never;
1624
1514
  /**
1625
1515
  * Cancel a trial
1626
- * @description Cancel a trial associated with an specified install.
1516
+ * @description Cancel a trial associated with a specific install.
1627
1517
  */
1628
1518
  delete: operations['installations/cancel-trial'];
1629
1519
  options?: never;
@@ -2248,6 +2138,37 @@ interface paths {
2248
2138
  patch?: never;
2249
2139
  trace?: never;
2250
2140
  };
2141
+ '/products/{product_id}/payments/{payment_id}/invoice.pdf': {
2142
+ parameters: {
2143
+ query?: never;
2144
+ header?: never;
2145
+ path: {
2146
+ /**
2147
+ * @description The ID of the product.
2148
+ * @example 1234
2149
+ */
2150
+ product_id: components['parameters']['product_id'];
2151
+ /**
2152
+ * @description The ID of the payment.
2153
+ * @example 1234
2154
+ */
2155
+ payment_id: components['parameters']['payment_id'];
2156
+ };
2157
+ cookie?: never;
2158
+ };
2159
+ /**
2160
+ * Download invoice
2161
+ * @description Download invoice of a payment.
2162
+ */
2163
+ get: operations['payments/download-invoice'];
2164
+ put?: never;
2165
+ post?: never;
2166
+ delete?: never;
2167
+ options?: never;
2168
+ head?: never;
2169
+ patch?: never;
2170
+ trace?: never;
2171
+ };
2251
2172
  '/products/{product_id}/ping.json': {
2252
2173
  parameters: {
2253
2174
  query?: never;
@@ -3918,7 +3839,7 @@ interface components {
3918
3839
  * @example ls
3919
3840
  * @enum {string}
3920
3841
  */
3921
- source_external_id?: 'freemius' | 'edd' | 'easydigitaldownloads' | 'woo' | 'wc' | 'woocommerce' | 'gumroad' | 'cc' | 'codecanyon' | 'tf' | 'themeforest' | 'appsumo' | 'sendowl' | 'whmcs' | 'ls' | 'lemonsqueezy';
3842
+ source_external_id?: 'freemius' | 'edd' | 'others' | 'easydigitaldownloads' | 'woo' | 'wc' | 'woocommerce' | 'gumroad' | 'cc' | 'codecanyon' | 'tf' | 'themeforest' | 'appsumo' | 'sendowl' | 'whmcs' | 'ls' | 'lemonsqueezy';
3922
3843
  /**
3923
3844
  * @description
3924
3845
  * The source of the migration data. To get support migrating from other platform please see our [documentation](https://freemius.com/help/documentation/migration/).
@@ -4516,6 +4437,14 @@ interface components {
4516
4437
  */
4517
4438
  is_featured?: boolean;
4518
4439
  };
4440
+ FeatureEnriched: components['schemas']['Feature'] & {
4441
+ /**
4442
+ * @description The value of the feature associated with the plan. For example the feature name could be "AI Credits" and the value could be "1000".
4443
+ * @example 1000 Units
4444
+ */
4445
+ value?: string;
4446
+ plan_id?: components['schemas']['CommonProperties']['plan_id'];
4447
+ };
4519
4448
  FeaturePlan: {
4520
4449
  id?: components['schemas']['CommonProperties']['id'];
4521
4450
  created?: components['schemas']['CommonProperties']['created'];
@@ -5872,6 +5801,8 @@ interface components {
5872
5801
  eur?: number;
5873
5802
  };
5874
5803
  };
5804
+ FSEndpointDeveloperPluginSubscriptions: components['schemas']['Discount'][];
5805
+ FSEndpointDeveloperPluginUserSubscriptions: components['schemas']['Discount'][];
5875
5806
  };
5876
5807
  responses: {
5877
5808
  /** @description The API has no content to send. This usually happens when some entity is deleted. */
@@ -7648,6 +7579,8 @@ interface operations {
7648
7579
  accepted_payments?: 0 | 1;
7649
7580
  /** @description `True` to expose license key to customers upon purchase/subscription. (Available for 'SaaS' products only) */
7650
7581
  expose_license_key?: boolean;
7582
+ /** @description `True` to include in the after-purchase emails the customer portal login link. */
7583
+ enable_after_purchase_email_login_link?: boolean;
7651
7584
  };
7652
7585
  };
7653
7586
  };
@@ -8963,6 +8896,9 @@ interface operations {
8963
8896
  'installations/cancel-trial': {
8964
8897
  parameters: {
8965
8898
  query?: {
8899
+ /** @description Optional cancellation reason IDs. */
8900
+ reason_ids?: components['schemas']['Uninstall']['reason_id'][];
8901
+ reason?: components['schemas']['Uninstall']['reason_info'];
8966
8902
  /**
8967
8903
  * @description Comma separated list of fields to return in the response. If not specified, all fields are returned.
8968
8904
  * @example id,name,slug
@@ -8984,16 +8920,17 @@ interface operations {
8984
8920
  };
8985
8921
  cookie?: never;
8986
8922
  };
8987
- requestBody?: {
8988
- content: {
8989
- 'application/json': {
8990
- reason_ids?: components['schemas']['Uninstall']['reason_id'][];
8991
- reason?: components['schemas']['Uninstall']['reason_info'];
8923
+ requestBody?: never;
8924
+ responses: {
8925
+ /** @description The install with cancelled trial. */
8926
+ 200: {
8927
+ headers: {
8928
+ [name: string]: unknown;
8929
+ };
8930
+ content: {
8931
+ 'application/json': components['schemas']['Install'];
8992
8932
  };
8993
8933
  };
8994
- };
8995
- responses: {
8996
- 204: components['responses']['204'];
8997
8934
  400: components['responses']['400'];
8998
8935
  401: components['responses']['401'];
8999
8936
  402: components['responses']['402'];
@@ -10128,6 +10065,47 @@ interface operations {
10128
10065
  404: components['responses']['404'];
10129
10066
  };
10130
10067
  };
10068
+ 'payments/download-invoice': {
10069
+ parameters: {
10070
+ query?: {
10071
+ /**
10072
+ * @description Comma separated list of fields to return in the response. If not specified, all fields are returned.
10073
+ * @example id,name,slug
10074
+ */
10075
+ fields?: components['parameters']['fields'];
10076
+ };
10077
+ header?: never;
10078
+ path: {
10079
+ /**
10080
+ * @description The ID of the product.
10081
+ * @example 1234
10082
+ */
10083
+ product_id: components['parameters']['product_id'];
10084
+ /**
10085
+ * @description The ID of the payment.
10086
+ * @example 1234
10087
+ */
10088
+ payment_id: components['parameters']['payment_id'];
10089
+ };
10090
+ cookie?: never;
10091
+ };
10092
+ requestBody?: never;
10093
+ responses: {
10094
+ /** @description PDF invoice */
10095
+ 200: {
10096
+ headers: {
10097
+ [name: string]: unknown;
10098
+ };
10099
+ content: {
10100
+ 'application/pdf': unknown;
10101
+ };
10102
+ };
10103
+ 400: components['responses']['400'];
10104
+ 401: components['responses']['401'];
10105
+ 402: components['responses']['402'];
10106
+ 404: components['responses']['404'];
10107
+ };
10108
+ };
10131
10109
  'products/gdpr-compliance-check': {
10132
10110
  parameters: {
10133
10111
  query: {
@@ -10806,25 +10784,34 @@ interface operations {
10806
10784
  };
10807
10785
  content: {
10808
10786
  'application/json': {
10809
- plugin?: components['schemas']['Plugin'];
10787
+ plugin?: {
10788
+ icon?: components['schemas']['Plugin']['icon'];
10789
+ slug?: components['schemas']['Plugin']['slug'];
10790
+ title?: components['schemas']['Plugin']['title'];
10791
+ type?: components['schemas']['Plugin']['type'];
10792
+ money_back_period?: components['schemas']['Plugin']['money_back_period'];
10793
+ refund_policy?: components['schemas']['Plugin']['refund_policy'];
10794
+ public_key?: components['schemas']['Plugin']['public_key'];
10795
+ parent_plugin_id?: components['schemas']['Plugin']['parent_plugin_id'];
10796
+ /** @description The label used for the selling unit of the product, e.g., 'Credit', 'Activation', etc. The resulting object will have both singular and plural. */
10797
+ selling_unit_label?: {
10798
+ /**
10799
+ * @description The singular form of the selling unit label.
10800
+ * @example Credit
10801
+ */
10802
+ singular?: string;
10803
+ /**
10804
+ * @description The plural form of the selling unit label.
10805
+ * @example Credits
10806
+ */
10807
+ plural?: string;
10808
+ };
10809
+ };
10810
10810
  plans?: (components['schemas']['Plan'] & {
10811
10811
  pricing?: components['schemas']['Pricing'][];
10812
10812
  } & {
10813
- features?: components['schemas']['Feature'][];
10813
+ features?: components['schemas']['FeatureEnriched'][];
10814
10814
  })[];
10815
- /** @description The label used for the selling unit of the product, e.g., 'Credit', 'Activation', etc. The resulting object will have both singular and plural. */
10816
- selling_unit_label?: {
10817
- /**
10818
- * @description The singular form of the selling unit label.
10819
- * @example Credit
10820
- */
10821
- singular?: string;
10822
- /**
10823
- * @description The plural form of the selling unit label.
10824
- * @example Credits
10825
- */
10826
- plural?: string;
10827
- };
10828
10815
  /** @description Verified and featured reviews of the product. */
10829
10816
  reviews?: components['schemas']['PluginReview'][];
10830
10817
  /**
@@ -11422,7 +11409,13 @@ interface operations {
11422
11409
  [name: string]: unknown;
11423
11410
  };
11424
11411
  content: {
11425
- 'application/json': components['schemas']['Subscription'];
11412
+ 'application/json': components['schemas']['Subscription'] & {
11413
+ /**
11414
+ * @description Shows whether a subscription cancellation discount was applied to the subscription.
11415
+ * @example false
11416
+ */
11417
+ has_subscription_cancellation_discount?: boolean | null;
11418
+ };
11426
11419
  };
11427
11420
  };
11428
11421
  401: components['responses']['401'];
@@ -11484,6 +11477,8 @@ interface operations {
11484
11477
  filter?: 'all' | 'active' | 'cancelled';
11485
11478
  /** @description When set to `true` enrich the subscriptions with the plan name, install URL & title, and user email. */
11486
11479
  extended?: boolean;
11480
+ /** @description When set to `true` enrich the subscription to include any cancellation discounts applied to the subscriptions. */
11481
+ enrich_with_cancellation_discounts?: boolean;
11487
11482
  /**
11488
11483
  * @description The number of records to return.
11489
11484
  * @example 10
@@ -11542,8 +11537,16 @@ interface operations {
11542
11537
  * @example Website title
11543
11538
  */
11544
11539
  title?: string | null;
11540
+ /**
11541
+ * @description Whether subscription cancellation discount was already applied. (Only available when `enrich_with_cancellation_discounts` is set to `true`.)
11542
+ * @example true
11543
+ */
11544
+ has_subscription_cancellation_discount?: boolean | null;
11545
11545
  })[];
11546
- discounts?: components['schemas']['Discount'][];
11546
+ /** @description The key represents the ID of the subscription */
11547
+ discounts?: {
11548
+ [key: string]: components['schemas']['Discount'][];
11549
+ };
11547
11550
  };
11548
11551
  };
11549
11552
  };
@@ -12715,6 +12718,8 @@ interface operations {
12715
12718
  sort?: 'id' | 'next_payment';
12716
12719
  /** @description Search by subscription ID, external subscription ID or user email. */
12717
12720
  search?: string;
12721
+ /** @description When set to `true` enrich the subscription to include any cancellation discounts applied to the subscriptions. */
12722
+ enrich_with_cancellation_discounts?: boolean;
12718
12723
  };
12719
12724
  header?: never;
12720
12725
  path: {
@@ -12761,8 +12766,16 @@ interface operations {
12761
12766
  * @example Website title
12762
12767
  */
12763
12768
  title?: string | null;
12769
+ /**
12770
+ * @description Shows whether a renewal discount was already applied to the subscription.
12771
+ * @example false
12772
+ */
12773
+ has_subscription_cancellation_discount?: boolean | null;
12764
12774
  })[];
12765
- discounts?: components['schemas']['Discount'][];
12775
+ /** @description The key represents the ID of the subscription */
12776
+ discounts?: {
12777
+ [key: string]: components['schemas']['Discount'][];
12778
+ };
12766
12779
  };
12767
12780
  };
12768
12781
  };
@@ -12897,6 +12910,13 @@ type ApiAuthParams = {
12897
12910
  type FSId = string | number | bigint;
12898
12911
  type SubscriptionEntity = components['schemas']['Subscription'];
12899
12912
  type SubscriptionFilterOptions = ApiEntitiesFilter<operations['subscriptions/list']['parameters']['query']>;
12913
+ type UserSubscriptionEntity = NonNullable<operations['users/list-subscriptions']['responses'][200]['content']['application/json']['subscriptions']>[number];
12914
+ type SubscriptionDiscountEntity = NonNullable<operations['users/list-subscriptions']['responses'][200]['content']['application/json']['discounts']>[string][number];
12915
+ type UserSubscriptionWithDiscounts = UserSubscriptionEntity & {
12916
+ discounts: SubscriptionDiscountEntity[];
12917
+ };
12918
+ type SubscriptionCancellationResult = operations['subscriptions/cancel']['responses'][200]['content']['application/json'];
12919
+ type SubscriptionRenewalCouponResult = operations['subscriptions/update']['responses'][200]['content']['application/json'];
12900
12920
  type UserEntity = components['schemas']['User'];
12901
12921
  type UserFilterOptions = ApiEntitiesFilter<operations['users/list']['parameters']['query']>;
12902
12922
  type UserBillingEntity = components['schemas']['Billing'];
@@ -12907,56 +12927,249 @@ type UserPluginEntity = components['schemas']['UserPluginEnriched'];
12907
12927
  type LicenseEntity = components['schemas']['License'];
12908
12928
  type LicenseFilterOptions = ApiEntitiesFilter<operations['licenses/list']['parameters']['query']>;
12909
12929
  type PaymentEntity = components['schemas']['Payment'];
12930
+ type PaymentFilterOptions = ApiEntitiesFilter<operations['payments/list']['parameters']['query']>;
12910
12931
  type ProductEntity = components['schemas']['Plugin'];
12911
12932
  type PricingTableData = operations['products/retrieve-pricing-table-data']['responses'][200]['content']['application/json'];
12912
12933
  type PricingEntity = components['schemas']['Pricing'];
12934
+ type PlanEntity = components['schemas']['Plan'];
12913
12935
  type BillingEntity = components['schemas']['Billing'];
12936
+ type BillingUpdatePayload = operations['users/update-or-create-billing']['requestBody']['content']['application/json'];
12914
12937
  type EventEntity = components['schemas']['EventLog'];
12915
12938
  type InstallEntity = components['schemas']['Install'];
12916
12939
  type BillingCycleApiEnum = components['schemas']['CommonEnums']['BillingCycle'];
12917
12940
  type CurrencyApiEnum = components['schemas']['CommonEnums']['Currency'];
12941
+ type SellingUnit = Required<NonNullable<NonNullable<operations['products/retrieve-pricing-table-data']['responses']['200']['content']['application/json']['plugin']>['selling_unit_label']>>;
12942
+ type CouponEntityEnriched = components['schemas']['CouponEntityEnriched'];
12943
+ type SubscriptionCancellationReasonType = components['schemas']['Uninstall']['reason_id'];
12918
12944
  //#endregion
12919
- //#region src/contracts/portal.d.ts
12920
- interface PortalSubscription {
12921
- subscriptionId: string;
12922
- licenseId: string;
12923
- planId: string;
12924
- pricingId: string;
12925
- planTitle: string;
12926
- renewalAmount: number;
12927
- initialAmount: number;
12928
- billingCycle: BILLING_CYCLE | null;
12929
- isActive: boolean;
12930
- renewalDate: Date | null;
12931
- currency: CURRENCY;
12932
- cancelledAt?: Date | null;
12933
- createdAt: Date;
12934
- checkoutUpgradeAuthorization?: string | null;
12935
- quota: number | null;
12936
- paymentMethod: PaymentMethod | null;
12945
+ //#region src/contracts/types.d.ts
12946
+ /**
12947
+ * This file holds all generic types used across the SDK, not specific to any contract.
12948
+ */
12949
+ declare enum BILLING_CYCLE {
12950
+ MONTHLY = "monthly",
12951
+ YEARLY = "yearly",
12952
+ ONEOFF = "oneoff",
12937
12953
  }
12938
- type PortalPlans = NonNullable<operations['products/retrieve-pricing-table-data']['responses']['200']['content']['application/json']['plans']>;
12939
- type PortalPayment = PaymentEntity & {
12940
- invoiceUrl: string;
12941
- paymentMethod: PaymentMethod;
12942
- createdAt: Date;
12943
- quota: number | null;
12944
- planTitle: string;
12945
- };
12946
- type SellingUnit = NonNullable<operations['products/retrieve-pricing-table-data']['responses']['200']['content']['application/json']['selling_unit_label']>;
12947
- interface PortalData {
12948
- user: UserEntity;
12949
- subscriptions: {
12950
- primary: PortalSubscription | null;
12951
- active: PortalSubscription[];
12952
- past: PortalSubscription[];
12953
- };
12954
- billing: BillingEntity | null;
12954
+ interface PagingOptions {
12955
+ count?: number;
12956
+ offset?: number;
12957
+ }
12958
+ type ApiEntitiesFilter<T> = Omit<NonNullable<T>, 'count' | 'offset'>;
12959
+ declare enum CURRENCY {
12960
+ USD = "USD",
12961
+ EUR = "EUR",
12962
+ GBP = "GBP",
12963
+ }
12964
+ type PaymentMethod = 'card' | 'paypal' | 'ideal';
12965
+ type UserRetriever = () => Promise<{
12966
+ id: FSId;
12967
+ primaryLicenseId?: FSId;
12968
+ email?: string;
12969
+ } | {
12970
+ email: string;
12971
+ } | null>;
12972
+ /**
12973
+ * @todo - Add a more unified way to get handlers so that we can simplify the Checkout & Customer Portal request processors.
12974
+ */
12975
+ interface RequestProcessor<Config> {
12976
+ createProcessor(config: Config): (request: Request) => Promise<Response>;
12977
+ process(config: Config, request: Request): Promise<Response>;
12978
+ }
12979
+ //#endregion
12980
+ //#region src/contracts/purchase.d.ts
12981
+ interface PurchaseData {
12982
+ /**
12983
+ * Email address of the user associated with the license. This is unique to the user and is used for communication regarding the license.
12984
+ */
12985
+ email: string;
12986
+ /**
12987
+ * First name of the user associated with the license.
12988
+ */
12989
+ firstName: string;
12990
+ /**
12991
+ * Last name of the user associated with the license.
12992
+ */
12993
+ lastName: string;
12994
+ /**
12995
+ * ID of the Freemius user.
12996
+ */
12997
+ userId: string;
12998
+ /**
12999
+ * ID of the Freemius plan the license is associated with.
13000
+ */
13001
+ planId: string;
13002
+ /**
13003
+ * ID of the Freemius pricing of the plan (used to determine the quota of the purchase).
13004
+ */
13005
+ pricingId: string;
13006
+ /**
13007
+ * ID of the Freemius license.
13008
+ *
13009
+ * Use this ID to make additional API calls related to the license and associated subscriptions.
13010
+ */
13011
+ licenseId: string;
13012
+ /**
13013
+ * Expiration date of the license.
13014
+ *
13015
+ * If `null` then the license never expires (for one-off purchases).
13016
+ */
13017
+ expiration: Date | null;
13018
+ /**
13019
+ * Indicates if the license is canceled.
13020
+ */
13021
+ canceled: boolean;
13022
+ /**
13023
+ * Quota/Units associated with the license. If `null`, then it means the license has unlimited quota.
13024
+ */
13025
+ quota: number | null;
13026
+ /**
13027
+ * ID of the Freemius subscription associated with the license, if any.
13028
+ *
13029
+ * This is optional and may be `null` if the license is not associated with a subscription (for one-off purchases or if the subscription is cancelled already).
13030
+ */
13031
+ subscriptionId: string | null;
13032
+ /**
13033
+ * Billing cycle of the subscription, if applicable.
13034
+ *
13035
+ * This is optional and may be `null` if the license is not associated with a subscription.
13036
+ * The billing cycle could be `oneoff`, in case a subscription was created against a one-off trial.
13037
+ */
13038
+ billingCycle: BILLING_CYCLE | null;
13039
+ /**
13040
+ * Indicates if the license is currently active. Only relevant for subscriptions.
13041
+ */
13042
+ isActive: boolean;
13043
+ /**
13044
+ * Initial amount charged for the purchase, if applicable.
13045
+ */
13046
+ initialAmount: number | null;
13047
+ /**
13048
+ * Renewal amount for the subscription, if applicable.
13049
+ */
13050
+ renewalAmount: number | null;
13051
+ /**
13052
+ * Renewal date for the subscription, if applicable.
13053
+ */
13054
+ renewalDate: Date | null;
13055
+ /**
13056
+ * Currency of the purchase, if applicable.
13057
+ */
13058
+ currency: CURRENCY | null;
13059
+ /**
13060
+ * Payment method used for the purchase, if applicable.
13061
+ */
13062
+ paymentMethod: PaymentMethod | null;
13063
+ /**
13064
+ * Date when the purchase was created. This reflects the created date of the license. The subscription however can get cancelled or updated durign the life-cycle and shouldn't be used to determine the purchase date.
13065
+ */
13066
+ created: Date;
13067
+ }
13068
+ type PurchaseEntitlementType = 'subscription' | 'oneoff';
13069
+ /**
13070
+ * Data structure representing a purchase entitlement, which links a user to a specific license and plan within the Freemius system.
13071
+ * This is what is typically stored in your own database to keep track of user entitlements.
13072
+ */
13073
+ interface PurchaseEntitlementData {
13074
+ /**
13075
+ * The unique identifier of the user in the Freemius system.
13076
+ */
13077
+ fsLicenseId: string;
13078
+ /**
13079
+ * The unique identifier of the plan in the Freemius system.
13080
+ */
13081
+ fsPlanId: string;
13082
+ /**
13083
+ * The unique identifier of the pricing in the Freemius system.
13084
+ */
13085
+ fsPricingId: string;
13086
+ /**
13087
+ * The unique identifier of the user in the Freemius system.
13088
+ */
13089
+ fsUserId: string;
13090
+ /**
13091
+ * The type of entitlement, which can be either 'subscription' or 'oneoff'.
13092
+ */
13093
+ type: PurchaseEntitlementType;
13094
+ /**
13095
+ * The expiration date of the entitlement. If `null`, the entitlement does not expire.
13096
+ * If you are passing a string, then it must of the format "YYYY-MM-DD HH:mm:ss" in UTC.
13097
+ */
13098
+ expiration: Date | null | string;
13099
+ /**
13100
+ * The date when the entitlement was created. This is useful for record-keeping and auditing purposes.
13101
+ */
13102
+ createdAt: Date | string;
13103
+ /**
13104
+ * Indicates whether the entitlement has been canceled.
13105
+ */
13106
+ isCanceled: boolean;
13107
+ }
13108
+ //#endregion
13109
+ //#region src/contracts/portal.d.ts
13110
+ interface PortalSubscription {
13111
+ subscriptionId: string;
13112
+ licenseId: string;
13113
+ planId: string;
13114
+ pricingId: string;
13115
+ planTitle: string;
13116
+ renewalAmount: number;
13117
+ initialAmount: number;
13118
+ billingCycle: BILLING_CYCLE | null;
13119
+ isActive: boolean;
13120
+ renewalDate: Date | null;
13121
+ currency: CURRENCY;
13122
+ cancelledAt?: Date | null;
13123
+ createdAt: Date;
13124
+ checkoutUpgradeAuthorization?: string | null;
13125
+ quota: number | null;
13126
+ paymentMethod: PaymentMethod | null;
13127
+ upgradeUrl?: string;
13128
+ isTrial: boolean;
13129
+ trialEnds: Date | null;
13130
+ isFreeTrial: boolean;
13131
+ applyRenewalCancellationCouponUrl: string | null;
13132
+ cancelRenewalUrl: string;
13133
+ }
13134
+ type PortalPlans = NonNullable<operations['products/retrieve-pricing-table-data']['responses']['200']['content']['application/json']['plans']>;
13135
+ type PortalPayment = PaymentEntity & {
13136
+ invoiceUrl: string;
13137
+ paymentMethod: PaymentMethod;
13138
+ createdAt: Date;
13139
+ quota: number | null;
13140
+ planTitle: string;
13141
+ };
13142
+ type PortalBilling = (BillingEntity | null) & {
13143
+ updateUrl: string;
13144
+ };
13145
+ type PortalSubscriptions = {
13146
+ primary: PortalSubscription | null;
13147
+ active: PortalSubscription[];
13148
+ past: PortalSubscription[];
13149
+ };
13150
+ interface PortalData {
13151
+ user: UserEntity;
13152
+ endpoint: string;
13153
+ subscriptions: PortalSubscriptions;
13154
+ billing: PortalBilling;
12955
13155
  payments: PortalPayment[] | null;
12956
13156
  plans: PortalPlans;
12957
13157
  sellingUnit: SellingUnit;
12958
13158
  productId: string;
12959
13159
  checkoutOptions: CheckoutOptions;
13160
+ cancellationCoupons: Pick<CouponEntityEnriched, 'has_renewals_discount' | 'type' | 'coupon_id' | 'discount' | 'discount_type' | 'discounts'>[] | null;
13161
+ }
13162
+ /**
13163
+ * Interface for actions that can be processed in the customer portal.
13164
+ */
13165
+ interface PortalAction {
13166
+ createAuthenticatedUrl(id: string, userId: FSId, endpoint: string): string;
13167
+ verifyAuthentication(request: Request): boolean;
13168
+ canHandle(request: Request): boolean;
13169
+ /**
13170
+ * Process the action and return a response.
13171
+ */
13172
+ processAction(request: Request): Promise<Response>;
12960
13173
  }
12961
13174
  //#endregion
12962
13175
  //#region src/contracts/checkout.d.ts
@@ -13037,6 +13250,87 @@ interface CheckoutRedirectData {
13037
13250
  */
13038
13251
  payment_id: string | null;
13039
13252
  }
13253
+ type CheckoutBuilderUserOptions = {
13254
+ email: string;
13255
+ firstName?: string;
13256
+ lastName?: string;
13257
+ name?: string;
13258
+ } | null | undefined;
13259
+ type CheckoutBuilderOptions = {
13260
+ /**
13261
+ * The user for whom the checkout is being created.
13262
+ * This should be an object containing user details like email, ID, etc.
13263
+ * If not provided, the checkout will be created without user context.
13264
+ */
13265
+ user?: CheckoutBuilderUserOptions;
13266
+ /**
13267
+ * Whether to use sandbox mode for the checkout.
13268
+ *
13269
+ * @default false
13270
+ */
13271
+ isSandbox?: boolean;
13272
+ /**
13273
+ * Whether to include the recommended option in the checkout for maximum conversion.
13274
+ *
13275
+ * @default true
13276
+ */
13277
+ withRecommendation?: boolean;
13278
+ /**
13279
+ * The title of the checkout modal.
13280
+ */
13281
+ title?: string;
13282
+ /**
13283
+ * Image to display in the checkout modal. Must be a valid https URL.
13284
+ */
13285
+ image?: string;
13286
+ /**
13287
+ * Optional plan ID to use for the checkout.
13288
+ * If provided, this will be used as the default plan for the checkout, instead of the first paid plan.
13289
+ */
13290
+ planId?: string;
13291
+ /**
13292
+ * Optional quota to set for the checkout.
13293
+ *
13294
+ * This is useful when purchasing credits or similar resources.
13295
+ */
13296
+ quota?: number;
13297
+ /**
13298
+ * Optional trial period configuration.
13299
+ *
13300
+ * This can be used to set a trial period for the checkout.
13301
+ * If not provided, the checkout will not have a trial period.
13302
+ */
13303
+ trial?: CheckoutOptions['trial'];
13304
+ };
13305
+ /**
13306
+ * Interface for actions that can be processed during the checkout flow.
13307
+ */
13308
+ interface CheckoutAction {
13309
+ /**
13310
+ * Determine if the action can be handled by this processor.
13311
+ */
13312
+ canHandle(request: Request): boolean;
13313
+ /**
13314
+ * Process the action and return a response.
13315
+ */
13316
+ processAction(request: Request): Promise<Response>;
13317
+ }
13318
+ //#endregion
13319
+ //#region src/contracts/pricing.d.ts
13320
+ type PricingData = {
13321
+ /**
13322
+ * Product's pricing plans to display in the paywall.
13323
+ */
13324
+ plans: PortalPlans;
13325
+ /**
13326
+ * Optional plan ID to use for top-up purchases.
13327
+ */
13328
+ topupPlan?: PortalPlans[number] | null;
13329
+ /**
13330
+ * The selling unit label for the product (e.g., "Credits", "Messages", etc.).
13331
+ */
13332
+ sellingUnit: SellingUnit;
13333
+ };
13040
13334
  //#endregion
13041
13335
  //#region src/api/parser.d.ts
13042
13336
  declare function idToNumber(id: FSId): number;
@@ -13055,7 +13349,7 @@ type FsApiClient = ReturnType<typeof createApiClient>;
13055
13349
  //#endregion
13056
13350
  //#region src/api/ApiBase.d.ts
13057
13351
  declare abstract class ApiBase<EntityType, FilterType extends Record<string, unknown> = Record<string, unknown>> {
13058
- readonly client: FsApiClient;
13352
+ protected readonly client: FsApiClient;
13059
13353
  readonly productId: number;
13060
13354
  constructor(productId: FSId, client: FsApiClient);
13061
13355
  abstract retrieve(id: FSId): Promise<EntityType | null>;
@@ -13078,6 +13372,10 @@ declare abstract class ApiBase<EntityType, FilterType extends Record<string, unk
13078
13372
  };
13079
13373
  getIdForPath(id: FSId): number;
13080
13374
  isGoodResponse(response: Response): boolean;
13375
+ /**
13376
+ * @note - We must use this serializer when sending arrays as query parameter to our API.
13377
+ */
13378
+ getQuerySerializerForArray(): QuerySerializerOptions;
13081
13379
  }
13082
13380
  //#endregion
13083
13381
  //#region src/api/License.d.ts
@@ -13144,6 +13442,7 @@ declare class Product extends ApiBase<ProductEntity, never> {
13144
13442
  retrieve(): Promise<ProductEntity | null>;
13145
13443
  retrieveMany(): Promise<ProductEntity[]>;
13146
13444
  retrievePricingData(): Promise<PricingTableData | null>;
13445
+ retrieveSubscriptionCancellationCoupon(): Promise<CouponEntityEnriched[] | null>;
13147
13446
  }
13148
13447
  //#endregion
13149
13448
  //#region src/api/Subscription.d.ts
@@ -13222,7 +13521,10 @@ declare class Subscription extends ApiBase<SubscriptionEntity, SubscriptionFilte
13222
13521
  email?: string | null;
13223
13522
  url?: string | null;
13224
13523
  title?: string | null;
13524
+ has_subscription_cancellation_discount?: boolean | null;
13225
13525
  })[]>;
13526
+ applyRenewalCoupon(subscriptionId: FSId, couponId: string, logAutoRenew: boolean): Promise<SubscriptionRenewalCouponResult | null>;
13527
+ cancel(subscriptionId: FSId, feedback?: string, reasonIds?: SubscriptionCancellationReasonType[]): Promise<SubscriptionCancellationResult | null>;
13226
13528
  }
13227
13529
  //#endregion
13228
13530
  //#region src/api/User.d.ts
@@ -13269,12 +13571,58 @@ declare class User extends ApiBase<UserEntity, UserFilterOptions> {
13269
13571
  }[]>;
13270
13572
  retrieveByEmail(email: string): Promise<UserEntity | null>;
13271
13573
  retrieveBilling(userId: FSId): Promise<UserBillingEntity | null>;
13272
- retrieveSubscriptions(userId: FSId, filters?: UserSubscriptionFilterOptions, pagination?: PagingOptions): Promise<SubscriptionEntity[]>;
13574
+ retrieveSubscriptions(userId: FSId, filters?: UserSubscriptionFilterOptions, pagination?: PagingOptions): Promise<UserSubscriptionWithDiscounts[]>;
13273
13575
  retrieveLicenses(userId: FSId, filters?: UserLicenseFilterOptions, pagination?: PagingOptions): Promise<LicenseEntity[]>;
13274
13576
  retrievePayments(userId: FSId, filters?: UserPaymentFilterOptions, pagination?: PagingOptions): Promise<PaymentEntity[]>;
13577
+ updateBilling(userId: FSId, payload: BillingUpdatePayload): Promise<UserBillingEntity | null>;
13578
+ }
13579
+ //#endregion
13580
+ //#region src/api/Payment.d.ts
13581
+ declare class Payment extends ApiBase<PaymentEntity, PaymentFilterOptions> {
13582
+ retrieve(paymentId: FSId): Promise<PaymentEntity | null>;
13583
+ retrieveMany(filter?: PaymentFilterOptions, pagination?: PagingOptions): Promise<({
13584
+ user_id?: components["schemas"]["CommonProperties"]["user_id"];
13585
+ install_id?: components["schemas"]["CommonProperties"]["install_id_nullable"];
13586
+ plan_id?: components["schemas"]["CommonProperties"]["plan_id"];
13587
+ pricing_id?: components["schemas"]["CommonProperties"]["pricing_id_nullable"];
13588
+ license_id?: components["schemas"]["CommonProperties"]["license_id"];
13589
+ ip?: components["schemas"]["CommonProperties"]["ip_nullable"];
13590
+ country_code?: components["schemas"]["CommonProperties"]["country_code"];
13591
+ zip_postal_code?: components["schemas"]["CommonProperties"]["zip_postal_code_nullable"];
13592
+ vat_id?: components["schemas"]["CommonProperties"]["vat_id_nullable"];
13593
+ coupon_id?: components["schemas"]["CommonProperties"]["coupon_id_nullable"];
13594
+ user_card_id?: string;
13595
+ source?: components["schemas"]["Migration"]["source"];
13596
+ plugin_id?: components["schemas"]["CommonProperties"]["plugin_id"];
13597
+ external_id?: string;
13598
+ gateway?: string | null;
13599
+ environment?: components["schemas"]["CommonProperties"]["environment"];
13600
+ id?: components["schemas"]["CommonProperties"]["id"];
13601
+ created?: components["schemas"]["CommonProperties"]["created"];
13602
+ updated?: components["schemas"]["CommonProperties"]["updated"];
13603
+ currency?: components["schemas"]["CommonEnums"]["Currency"];
13604
+ refund_reason?: string | null;
13605
+ subscription_id?: components["schemas"]["CommonProperties"]["subscription_id_nullable"];
13606
+ gross?: number;
13607
+ bound_payment_id?: string;
13608
+ gateway_fee: number;
13609
+ vat?: components["schemas"]["CommonProperties"]["vat"];
13610
+ is_renewal: boolean;
13611
+ type?: components["schemas"]["CommonEnums"]["PaymentType"];
13612
+ } & {
13613
+ email?: components["schemas"]["User"]["email"];
13614
+ url?: components["schemas"]["Install"]["url"];
13615
+ billing_cycle?: components["schemas"]["Subscription"]["billing_cycle"];
13616
+ plan_name?: string;
13617
+ refund_reason?: string;
13618
+ })[]>;
13619
+ retrieveInvoice(paymentId: FSId): Promise<Blob | null>;
13275
13620
  }
13276
13621
  //#endregion
13277
13622
  //#region src/services/ApiService.d.ts
13623
+ /**
13624
+ * @todo - Add a proper user-agent string with SDK version.
13625
+ */
13278
13626
  declare class ApiService {
13279
13627
  private readonly secretKey;
13280
13628
  private readonly publicKey;
@@ -13284,6 +13632,7 @@ declare class ApiService {
13284
13632
  readonly license: License;
13285
13633
  readonly product: Product;
13286
13634
  readonly subscription: Subscription;
13635
+ readonly payment: Payment;
13287
13636
  readonly baseUrl: string;
13288
13637
  constructor(productId: FSId, apiKey: string, secretKey: string, publicKey: string);
13289
13638
  /**
@@ -13293,9 +13642,10 @@ declare class ApiService {
13293
13642
  * For regular operations, prefer using the provided services like `User`, `Subscription`, `License` etc.
13294
13643
  */
13295
13644
  get __unstable_ApiClient(): FsApiClient;
13645
+ createSignedUrl(path: string): string;
13296
13646
  createUrl(path: string): string;
13297
13647
  /**
13298
- * Generate signed URL for the given full URL
13648
+ * Generate signed URL for the given full URL. The authentication is valid for 15 minutes only.
13299
13649
  */
13300
13650
  getSignedUrl(fullUrl: string): string;
13301
13651
  /**
@@ -13312,35 +13662,32 @@ declare class ApiService {
13312
13662
  private toDateTimeString;
13313
13663
  }
13314
13664
  //#endregion
13315
- //#region src/models/CheckoutBuilder.d.ts
13316
- type CheckoutBuilderUserOptions = {
13317
- email: string;
13318
- firstName?: string;
13319
- lastName?: string;
13320
- name?: string;
13321
- } | null | undefined;
13665
+ //#region src/checkout/Checkout.d.ts
13666
+ type CheckoutSerialized = {
13667
+ options: CheckoutOptions;
13668
+ link: string;
13669
+ baseUrl: string;
13670
+ };
13322
13671
  /**
13323
13672
  * A builder class for constructing checkout parameters. This class provides a fluent
13324
13673
  * API to create Checkout parameters for a product with various configurations.
13325
13674
  *
13326
- *
13327
- *
13328
- * Every method returns a new instance of the builder with the updated options,
13329
- * allowing for method chaining. The final `toOptions()` method returns the constructed
13330
- * `CheckoutOptions` object. So the class itself is immutable and does not modify the original instance.
13675
+ * Every method returns the existing instance of the builder for chainability,
13676
+ * The final `getOptions()` method returns the constructed `CheckoutOptions` object.
13331
13677
  */
13332
- declare class CheckoutBuilder {
13333
- private readonly options;
13678
+ declare class Checkout {
13334
13679
  private readonly productId;
13335
- private readonly publicKey?;
13336
- private readonly secretKey?;
13337
- constructor(options: Omit<CheckoutPopupParams, 'plugin_id'> & CheckoutPopupArbitraryParams, productId: string, publicKey?: string | undefined, secretKey?: string | undefined);
13680
+ private readonly publicKey;
13681
+ private readonly secretKey;
13682
+ static createSandboxToken(productId: string, secretKey: string, publicKey: string): NonNullable<CheckoutPopupParams['sandbox']>;
13683
+ private options;
13684
+ constructor(productId: string, publicKey: string, secretKey: string);
13338
13685
  /**
13339
13686
  * Enables sandbox mode for testing purposes.
13340
13687
  *
13341
13688
  * @returns A new builder instance with sandbox configuration
13342
13689
  */
13343
- inSandbox(): CheckoutBuilder;
13690
+ setSandbox(): Checkout;
13344
13691
  /**
13345
13692
  * Sets user information for the checkout session.
13346
13693
  *
@@ -13349,30 +13696,30 @@ declare class CheckoutBuilder {
13349
13696
  *
13350
13697
  * @returns A new builder instance with user configuration
13351
13698
  */
13352
- withUser(user: CheckoutBuilderUserOptions, readonly?: boolean): CheckoutBuilder;
13699
+ setUser(user: CheckoutBuilderUserOptions, readonly?: boolean): Checkout;
13353
13700
  /**
13354
13701
  * Applies recommended UI settings for better user experience.
13355
13702
  * This includes fullscreen mode, upsells, refund badge, and reviews display.
13356
13703
  *
13357
13704
  * @returns A new builder instance with recommended UI settings
13358
13705
  */
13359
- withRecommendation(): CheckoutBuilder;
13706
+ setRecommendations(): Checkout;
13360
13707
  /**
13361
13708
  * Sets the plan ID for the checkout.
13362
13709
  *
13363
13710
  * @param planId The plan ID to purchase
13364
13711
  * @returns A new builder instance with plan ID set
13365
13712
  */
13366
- withPlan(planId: string | number): CheckoutBuilder;
13713
+ setPlan(planId: string | number): Checkout;
13367
13714
  /**
13368
13715
  * Sets the number of licenses to purchase.
13369
13716
  *
13370
13717
  * @param count Number of licenses
13371
13718
  * @returns A new builder instance with license count set
13372
13719
  */
13373
- withQuota(count: number): CheckoutBuilder;
13374
- withPricing(pricingId: string | number): CheckoutBuilder;
13375
- withTitle(title: string): CheckoutBuilder;
13720
+ setQuota(count: number): Checkout;
13721
+ setPricing(pricingId: string | number): Checkout;
13722
+ setTitle(title: string): Checkout;
13376
13723
  /**
13377
13724
  * Sets a coupon code for the checkout.
13378
13725
  *
@@ -13380,42 +13727,42 @@ declare class CheckoutBuilder {
13380
13727
  * @param hideUI Whether to hide the coupon input field from users
13381
13728
  * @returns A new builder instance with coupon configuration
13382
13729
  */
13383
- withCoupon(options: {
13730
+ setCoupon(options: {
13384
13731
  code: string;
13385
13732
  hideUI?: boolean;
13386
- }): CheckoutBuilder;
13733
+ }): Checkout;
13387
13734
  /**
13388
13735
  * Enables trial mode for the checkout.
13389
13736
  *
13390
13737
  * @param mode Trial type - true/false for plan default, or specific 'free'/'paid' mode
13391
13738
  * @returns A new builder instance with trial configuration
13392
13739
  */
13393
- inTrial(mode?: 'free' | 'paid' | boolean): CheckoutBuilder;
13740
+ setTrial(mode?: 'free' | 'paid' | boolean): Checkout;
13394
13741
  /**
13395
13742
  * Configures the visual layout and appearance of the checkout.
13396
13743
  *
13397
13744
  * @param options Appearance configuration options
13398
13745
  * @returns A new builder instance with appearance configuration
13399
13746
  */
13400
- withAppearance(options: {
13747
+ setAppearance(options: {
13401
13748
  layout?: 'vertical' | 'horizontal' | null;
13402
13749
  formPosition?: 'left' | 'right';
13403
13750
  fullscreen?: boolean;
13404
13751
  modalTitle?: string;
13405
13752
  id?: string;
13406
- }): CheckoutBuilder;
13753
+ }): Checkout;
13407
13754
  /**
13408
13755
  * Configures discount display settings.
13409
13756
  *
13410
13757
  * @param options Discount configuration options
13411
13758
  * @returns A new builder instance with discount configuration
13412
13759
  */
13413
- withDiscounts(options: {
13760
+ setDiscounts(options: {
13414
13761
  annual?: boolean;
13415
13762
  multisite?: boolean | 'auto';
13416
13763
  bundle?: boolean | 'maximize';
13417
13764
  showMonthlySwitch?: boolean;
13418
- }): CheckoutBuilder;
13765
+ }): Checkout;
13419
13766
  /**
13420
13767
  * Configures billing cycle selector interface.
13421
13768
  *
@@ -13423,26 +13770,26 @@ declare class CheckoutBuilder {
13423
13770
  * @param defaultCycle Default billing cycle to select
13424
13771
  * @returns A new builder instance with billing cycle configuration
13425
13772
  */
13426
- withBillingCycle(defaultCycle: 'monthly' | 'annual' | 'lifetime', selector?: 'list' | 'responsive_list' | 'dropdown'): CheckoutBuilder;
13773
+ setBillingCycle(defaultCycle: 'monthly' | 'annual' | 'lifetime', selector?: 'list' | 'responsive_list' | 'dropdown'): Checkout;
13427
13774
  /**
13428
13775
  * Sets the language/locale for the checkout.
13429
13776
  *
13430
13777
  * @param locale Language setting - 'auto', 'auto-beta', or specific locale like 'en_US'
13431
13778
  * @returns A new builder instance with locale configuration
13432
13779
  */
13433
- withLanguage(locale?: 'auto' | 'auto-beta' | string): CheckoutBuilder;
13780
+ setLanguage(locale?: 'auto' | 'auto-beta' | string): Checkout;
13434
13781
  /**
13435
13782
  * Configures review and badge display settings.
13436
13783
  *
13437
13784
  * @param options Review and badge configuration
13438
13785
  * @returns A new builder instance with reviews and badges configuration
13439
13786
  */
13440
- withReviewsAndBadges(options: {
13787
+ setSocialProofing(options: {
13441
13788
  showReviews?: boolean;
13442
13789
  reviewId?: number;
13443
13790
  showRefundBadge?: boolean;
13444
13791
  refundPolicyPosition?: 'below_form' | 'below_breakdown' | 'dynamic';
13445
- }): CheckoutBuilder;
13792
+ }): Checkout;
13446
13793
  /**
13447
13794
  * Enhanced currency configuration.
13448
13795
  *
@@ -13451,7 +13798,7 @@ declare class CheckoutBuilder {
13451
13798
  * @param showInlineSelector Whether to show inline currency selector
13452
13799
  * @returns A new builder instance with currency configuration
13453
13800
  */
13454
- withCurrency(currency: 'usd' | 'eur' | 'gbp' | 'auto', defaultCurrency?: 'usd' | 'eur' | 'gbp', showInlineSelector?: boolean): CheckoutBuilder;
13801
+ setCurrency(currency: 'usd' | 'eur' | 'gbp' | 'auto', defaultCurrency?: 'usd' | 'eur' | 'gbp', showInlineSelector?: boolean): Checkout;
13455
13802
  /**
13456
13803
  * Configures navigation and cancel behavior.
13457
13804
  *
@@ -13459,35 +13806,141 @@ declare class CheckoutBuilder {
13459
13806
  * @param cancelIcon Custom cancel icon URL
13460
13807
  * @returns A new builder instance with navigation configuration
13461
13808
  */
13462
- withNavigation(cancelUrl?: string, cancelIcon?: string): CheckoutBuilder;
13809
+ setCancelButton(cancelUrl?: string, cancelIcon?: string): Checkout;
13463
13810
  /**
13464
13811
  * Associates purchases with an affiliate account.
13465
13812
  *
13466
13813
  * @param userId Affiliate user ID
13467
13814
  * @returns A new builder instance with affiliate configuration
13468
13815
  */
13469
- withAffiliate(userId: number): CheckoutBuilder;
13816
+ setAffiliate(userId: number): Checkout;
13470
13817
  /**
13471
13818
  * Sets a custom image/icon for the checkout.
13472
13819
  *
13473
13820
  * @param imageUrl Secure HTTPS URL to the image
13474
13821
  * @returns A new builder instance with custom image
13475
13822
  */
13476
- withImage(imageUrl: string): CheckoutBuilder;
13823
+ setImage(imageUrl: string): Checkout;
13477
13824
  /**
13478
13825
  * Configures the checkout for license renewal.
13479
13826
  *
13480
13827
  * @param licenseKey The license key to renew
13481
13828
  * @returns A new builder instance configured for renewal
13482
13829
  */
13483
- forRenewal(licenseKey: string): CheckoutBuilder;
13830
+ setLicenseRenewal(licenseKey: string): Checkout;
13484
13831
  /**
13485
13832
  * Builds and returns the final checkout options to be used with the `@freemius/checkout` package.
13486
13833
  *
13834
+ * @note - This is async by purpose so that we can allow for future enhancements that might require async operations.
13835
+ *
13487
13836
  * @returns The constructed CheckoutOptions object
13488
13837
  */
13489
- toOptions(additionalOptions?: Omit<CheckoutPopupParams, 'plugin_id'> & CheckoutPopupArbitraryParams): CheckoutOptions;
13490
- toLink(): string;
13838
+ getOptions(): CheckoutOptions;
13839
+ /**
13840
+ * Generates a checkout link based on the current builder state.
13841
+ *
13842
+ * @note - This is async by purpose so that we can allow for future enhancements that might require async operations.
13843
+ */
13844
+ getLink(): string;
13845
+ serialize(): CheckoutSerialized;
13846
+ private getBaseUrl;
13847
+ }
13848
+ //#endregion
13849
+ //#region src/models/PurchaseInfo.d.ts
13850
+ declare class PurchaseInfo implements PurchaseData {
13851
+ readonly email: string;
13852
+ readonly firstName: string;
13853
+ readonly lastName: string;
13854
+ readonly userId: string;
13855
+ readonly planId: string;
13856
+ readonly pricingId: string;
13857
+ readonly licenseId: string;
13858
+ readonly expiration: Date | null;
13859
+ readonly canceled: boolean;
13860
+ readonly subscriptionId: string | null;
13861
+ readonly billingCycle: BILLING_CYCLE | null;
13862
+ readonly quota: number | null;
13863
+ readonly initialAmount: number | null;
13864
+ readonly renewalAmount: number | null;
13865
+ readonly currency: CURRENCY | null;
13866
+ readonly renewalDate: Date | null;
13867
+ readonly paymentMethod: 'card' | 'paypal' | 'ideal' | null;
13868
+ readonly created: Date;
13869
+ constructor(user: UserEntity, license: LicenseEntity, subscription: SubscriptionEntity | null);
13870
+ isPlan(planId: FSId): boolean;
13871
+ isFromPlans(planIds: FSId[]): boolean;
13872
+ toData(): PurchaseData;
13873
+ /**
13874
+ * A convenience method to convert the purchase info to a format suitable for database storage.
13875
+ */
13876
+ toEntitlementRecord<T extends Record<string, unknown>>(additionalData?: T): PurchaseEntitlementData & T;
13877
+ get isActive(): boolean;
13878
+ isSubscription(): boolean;
13879
+ isAnnual(): boolean;
13880
+ isMonthly(): boolean;
13881
+ isOneOff(): boolean;
13882
+ getPlanTitle(pricingData: PricingTableData | null): string;
13883
+ }
13884
+ //#endregion
13885
+ //#region src/services/PurchaseService.d.ts
13886
+ declare class PurchaseService {
13887
+ private readonly api;
13888
+ constructor(api: ApiService);
13889
+ /**
13890
+ * Retrieve purchase information from the Freemius API based on the license ID.
13891
+ *
13892
+ * The license is the primary entitlement for a purchase, and it may or may not be associated with a subscription.
13893
+ * With this method, you can retrieve detailed information about the purchase, including user details, plan, expiration, and more.
13894
+ */
13895
+ retrievePurchase(licenseId: FSId): Promise<PurchaseInfo | null>;
13896
+ /**
13897
+ * A helper method to retrieve raw purchase data instead of a full PurchaseInfo object.
13898
+ *
13899
+ * This is useful when passing data from server to client in frameworks like Next.js, where only serializable data should be sent.
13900
+ */
13901
+ retrievePurchaseData(licenseId: FSId): Promise<PurchaseData | null>;
13902
+ retrievePurchases(userOrEntity: FSId | UserEntity, pagination?: PagingOptions): Promise<PurchaseInfo[]>;
13903
+ retrievePurchasesData(userOrEntity: FSId | UserEntity, pagination?: PagingOptions): Promise<PurchaseData[]>;
13904
+ /**
13905
+ * Retrieve a list of active subscriptions for a user. You can use this method to find or sync subscriptions from freemius to your system.
13906
+ */
13907
+ retrieveSubscriptions(userOrEntity: FSId | UserEntity, pagination?: PagingOptions): Promise<PurchaseInfo[]>;
13908
+ /**
13909
+ * Retrieve a list of purchase data for a user.
13910
+ *
13911
+ * This is a convenience method that returns the purchase data in a format suitable for client-side rendering or serialization.
13912
+ */
13913
+ retrieveSubscriptionsData(userId: FSId, pagination?: PagingOptions): Promise<PurchaseData[]>;
13914
+ retrieveBySubscription(subscription: SubscriptionEntity, subscriptionUser?: UserEntity): Promise<PurchaseInfo | null>;
13915
+ retrieveSubscriptionsByEmail(email: string, pagination?: PagingOptions): Promise<PurchaseInfo[]>;
13916
+ retrievePurchasesByEmail(email: string, pagination?: PagingOptions): Promise<PurchaseInfo[]>;
13917
+ }
13918
+ //#endregion
13919
+ //#region src/services/PricingService.d.ts
13920
+ declare class PricingService {
13921
+ private readonly api;
13922
+ constructor(api: ApiService);
13923
+ retrieve(topupPlanId?: FSId): Promise<PricingData>;
13924
+ findTopupPlan(plans?: PortalPlans, planId?: FSId): PortalPlans[number] | null;
13925
+ private isValidPricing;
13926
+ }
13927
+ //#endregion
13928
+ //#region src/checkout/PricingRetriever.d.ts
13929
+ declare class PricingRetriever implements CheckoutAction {
13930
+ private readonly pricing;
13931
+ constructor(pricing: PricingService);
13932
+ canHandle(request: Request): boolean;
13933
+ processAction(request: Request): Promise<Response>;
13934
+ }
13935
+ //#endregion
13936
+ //#region src/checkout/PurchaseProcessor.d.ts
13937
+ type PurchaseCallback = (purchase: PurchaseInfo) => Promise<Response | void>;
13938
+ declare class PurchaseProcessor implements CheckoutAction {
13939
+ private readonly purchase;
13940
+ private readonly callback?;
13941
+ constructor(purchase: PurchaseService, callback?: PurchaseCallback | undefined);
13942
+ canHandle(request: Request): boolean;
13943
+ processAction(request: Request): Promise<Response>;
13491
13944
  }
13492
13945
  //#endregion
13493
13946
  //#region src/models/CheckoutRedirectInfo.d.ts
@@ -13512,12 +13965,95 @@ declare class CheckoutRedirectInfo implements CheckoutRedirectData {
13512
13965
  toData(): CheckoutRedirectData;
13513
13966
  }
13514
13967
  //#endregion
13968
+ //#region src/checkout/RedirectProcessor.d.ts
13969
+ type RedirectCallback = (info: CheckoutRedirectInfo) => Promise<Response | void>;
13970
+ declare class RedirectProcessor implements CheckoutAction {
13971
+ private readonly secretKey;
13972
+ private readonly proxyUrl?;
13973
+ private readonly callback?;
13974
+ private readonly afterProcessUrl?;
13975
+ constructor(secretKey: string, proxyUrl?: string | undefined, callback?: RedirectCallback | undefined, afterProcessUrl?: string | undefined);
13976
+ canHandle(request: Request): boolean;
13977
+ processAction(request: Request): Promise<Response>;
13978
+ getRedirectInfo(currentUrl: string): Promise<CheckoutRedirectInfo | null>;
13979
+ getCleanUrl(url: string): string;
13980
+ }
13981
+ //#endregion
13982
+ //#region src/checkout/CheckoutRequestProcessor.d.ts
13983
+ type CheckoutRequestConfig = {
13984
+ /**
13985
+ * The real public/proxy URL where the application is accessible from the internet.
13986
+ * This is useful for authenticating the Checkout Redirection requests.
13987
+ */
13988
+ proxyUrl?: string;
13989
+ /**
13990
+ * The function to be called when a purchase is made.
13991
+ */
13992
+ onPurchase?: PurchaseCallback;
13993
+ /**
13994
+ * The function to be called when a redirect is made after checkout.
13995
+ */
13996
+ onRedirect?: RedirectCallback;
13997
+ /**
13998
+ * Specifies a URL to redirect to after processing the redirect action. If not provided, it will redirect to the `proxyUrl` or the original request URL.
13999
+ */
14000
+ afterProcessUrl?: string;
14001
+ };
14002
+ declare class CheckoutRequestProcessor implements RequestProcessor<CheckoutRequestConfig> {
14003
+ private readonly purchase;
14004
+ private readonly pricing;
14005
+ private readonly secretKey;
14006
+ constructor(purchase: PurchaseService, pricing: PricingService, secretKey: string);
14007
+ createProcessor(config: CheckoutRequestConfig): (request: Request) => Promise<Response>;
14008
+ process(config: CheckoutRequestConfig, request: Request): Promise<Response>;
14009
+ /**
14010
+ * Processes the redirect from Freemius Checkout.
14011
+ *
14012
+ * This method verifies the signature in the URL and returns a CheckoutRedirectInfo object if successful.
14013
+ *
14014
+ * For nextjs like applications, make sure to replace the URL from the `Request` object with the right hostname to take care of the proxy.
14015
+ *
14016
+ * For example, if you have put the nextjs application behind nginx proxy (or ngrok during local development), then nextjs will still see the `request.url` as `https://localhost:3000/...`.
14017
+ * In this case, you should replace it with the actual URL of your application, like `https://xyz.ngrok-free.app/...`.
14018
+ *
14019
+ * @example
14020
+ * ```ts
14021
+ * export async function GET(request: Request) {
14022
+ * // Replace the URL with the actual hostname of your application
14023
+ * // This is important for the signature verification to work correctly.
14024
+ * const data = await freemius.checkout.action.getRedirectProcessor({
14025
+ * proxyUrl: 'https://xyz.ngrok-free.app',
14026
+ * async callback(info) {
14027
+ * // Handle the redirect info here, like creating a license, etc.
14028
+ * // Return a Response object to override the default redirect behavior.
14029
+ * return Response.redirect('/custom-success-page', 302);
14030
+ * },
14031
+ * });
14032
+ *
14033
+ * return data.processAction(request);
14034
+ * }
14035
+ * ```
14036
+ */
14037
+ getRedirectProcessor(config: {
14038
+ proxyUrl?: string | undefined;
14039
+ callback?: RedirectCallback | undefined;
14040
+ afterProcessUrl?: string | undefined;
14041
+ }): RedirectProcessor;
14042
+ getPurchaseProcessor(config: {
14043
+ callback?: PurchaseCallback | undefined;
14044
+ }): PurchaseProcessor;
14045
+ getPricingRetriever(): PricingRetriever;
14046
+ }
14047
+ //#endregion
13515
14048
  //#region src/services/CheckoutService.d.ts
13516
14049
  declare class CheckoutService {
13517
14050
  private readonly productId;
13518
14051
  private readonly publicKey;
13519
14052
  private readonly secretKey;
13520
- constructor(productId: FSId, publicKey: string, secretKey: string);
14053
+ private readonly purchase;
14054
+ private readonly pricing;
14055
+ readonly request: CheckoutRequestProcessor;
14056
+ constructor(productId: FSId, publicKey: string, secretKey: string, purchase: PurchaseService, pricing: PricingService);
13521
14057
  /**
13522
14058
  * Use this to build a Checkout for your product.
13523
14059
  * You can build a Checkout link or options for the popup.
@@ -13529,63 +14065,28 @@ declare class CheckoutService {
13529
14065
  * @example
13530
14066
  * Basic usage:
13531
14067
  * ```typescript
13532
- * const options = freemius.checkout.params()
13533
- * .withUser(session?.user)
13534
- * .inSandbox()
13535
- * .withRecommendation()
13536
- * .toOptions(); // Or .toLink() for a hosted checkout link
14068
+ * const checkout = await freemius.checkout.create({user: session?.user})
14069
+ * .getOptions(); // Or .getLink() for a hosted checkout link
13537
14070
  * ```
13538
14071
  *
13539
14072
  * @example
13540
- * Advanced configuration:
14073
+ * Advanced configuration: You can also skip the convenience options and rather use the builder directly to configure the checkout.
14074
+ *
13541
14075
  * ```typescript
13542
- * const checkoutOptions = freemius.checkout.params()
13543
- * .withUser(user, true)
13544
- * .withPlan('1234')
13545
- * .withQuota(5)
13546
- * .withCurrency('eur')
13547
- * .withCoupon({
14076
+ * const checkout = freemius.checkout.create()
14077
+ * .setUser(user, true)
14078
+ * .setPlan('1234')
14079
+ * .setCoupon({
13548
14080
  * code: 'DISCOUNT2023',
13549
14081
  * hideUI: false
13550
14082
  * })
13551
- * .inTrial('paid')
13552
- * .withAppearance({
13553
- * layout: 'horizontal',
13554
- * formPosition: 'left',
13555
- * fullscreen: true,
13556
- * modalTitle: 'Upgrade Now'
13557
- * })
13558
- * .withDiscounts({
13559
- * annual: true,
13560
- * multisite: 'auto',
13561
- * bundle: 'maximize',
13562
- * showMonthlySwitch: true
13563
- * })
13564
- * .withReviewsAndBadges({
13565
- * showReviews: true,
13566
- * showRefundBadge: true,
13567
- * refundPolicyPosition: 'below_form'
13568
- * })
13569
- * .withBillingCycle('dropdown', 'annual')
13570
- * .withLocale('en_US')
13571
- * .withAffiliate(12345)
13572
- * .inSandbox()
13573
- * .toOptions();
14083
+ * .setSandbox()
14084
+ * .getOptions();
13574
14085
  * ```
13575
- */
13576
- create(withRecommendation?: boolean): CheckoutBuilder;
13577
- /**
13578
- * Convenience method to create checkout options for a specific user with or without sandbox mode.
13579
14086
  *
13580
- * Useful for generating recommended checkout options for SaaS.
13581
- */
13582
- createUserOptions(user: CheckoutBuilderUserOptions, isSandbox?: boolean): CheckoutOptions;
13583
- /**
13584
- * Convenience method to create a checkout link for a specific user with or without sandbox mode.
13585
- *
13586
- * Useful for generating recommended checkout links for SaaS.
14087
+ * @example
13587
14088
  */
13588
- createUserLink(user: CheckoutBuilderUserOptions, isSandbox?: boolean): string;
14089
+ create(options?: CheckoutBuilderOptions): Promise<Checkout>;
13589
14090
  /**
13590
14091
  * Retrieves the sandbox parameters for the checkout.
13591
14092
  *
@@ -13598,110 +14099,268 @@ declare class CheckoutService {
13598
14099
  */
13599
14100
  getSandboxParams(): Promise<NonNullable<CheckoutPopupParams['sandbox']>>;
13600
14101
  /**
13601
- * Processes the redirect from Freemius Checkout.
14102
+ * Processes a redirect URL and returns the checkout redirect information if valid.
13602
14103
  *
13603
- * This method verifies the signature in the URL and returns a CheckoutRedirectInfo object if successful.
14104
+ * This is useful for handling redirects from the checkout portal back to your application.
13604
14105
  *
13605
- * For nextjs like applications, make sure to replace the URL from the `Request` object with the right hostname to take care of the proxy.
14106
+ * @param url The current URL to process.
14107
+ * @param proxyUrl Optional proxy URL to replace parts of the URL for signature verification.
13606
14108
  *
13607
- * For example, if you have put the nextjs application behind nginx proxy (or ngrok during local development), then nextjs will still see the `request.url` as `https://localhost:3000/...`.
13608
- * In this case, you should replace it with the actual URL of your application, like `https://xyz.ngrok-free.app/...`.
14109
+ * @returns A promise that resolves to the checkout redirect information or null if invalid.
13609
14110
  *
13610
14111
  * @example
13611
- * ```ts
13612
- * export async function GET(request: Request) {
13613
- * // Replace the URL with the actual hostname of your application
13614
- * // This is important for the signature verification to work correctly.
13615
- * const data = await freemius.checkout.processRedirect(
13616
- * request.url.replace('https://localhost:3000', 'https://xyz.ngrok-free.app')
13617
- * );
14112
+ * ```typescript
14113
+ * const redirectInfo = await freemius.checkout.processRedirect(window.location.href);
14114
+ *
14115
+ * if (redirectInfo) {
14116
+ * // Handle valid redirect info
14117
+ * } else {
14118
+ * // Handle invalid or missing redirect info
13618
14119
  * }
13619
14120
  * ```
13620
14121
  */
13621
- processRedirect(currentUrl: string): Promise<CheckoutRedirectInfo | null>;
13622
- private getCleanUrl;
14122
+ processRedirect(url: string, proxyUrl?: string): Promise<CheckoutRedirectInfo | null>;
13623
14123
  }
13624
14124
  //#endregion
13625
- //#region src/services/CustomerPortalService.d.ts
13626
- declare class CustomerPortalService {
13627
- private readonly api;
13628
- private readonly checkout;
13629
- constructor(api: ApiService, checkout: CheckoutService);
14125
+ //#region src/services/AuthService.d.ts
14126
+ declare class AuthService {
14127
+ private readonly productId;
14128
+ private readonly secretKey;
14129
+ private static readonly TOKEN_SEPARATOR;
14130
+ private static readonly DEFAULT_EXPIRY_MINUTES;
14131
+ constructor(productId: FSId, secretKey: string);
13630
14132
  /**
13631
- * Retrieves the customer portal data for a user, including subscriptions, billing, and payments.
14133
+ * Creates a secure token for a specific action that can be performed by a user.
13632
14134
  *
13633
- * @param userId The ID of the user for whom to retrieve portal data.
13634
- * @param primaryLicenseId Optional primary license ID to include in the portal data. If present then the `primary` field will be populated with related information which our `@freemius/saas-starter` package uses to display the primary purchase information.
14135
+ * @param action The action identifier (e.g., 'download_invoice', 'update_billing')
14136
+ * @param userId The ID of the user who can perform this action
14137
+ * @param expiryMinutes Optional expiry time in minutes (default: 60 minutes)
14138
+ * @returns A secure token string
13635
14139
  */
13636
- retrieveData(userId: FSId, primaryLicenseId?: FSId | null, sandbox?: boolean): Promise<PortalData | null>;
14140
+ createActionToken(action: string, userId: FSId, expiryMinutes?: number): string;
13637
14141
  /**
13638
- * @todo - Implement this method to handle actions like get cancel coupon, cancel subscription, update billing, get upgrade auth for Checkout etc.
14142
+ * Verifies and validates an action token.
14143
+ *
14144
+ * @param token The token to verify
14145
+ * @param action The expected action
14146
+ * @param userId The expected user ID
14147
+ * @returns true if valid, false otherwise
13639
14148
  */
13640
- private getPlanTitleById;
13641
- private getPricingById;
14149
+ verifyActionToken(token: string, action: string, userId: FSId): boolean;
14150
+ private encodeTokenPayload;
14151
+ private decodeTokenPayload;
14152
+ private signData;
14153
+ private constantTimeEqual;
13642
14154
  }
13643
14155
  //#endregion
13644
- //#region src/models/PurchaseInfo.d.ts
13645
- declare class PurchaseInfo implements PurchaseData {
13646
- readonly email: string;
13647
- readonly firstName: string;
13648
- readonly lastName: string;
13649
- readonly userId: string;
13650
- readonly planId: string;
13651
- readonly pricingId: string;
13652
- readonly licenseId: string;
13653
- readonly expiration: Date | null;
13654
- readonly canceled: boolean;
13655
- readonly subscriptionId: string | null;
13656
- readonly billingCycle: BILLING_CYCLE | null;
13657
- readonly quota: number | null;
13658
- readonly initialAmount: number | null;
13659
- readonly renewalAmount: number | null;
13660
- readonly currency: CURRENCY | null;
13661
- readonly renewalDate: Date | null;
13662
- readonly paymentMethod: 'card' | 'paypal' | 'ideal' | null;
13663
- readonly created: Date;
13664
- constructor(user: UserEntity, license: LicenseEntity, subscription: SubscriptionEntity | null);
13665
- isPlan(planId: FSId): boolean;
13666
- isFromPlans(planIds: FSId[]): boolean;
13667
- toData(): PurchaseData;
13668
- get isActive(): boolean;
13669
- hasSubscription(): boolean;
13670
- isAnnual(): boolean;
13671
- isMonthly(): boolean;
13672
- isOneOff(): boolean;
13673
- getPlanTitle(pricingData: PricingTableData | null): string;
14156
+ //#region src/customer-portal/BillingAction.d.ts
14157
+ declare const schema$2: zod.ZodObject<{
14158
+ business_name: zod.ZodOptional<zod.ZodString>;
14159
+ tax_id: zod.ZodOptional<zod.ZodString>;
14160
+ phone: zod.ZodOptional<zod.ZodString>;
14161
+ address_apt: zod.ZodOptional<zod.ZodString>;
14162
+ address_street: zod.ZodOptional<zod.ZodString>;
14163
+ address_city: zod.ZodOptional<zod.ZodString>;
14164
+ address_state: zod.ZodOptional<zod.ZodString>;
14165
+ address_country_code: zod.ZodOptional<zod.ZodString>;
14166
+ address_zip: zod.ZodOptional<zod.ZodString>;
14167
+ }, zod.z.core.$strip>;
14168
+ type BillingRequest = zod.infer<typeof schema$2>;
14169
+ declare class BillingAction implements PortalAction {
14170
+ private readonly api;
14171
+ private readonly auth;
14172
+ private readonly actionName;
14173
+ constructor(api: ApiService, auth: AuthService);
14174
+ private createAction;
14175
+ createAuthenticatedUrl(id: string, userId: string, endpoint: string): string;
14176
+ verifyAuthentication(request: Request): boolean;
14177
+ canHandle(request: Request): boolean;
14178
+ processAction(request: Request): Promise<Response>;
13674
14179
  }
13675
14180
  //#endregion
13676
- //#region src/services/PurchaseService.d.ts
13677
- declare class PurchaseService {
14181
+ //#region src/customer-portal/InvoiceAction.d.ts
14182
+ declare class InvoiceAction implements PortalAction {
13678
14183
  private readonly api;
13679
- constructor(api: ApiService);
14184
+ private readonly auth;
14185
+ private readonly actionName;
14186
+ constructor(api: ApiService, auth: AuthService);
14187
+ private createAction;
14188
+ createAuthenticatedUrl(id: string, userId: string, endpoint: string): string;
14189
+ verifyAuthentication(request: Request): boolean;
14190
+ canHandle(request: Request): boolean;
14191
+ processAction(request: Request): Promise<Response>;
14192
+ }
14193
+ //#endregion
14194
+ //#region src/customer-portal/SubscriptionCancellationAction.d.ts
14195
+ declare const schema$1: zod.ZodObject<{
14196
+ feedback: zod.ZodOptional<zod.ZodString>;
14197
+ reason_ids: zod.ZodOptional<zod.ZodArray<zod.ZodEnum<{
14198
+ 1: "1";
14199
+ 2: "2";
14200
+ 3: "3";
14201
+ 4: "4";
14202
+ 5: "5";
14203
+ 6: "6";
14204
+ 7: "7";
14205
+ 8: "8";
14206
+ 9: "9";
14207
+ 10: "10";
14208
+ 11: "11";
14209
+ 12: "12";
14210
+ 13: "13";
14211
+ 14: "14";
14212
+ 15: "15";
14213
+ }>>>;
14214
+ }, zod.z.core.$strip>;
14215
+ type SubscriptionCancellationRequest = zod.infer<typeof schema$1>;
14216
+ declare class SubscriptionCancellationAction implements PortalAction {
14217
+ private readonly api;
14218
+ private readonly auth;
14219
+ private readonly actionName;
14220
+ constructor(api: ApiService, auth: AuthService);
14221
+ private createAction;
14222
+ createAuthenticatedUrl(id: string, userId: FSId, endpoint: string): string;
14223
+ verifyAuthentication(request: Request): boolean;
14224
+ canHandle(request: Request): boolean;
14225
+ processAction(request: Request): Promise<Response>;
14226
+ }
14227
+ //#endregion
14228
+ //#region src/customer-portal/SubscriptionRenewalCouponAction.d.ts
14229
+ declare const schema: zod.ZodObject<{
14230
+ couponId: zod.ZodString;
14231
+ }, zod.z.core.$strip>;
14232
+ type ApplyRenewalCouponRequest = zod.infer<typeof schema>;
14233
+ declare class SubscriptionRenewalCouponAction implements PortalAction {
14234
+ private readonly api;
14235
+ private readonly auth;
14236
+ private readonly actionName;
14237
+ constructor(api: ApiService, auth: AuthService);
14238
+ private createAction;
14239
+ createAuthenticatedUrl(id: string, userId: FSId, endpoint: string): string;
14240
+ verifyAuthentication(request: Request): boolean;
14241
+ canHandle(request: Request): boolean;
14242
+ processAction(request: Request): Promise<Response>;
14243
+ }
14244
+ //#endregion
14245
+ //#region src/customer-portal/CustomerPortalActionService.d.ts
14246
+ declare class CustomerPortalActionService {
14247
+ private readonly api;
14248
+ private readonly authService;
14249
+ readonly invoice: InvoiceAction;
14250
+ readonly billing: BillingAction;
14251
+ readonly renewalCoupon: SubscriptionRenewalCouponAction;
14252
+ readonly cancelRenewal: SubscriptionCancellationAction;
14253
+ constructor(api: ApiService, authService: AuthService);
14254
+ getAllHandlers(): PortalAction[];
14255
+ }
14256
+ //#endregion
14257
+ //#region src/customer-portal/PortalDataRepository.d.ts
14258
+ type CustomerPortalDataOption = {
13680
14259
  /**
13681
- * Retrieve purchase information from the Freemius API based on the license ID.
13682
- *
13683
- * The license is the primary entitlement for a purchase, and it may or may not be associated with a subscription.
13684
- * With this method, you can retrieve detailed information about the purchase, including user details, plan, expiration, and more.
14260
+ * The API endpoint for which secure authenticated signed URLs will be created where the customer portal will send requests to fetch additional data (e.g., invoices, licenses, subscriptions). This should be an endpoint in your SaaS application that you will implement to handle these requests.
13685
14261
  */
13686
- retrievePurchase(licenseId: FSId): Promise<PurchaseInfo | null>;
14262
+ endpoint: string;
13687
14263
  /**
13688
- * A helper method to retrieve raw purchase data instead of a full PurchaseInfo object.
13689
- *
13690
- * This is useful when passing data from server to client in frameworks like Next.js, where only serializable data should be sent.
14264
+ * ID of the primary licenses, in case your software has pricing model supporting multiple active subscriptions. If not provided the first active subscription will be used instead.
13691
14265
  */
13692
- retrievePurchaseData(licenseId: FSId): Promise<PurchaseData | null>;
14266
+ primaryLicenseId?: FSId | null;
13693
14267
  /**
13694
- * Retrieve a list of active subscriptions for a user. You can use this method to find or sync subscriptions from freemius to your system.
14268
+ * Whether to create actions in sandbox mode (For example Checkout, Upgrade etc).
13695
14269
  */
13696
- retrieveSubscriptions(userId: FSId, pagination?: PagingOptions): Promise<PurchaseInfo[]>;
14270
+ sandbox?: boolean;
14271
+ };
14272
+ type CustomerPortalDataWithUserOption = {
13697
14273
  /**
13698
- * Retrieve a list of purchase data for a user.
14274
+ * ID of the user from Freemius.
14275
+ */
14276
+ userId: FSId;
14277
+ } & CustomerPortalDataOption;
14278
+ type CustomerPortalDataWithEmailOption = {
14279
+ /**
14280
+ * The email address of the user from Freemius.
14281
+ */
14282
+ email: string;
14283
+ } & CustomerPortalDataOption;
14284
+ declare class PortalDataRepository {
14285
+ private readonly api;
14286
+ private readonly action;
14287
+ private readonly checkout;
14288
+ constructor(api: ApiService, action: CustomerPortalActionService, checkout: CheckoutService);
14289
+ retrievePortalDataByEmail(config: CustomerPortalDataWithEmailOption): Promise<PortalData | null>;
14290
+ retrievePortalDataByUserId(config: CustomerPortalDataWithUserOption): Promise<PortalData | null>;
14291
+ retrievePortalData(config: {
14292
+ user: UserEntity;
14293
+ endpoint: string;
14294
+ primaryLicenseId?: FSId | null;
14295
+ sandbox?: boolean;
14296
+ }): Promise<PortalData | null>;
14297
+ retrieveApiData(userId: FSId): Promise<{
14298
+ pricingData: PricingTableData;
14299
+ subscriptions: UserSubscriptionEntity[];
14300
+ payments: PaymentEntity[];
14301
+ billing: BillingEntity | null;
14302
+ coupons: CouponEntityEnriched[] | null;
14303
+ } | null>;
14304
+ getPayments(payments: PaymentEntity[], plans: Map<string, PlanEntity>, pricings: Map<string, PricingEntity>, userId: FSId, endpoint: string): PortalPayment[];
14305
+ getPlansById(pricingData: PricingTableData): Map<string, PlanEntity>;
14306
+ getPricingById(pricingData: PricingTableData): Map<string, PricingEntity>;
14307
+ getBilling(billing: BillingEntity | null, userId: FSId, endpoint: string): PortalBilling;
14308
+ getSubscriptions(subscriptions: UserSubscriptionEntity[], plans: Map<string, PlanEntity>, pricings: Map<string, PricingEntity>, primaryLicenseId: (FSId | null) | undefined, endpoint: string): Promise<PortalSubscriptions>;
14309
+ /**
14310
+ * Check if coupon application is impossible due to certain conditions.
14311
+ * This function can be used to determine if a coupon can be applied to a subscription.
14312
+ * Introduced initially for PayPal subscriptions with a renewal date less than 48 hours in the future.
13699
14313
  *
13700
- * This is a convenience method that returns the purchase data in a format suitable for client-side rendering or serialization.
14314
+ * @author @DanieleAlessandra
14315
+ * @author @swashata (Ported to SDK)
14316
+ *
14317
+ * @returns boolean
13701
14318
  */
13702
- retrieveSubscriptionsData(userId: FSId, pagination?: PagingOptions): Promise<PurchaseData[]>;
13703
- retrieveBySubscription(subscription: SubscriptionEntity, subscriptionUser?: UserEntity): Promise<PurchaseInfo | null>;
13704
- retrieveActiveSubscriptionByEmail(email: string, pagination?: PagingOptions): Promise<PurchaseInfo[] | null>;
14319
+ isRenewalCancellationCouponApplicable(subscription: UserSubscriptionEntity): boolean;
14320
+ }
14321
+ //#endregion
14322
+ //#region src/customer-portal/PurchaseRestorer.d.ts
14323
+ type RestoreCallback = (purchases: PurchaseInfo[]) => Promise<Response | void>;
14324
+ //#endregion
14325
+ //#region src/customer-portal/PortalRequestProcessor.d.ts
14326
+ type PortalRequestConfig = {
14327
+ getUser: UserRetriever;
14328
+ onRestore?: RestoreCallback;
14329
+ restoreSubscriptionsOnly?: boolean;
14330
+ isSandbox?: boolean;
14331
+ portalEndpoint: string;
14332
+ };
14333
+ declare class PortalRequestProcessor implements RequestProcessor<PortalRequestConfig> {
14334
+ private readonly repository;
14335
+ private readonly action;
14336
+ private readonly purchase;
14337
+ constructor(repository: PortalDataRepository, action: CustomerPortalActionService, purchase: PurchaseService);
14338
+ createProcessor(config: PortalRequestConfig): (request: Request) => Promise<Response>;
14339
+ /**
14340
+ * Process actions done by the user in the customer portal.
14341
+ */
14342
+ process(config: PortalRequestConfig, request: Request): Promise<Response>;
14343
+ }
14344
+ //#endregion
14345
+ //#region src/services/CustomerPortalService.d.ts
14346
+ declare class CustomerPortalService {
14347
+ private readonly api;
14348
+ private readonly checkout;
14349
+ private readonly authService;
14350
+ private readonly purchase;
14351
+ private readonly repository;
14352
+ readonly action: CustomerPortalActionService;
14353
+ readonly request: PortalRequestProcessor;
14354
+ constructor(api: ApiService, checkout: CheckoutService, authService: AuthService, purchase: PurchaseService);
14355
+ /**
14356
+ * Retrieves the customer portal data for a user, including subscriptions, billing, and payments.
14357
+ */
14358
+ retrieveData(option: CustomerPortalDataWithUserOption): Promise<PortalData | null>;
14359
+ retrieveDataByEmail(option: CustomerPortalDataWithEmailOption): Promise<PortalData | null>;
14360
+ /**
14361
+ * Creates a restorer function that processes an array of purchases by invoking the provided callback for each purchase.
14362
+ */
14363
+ createRestorer(callback: (purchase: PurchaseInfo) => Promise<void>): (purchases: PurchaseInfo[]) => Promise<void>;
13705
14364
  }
13706
14365
  //#endregion
13707
14366
  //#region src/webhook/license.events.d.ts
@@ -13739,6 +14398,8 @@ interface LicenseEventDataMap {
13739
14398
  to: string;
13740
14399
  /** Unique identifier for the license */
13741
14400
  license_id: string;
14401
+ /** Determines if the license was renewed due to the renewal of the associated subscription */
14402
+ is_renewal?: boolean;
13742
14403
  };
13743
14404
  };
13744
14405
  'license.shortened': {
@@ -13907,16 +14568,32 @@ interface SubscriptionEventDataMap {
13907
14568
  }
13908
14569
  //#endregion
13909
14570
  //#region src/webhook/events.d.ts
13910
- interface EventDataMap extends LicenseEventDataMap, SubscriptionEventDataMap {}
13911
- type FreemiusEventType = keyof EventDataMap;
13912
- type FreemiusEvent<T extends FreemiusEventType = FreemiusEventType> = {
14571
+ /**
14572
+ * We unify all event data maps into a single map for easier reference.
14573
+ */
14574
+ interface WebhookEventDataMap extends LicenseEventDataMap, SubscriptionEventDataMap {}
14575
+ /**
14576
+ * All possible webhook event types. For example `'license.created'`, `subscription.created`, etc.
14577
+ */
14578
+ type WebhookEventType = keyof WebhookEventDataMap;
14579
+ /**
14580
+ * The structure of a webhook event received from Freemius.
14581
+ *
14582
+ * The `data` and `objects` properties are dynamically typed based on the event type.
14583
+ *
14584
+ * @template T The type of the webhook event.
14585
+ */
14586
+ type WebhookEvent<T extends WebhookEventType = WebhookEventType> = {
13913
14587
  id: string;
13914
14588
  type: T;
13915
14589
  created: string;
13916
14590
  updated: string | null;
13917
14591
  state: NonNullable<EventEntity['state']>;
13918
- } & EventDataMap[T];
13919
- type EventHandler<T extends FreemiusEventType> = (event: FreemiusEvent<T>) => Promise<void>;
14592
+ } & WebhookEventDataMap[T];
14593
+ /**
14594
+ * A handler function for a specific webhook event type.
14595
+ */
14596
+ type WebhookEventHandler<T extends WebhookEventType> = (event: WebhookEvent<T>) => Promise<void>;
13920
14597
  //#endregion
13921
14598
  //#region src/webhook/WebhookListener.d.ts
13922
14599
  interface NormalizedRequest {
@@ -13936,16 +14613,17 @@ declare class WebhookListener {
13936
14613
  private readonly onError;
13937
14614
  private eventHandlers;
13938
14615
  constructor(secretKey: string, onError?: (error: unknown) => void);
13939
- on<T extends FreemiusEventType>(type: T, handler: EventHandler<T>): this;
13940
- off<T extends FreemiusEventType>(type: T, handler: EventHandler<T>): this;
13941
- onMultiple<T extends FreemiusEventType>(handlers: Partial<Record<T, EventHandler<T>>>): this;
13942
- removeAll<T extends FreemiusEventType>(type: T): this;
13943
- getHandlerCount<T extends FreemiusEventType>(type: T): number;
14616
+ on<T extends WebhookEventType>(type: T, handler: WebhookEventHandler<T>): this;
14617
+ on<T extends WebhookEventType>(types: T[], handler: WebhookEventHandler<T>): this;
14618
+ off<T extends WebhookEventType>(type: T, handler: WebhookEventHandler<T>): this;
14619
+ off<T extends WebhookEventType>(types: T[], handler: WebhookEventHandler<T>): this;
14620
+ removeAll<T extends WebhookEventType>(typeOrTypes: T | T[]): this;
14621
+ getHandlerCount<T extends WebhookEventType>(type: T): number;
13944
14622
  getEventTypeCount(): number;
13945
- getRegisteredEventTypes(): FreemiusEventType[];
13946
- hasHandlers<T extends FreemiusEventType>(type: T): boolean;
13947
- hasHandler<T extends FreemiusEventType>(type: T, handler: EventHandler<T>): boolean;
13948
- getHandlers<T extends FreemiusEventType>(type: T): Set<EventHandler<FreemiusEventType>>;
14623
+ getRegisteredEventTypes(): WebhookEventType[];
14624
+ hasHandlers<T extends WebhookEventType>(type: T): boolean;
14625
+ hasHandler<T extends WebhookEventType>(type: T, handler: WebhookEventHandler<T>): boolean;
14626
+ getHandlers<T extends WebhookEventType>(type: T): Set<WebhookEventHandler<WebhookEventType>>;
13949
14627
  getTotalHandlerCount(): number;
13950
14628
  /**
13951
14629
  * Verify hex HMAC signature against the raw body.
@@ -13964,6 +14642,7 @@ declare class WebhookService {
13964
14642
  private readonly secretKey;
13965
14643
  constructor(secretKey: string);
13966
14644
  createListener(onError?: (error: unknown) => void): WebhookListener;
14645
+ createRequestProcessor(listener: WebhookListener): (request: Request) => Promise<Response>;
13967
14646
  /**
13968
14647
  * WHATWG Fetch API adapter for modern JavaScript environments.
13969
14648
  *
@@ -14023,15 +14702,58 @@ declare class WebhookService {
14023
14702
  processNodeHttp(listener: WebhookListener, req: http0.IncomingMessage, res: http0.ServerResponse): Promise<void>;
14024
14703
  }
14025
14704
  //#endregion
14705
+ //#region src/services/EntitlementService.d.ts
14706
+ declare class EntitlementService {
14707
+ /**
14708
+ * Get the active subscription entitlement from a list of entitlements stored in your own database.
14709
+ *
14710
+ * @param entitlements - Array of entitlements to filter
14711
+ * @returns The single active entitlement, or null if none found
14712
+ * @throws Error if multiple active entitlements are found
14713
+ */
14714
+ getActive<T extends PurchaseEntitlementData>(entitlements: T[] | null): T | null;
14715
+ /**
14716
+ * Get all active subscription entitlements from a list of entitlements stored in your own database.
14717
+ *
14718
+ * @param entitlements - Array of entitlements to filter
14719
+ * @returns Array of active entitlements, or null if none found
14720
+ */
14721
+ getActives<T extends PurchaseEntitlementData>(entitlements: T[] | null): T[] | null;
14722
+ getFsUser(entitlement: PurchaseEntitlementData | null, email?: string): Awaited<ReturnType<UserRetriever>>;
14723
+ /**
14724
+ * Calculates the number of complete months elapsed since the entitlement subscription was created.
14725
+ *
14726
+ * @param entitlement - The entitlement to check
14727
+ * @returns Number of complete months elapsed, or -1 if entitlement is null
14728
+ */
14729
+ getElapsedMonth(entitlement: PurchaseEntitlementData | null): number;
14730
+ /**
14731
+ * Calculates the number of complete years elapsed since the entitlement subscription was created.
14732
+ *
14733
+ * @param entitlement - The entitlement to check
14734
+ * @returns Number of complete years elapsed, or -1 if entitlement is null
14735
+ */
14736
+ getElapsedYear(entitlement: PurchaseEntitlementData | null): number;
14737
+ }
14738
+ //#endregion
14026
14739
  //#region src/Freemius.d.ts
14740
+ type FreemiusConfig = {
14741
+ productId: FSId;
14742
+ apiKey: string;
14743
+ secretKey: string;
14744
+ publicKey: string;
14745
+ };
14027
14746
  declare class Freemius {
14028
14747
  readonly api: ApiService;
14029
14748
  readonly checkout: CheckoutService;
14030
14749
  readonly purchase: PurchaseService;
14031
14750
  readonly customerPortal: CustomerPortalService;
14032
14751
  readonly webhook: WebhookService;
14033
- constructor(productId: FSId, apiKey: string, secretKey: string, publicKey: string);
14752
+ readonly pricing: PricingService;
14753
+ readonly entitlement: EntitlementService;
14754
+ private readonly auth;
14755
+ constructor(config: FreemiusConfig);
14034
14756
  }
14035
14757
  //#endregion
14036
- export { ApiAuthParams, ApiEntitiesFilter, type ApiService, BILLING_CYCLE, BillingCycleApiEnum, BillingEntity, CURRENCY, CheckoutRedirectData, type CheckoutService, CurrencyApiEnum, type CustomerPortalService, EventEntity, FSId, Freemius, InstallEntity, LicenseEntity, LicenseFilterOptions, PagingOptions, PaymentEntity, PaymentMethod, PortalData, PortalPayment, PortalPlans, PortalSubscription, PricingEntity, PricingTableData, ProductEntity, PurchaseData, PurchaseInfo, type PurchaseService, SellingUnit, SubscriptionEntity, SubscriptionFilterOptions, UserBillingEntity, UserEntity, UserFilterOptions, UserLicenseFilterOptions, UserPaymentFilterOptions, UserPluginEntity, UserSubscriptionFilterOptions, type WebhookService, idToNumber, idToString, isIdsEqual, parseBillingCycle, parseCurrency, parseDate, parseDateTime, parseNumber, parsePaymentMethod };
14758
+ export { ApiAuthParams, ApiEntitiesFilter, type ApiService, type ApplyRenewalCouponRequest, BILLING_CYCLE, BillingCycleApiEnum, BillingEntity, type BillingRequest, BillingUpdatePayload, CURRENCY, type Checkout, CheckoutAction, type CheckoutRequestConfig as CheckoutActionConfig, CheckoutBuilderOptions, CheckoutBuilderUserOptions, CheckoutRedirectData, type CheckoutRedirectInfo, type CheckoutSerialized, type CheckoutService, CouponEntityEnriched, CurrencyApiEnum, type CustomerPortalDataWithEmailOption, type CustomerPortalDataWithUserOption, type CustomerPortalService, EventEntity, FSId, Freemius, FreemiusConfig, InstallEntity, LicenseEntity, LicenseFilterOptions, PagingOptions, PaymentEntity, PaymentFilterOptions, PaymentMethod, PlanEntity, PortalAction, PortalBilling, PortalData, PortalPayment, PortalPlans, type PortalRequestConfig, PortalSubscription, PortalSubscriptions, PricingData, PricingEntity, type PricingService, PricingTableData, ProductEntity, PurchaseData, PurchaseEntitlementData, PurchaseEntitlementType, type PurchaseInfo, type PurchaseService, RequestProcessor, SellingUnit, SubscriptionCancellationReasonType, type SubscriptionCancellationRequest, SubscriptionCancellationResult, SubscriptionDiscountEntity, SubscriptionEntity, SubscriptionFilterOptions, SubscriptionRenewalCouponResult, UserBillingEntity, UserEntity, UserFilterOptions, UserLicenseFilterOptions, UserPaymentFilterOptions, UserPluginEntity, UserRetriever, UserSubscriptionEntity, UserSubscriptionFilterOptions, UserSubscriptionWithDiscounts, type WebhookEvent, type WebhookEventDataMap, type WebhookEventHandler, type WebhookEventType, type WebhookService, idToNumber, idToString, isIdsEqual, parseBillingCycle, parseCurrency, parseDate, parseDateTime, parseNumber, parsePaymentMethod };
14037
14759
  //# sourceMappingURL=index.d.mts.map