@nextblock-cms/ecom 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_virtual/_rolldown/runtime.cjs.js +1 -0
- package/index.cjs.js +1 -1
- package/index.es.js +38 -146
- package/lib/CurrencyProvider.cjs.js +1 -1
- package/lib/CurrencyProvider.d.ts +1 -1
- package/lib/CurrencyProvider.es.js +85 -95
- package/lib/PaymentReadinessProvider.cjs.js +1 -1
- package/lib/PaymentReadinessProvider.d.ts +1 -1
- package/lib/PaymentReadinessProvider.es.js +24 -27
- package/lib/cart-store.cjs.js +1 -1
- package/lib/cart-store.es.js +109 -121
- package/lib/components/AccountNavigationMenu.cjs.js +1 -1
- package/lib/components/AccountNavigationMenu.d.ts +1 -1
- package/lib/components/AccountNavigationMenu.es.js +36 -50
- package/lib/components/AddToCartButton.cjs.js +1 -1
- package/lib/components/AddToCartButton.d.ts +1 -1
- package/lib/components/AddToCartButton.es.js +94 -89
- package/lib/components/Cart.cjs.js +1 -1
- package/lib/components/Cart.d.ts +1 -1
- package/lib/components/Cart.es.js +261 -180
- package/lib/components/CartDrawer.cjs.js +1 -1
- package/lib/components/CartDrawer.d.ts +1 -1
- package/lib/components/CartDrawer.es.js +218 -148
- package/lib/components/CartIcon.cjs.js +1 -1
- package/lib/components/CartIcon.d.ts +1 -1
- package/lib/components/CartIcon.es.js +33 -35
- package/lib/components/Checkout.cjs.js +1 -1
- package/lib/components/Checkout.d.ts +1 -1
- package/lib/components/Checkout.es.js +1092 -1108
- package/lib/components/CouponForm.cjs.js +1 -1
- package/lib/components/CouponForm.d.ts +1 -1
- package/lib/components/CouponForm.es.js +136 -148
- package/lib/components/CurrencySwitcher.cjs.js +1 -1
- package/lib/components/CurrencySwitcher.d.ts +1 -1
- package/lib/components/CurrencySwitcher.es.js +22 -18
- package/lib/components/CustomerProfileForm.cjs.js +1 -1
- package/lib/components/CustomerProfileForm.es.js +454 -313
- package/lib/components/FeaturedProduct.cjs.js +1 -1
- package/lib/components/FeaturedProduct.d.ts +1 -1
- package/lib/components/FeaturedProduct.es.js +98 -83
- package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
- package/lib/components/FreemiusLicensePanel.d.ts +1 -1
- package/lib/components/FreemiusLicensePanel.es.js +70 -65
- package/lib/components/InvoiceDocument.cjs.js +1 -1
- package/lib/components/InvoiceDocument.es.js +256 -192
- package/lib/components/InvoiceViewerShell.cjs.js +2 -2
- package/lib/components/InvoiceViewerShell.d.ts +1 -1
- package/lib/components/InvoiceViewerShell.es.js +75 -106
- package/lib/components/ProductCard.cjs.js +1 -1
- package/lib/components/ProductCard.d.ts +1 -1
- package/lib/components/ProductCard.es.js +186 -171
- package/lib/components/ProductDetailsLayout.cjs.js +1 -1
- package/lib/components/ProductDetailsLayout.es.js +405 -404
- package/lib/components/ProductGallery.cjs.js +1 -1
- package/lib/components/ProductGallery.d.ts +1 -1
- package/lib/components/ProductGallery.es.js +51 -54
- package/lib/components/ProductGrid.cjs.js +1 -1
- package/lib/components/ProductGrid.d.ts +1 -1
- package/lib/components/ProductGrid.es.js +23 -25
- package/lib/components/ShippingEstimator.cjs.js +1 -1
- package/lib/components/ShippingEstimator.d.ts +1 -1
- package/lib/components/ShippingEstimator.es.js +158 -153
- package/lib/components/ShortDescription.cjs.js +1 -1
- package/lib/components/ShortDescription.es.js +17 -17
- package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
- package/lib/components/SimpleTiptapRenderer.es.js +238 -211
- package/lib/components/SubscriptionSelector.cjs.js +1 -1
- package/lib/components/SubscriptionSelector.es.js +159 -154
- package/lib/countries.cjs.js +1 -1
- package/lib/countries.es.js +232 -75
- package/lib/coupon-server.cjs.js +1 -1
- package/lib/coupon-server.es.js +180 -224
- package/lib/coupons.cjs.js +1 -1
- package/lib/coupons.es.js +12 -14
- package/lib/currency-constants.cjs.js +1 -1
- package/lib/currency-constants.es.js +4 -4
- package/lib/currency-rest-client.cjs.js +1 -1
- package/lib/currency-rest-client.es.js +15 -22
- package/lib/currency-store.cjs.js +1 -1
- package/lib/currency-store.es.js +20 -27
- package/lib/currency-sync.cjs.js +1 -1
- package/lib/currency-sync.es.js +124 -170
- package/lib/currency.cjs.js +1 -1
- package/lib/currency.es.js +242 -310
- package/lib/customer-addresses.cjs.js +1 -1
- package/lib/customer-addresses.es.js +80 -109
- package/lib/customer-orders.cjs.js +1 -1
- package/lib/customer-orders.es.js +31 -43
- package/lib/customer.cjs.js +1 -1
- package/lib/customer.es.js +43 -52
- package/lib/export-helpers.cjs.js +1 -1
- package/lib/export-helpers.es.js +53 -52
- package/lib/factory.cjs.js +1 -1
- package/lib/factory.es.js +10 -7
- package/lib/freemius-coupons.cjs.js +1 -1
- package/lib/freemius-coupons.es.js +245 -262
- package/lib/freemius-license-claim.cjs.js +1 -1
- package/lib/freemius-license-claim.es.js +87 -71
- package/lib/freemius-license.cjs.js +1 -1
- package/lib/freemius-license.es.js +32 -39
- package/lib/freemius-order-sync.cjs.js +1 -1
- package/lib/freemius-order-sync.es.js +226 -290
- package/lib/freemius-trial-provision.cjs.js +1 -1
- package/lib/freemius-trial-provision.es.js +136 -130
- package/lib/inventory-settings.cjs.js +1 -1
- package/lib/inventory-settings.es.js +69 -77
- package/lib/invoice-server.cjs.js +3 -3
- package/lib/invoice-server.es.js +94 -141
- package/lib/invoice-ui.cjs.js +1 -1
- package/lib/invoice-ui.es.js +50 -66
- package/lib/invoice.cjs.js +1 -1
- package/lib/invoice.es.js +85 -94
- package/lib/order-inventory.cjs.js +25 -25
- package/lib/order-inventory.es.js +67 -79
- package/lib/order-tax-details.cjs.js +1 -1
- package/lib/order-tax-details.es.js +142 -153
- package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
- package/lib/pages/cms/coupons/CouponEditorForm.d.ts +1 -1
- package/lib/pages/cms/coupons/CouponEditorForm.es.js +227 -185
- package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
- package/lib/pages/cms/coupons/CouponsPage.d.ts +1 -1
- package/lib/pages/cms/coupons/CouponsPage.es.js +235 -166
- package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
- package/lib/pages/cms/coupons/CreateCouponDialog.d.ts +1 -1
- package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -34
- package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
- package/lib/pages/cms/coupons/EditCouponPage.d.ts +1 -1
- package/lib/pages/cms/coupons/EditCouponPage.es.js +47 -47
- package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
- package/lib/pages/cms/coupons/ProductScopePicker.d.ts +1 -1
- package/lib/pages/cms/coupons/ProductScopePicker.es.js +128 -117
- package/lib/pages/cms/coupons/actions.cjs.js +1 -1
- package/lib/pages/cms/coupons/actions.es.js +112 -115
- package/lib/pages/cms/coupons/index.cjs.js +1 -0
- package/lib/pages/cms/coupons/index.es.js +3 -0
- package/lib/pages/cms/coupons/product-options.cjs.js +1 -1
- package/lib/pages/cms/coupons/product-options.es.js +21 -23
- package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
- package/lib/pages/cms/orders/ExportReportsDialog.es.js +135 -129
- package/lib/pages/cms/orders/MarkPaidButton.d.ts +1 -1
- package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderDetailPage.d.ts +1 -1
- package/lib/pages/cms/orders/OrderDetailPage.es.js +186 -134
- package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderPrintButton.d.ts +1 -1
- package/lib/pages/cms/orders/OrderPrintButton.es.js +15 -21
- package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderStatusForm.d.ts +1 -1
- package/lib/pages/cms/orders/OrderStatusForm.es.js +85 -69
- package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
- package/lib/pages/cms/orders/OrdersPage.d.ts +1 -1
- package/lib/pages/cms/orders/OrdersPage.es.js +170 -102
- package/lib/pages/cms/orders/actions.cjs.js +3 -3
- package/lib/pages/cms/orders/actions.es.js +53 -69
- package/lib/pages/cms/orders/export-actions.cjs.js +1 -1
- package/lib/pages/cms/orders/export-actions.es.js +23 -26
- package/lib/pages/cms/orders/index.cjs.js +1 -0
- package/lib/pages/cms/orders/index.es.js +6 -0
- package/lib/pages/cms/orders/server-actions.cjs.js +1 -1
- package/lib/pages/cms/orders/server-actions.es.js +60 -51
- package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
- package/lib/pages/cms/payments/PaymentsClient.d.ts +1 -1
- package/lib/pages/cms/payments/PaymentsClient.es.js +316 -346
- package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
- package/lib/pages/cms/payments/PaymentsPage.d.ts +1 -1
- package/lib/pages/cms/payments/PaymentsPage.es.js +29 -32
- package/lib/pages/cms/payments/actions.cjs.js +1 -1
- package/lib/pages/cms/payments/actions.es.js +38 -48
- package/lib/pages/cms/payments/index.cjs.js +1 -0
- package/lib/pages/cms/payments/index.es.js +3 -0
- package/lib/pages/cms/payments/queries.cjs.js +1 -1
- package/lib/pages/cms/payments/queries.es.js +38 -48
- package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
- package/lib/pages/cms/products/ProductsPage.d.ts +1 -1
- package/lib/pages/cms/products/ProductsPage.es.js +63 -66
- package/lib/pages/cms/products/[id]/edit/EditProductPage.d.ts +1 -1
- package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
- package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +138 -155
- package/lib/pages/cms/products/actions.cjs.js +4 -4
- package/lib/pages/cms/products/actions.es.js +121 -162
- package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
- package/lib/pages/cms/products/attributes/AttributeManagementPage.d.ts +1 -1
- package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +55 -47
- package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
- package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +1 -1
- package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +285 -290
- package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
- package/lib/pages/cms/products/categories/CategoryManagementPage.d.ts +1 -1
- package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +43 -35
- package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
- package/lib/pages/cms/products/categories/components/CategoryManager.es.js +315 -262
- package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
- package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +115 -113
- package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
- package/lib/pages/cms/products/components/CurrencyPriceFields.d.ts +1 -1
- package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +136 -145
- package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
- package/lib/pages/cms/products/components/DeleteProductButton.d.ts +1 -1
- package/lib/pages/cms/products/components/DeleteProductButton.es.js +35 -47
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.d.ts +1 -1
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +106 -84
- package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductCategorySelector.es.js +156 -159
- package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductForm.es.js +872 -693
- package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductMediaManager.es.js +106 -103
- package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +1 -1
- package/lib/pages/cms/products/components/ProductsBulkTable.es.js +303 -294
- package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
- package/lib/pages/cms/products/components/SaleScheduleFields.d.ts +1 -1
- package/lib/pages/cms/products/components/SaleScheduleFields.es.js +111 -134
- package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
- package/lib/pages/cms/products/components/SyncFreemiusButton.d.ts +1 -1
- package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +29 -35
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.d.ts +1 -1
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +36 -48
- package/lib/pages/cms/products/components/SyncProductForm.d.ts +1 -1
- package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
- package/lib/pages/cms/products/components/VariationsEditor.d.ts +1 -1
- package/lib/pages/cms/products/components/VariationsEditor.es.js +396 -405
- package/lib/pages/cms/products/index.cjs.js +1 -0
- package/lib/pages/cms/products/index.es.js +8 -0
- package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
- package/lib/pages/cms/products/inventory/InventoryPage.d.ts +1 -1
- package/lib/pages/cms/products/inventory/InventoryPage.es.js +21 -15
- package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
- package/lib/pages/cms/products/inventory/InventoryTableClient.d.ts +1 -1
- package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +230 -209
- package/lib/pages/cms/products/inventory/actions.cjs.js +3 -3
- package/lib/pages/cms/products/inventory/actions.es.js +83 -91
- package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
- package/lib/pages/cms/products/new/NewProductPage.d.ts +1 -1
- package/lib/pages/cms/products/new/NewProductPage.es.js +58 -74
- package/lib/pages/cms/products/product-price-sync.cjs.js +1 -1
- package/lib/pages/cms/products/product-price-sync.es.js +74 -89
- package/lib/pages/cms/products/server-actions.cjs.js +1 -1
- package/lib/pages/cms/products/server-actions.es.js +250 -233
- package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
- package/lib/pages/cms/shipping/ShippingPage.es.js +287 -209
- package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
- package/lib/pages/cms/shipping/components/RateForm.d.ts +1 -1
- package/lib/pages/cms/shipping/components/RateForm.es.js +439 -436
- package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
- package/lib/pages/cms/shipping/components/ZoneForm.es.js +245 -224
- package/lib/pages/cms/shipping/index.cjs.js +1 -0
- package/lib/pages/cms/shipping/index.es.js +3 -0
- package/lib/pages/cms/shipping/server-actions.cjs.js +1 -1
- package/lib/pages/cms/shipping/server-actions.es.js +131 -149
- package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
- package/lib/pages/cms/taxes/TaxesPage.d.ts +1 -1
- package/lib/pages/cms/taxes/TaxesPage.es.js +211 -169
- package/lib/pages/cms/taxes/actions.cjs.js +1 -1
- package/lib/pages/cms/taxes/actions.es.js +41 -53
- package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
- package/lib/pages/cms/taxes/components/TaxRateForm.d.ts +1 -1
- package/lib/pages/cms/taxes/components/TaxRateForm.es.js +112 -99
- package/lib/pages/cms/taxes/index.cjs.js +1 -0
- package/lib/pages/cms/taxes/index.es.js +3 -0
- package/lib/payment-config.cjs.js +1 -1
- package/lib/payment-config.es.js +110 -126
- package/lib/product-actions.cjs.js +4 -4
- package/lib/product-actions.es.js +289 -544
- package/lib/product-context.cjs.js +1 -1
- package/lib/product-context.es.js +13 -15
- package/lib/product-schema.cjs.js +1 -1
- package/lib/product-schema.es.js +99 -134
- package/lib/providers/freemius.cjs.js +1 -5
- package/lib/providers/freemius.es.js +446 -530
- package/lib/providers/stripe.cjs.js +1 -1
- package/lib/providers/stripe.es.js +417 -477
- package/lib/server-actions/coupon-actions.cjs.js +1 -1
- package/lib/server-actions/coupon-actions.es.js +22 -22
- package/lib/server-actions/customer-actions.cjs.js +1 -1
- package/lib/server-actions/customer-actions.es.js +26 -28
- package/lib/server-actions/product-actions.cjs.js +1 -1
- package/lib/server-actions/product-actions.es.js +9 -15
- package/lib/server-actions/shipping-actions.cjs.js +1 -1
- package/lib/server-actions/shipping-actions.es.js +27 -24
- package/lib/server-actions/tax-actions.cjs.js +1 -1
- package/lib/server-actions/tax-actions.es.js +33 -39
- package/lib/shared-inventory.cjs.js +2 -2
- package/lib/shared-inventory.es.js +111 -160
- package/lib/shipping/resolver.cjs.js +2 -2
- package/lib/shipping/resolver.es.js +44 -61
- package/lib/shipping-rate-currency.cjs.js +1 -1
- package/lib/shipping-rate-currency.es.js +52 -67
- package/lib/states.cjs.js +1 -1
- package/lib/states.es.js +333 -154
- package/lib/stripe/checkout.cjs.js +1 -1
- package/lib/stripe/checkout.es.js +125 -181
- package/lib/stripe/client.cjs.js +1 -1
- package/lib/stripe/client.es.js +14 -19
- package/lib/stripe/order-sync.cjs.js +1 -1
- package/lib/stripe/order-sync.es.js +106 -126
- package/lib/stripe/webhooks.cjs.js +1 -1
- package/lib/stripe/webhooks.es.js +37 -31
- package/lib/tax-calculation.cjs.js +1 -1
- package/lib/tax-calculation.es.js +84 -98
- package/lib/trials.cjs.js +1 -1
- package/lib/trials.es.js +24 -30
- package/lib/types.cjs.js +1 -1
- package/lib/types.es.js +21 -27
- package/lib/use-cart.cjs.js +1 -1
- package/lib/use-cart.es.js +38 -40
- package/lib/use-price-formatter.cjs.js +1 -1
- package/lib/use-price-formatter.es.js +10 -11
- package/lib/variation-utils.cjs.js +1 -1
- package/lib/variation-utils.es.js +199 -261
- package/lib/zod-config.cjs.js +1 -1
- package/lib/zod-config.es.js +5 -6
- package/package.json +16 -16
- package/server.cjs.js +1 -1
- package/server.es.js +56 -211
|
@@ -1,294 +1,230 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return e === "pending" || e === "trial";
|
|
1
|
+
import { parseFreemiusCheckoutCredentialsMap as e, readFreemiusEnvValue as t, resolveFreemiusCheckoutCredentials as n } from "./providers/freemius.es.js";
|
|
2
|
+
import { applyOrderInventoryDeduction as r } from "./order-inventory.es.js";
|
|
3
|
+
import { assignInvoiceMetadata as i } from "./invoice-server.es.js";
|
|
4
|
+
import { createClient as a } from "@supabase/supabase-js";
|
|
5
|
+
import o from "crypto";
|
|
6
|
+
import { Freemius as s } from "@freemius/sdk";
|
|
7
|
+
//#region libs/ecommerce/src/lib/freemius-order-sync.ts
|
|
8
|
+
function c(e) {
|
|
9
|
+
return e == null || e === "" ? null : String(e);
|
|
10
|
+
}
|
|
11
|
+
function l(e) {
|
|
12
|
+
let t = c(e);
|
|
13
|
+
if (!t) return null;
|
|
14
|
+
let n = t.includes("T") ? t : t.replace(" ", "T") + "Z", r = new Date(n);
|
|
15
|
+
return Number.isNaN(r.getTime()) ? t : r.toISOString();
|
|
16
|
+
}
|
|
17
|
+
function u(e) {
|
|
18
|
+
if (e == null || e === "") return null;
|
|
19
|
+
let t = Number(e);
|
|
20
|
+
return Number.isFinite(t) ? t : null;
|
|
21
|
+
}
|
|
22
|
+
function d(...e) {
|
|
23
|
+
return e.some((e) => {
|
|
24
|
+
let t = u(e);
|
|
25
|
+
return t !== null && t > 0;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function f(e) {
|
|
29
|
+
return e === "pending" || e === "trial";
|
|
31
30
|
}
|
|
32
31
|
function p(e) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
};
|
|
147
|
-
const i = N(e.checkoutResponse);
|
|
148
|
-
let n = null;
|
|
149
|
-
if (i.freemius_license_id)
|
|
150
|
-
try {
|
|
151
|
-
n = await h(
|
|
152
|
-
i.freemius_product_id ?? t.freemius_product_id,
|
|
153
|
-
i.freemius_license_id
|
|
154
|
-
);
|
|
155
|
-
} catch (F) {
|
|
156
|
-
console.error("[Freemius Checkout Sync] Failed to retrieve purchase data:", F);
|
|
157
|
-
}
|
|
158
|
-
const c = {
|
|
159
|
-
type: "checkout.purchaseCompleted",
|
|
160
|
-
data: { license_id: i.freemius_license_id },
|
|
161
|
-
objects: {}
|
|
162
|
-
}, u = {
|
|
163
|
-
...i,
|
|
164
|
-
...g(c, n)
|
|
165
|
-
}, d = M(
|
|
166
|
-
e.checkoutResponse,
|
|
167
|
-
t.status
|
|
168
|
-
), l = n ? y({
|
|
169
|
-
event: c,
|
|
170
|
-
currentStatus: t.status,
|
|
171
|
-
purchaseData: n
|
|
172
|
-
}) : null, I = d === "paid" ? t.status : d, w = P(
|
|
173
|
-
t.status,
|
|
174
|
-
I,
|
|
175
|
-
l
|
|
176
|
-
), v = await S({
|
|
177
|
-
client: r,
|
|
178
|
-
order: t,
|
|
179
|
-
nextStatus: w,
|
|
180
|
-
metadata: u,
|
|
181
|
-
eventType: "checkout.purchaseCompleted"
|
|
182
|
-
});
|
|
183
|
-
return {
|
|
184
|
-
success: !0,
|
|
185
|
-
orderId: t.id,
|
|
186
|
-
status: v,
|
|
187
|
-
metadata: u
|
|
188
|
-
};
|
|
32
|
+
return [
|
|
33
|
+
"license.cancelled",
|
|
34
|
+
"license.deleted",
|
|
35
|
+
"license.expired",
|
|
36
|
+
"subscription.cancelled",
|
|
37
|
+
"subscription.renewal.failed.last",
|
|
38
|
+
"trial.cancelled",
|
|
39
|
+
"trial.expired"
|
|
40
|
+
].includes(e || "");
|
|
41
|
+
}
|
|
42
|
+
function m(e, t) {
|
|
43
|
+
return e === "license.extended" && (t?.is_renewal === !0 || t?.is_renewal === 1 || t?.is_renewal === "1" || t?.is_renewal === "true");
|
|
44
|
+
}
|
|
45
|
+
function h(e) {
|
|
46
|
+
let t = e.objects?.payment ?? e.data?.payment ?? e.data;
|
|
47
|
+
return e.type === "payment.created" && d(t?.gross, t?.total_gross, t?.amount, t?.initial_amount);
|
|
48
|
+
}
|
|
49
|
+
function g(e) {
|
|
50
|
+
let t = e?.purchase ?? null, n = e?.trial ?? null;
|
|
51
|
+
return {
|
|
52
|
+
freemius_product_id: c(t?.plugin_id) ?? c(t?.product_id) ?? c(t?.productId) ?? c(n?.plugin_id) ?? c(n?.product_id) ?? c(n?.productId),
|
|
53
|
+
freemius_plan_id: c(t?.plan_id) ?? c(t?.planId),
|
|
54
|
+
freemius_license_id: c(t?.license_id) ?? c(t?.licenseId) ?? c(n?.license_id) ?? c(n?.licenseId),
|
|
55
|
+
freemius_subscription_id: c(t?.subscription_id) ?? c(t?.subscriptionId) ?? c(n?.subscription_id) ?? c(n?.subscriptionId),
|
|
56
|
+
freemius_trial_id: c(n?.id),
|
|
57
|
+
freemius_user_id: c(t?.user_id) ?? c(t?.userId) ?? c(n?.user_id) ?? c(n?.userId) ?? c(e?.user?.id),
|
|
58
|
+
freemius_trial_ends_at: l(n?.trial_ends_at) ?? l(n?.trialEndsAt) ?? l(t?.trial_ends) ?? l(t?.trialEnds)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function _(e, t = "pending") {
|
|
62
|
+
let n = e?.purchase ?? null, r = e?.trial ?? null;
|
|
63
|
+
return t === "paid" ? "paid" : r && (r.canceled_at || r.canceledAt) && f(t) ? "cancelled" : r ? "trial" : n ? (n.canceled_at || n.canceledAt) && f(t) ? "cancelled" : d(n.initial_amount, n.initialAmount, n.gross, n.total_gross, n.totalGross) ? "paid" : n.trial_ends || n.trialEnds || n.subscription_id || n.subscriptionId ? "trial" : t : t;
|
|
64
|
+
}
|
|
65
|
+
function v(e) {
|
|
66
|
+
let { event: t, currentStatus: n, purchaseData: r } = e;
|
|
67
|
+
return n === "paid" && p(t.type) ? "paid" : p(t.type) ? f(n) ? "cancelled" : n : h(t) || m(t.type, t.data) || r && d(r.initialAmount, r.initial_amount, r.gross, r.totalGross, r.total_gross) ? "paid" : r?.canceled === !0 && f(n) ? "cancelled" : n === "pending" && (r?.trialEndsAt || r?.trial_ends_at || r?.trialEnds || r?.trial_ends) || (r?.subscriptionId || r?.subscription_id || t.type === "subscription.created" || t.type === "license.created") && n === "pending" ? "trial" : n;
|
|
68
|
+
}
|
|
69
|
+
function y(e, ...t) {
|
|
70
|
+
let n = t.filter((e) => !!e);
|
|
71
|
+
return e === "paid" || n.includes("paid") ? "paid" : n.includes("cancelled") ? "cancelled" : n.includes("trial") ? "trial" : n.includes("shipped") ? "shipped" : n.includes("refunded") ? "refunded" : e;
|
|
72
|
+
}
|
|
73
|
+
function b(e, t) {
|
|
74
|
+
let n = {
|
|
75
|
+
freemius_last_event_type: t,
|
|
76
|
+
freemius_last_synced_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
77
|
+
};
|
|
78
|
+
for (let [t, r] of Object.entries(e)) r != null && r !== "" && (n[t] = r);
|
|
79
|
+
return n;
|
|
80
|
+
}
|
|
81
|
+
function x() {
|
|
82
|
+
let e = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, t = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY;
|
|
83
|
+
if (!e || !t) throw Error("Missing Supabase Service Role environment variables");
|
|
84
|
+
return a(e, t, { auth: {
|
|
85
|
+
autoRefreshToken: !1,
|
|
86
|
+
persistSession: !1
|
|
87
|
+
} });
|
|
88
|
+
}
|
|
89
|
+
async function S(e, t) {
|
|
90
|
+
let { data: n, error: r } = await e.from("orders").select("id, status, provider, freemius_product_id, freemius_plan_id, freemius_license_id, freemius_subscription_id, freemius_trial_id, freemius_user_id, freemius_trial_ends_at").eq("id", t).single();
|
|
91
|
+
if (r || !n) throw Error(r?.message || "Order not found");
|
|
92
|
+
return n;
|
|
93
|
+
}
|
|
94
|
+
async function C(e, t) {
|
|
95
|
+
let { data: n, error: r } = await e.from("orders").select("id, status, provider, freemius_product_id, freemius_plan_id, freemius_license_id, freemius_subscription_id, freemius_trial_id, freemius_user_id, freemius_trial_ends_at").eq("freemius_license_id", t).order("created_at", { ascending: !1 }).limit(1).maybeSingle();
|
|
96
|
+
if (r) throw Error(r.message);
|
|
97
|
+
return n ?? null;
|
|
98
|
+
}
|
|
99
|
+
async function w(e) {
|
|
100
|
+
let t = b(e.metadata, e.eventType), n = e.order.status, a = n === "paid" && e.nextStatus !== "paid" ? "paid" : e.nextStatus;
|
|
101
|
+
a !== n && (t.status = a);
|
|
102
|
+
let { error: o } = await e.client.from("orders").update(t).eq("id", e.order.id);
|
|
103
|
+
if (o) throw Error(o.message);
|
|
104
|
+
return a === "paid" && n !== "paid" && (await i({
|
|
105
|
+
orderId: e.order.id,
|
|
106
|
+
client: e.client
|
|
107
|
+
}), await r(e.client, e.order.id)), a;
|
|
108
|
+
}
|
|
109
|
+
async function T(e) {
|
|
110
|
+
let t = e.client ?? x(), n = await S(t, e.orderId);
|
|
111
|
+
if (n.provider !== "freemius") return {
|
|
112
|
+
success: !1,
|
|
113
|
+
error: "Only Freemius orders can be synced from Freemius checkout"
|
|
114
|
+
};
|
|
115
|
+
let r = g(e.checkoutResponse), i = null;
|
|
116
|
+
if (r.freemius_license_id) try {
|
|
117
|
+
i = await O(r.freemius_product_id ?? n.freemius_product_id, r.freemius_license_id);
|
|
118
|
+
} catch (e) {
|
|
119
|
+
console.error("[Freemius Checkout Sync] Failed to retrieve purchase data:", e);
|
|
120
|
+
}
|
|
121
|
+
let a = {
|
|
122
|
+
type: "checkout.purchaseCompleted",
|
|
123
|
+
data: { license_id: r.freemius_license_id },
|
|
124
|
+
objects: {}
|
|
125
|
+
}, o = {
|
|
126
|
+
...r,
|
|
127
|
+
...D(a, i)
|
|
128
|
+
}, s = _(e.checkoutResponse, n.status), c = i ? v({
|
|
129
|
+
event: a,
|
|
130
|
+
currentStatus: n.status,
|
|
131
|
+
purchaseData: i
|
|
132
|
+
}) : null, l = s === "paid" ? n.status : s, u = await w({
|
|
133
|
+
client: t,
|
|
134
|
+
order: n,
|
|
135
|
+
nextStatus: y(n.status, l, c),
|
|
136
|
+
metadata: o,
|
|
137
|
+
eventType: "checkout.purchaseCompleted"
|
|
138
|
+
});
|
|
139
|
+
return {
|
|
140
|
+
success: !0,
|
|
141
|
+
orderId: n.id,
|
|
142
|
+
status: u,
|
|
143
|
+
metadata: o
|
|
144
|
+
};
|
|
189
145
|
}
|
|
190
146
|
function E(e) {
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
function
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
async function
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const i = f.createHmac("sha256", t).update(e).digest("hex");
|
|
276
|
-
try {
|
|
277
|
-
return f.timingSafeEqual(
|
|
278
|
-
Buffer.from(i, "hex"),
|
|
279
|
-
Buffer.from(r, "hex")
|
|
280
|
-
);
|
|
281
|
-
} catch {
|
|
282
|
-
return !1;
|
|
283
|
-
}
|
|
284
|
-
}) : !1;
|
|
285
|
-
}
|
|
286
|
-
export {
|
|
287
|
-
N as extractFreemiusCheckoutMetadata,
|
|
288
|
-
q as getFreemiusWebhookSecretCandidates,
|
|
289
|
-
M as resolveFreemiusStatusFromCheckoutResponse,
|
|
290
|
-
y as resolveFreemiusStatusFromWebhookEvent,
|
|
291
|
-
H as syncFreemiusCheckoutOrder,
|
|
292
|
-
Z as syncFreemiusOrderFromWebhookEvent,
|
|
293
|
-
J as verifyFreemiusWebhookSignature
|
|
294
|
-
};
|
|
147
|
+
return c(e.data?.license_id) ?? c(e.objects?.license?.id) ?? c(e.objects?.subscription?.license_id) ?? c(e.objects?.payment?.license_id) ?? c(e.data?.payment?.license_id);
|
|
148
|
+
}
|
|
149
|
+
function D(e, t) {
|
|
150
|
+
let n = e.objects?.license, r = e.objects?.subscription, i = e.objects?.trial, a = e.objects?.payment ?? e.data?.payment;
|
|
151
|
+
return {
|
|
152
|
+
freemius_product_id: c(t?.productId) ?? c(t?.product_id) ?? c(n?.plugin_id) ?? c(r?.plugin_id) ?? c(a?.plugin_id),
|
|
153
|
+
freemius_plan_id: c(t?.planId) ?? c(t?.plan_id) ?? c(n?.plan_id),
|
|
154
|
+
freemius_license_id: c(t?.licenseId) ?? c(t?.license_id) ?? E(e),
|
|
155
|
+
freemius_subscription_id: c(t?.subscriptionId) ?? c(t?.subscription_id) ?? c(r?.id) ?? c(e.data?.subscription_id),
|
|
156
|
+
freemius_trial_id: c(i?.id) ?? c(e.data?.trial_id),
|
|
157
|
+
freemius_user_id: c(t?.userId) ?? c(t?.user_id) ?? c(e.objects?.user?.id),
|
|
158
|
+
freemius_trial_ends_at: l(i?.trial_ends_at) ?? l(i?.trial_ends) ?? l(n?.trial_ends) ?? l(t?.trialEndsAt) ?? l(t?.trial_ends_at)
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
async function O(e, t) {
|
|
162
|
+
if (!e) return null;
|
|
163
|
+
let r = n(e);
|
|
164
|
+
return !r.apiKey || !r.secretKey || !r.publicKey ? null : new s({
|
|
165
|
+
productId: Number(e),
|
|
166
|
+
apiKey: r.apiKey,
|
|
167
|
+
secretKey: r.secretKey,
|
|
168
|
+
publicKey: r.publicKey
|
|
169
|
+
}).purchase.retrievePurchaseData(t);
|
|
170
|
+
}
|
|
171
|
+
async function k(e) {
|
|
172
|
+
let t = e.client ?? x(), n = E(e.event);
|
|
173
|
+
if (!n) return {
|
|
174
|
+
success: !0,
|
|
175
|
+
ignored: !0,
|
|
176
|
+
reason: "missing_license_id",
|
|
177
|
+
type: e.event.type
|
|
178
|
+
};
|
|
179
|
+
let r = await C(t, n);
|
|
180
|
+
if (!r) return {
|
|
181
|
+
success: !0,
|
|
182
|
+
ignored: !0,
|
|
183
|
+
reason: "unknown_license_id",
|
|
184
|
+
licenseId: n,
|
|
185
|
+
type: e.event.type
|
|
186
|
+
};
|
|
187
|
+
let i = null;
|
|
188
|
+
try {
|
|
189
|
+
i = await O(r.freemius_product_id ?? e.event.objects?.license?.plugin_id, n);
|
|
190
|
+
} catch (e) {
|
|
191
|
+
console.error("[Freemius Sync] Failed to retrieve purchase data:", e);
|
|
192
|
+
}
|
|
193
|
+
let a = D(e.event, i), o = await w({
|
|
194
|
+
client: t,
|
|
195
|
+
order: r,
|
|
196
|
+
nextStatus: v({
|
|
197
|
+
event: e.event,
|
|
198
|
+
currentStatus: r.status,
|
|
199
|
+
purchaseData: i
|
|
200
|
+
}),
|
|
201
|
+
metadata: a,
|
|
202
|
+
eventType: e.event.type ?? null
|
|
203
|
+
});
|
|
204
|
+
return {
|
|
205
|
+
success: !0,
|
|
206
|
+
orderId: r.id,
|
|
207
|
+
status: o,
|
|
208
|
+
type: e.event.type
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function A() {
|
|
212
|
+
let n = [
|
|
213
|
+
t("FREEMIUS_SECRET_KEY"),
|
|
214
|
+
t("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY"),
|
|
215
|
+
...Object.values(e() ?? {}).map((e) => e.secretKey ?? null)
|
|
216
|
+
];
|
|
217
|
+
return Array.from(new Set(n.filter((e) => !!e)));
|
|
218
|
+
}
|
|
219
|
+
function j(e, t) {
|
|
220
|
+
return t ? A().some((n) => {
|
|
221
|
+
let r = o.createHmac("sha256", n).update(e).digest("hex");
|
|
222
|
+
try {
|
|
223
|
+
return o.timingSafeEqual(Buffer.from(r, "hex"), Buffer.from(t, "hex"));
|
|
224
|
+
} catch {
|
|
225
|
+
return !1;
|
|
226
|
+
}
|
|
227
|
+
}) : !1;
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
export { g as extractFreemiusCheckoutMetadata, A as getFreemiusWebhookSecretCandidates, _ as resolveFreemiusStatusFromCheckoutResponse, v as resolveFreemiusStatusFromWebhookEvent, T as syncFreemiusCheckoutOrder, k as syncFreemiusOrderFromWebhookEvent, j as verifyFreemiusWebhookSignature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require("./payment-config.cjs.js"),t=require("./providers/freemius.cjs.js");let n=require("@freemius/sdk");var r=`A NextBlock license or trial already exists for this email. Activate that key from CMS Settings → Packages, or purchase a license at nextblock.dev.`,i=`The trial could not be provisioned automatically. Start it from CMS Settings → Packages instead.`;function a(e){return e.toISOString().slice(0,19).replace(`T`,` `)}function o(e,t){let n=Number.isFinite(t)&&t>0?Math.floor(t):30;return new Date(e.getTime()+n*24*60*60*1e3)}function s(e){let t=e.filter(e=>e.id!==null&&e.id!==void 0);if(t.length===0)return null;let n=t.filter(e=>!e.is_hidden);return[...n.length>0?n:t].sort((e,t)=>(e.licenses===null||e.licenses===void 0?1/0:e.licenses)-(t.licenses===null||t.licenses===void 0?1/0:t.licenses))[0]}function c(e){return e.existingLicenses.some(t=>t.plugin_id===null||t.plugin_id===void 0||String(t.plugin_id).trim()===String(e.productId).trim())?{ok:!1,reason:`already_licensed`}:{ok:!0}}function l(e){return e.trim().toLowerCase()}async function u(u,d){await e.hydrateFreemiusEnvFromDb();let f=t.resolveFreemiusCheckoutCredentials(u.productId);if(!f.apiKey||!f.secretKey||!f.publicKey)return{error:`The license service is not configured for this product.`,ok:!1,reason:`not_configured`,status:503};let p=new n.Freemius({apiKey:f.apiKey,productId:Number(u.productId),publicKey:f.publicKey,secretKey:f.secretKey}),m=l(u.email),h=p.api.__unstable_ApiClient,g={product_id:u.productId},_=[];try{let e=await p.api.user.retrieveByEmail(m);e?.id!==null&&e?.id!==void 0&&(_=await p.api.user.retrieveLicenses(e.id))}catch(e){return console.error(`[Freemius trial] user lookup failed:`,e),{error:`Freemius could not be reached to verify eligibility.`,ok:!1,reason:`upstream_error`,status:502}}if(!c({existingLicenses:_,productId:u.productId}).ok)return{error:r,ok:!1,reason:`already_licensed`,status:409};let v=null;try{let{data:e,error:t}=await h.GET(`/products/{product_id}/plans/{plan_id}/pricing.json`,{params:{path:{...g,plan_id:u.planId}}});if(t)throw Error(JSON.stringify(t));let n=s(e?.pricing??[]);v=n?.id!==null&&n?.id!==void 0?String(n.id):null}catch(e){return console.error(`[Freemius trial] pricing lookup failed:`,e),{error:`Freemius could not be reached to resolve the plan pricing.`,ok:!1,reason:`upstream_error`,status:502}}if(!v)return{error:i,ok:!1,reason:`no_pricing`,status:502};let y=a(o(d?.now??new Date,u.trialDays)),b=null,x=null;try{let{data:e,error:t}=await h.POST(`/products/{product_id}/plans/{plan_id}/pricing/{pricing_id}/licenses.json`,{body:{expires_at:y,is_block_features:!0,send_email:!1},params:{path:{...g,plan_id:u.planId,pricing_id:v}}});if(t)throw Error(JSON.stringify(t));let n=e?.license;b=n?.secret_key?.trim()||null,x=n?.id!==null&&n?.id!==void 0?String(n.id):null}catch(e){return console.error(`[Freemius trial] license creation failed:`,e),{error:`Freemius could not create the trial license.`,ok:!1,reason:`upstream_error`,status:502}}if(!b)return{error:i,ok:!1,reason:`no_key`,status:502};let S=!1;try{let{error:e}=await h.PUT(`/products/{product_id}/licenses.json`,{body:{email:m,license_key:b,name:u.name.trim()},params:{path:g}});S=!e,e&&console.warn(`[Freemius trial] license assignment refused:`,JSON.stringify(e))}catch(e){console.warn(`[Freemius trial] license assignment failed:`,e)}return{assigned:S,expiresAt:y,licenseId:x,licenseKey:b,ok:!0,planId:u.planId,pricingId:v}}exports.FREEMIUS_TRIAL_ALREADY_USED_MESSAGE=r,exports.FREEMIUS_TRIAL_PROVISION_FAILED_MESSAGE=i,exports.computeTrialExpiry=o,exports.evaluateTrialEligibility=c,exports.formatFreemiusTimestamp=a,exports.pickTrialPricing=s,exports.provisionFreemiusTrialLicense=u;
|