@nextblock-cms/ecom 0.20.3 → 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.
Files changed (317) hide show
  1. package/_virtual/_rolldown/runtime.cjs.js +1 -0
  2. package/index.cjs.js +1 -1
  3. package/index.es.js +38 -146
  4. package/lib/CurrencyProvider.cjs.js +1 -1
  5. package/lib/CurrencyProvider.d.ts +1 -1
  6. package/lib/CurrencyProvider.es.js +85 -95
  7. package/lib/PaymentReadinessProvider.cjs.js +1 -1
  8. package/lib/PaymentReadinessProvider.d.ts +1 -1
  9. package/lib/PaymentReadinessProvider.es.js +24 -27
  10. package/lib/cart-store.cjs.js +1 -1
  11. package/lib/cart-store.es.js +109 -121
  12. package/lib/components/AccountNavigationMenu.cjs.js +1 -1
  13. package/lib/components/AccountNavigationMenu.d.ts +1 -1
  14. package/lib/components/AccountNavigationMenu.es.js +36 -50
  15. package/lib/components/AddToCartButton.cjs.js +1 -1
  16. package/lib/components/AddToCartButton.d.ts +1 -1
  17. package/lib/components/AddToCartButton.es.js +94 -89
  18. package/lib/components/Cart.cjs.js +1 -1
  19. package/lib/components/Cart.d.ts +1 -1
  20. package/lib/components/Cart.es.js +261 -180
  21. package/lib/components/CartDrawer.cjs.js +1 -1
  22. package/lib/components/CartDrawer.d.ts +1 -1
  23. package/lib/components/CartDrawer.es.js +218 -148
  24. package/lib/components/CartIcon.cjs.js +1 -1
  25. package/lib/components/CartIcon.d.ts +1 -1
  26. package/lib/components/CartIcon.es.js +33 -35
  27. package/lib/components/Checkout.cjs.js +1 -1
  28. package/lib/components/Checkout.d.ts +1 -1
  29. package/lib/components/Checkout.es.js +1092 -1108
  30. package/lib/components/CouponForm.cjs.js +1 -1
  31. package/lib/components/CouponForm.d.ts +1 -1
  32. package/lib/components/CouponForm.es.js +136 -148
  33. package/lib/components/CurrencySwitcher.cjs.js +1 -1
  34. package/lib/components/CurrencySwitcher.d.ts +1 -1
  35. package/lib/components/CurrencySwitcher.es.js +22 -18
  36. package/lib/components/CustomerProfileForm.cjs.js +1 -1
  37. package/lib/components/CustomerProfileForm.es.js +454 -313
  38. package/lib/components/FeaturedProduct.cjs.js +1 -1
  39. package/lib/components/FeaturedProduct.d.ts +1 -1
  40. package/lib/components/FeaturedProduct.es.js +98 -83
  41. package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
  42. package/lib/components/FreemiusLicensePanel.d.ts +1 -1
  43. package/lib/components/FreemiusLicensePanel.es.js +70 -65
  44. package/lib/components/InvoiceDocument.cjs.js +1 -1
  45. package/lib/components/InvoiceDocument.es.js +256 -192
  46. package/lib/components/InvoiceViewerShell.cjs.js +2 -2
  47. package/lib/components/InvoiceViewerShell.d.ts +1 -1
  48. package/lib/components/InvoiceViewerShell.es.js +75 -106
  49. package/lib/components/ProductCard.cjs.js +1 -1
  50. package/lib/components/ProductCard.d.ts +1 -1
  51. package/lib/components/ProductCard.es.js +186 -171
  52. package/lib/components/ProductDetailsLayout.cjs.js +1 -1
  53. package/lib/components/ProductDetailsLayout.es.js +405 -404
  54. package/lib/components/ProductGallery.cjs.js +1 -1
  55. package/lib/components/ProductGallery.d.ts +1 -1
  56. package/lib/components/ProductGallery.es.js +51 -54
  57. package/lib/components/ProductGrid.cjs.js +1 -1
  58. package/lib/components/ProductGrid.d.ts +1 -1
  59. package/lib/components/ProductGrid.es.js +23 -25
  60. package/lib/components/ShippingEstimator.cjs.js +1 -1
  61. package/lib/components/ShippingEstimator.d.ts +1 -1
  62. package/lib/components/ShippingEstimator.es.js +158 -153
  63. package/lib/components/ShortDescription.cjs.js +1 -1
  64. package/lib/components/ShortDescription.es.js +17 -17
  65. package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
  66. package/lib/components/SimpleTiptapRenderer.es.js +238 -211
  67. package/lib/components/SubscriptionSelector.cjs.js +1 -1
  68. package/lib/components/SubscriptionSelector.es.js +159 -154
  69. package/lib/countries.cjs.js +1 -1
  70. package/lib/countries.es.js +232 -75
  71. package/lib/coupon-server.cjs.js +1 -1
  72. package/lib/coupon-server.es.js +180 -224
  73. package/lib/coupons.cjs.js +1 -1
  74. package/lib/coupons.es.js +12 -14
  75. package/lib/currency-constants.cjs.js +1 -1
  76. package/lib/currency-constants.es.js +4 -4
  77. package/lib/currency-rest-client.cjs.js +1 -1
  78. package/lib/currency-rest-client.es.js +15 -22
  79. package/lib/currency-store.cjs.js +1 -1
  80. package/lib/currency-store.es.js +20 -27
  81. package/lib/currency-sync.cjs.js +1 -1
  82. package/lib/currency-sync.es.js +124 -170
  83. package/lib/currency.cjs.js +1 -1
  84. package/lib/currency.es.js +242 -310
  85. package/lib/customer-addresses.cjs.js +1 -1
  86. package/lib/customer-addresses.es.js +80 -109
  87. package/lib/customer-orders.cjs.js +1 -1
  88. package/lib/customer-orders.es.js +31 -43
  89. package/lib/customer.cjs.js +1 -1
  90. package/lib/customer.es.js +43 -52
  91. package/lib/export-helpers.cjs.js +1 -1
  92. package/lib/export-helpers.es.js +53 -52
  93. package/lib/factory.cjs.js +1 -1
  94. package/lib/factory.es.js +10 -7
  95. package/lib/freemius-coupons.cjs.js +1 -1
  96. package/lib/freemius-coupons.es.js +245 -262
  97. package/lib/freemius-license-claim.cjs.js +1 -1
  98. package/lib/freemius-license-claim.es.js +87 -71
  99. package/lib/freemius-license.cjs.js +1 -1
  100. package/lib/freemius-license.es.js +32 -39
  101. package/lib/freemius-order-sync.cjs.js +1 -1
  102. package/lib/freemius-order-sync.es.js +226 -290
  103. package/lib/freemius-trial-provision.cjs.js +1 -1
  104. package/lib/freemius-trial-provision.es.js +136 -130
  105. package/lib/inventory-settings.cjs.js +1 -1
  106. package/lib/inventory-settings.es.js +69 -77
  107. package/lib/invoice-server.cjs.js +3 -3
  108. package/lib/invoice-server.es.js +94 -141
  109. package/lib/invoice-ui.cjs.js +1 -1
  110. package/lib/invoice-ui.es.js +50 -66
  111. package/lib/invoice.cjs.js +1 -1
  112. package/lib/invoice.es.js +85 -94
  113. package/lib/order-inventory.cjs.js +25 -25
  114. package/lib/order-inventory.es.js +67 -79
  115. package/lib/order-tax-details.cjs.js +1 -1
  116. package/lib/order-tax-details.es.js +142 -153
  117. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
  118. package/lib/pages/cms/coupons/CouponEditorForm.d.ts +1 -1
  119. package/lib/pages/cms/coupons/CouponEditorForm.es.js +227 -185
  120. package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
  121. package/lib/pages/cms/coupons/CouponsPage.d.ts +1 -1
  122. package/lib/pages/cms/coupons/CouponsPage.es.js +235 -166
  123. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
  124. package/lib/pages/cms/coupons/CreateCouponDialog.d.ts +1 -1
  125. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -34
  126. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
  127. package/lib/pages/cms/coupons/EditCouponPage.d.ts +1 -1
  128. package/lib/pages/cms/coupons/EditCouponPage.es.js +47 -47
  129. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
  130. package/lib/pages/cms/coupons/ProductScopePicker.d.ts +1 -1
  131. package/lib/pages/cms/coupons/ProductScopePicker.es.js +128 -117
  132. package/lib/pages/cms/coupons/actions.cjs.js +1 -1
  133. package/lib/pages/cms/coupons/actions.es.js +112 -115
  134. package/lib/pages/cms/coupons/index.cjs.js +1 -0
  135. package/lib/pages/cms/coupons/index.es.js +3 -0
  136. package/lib/pages/cms/coupons/product-options.cjs.js +1 -1
  137. package/lib/pages/cms/coupons/product-options.es.js +21 -23
  138. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
  139. package/lib/pages/cms/orders/ExportReportsDialog.es.js +135 -129
  140. package/lib/pages/cms/orders/MarkPaidButton.d.ts +1 -1
  141. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
  142. package/lib/pages/cms/orders/OrderDetailPage.d.ts +1 -1
  143. package/lib/pages/cms/orders/OrderDetailPage.es.js +186 -134
  144. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
  145. package/lib/pages/cms/orders/OrderPrintButton.d.ts +1 -1
  146. package/lib/pages/cms/orders/OrderPrintButton.es.js +15 -21
  147. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
  148. package/lib/pages/cms/orders/OrderStatusForm.d.ts +1 -1
  149. package/lib/pages/cms/orders/OrderStatusForm.es.js +85 -69
  150. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
  151. package/lib/pages/cms/orders/OrdersPage.d.ts +1 -1
  152. package/lib/pages/cms/orders/OrdersPage.es.js +170 -102
  153. package/lib/pages/cms/orders/actions.cjs.js +3 -3
  154. package/lib/pages/cms/orders/actions.es.js +53 -69
  155. package/lib/pages/cms/orders/export-actions.cjs.js +1 -1
  156. package/lib/pages/cms/orders/export-actions.es.js +23 -26
  157. package/lib/pages/cms/orders/index.cjs.js +1 -0
  158. package/lib/pages/cms/orders/index.es.js +6 -0
  159. package/lib/pages/cms/orders/server-actions.cjs.js +1 -1
  160. package/lib/pages/cms/orders/server-actions.es.js +60 -51
  161. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
  162. package/lib/pages/cms/payments/PaymentsClient.d.ts +1 -1
  163. package/lib/pages/cms/payments/PaymentsClient.es.js +316 -346
  164. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
  165. package/lib/pages/cms/payments/PaymentsPage.d.ts +1 -1
  166. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -32
  167. package/lib/pages/cms/payments/actions.cjs.js +1 -1
  168. package/lib/pages/cms/payments/actions.es.js +38 -48
  169. package/lib/pages/cms/payments/index.cjs.js +1 -0
  170. package/lib/pages/cms/payments/index.es.js +3 -0
  171. package/lib/pages/cms/payments/queries.cjs.js +1 -1
  172. package/lib/pages/cms/payments/queries.es.js +38 -48
  173. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
  174. package/lib/pages/cms/products/ProductsPage.d.ts +1 -1
  175. package/lib/pages/cms/products/ProductsPage.es.js +63 -66
  176. package/lib/pages/cms/products/[id]/edit/EditProductPage.d.ts +1 -1
  177. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
  178. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +138 -155
  179. package/lib/pages/cms/products/actions.cjs.js +4 -4
  180. package/lib/pages/cms/products/actions.es.js +121 -162
  181. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
  182. package/lib/pages/cms/products/attributes/AttributeManagementPage.d.ts +1 -1
  183. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +55 -47
  184. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
  185. package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +1 -1
  186. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +285 -290
  187. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
  188. package/lib/pages/cms/products/categories/CategoryManagementPage.d.ts +1 -1
  189. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +43 -35
  190. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
  191. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +315 -262
  192. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
  193. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +115 -113
  194. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
  195. package/lib/pages/cms/products/components/CurrencyPriceFields.d.ts +1 -1
  196. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +136 -145
  197. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
  198. package/lib/pages/cms/products/components/DeleteProductButton.d.ts +1 -1
  199. package/lib/pages/cms/products/components/DeleteProductButton.es.js +35 -47
  200. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
  201. package/lib/pages/cms/products/components/FreemiusPricingDashboard.d.ts +1 -1
  202. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +106 -84
  203. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
  204. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +156 -159
  205. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
  206. package/lib/pages/cms/products/components/ProductForm.es.js +872 -693
  207. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
  208. package/lib/pages/cms/products/components/ProductMediaManager.es.js +106 -103
  209. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
  210. package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +1 -1
  211. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +303 -294
  212. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
  213. package/lib/pages/cms/products/components/SaleScheduleFields.d.ts +1 -1
  214. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +111 -134
  215. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
  216. package/lib/pages/cms/products/components/SyncFreemiusButton.d.ts +1 -1
  217. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +29 -35
  218. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
  219. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.d.ts +1 -1
  220. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +36 -48
  221. package/lib/pages/cms/products/components/SyncProductForm.d.ts +1 -1
  222. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
  223. package/lib/pages/cms/products/components/VariationsEditor.d.ts +1 -1
  224. package/lib/pages/cms/products/components/VariationsEditor.es.js +396 -405
  225. package/lib/pages/cms/products/index.cjs.js +1 -0
  226. package/lib/pages/cms/products/index.es.js +8 -0
  227. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
  228. package/lib/pages/cms/products/inventory/InventoryPage.d.ts +1 -1
  229. package/lib/pages/cms/products/inventory/InventoryPage.es.js +21 -15
  230. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
  231. package/lib/pages/cms/products/inventory/InventoryTableClient.d.ts +1 -1
  232. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +230 -209
  233. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -3
  234. package/lib/pages/cms/products/inventory/actions.es.js +83 -91
  235. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
  236. package/lib/pages/cms/products/new/NewProductPage.d.ts +1 -1
  237. package/lib/pages/cms/products/new/NewProductPage.es.js +58 -74
  238. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -1
  239. package/lib/pages/cms/products/product-price-sync.es.js +74 -89
  240. package/lib/pages/cms/products/server-actions.cjs.js +1 -1
  241. package/lib/pages/cms/products/server-actions.es.js +250 -233
  242. package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
  243. package/lib/pages/cms/shipping/ShippingPage.es.js +287 -209
  244. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
  245. package/lib/pages/cms/shipping/components/RateForm.d.ts +1 -1
  246. package/lib/pages/cms/shipping/components/RateForm.es.js +439 -436
  247. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
  248. package/lib/pages/cms/shipping/components/ZoneForm.es.js +245 -224
  249. package/lib/pages/cms/shipping/index.cjs.js +1 -0
  250. package/lib/pages/cms/shipping/index.es.js +3 -0
  251. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -1
  252. package/lib/pages/cms/shipping/server-actions.es.js +131 -149
  253. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
  254. package/lib/pages/cms/taxes/TaxesPage.d.ts +1 -1
  255. package/lib/pages/cms/taxes/TaxesPage.es.js +211 -169
  256. package/lib/pages/cms/taxes/actions.cjs.js +1 -1
  257. package/lib/pages/cms/taxes/actions.es.js +41 -53
  258. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
  259. package/lib/pages/cms/taxes/components/TaxRateForm.d.ts +1 -1
  260. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +112 -99
  261. package/lib/pages/cms/taxes/index.cjs.js +1 -0
  262. package/lib/pages/cms/taxes/index.es.js +3 -0
  263. package/lib/payment-config.cjs.js +1 -1
  264. package/lib/payment-config.es.js +110 -126
  265. package/lib/product-actions.cjs.js +4 -4
  266. package/lib/product-actions.es.js +289 -544
  267. package/lib/product-context.cjs.js +1 -1
  268. package/lib/product-context.es.js +13 -15
  269. package/lib/product-schema.cjs.js +1 -1
  270. package/lib/product-schema.es.js +99 -134
  271. package/lib/providers/freemius.cjs.js +1 -5
  272. package/lib/providers/freemius.es.js +446 -530
  273. package/lib/providers/stripe.cjs.js +1 -1
  274. package/lib/providers/stripe.es.js +417 -477
  275. package/lib/server-actions/coupon-actions.cjs.js +1 -1
  276. package/lib/server-actions/coupon-actions.es.js +22 -22
  277. package/lib/server-actions/customer-actions.cjs.js +1 -1
  278. package/lib/server-actions/customer-actions.es.js +26 -28
  279. package/lib/server-actions/product-actions.cjs.js +1 -1
  280. package/lib/server-actions/product-actions.es.js +9 -15
  281. package/lib/server-actions/shipping-actions.cjs.js +1 -1
  282. package/lib/server-actions/shipping-actions.es.js +27 -24
  283. package/lib/server-actions/tax-actions.cjs.js +1 -1
  284. package/lib/server-actions/tax-actions.es.js +33 -39
  285. package/lib/shared-inventory.cjs.js +2 -2
  286. package/lib/shared-inventory.es.js +111 -160
  287. package/lib/shipping/resolver.cjs.js +2 -2
  288. package/lib/shipping/resolver.es.js +44 -61
  289. package/lib/shipping-rate-currency.cjs.js +1 -1
  290. package/lib/shipping-rate-currency.es.js +52 -67
  291. package/lib/states.cjs.js +1 -1
  292. package/lib/states.es.js +333 -154
  293. package/lib/stripe/checkout.cjs.js +1 -1
  294. package/lib/stripe/checkout.es.js +125 -181
  295. package/lib/stripe/client.cjs.js +1 -1
  296. package/lib/stripe/client.es.js +14 -19
  297. package/lib/stripe/order-sync.cjs.js +1 -1
  298. package/lib/stripe/order-sync.es.js +106 -126
  299. package/lib/stripe/webhooks.cjs.js +1 -1
  300. package/lib/stripe/webhooks.es.js +37 -31
  301. package/lib/tax-calculation.cjs.js +1 -1
  302. package/lib/tax-calculation.es.js +84 -98
  303. package/lib/trials.cjs.js +1 -1
  304. package/lib/trials.es.js +24 -30
  305. package/lib/types.cjs.js +1 -1
  306. package/lib/types.es.js +21 -27
  307. package/lib/use-cart.cjs.js +1 -1
  308. package/lib/use-cart.es.js +38 -40
  309. package/lib/use-price-formatter.cjs.js +1 -1
  310. package/lib/use-price-formatter.es.js +10 -11
  311. package/lib/variation-utils.cjs.js +1 -1
  312. package/lib/variation-utils.es.js +199 -261
  313. package/lib/zod-config.cjs.js +1 -1
  314. package/lib/zod-config.es.js +5 -6
  315. package/package.json +16 -16
  316. package/server.cjs.js +1 -1
  317. package/server.es.js +56 -211
@@ -1,546 +1,462 @@
1
- import { createClient as H } from "@supabase/supabase-js";
2
- import Q from "crypto";
3
- import { Freemius as te } from "@freemius/sdk";
4
- import { hydrateFreemiusEnvFromDb as ne } from "../payment-config.es.js";
5
- import { normalizeOrderCustomerDetails as se } from "../customer.es.js";
6
- import { getCouponQuote as ie, recordCouponRedemption as oe } from "../coupon-server.es.js";
7
- import { upsertDefaultUserAddresses as ce, fillMissingUserProfileCheckoutDetails as ae } from "../customer-addresses.es.js";
8
- import { getDefaultCurrency as le, resolveEffectivePriceForCurrency as ue, isSaleWindowActive as z } from "../currency.es.js";
9
- function o(e) {
10
- const r = process.env[e];
11
- if (!r)
12
- return null;
13
- const t = r.trim();
14
- return t.startsWith('"') && t.endsWith('"') || t.startsWith("'") && t.endsWith("'") ? t.slice(1, -1).trim() : t;
1
+ import { getDefaultCurrency as e, isSaleWindowActive as t, resolveEffectivePriceForCurrency as n } from "../currency.es.js";
2
+ import { getCouponQuote as r, recordCouponRedemption as i } from "../coupon-server.es.js";
3
+ import { normalizeOrderCustomerDetails as a } from "../customer.es.js";
4
+ import { fillMissingUserProfileCheckoutDetails as o, upsertDefaultUserAddresses as s } from "../customer-addresses.es.js";
5
+ import { hydrateFreemiusEnvFromDb as c } from "../payment-config.es.js";
6
+ import { createClient as l } from "@supabase/supabase-js";
7
+ import u from "crypto";
8
+ import { Freemius as d } from "@freemius/sdk";
9
+ //#region libs/ecommerce/src/lib/providers/freemius.ts
10
+ function f(e) {
11
+ let t = process.env[e];
12
+ if (!t) return null;
13
+ let n = t.trim();
14
+ return n.startsWith("\"") && n.endsWith("\"") || n.startsWith("'") && n.endsWith("'") ? n.slice(1, -1).trim() : n;
15
15
  }
16
- function de(e) {
17
- const r = e?.trim();
18
- if (!r)
19
- return {
20
- firstName: null,
21
- lastName: null
22
- };
23
- const [t, ...s] = r.split(/\s+/);
24
- return {
25
- firstName: t || null,
26
- lastName: s.length > 0 ? s.join(" ") : null
27
- };
16
+ function p(e) {
17
+ let t = e?.trim();
18
+ if (!t) return {
19
+ firstName: null,
20
+ lastName: null
21
+ };
22
+ let [n, ...r] = t.split(/\s+/);
23
+ return {
24
+ firstName: n || null,
25
+ lastName: r.length > 0 ? r.join(" ") : null
26
+ };
28
27
  }
29
- function G(e) {
30
- if (e == null || e === "")
31
- return 0;
32
- const r = Number(e);
33
- return !Number.isFinite(r) || r <= 0 ? 0 : Math.round(r);
28
+ function m(e) {
29
+ if (e == null || e === "") return 0;
30
+ let t = Number(e);
31
+ return !Number.isFinite(t) || t <= 0 ? 0 : Math.round(t);
34
32
  }
35
- function pe(e) {
36
- return e === !0 || e === 1 || e === "1" || e === "true";
33
+ function h(e) {
34
+ return e === !0 || e === 1 || e === "1" || e === "true";
37
35
  }
38
- function _e(e, r) {
39
- const t = e?.[r];
40
- return Array.isArray(t) ? t : t && typeof t == "object" ? [t] : [];
36
+ function g(e, t) {
37
+ let n = e?.[t];
38
+ return Array.isArray(n) ? n : n && typeof n == "object" ? [n] : [];
41
39
  }
42
- function X(e, r) {
43
- for (const t of r) {
44
- const s = _e(e, t);
45
- if (s.length > 0)
46
- return s;
47
- }
48
- return Array.isArray(e) ? e : [];
40
+ function _(e, t) {
41
+ for (let n of t) {
42
+ let t = g(e, n);
43
+ if (t.length > 0) return t;
44
+ }
45
+ return Array.isArray(e) ? e : [];
49
46
  }
50
- function k(e) {
51
- if (e == null || e === "")
52
- return null;
53
- const r = Number(e);
54
- return Number.isFinite(r) ? r : null;
47
+ function v(e) {
48
+ if (e == null || e === "") return null;
49
+ let t = Number(e);
50
+ return Number.isFinite(t) ? t : null;
55
51
  }
56
- function me(e) {
57
- return e === null ? 0 : e > 5e3 ? (console.warn(
58
- `[Freemius Sync] Suspiciously high price detected: ${e}. Assuming it is already in cents.`
59
- ), Math.round(e)) : Math.round(e * 100);
52
+ function y(e) {
53
+ return e === null ? 0 : e > 5e3 ? (console.warn(`[Freemius Sync] Suspiciously high price detected: ${e}. Assuming it is already in cents.`), Math.round(e)) : Math.round(e * 100);
60
54
  }
61
- function fe(e) {
62
- const r = Number(e);
63
- return !Number.isFinite(r) || r < 1 ? 1 : Math.round(r);
55
+ function b(e) {
56
+ let t = Number(e);
57
+ return !Number.isFinite(t) || t < 1 ? 1 : Math.round(t);
64
58
  }
65
- function Ee() {
66
- const e = o("FREEMIUS_CHECKOUT_PRODUCTS_JSON");
67
- if (!e)
68
- return null;
69
- try {
70
- const r = JSON.parse(e);
71
- return r && typeof r == "object" ? r : null;
72
- } catch (r) {
73
- return console.error(
74
- "[Freemius Checkout] Failed to parse FREEMIUS_CHECKOUT_PRODUCTS_JSON:",
75
- r
76
- ), null;
77
- }
59
+ function x() {
60
+ let e = f("FREEMIUS_CHECKOUT_PRODUCTS_JSON");
61
+ if (!e) return null;
62
+ try {
63
+ let t = JSON.parse(e);
64
+ return t && typeof t == "object" ? t : null;
65
+ } catch (e) {
66
+ return console.error("[Freemius Checkout] Failed to parse FREEMIUS_CHECKOUT_PRODUCTS_JSON:", e), null;
67
+ }
78
68
  }
79
- function ge(e) {
80
- const r = Ee(), t = String(e), s = r?.[t], c = o("FREEMIUS_PRODUCT_ID"), d = o(
81
- "FREEMIUS_ECOMMERCE_SANDBOX_PUBLIC_KEY"
82
- ), f = o(
83
- "FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY"
84
- );
85
- return s?.publicKey ? {
86
- publicKey: s.publicKey,
87
- secretKey: s.secretKey ?? null,
88
- apiKey: s.apiKey ?? null,
89
- source: "product-map"
90
- } : process.env.FREEMIUS_SANDBOX_ENABLED === "true" && c && c === t && d ? {
91
- publicKey: d,
92
- secretKey: f,
93
- apiKey: o("FREEMIUS_API_KEY"),
94
- source: "single-product-sandbox-env"
95
- } : c && c === t && o("FREEMIUS_PUBLIC_KEY") ? {
96
- publicKey: o("FREEMIUS_PUBLIC_KEY"),
97
- secretKey: o("FREEMIUS_SECRET_KEY"),
98
- apiKey: o("FREEMIUS_API_KEY"),
99
- source: "single-product-env"
100
- } : {
101
- publicKey: o("FREEMIUS_PUBLIC_KEY"),
102
- secretKey: o("FREEMIUS_SECRET_KEY"),
103
- apiKey: o("FREEMIUS_API_KEY"),
104
- source: "legacy-env"
105
- };
69
+ function S(e) {
70
+ let t = x(), n = String(e), r = t?.[n], i = f("FREEMIUS_PRODUCT_ID"), a = f("FREEMIUS_ECOMMERCE_SANDBOX_PUBLIC_KEY"), o = f("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY");
71
+ return r?.publicKey ? {
72
+ publicKey: r.publicKey,
73
+ secretKey: r.secretKey ?? null,
74
+ apiKey: r.apiKey ?? null,
75
+ source: "product-map"
76
+ } : process.env.FREEMIUS_SANDBOX_ENABLED === "true" && i && i === n && a ? {
77
+ publicKey: a,
78
+ secretKey: o,
79
+ apiKey: f("FREEMIUS_API_KEY"),
80
+ source: "single-product-sandbox-env"
81
+ } : i && i === n && f("FREEMIUS_PUBLIC_KEY") ? {
82
+ publicKey: f("FREEMIUS_PUBLIC_KEY"),
83
+ secretKey: f("FREEMIUS_SECRET_KEY"),
84
+ apiKey: f("FREEMIUS_API_KEY"),
85
+ source: "single-product-env"
86
+ } : {
87
+ publicKey: f("FREEMIUS_PUBLIC_KEY"),
88
+ secretKey: f("FREEMIUS_SECRET_KEY"),
89
+ apiKey: f("FREEMIUS_API_KEY"),
90
+ source: "legacy-env"
91
+ };
106
92
  }
107
- async function ye(e) {
108
- if (!e.apiKey)
109
- throw new Error("Missing Freemius API key for SDK sandbox generation.");
110
- return new te({
111
- productId: Number(e.productId),
112
- apiKey: e.apiKey,
113
- secretKey: e.secretKey,
114
- publicKey: e.publicKey
115
- }).checkout.getSandboxParams();
93
+ async function C(e) {
94
+ if (!e.apiKey) throw Error("Missing Freemius API key for SDK sandbox generation.");
95
+ return new d({
96
+ productId: Number(e.productId),
97
+ apiKey: e.apiKey,
98
+ secretKey: e.secretKey,
99
+ publicKey: e.publicKey
100
+ }).checkout.getSandboxParams();
116
101
  }
117
- class Ue {
118
- getProviderName() {
119
- return "Freemius";
120
- }
121
- async createCheckoutSession({
122
- items: r,
123
- customerEmail: t,
124
- customerPhone: s,
125
- userId: c,
126
- billingAddress: d,
127
- shippingAddress: f,
128
- currencyCode: m,
129
- couponCode: b,
130
- couponContextItems: E
131
- }) {
132
- const a = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, l = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY;
133
- if (!a || !l)
134
- return { error: "Missing Supabase credentials for checkout (Service Key required).", url: null };
135
- const p = H(a, l);
136
- if (!r || r.length === 0)
137
- return { error: "Cart is empty", url: null };
138
- if (r.length !== 1)
139
- return { error: "Freemius items must be checked out one at a time.", url: null };
140
- const { data: g, error: K } = await p.from("currencies").select(
141
- "code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount"
142
- ).eq("is_active", !0).order("code", { ascending: !0 }), v = g ?? [];
143
- if (K || v.length === 0)
144
- return { error: "Failed to resolve store currencies", url: null };
145
- const j = le(v), w = v.find((u) => u.code === (m || "").toUpperCase()) ?? j, y = r[0], { data: i, error: I } = await p.from("products").select("id, title, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, freemius_plan_id, freemius_product_id, trial_period_days, trial_requires_payment_method").eq("id", y.product_id).single();
146
- if (I || !i)
147
- return { error: "Product not found", url: null };
148
- const R = i.freemius_plan_id, P = i.freemius_product_id;
149
- if (!R || !P)
150
- return { error: "Product is not configured for Freemius checkout (missing Plan ID or Product ID)", url: null };
151
- const D = ue({
152
- prices: i.prices || {},
153
- salePrices: i.sale_prices || {},
154
- fallbackPrice: i.price,
155
- fallbackSalePrice: i.sale_price,
156
- saleStartAt: i.sale_start_at,
157
- saleEndAt: i.sale_end_at,
158
- scheduledPrice: i.scheduled_price,
159
- scheduledPrices: i.scheduled_prices || {},
160
- scheduledPriceAt: i.scheduled_price_at,
161
- currencyCode: w.code,
162
- currencies: v
163
- }), N = D.sale_price ?? D.price, x = z({
164
- saleStartAt: i.sale_start_at,
165
- saleEndAt: i.sale_end_at
166
- }), S = N * y.quantity;
167
- let n = null, _ = 0;
168
- if (b) {
169
- const u = await ie({
170
- client: p,
171
- code: b,
172
- items: E && E.length > 0 ? E : r,
173
- currencyCode: w.code
174
- });
175
- if (!u.success)
176
- return {
177
- error: u.error,
178
- errorKey: u.errorKey,
179
- errorStatus: 400,
180
- url: null
181
- };
182
- n = u.quote, _ = Math.min(
183
- S,
184
- n.lineDiscounts.filter(($) => $.product_id === i.id).reduce(($, q) => $ + q.discount, 0)
185
- );
186
- }
187
- const F = G(i.trial_period_days), U = F > 0 ? y.trial_preference ? y.trial_preference : i.trial_requires_payment_method ? "paid" : "free" : null, B = "pending", h = de(
188
- d?.recipient_name ?? null
189
- ), { data: Y, error: V } = await p.from("orders").insert({
190
- status: B,
191
- total: Math.max(0, S - _),
192
- currency: w.code,
193
- exchange_rate_at_purchase: w.exchange_rate,
194
- subtotal: S,
195
- discount_total: _,
196
- coupon_id: n?.couponId ?? null,
197
- coupon_code: n?.code ?? null,
198
- discount_details: n ? {
199
- code: n.code,
200
- discount_type: n.discountType,
201
- discount_amount: n.discountAmount,
202
- provider: "freemius",
203
- provider_discounts: n.providerDiscounts,
204
- line_discounts: n.lineDiscounts,
205
- final_amount_owned_by: "freemius"
206
- } : null,
207
- provider: "freemius",
208
- freemius_product_id: String(P),
209
- freemius_plan_id: String(R),
210
- user_id: c || null,
211
- customer_details: se({
212
- email: t,
213
- phone: s,
214
- name: d?.recipient_name,
215
- billing: d,
216
- shipping: f
217
- })
218
- }).select("id").single();
219
- if (V || !Y)
220
- return console.error("Failed to create pending order:", V), { error: "Failed to initiate order", url: null };
221
- const { error: J } = await p.from("order_items").insert([{
222
- order_id: Y.id,
223
- product_id: i.id,
224
- quantity: y.quantity,
225
- price_at_purchase: N
226
- }]);
227
- if (J && console.error("Failed to insert order items:", J), c)
228
- try {
229
- await ce({
230
- userId: c,
231
- billingAddress: d,
232
- shippingAddress: f,
233
- client: p
234
- }), await ae({
235
- userId: c,
236
- fullName: d?.recipient_name ?? f?.recipient_name ?? null,
237
- phone: s,
238
- client: p
239
- });
240
- } catch (u) {
241
- console.error(
242
- "Failed to sync checkout profile defaults before checkout:",
243
- u
244
- );
245
- }
246
- n && await oe({
247
- client: p,
248
- quote: n,
249
- orderId: Y.id,
250
- provider: "freemius",
251
- discountTotal: _,
252
- userId: c,
253
- customerEmail: t,
254
- metadata: {
255
- currency: w.code,
256
- subtotal: S,
257
- final_amount_owned_by: "freemius"
258
- }
259
- }), await ne();
260
- const O = process.env.FREEMIUS_SANDBOX_ENABLED === "true", M = ge(P), A = M.publicKey, L = M.secretKey, W = M.apiKey;
261
- if (!A || O && !L)
262
- return console.error(
263
- "Freemius checkout blocked: missing credentials (PUBLIC_KEY or SECRET_KEY) in CMS → Payments or environment."
264
- ), {
265
- error: "This store is not able to take payments right now. Please contact the seller to complete your purchase.",
266
- errorKey: "ecommerce.checkout_payments_unavailable",
267
- errorStatus: 503,
268
- url: null
269
- };
270
- if (O && M.source === "legacy-env") {
271
- const u = o("FREEMIUS_PRODUCT_ID"), $ = !!o("FREEMIUS_ECOMMERCE_SANDBOX_PUBLIC_KEY"), q = !!o("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY");
272
- console.warn(
273
- `[Freemius Checkout] Sandbox is enabled for product ${P}, but no product-scoped checkout credentials were selected. Falling back to legacy FREEMIUS_PUBLIC_KEY/FREEMIUS_SECRET_KEY may open live checkout instead of sandbox.`,
274
- {
275
- configuredProductId: u,
276
- productIdsMatch: u === String(P),
277
- hasSandboxOverridePublicKey: $,
278
- hasSandboxOverrideSecretKey: q,
279
- hasCheckoutProductsJson: !!o("FREEMIUS_CHECKOUT_PRODUCTS_JSON")
280
- }
281
- );
282
- }
283
- let T = !1;
284
- if (O && L && A)
285
- try {
286
- T = await ye({
287
- productId: P,
288
- publicKey: A,
289
- secretKey: L,
290
- apiKey: W
291
- });
292
- } catch (u) {
293
- console.warn(
294
- "Freemius Checkout - SDK sandbox generation failed. Falling back to manual token generation.",
295
- u,
296
- {
297
- credentialSource: M.source,
298
- hasApiKey: !!W
299
- }
300
- );
301
- const $ = Math.floor(Date.now() / 1e3).toString(), q = `${$}${P}${L}${A}checkout`, re = Q.createHash("md5").update(q).digest("hex");
302
- T = {
303
- ctx: $,
304
- token: re
305
- };
306
- }
307
- const C = new URL(`https://checkout.freemius.com/app/${P}/plan/${R}/`);
308
- if (O && L && A ? (C.searchParams.append("sandbox", T.token), C.searchParams.append("s_ctx_ts", T.ctx)) : O && C.searchParams.append("sandbox", "true"), t && C.searchParams.append("user_email", t), h.firstName && C.searchParams.append("user_firstname", h.firstName), h.lastName && C.searchParams.append("user_lastname", h.lastName), C.searchParams.append("currency", w.code.toLowerCase()), y.billing_cycle && C.searchParams.append("billing_cycle", y.billing_cycle), U && C.searchParams.append("trial", U), n)
309
- C.searchParams.append("coupon", n.code);
310
- else if (x) {
311
- const { data: u } = await p.from("product_freemius_sale_coupons").select("freemius_coupon_code, is_active, starts_at, ends_at, sync_status").eq("product_id", i.id).maybeSingle();
312
- u?.is_active && u.sync_status === "synced" && u.freemius_coupon_code && z({
313
- saleStartAt: u.starts_at,
314
- saleEndAt: u.ends_at
315
- }) && C.searchParams.append("coupon", u.freemius_coupon_code);
316
- }
317
- return {
318
- url: C.toString(),
319
- customProps: {
320
- provider: "freemius",
321
- plugin_id: P,
322
- plan_id: R,
323
- public_key: A,
324
- user_email: t,
325
- user_firstname: h.firstName,
326
- user_lastname: h.lastName,
327
- credential_source: M.source,
328
- sandbox: T,
329
- billing_cycle: y.billing_cycle,
330
- trial: U,
331
- trial_period_days: F,
332
- trial_requires_payment_method: i.trial_requires_payment_method,
333
- initial_order_status: B,
334
- coupon: n?.code ?? null,
335
- order_id: Y.id
336
- }
337
- };
338
- }
339
- }
340
- async function Z(e, r, t, s) {
341
- const d = (/* @__PURE__ */ new Date()).toUTCString().replace("GMT", "+0000"), f = `GET
342
-
343
-
344
- ${d}
345
- ${e}`, m = Q.createHmac("sha256", s).update(f).digest("hex"), b = Buffer.from(m).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ""), E = `FS ${r}:${t}:${b}`, a = await fetch(`https://api.freemius.com${e}`, {
346
- headers: {
347
- Authorization: E,
348
- Date: d,
349
- Accept: "application/json"
350
- }
351
- });
352
- if (!a.ok) {
353
- const l = await a.text();
354
- throw console.error(`[Freemius API] [ERROR] ${e} returned ${a.status}: ${l}`), new Error(`Freemius API failed on ${e}: ${a.status} - ${l}`);
355
- }
356
- return a.json();
102
+ var w = class {
103
+ getProviderName() {
104
+ return "Freemius";
105
+ }
106
+ async createCheckoutSession({ items: d, customerEmail: h, customerPhone: g, userId: _, billingAddress: v, shippingAddress: y, currencyCode: b, couponCode: x, couponContextItems: w }) {
107
+ let T = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, E = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY;
108
+ if (!T || !E) return {
109
+ error: "Missing Supabase credentials for checkout (Service Key required).",
110
+ url: null
111
+ };
112
+ let D = l(T, E);
113
+ if (!d || d.length === 0) return {
114
+ error: "Cart is empty",
115
+ url: null
116
+ };
117
+ if (d.length !== 1) return {
118
+ error: "Freemius items must be checked out one at a time.",
119
+ url: null
120
+ };
121
+ let { data: O, error: k } = await D.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active", !0).order("code", { ascending: !0 }), A = O ?? [];
122
+ if (k || A.length === 0) return {
123
+ error: "Failed to resolve store currencies",
124
+ url: null
125
+ };
126
+ let ee = e(A), j = A.find((e) => e.code === (b || "").toUpperCase()) ?? ee, M = d[0], { data: N, error: te } = await D.from("products").select("id, title, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, freemius_plan_id, freemius_product_id, trial_period_days, trial_requires_payment_method").eq("id", M.product_id).single();
127
+ if (te || !N) return {
128
+ error: "Product not found",
129
+ url: null
130
+ };
131
+ let P = N.freemius_plan_id, F = N.freemius_product_id;
132
+ if (!P || !F) return {
133
+ error: "Product is not configured for Freemius checkout (missing Plan ID or Product ID)",
134
+ url: null
135
+ };
136
+ let I = n({
137
+ prices: N.prices || {},
138
+ salePrices: N.sale_prices || {},
139
+ fallbackPrice: N.price,
140
+ fallbackSalePrice: N.sale_price,
141
+ saleStartAt: N.sale_start_at,
142
+ saleEndAt: N.sale_end_at,
143
+ scheduledPrice: N.scheduled_price,
144
+ scheduledPrices: N.scheduled_prices || {},
145
+ scheduledPriceAt: N.scheduled_price_at,
146
+ currencyCode: j.code,
147
+ currencies: A
148
+ }), L = I.sale_price ?? I.price, ne = t({
149
+ saleStartAt: N.sale_start_at,
150
+ saleEndAt: N.sale_end_at
151
+ }), R = L * M.quantity, z = null, B = 0;
152
+ if (x) {
153
+ let e = await r({
154
+ client: D,
155
+ code: x,
156
+ items: w && w.length > 0 ? w : d,
157
+ currencyCode: j.code
158
+ });
159
+ if (!e.success) return {
160
+ error: e.error,
161
+ errorKey: e.errorKey,
162
+ errorStatus: 400,
163
+ url: null
164
+ };
165
+ z = e.quote, B = Math.min(R, z.lineDiscounts.filter((e) => e.product_id === N.id).reduce((e, t) => e + t.discount, 0));
166
+ }
167
+ let V = m(N.trial_period_days), H = V > 0 ? M.trial_preference ? M.trial_preference : N.trial_requires_payment_method ? "paid" : "free" : null, U = "pending", W = p(v?.recipient_name ?? null), { data: G, error: K } = await D.from("orders").insert({
168
+ status: U,
169
+ total: Math.max(0, R - B),
170
+ currency: j.code,
171
+ exchange_rate_at_purchase: j.exchange_rate,
172
+ subtotal: R,
173
+ discount_total: B,
174
+ coupon_id: z?.couponId ?? null,
175
+ coupon_code: z?.code ?? null,
176
+ discount_details: z ? {
177
+ code: z.code,
178
+ discount_type: z.discountType,
179
+ discount_amount: z.discountAmount,
180
+ provider: "freemius",
181
+ provider_discounts: z.providerDiscounts,
182
+ line_discounts: z.lineDiscounts,
183
+ final_amount_owned_by: "freemius"
184
+ } : null,
185
+ provider: "freemius",
186
+ freemius_product_id: String(F),
187
+ freemius_plan_id: String(P),
188
+ user_id: _ || null,
189
+ customer_details: a({
190
+ email: h,
191
+ phone: g,
192
+ name: v?.recipient_name,
193
+ billing: v,
194
+ shipping: y
195
+ })
196
+ }).select("id").single();
197
+ if (K || !G) return console.error("Failed to create pending order:", K), {
198
+ error: "Failed to initiate order",
199
+ url: null
200
+ };
201
+ let { error: q } = await D.from("order_items").insert([{
202
+ order_id: G.id,
203
+ product_id: N.id,
204
+ quantity: M.quantity,
205
+ price_at_purchase: L
206
+ }]);
207
+ if (q && console.error("Failed to insert order items:", q), _) try {
208
+ await s({
209
+ userId: _,
210
+ billingAddress: v,
211
+ shippingAddress: y,
212
+ client: D
213
+ }), await o({
214
+ userId: _,
215
+ fullName: v?.recipient_name ?? y?.recipient_name ?? null,
216
+ phone: g,
217
+ client: D
218
+ });
219
+ } catch (e) {
220
+ console.error("Failed to sync checkout profile defaults before checkout:", e);
221
+ }
222
+ z && await i({
223
+ client: D,
224
+ quote: z,
225
+ orderId: G.id,
226
+ provider: "freemius",
227
+ discountTotal: B,
228
+ userId: _,
229
+ customerEmail: h,
230
+ metadata: {
231
+ currency: j.code,
232
+ subtotal: R,
233
+ final_amount_owned_by: "freemius"
234
+ }
235
+ }), await c();
236
+ let J = process.env.FREEMIUS_SANDBOX_ENABLED === "true", Y = S(F), X = Y.publicKey, Z = Y.secretKey, re = Y.apiKey;
237
+ if (!X || J && !Z) return console.error("Freemius checkout blocked: missing credentials (PUBLIC_KEY or SECRET_KEY) in CMS → Payments or environment."), {
238
+ error: "This store is not able to take payments right now. Please contact the seller to complete your purchase.",
239
+ errorKey: "ecommerce.checkout_payments_unavailable",
240
+ errorStatus: 503,
241
+ url: null
242
+ };
243
+ if (J && Y.source === "legacy-env") {
244
+ let e = f("FREEMIUS_PRODUCT_ID"), t = !!f("FREEMIUS_ECOMMERCE_SANDBOX_PUBLIC_KEY"), n = !!f("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY");
245
+ console.warn(`[Freemius Checkout] Sandbox is enabled for product ${F}, but no product-scoped checkout credentials were selected. Falling back to legacy FREEMIUS_PUBLIC_KEY/FREEMIUS_SECRET_KEY may open live checkout instead of sandbox.`, {
246
+ configuredProductId: e,
247
+ productIdsMatch: e === String(F),
248
+ hasSandboxOverridePublicKey: t,
249
+ hasSandboxOverrideSecretKey: n,
250
+ hasCheckoutProductsJson: !!f("FREEMIUS_CHECKOUT_PRODUCTS_JSON")
251
+ });
252
+ }
253
+ let Q = !1;
254
+ if (J && Z && X) try {
255
+ Q = await C({
256
+ productId: F,
257
+ publicKey: X,
258
+ secretKey: Z,
259
+ apiKey: re
260
+ });
261
+ } catch (e) {
262
+ console.warn("Freemius Checkout - SDK sandbox generation failed. Falling back to manual token generation.", e, {
263
+ credentialSource: Y.source,
264
+ hasApiKey: !!re
265
+ });
266
+ let t = Math.floor(Date.now() / 1e3).toString(), n = `${t}${F}${Z}${X}checkout`;
267
+ Q = {
268
+ ctx: t,
269
+ token: u.createHash("md5").update(n).digest("hex")
270
+ };
271
+ }
272
+ let $ = new URL(`https://checkout.freemius.com/app/${F}/plan/${P}/`);
273
+ if (J && Z && X ? ($.searchParams.append("sandbox", Q.token), $.searchParams.append("s_ctx_ts", Q.ctx)) : J && $.searchParams.append("sandbox", "true"), h && $.searchParams.append("user_email", h), W.firstName && $.searchParams.append("user_firstname", W.firstName), W.lastName && $.searchParams.append("user_lastname", W.lastName), $.searchParams.append("currency", j.code.toLowerCase()), M.billing_cycle && $.searchParams.append("billing_cycle", M.billing_cycle), H && $.searchParams.append("trial", H), z) $.searchParams.append("coupon", z.code);
274
+ else if (ne) {
275
+ let { data: e } = await D.from("product_freemius_sale_coupons").select("freemius_coupon_code, is_active, starts_at, ends_at, sync_status").eq("product_id", N.id).maybeSingle();
276
+ e?.is_active && e.sync_status === "synced" && e.freemius_coupon_code && t({
277
+ saleStartAt: e.starts_at,
278
+ saleEndAt: e.ends_at
279
+ }) && $.searchParams.append("coupon", e.freemius_coupon_code);
280
+ }
281
+ return {
282
+ url: $.toString(),
283
+ customProps: {
284
+ provider: "freemius",
285
+ plugin_id: F,
286
+ plan_id: P,
287
+ public_key: X,
288
+ user_email: h,
289
+ user_firstname: W.firstName,
290
+ user_lastname: W.lastName,
291
+ credential_source: Y.source,
292
+ sandbox: Q,
293
+ billing_cycle: M.billing_cycle,
294
+ trial: H,
295
+ trial_period_days: V,
296
+ trial_requires_payment_method: N.trial_requires_payment_method,
297
+ initial_order_status: U,
298
+ coupon: z?.code ?? null,
299
+ order_id: G.id
300
+ }
301
+ };
302
+ }
303
+ };
304
+ async function T(e, t, n, r) {
305
+ let i = (/* @__PURE__ */ new Date()).toUTCString().replace("GMT", "+0000"), a = `GET\n\n\n${i}\n${e}`, o = u.createHmac("sha256", r).update(a).digest("hex"), s = `FS ${t}:${n}:${Buffer.from(o).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "")}`, c = await fetch(`https://api.freemius.com${e}`, { headers: {
306
+ Authorization: s,
307
+ Date: i,
308
+ Accept: "application/json"
309
+ } });
310
+ if (!c.ok) {
311
+ let t = await c.text();
312
+ throw console.error(`[Freemius API] [ERROR] ${e} returned ${c.status}: ${t}`), Error(`Freemius API failed on ${e}: ${c.status} - ${t}`);
313
+ }
314
+ return c.json();
357
315
  }
358
- async function Re() {
359
- const e = o("FREEMIUS_DEVELOPER_ID"), r = o("FREEMIUS_PUBLIC_KEY"), t = o("FREEMIUS_SECRET_KEY"), s = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, c = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY;
360
- if (!e || !r || !t || !s || !c)
361
- throw new Error("Missing necessary environment variables for Freemius Sync.");
362
- const d = H(s, c, {
363
- auth: { autoRefreshToken: !1, persistSession: !1 }
364
- }), f = (m) => Z(m, e, r, t);
365
- try {
366
- console.log(`[Freemius Sync] Fetching all plugins for developer ${e}...`);
367
- const m = await f(`/v1/developers/${e}/plugins.json`), b = X(m, ["plugins", "plugin"]);
368
- console.log(`[Freemius Sync] Found ${b.length} plugins. Syncing plans...`);
369
- let E = 0;
370
- const { data: a } = await d.from("languages").select("id").eq("code", "en").single(), l = a?.id;
371
- if (!l)
372
- throw new Error("English language not found in database. Cannot sync products.");
373
- for (const p of b) {
374
- const g = p.id?.toString();
375
- if (!g) {
376
- console.warn("[Freemius Sync] Skipping plugin without an id:", p);
377
- continue;
378
- }
379
- const K = await ee(
380
- d,
381
- e,
382
- g,
383
- p.title || p.name || `Freemius Product ${g}`,
384
- f,
385
- l
386
- );
387
- E += K;
388
- }
389
- return { success: !0, count: E };
390
- } catch (m) {
391
- throw console.error("[Freemius Sync] Global Error:", m), m;
392
- }
316
+ async function E() {
317
+ let e = f("FREEMIUS_DEVELOPER_ID"), t = f("FREEMIUS_PUBLIC_KEY"), n = f("FREEMIUS_SECRET_KEY"), r = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, i = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY;
318
+ if (!e || !t || !n || !r || !i) throw Error("Missing necessary environment variables for Freemius Sync.");
319
+ let a = l(r, i, { auth: {
320
+ autoRefreshToken: !1,
321
+ persistSession: !1
322
+ } }), o = (r) => T(r, e, t, n);
323
+ try {
324
+ console.log(`[Freemius Sync] Fetching all plugins for developer ${e}...`);
325
+ let t = _(await o(`/v1/developers/${e}/plugins.json`), ["plugins", "plugin"]);
326
+ console.log(`[Freemius Sync] Found ${t.length} plugins. Syncing plans...`);
327
+ let n = 0, { data: r } = await a.from("languages").select("id").eq("code", "en").single(), i = r?.id;
328
+ if (!i) throw Error("English language not found in database. Cannot sync products.");
329
+ for (let r of t) {
330
+ let t = r.id?.toString();
331
+ if (!t) {
332
+ console.warn("[Freemius Sync] Skipping plugin without an id:", r);
333
+ continue;
334
+ }
335
+ let s = await O(a, e, t, r.title || r.name || `Freemius Product ${t}`, o, i);
336
+ n += s;
337
+ }
338
+ return {
339
+ success: !0,
340
+ count: n
341
+ };
342
+ } catch (e) {
343
+ throw console.error("[Freemius Sync] Global Error:", e), e;
344
+ }
393
345
  }
394
- async function $e(e) {
395
- const r = o("FREEMIUS_DEVELOPER_ID"), t = o("FREEMIUS_PUBLIC_KEY"), s = o("FREEMIUS_SECRET_KEY"), c = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, d = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY;
396
- if (!r || !t || !s || !c || !d)
397
- throw new Error("Missing environment variables for Freemius Sync.");
398
- const f = H(c, d), m = (g) => Z(g, r, t, s), { data: b } = await f.from("languages").select("id").eq("code", "en").single(), E = b?.id;
399
- if (!E)
400
- throw new Error("English language not found in database. Cannot sync products.");
401
- const a = await m(`/v1/developers/${r}/plugins/${e}.json`), l = a.plugin ?? a;
402
- return { success: !0, count: await ee(
403
- f,
404
- r,
405
- e,
406
- l.title || l.name || `Freemius Product ${e}`,
407
- m,
408
- E
409
- ) };
346
+ async function D(e) {
347
+ let t = f("FREEMIUS_DEVELOPER_ID"), n = f("FREEMIUS_PUBLIC_KEY"), r = f("FREEMIUS_SECRET_KEY"), i = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, a = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY;
348
+ if (!t || !n || !r || !i || !a) throw Error("Missing environment variables for Freemius Sync.");
349
+ let o = l(i, a), s = (e) => T(e, t, n, r), { data: c } = await o.from("languages").select("id").eq("code", "en").single(), u = c?.id;
350
+ if (!u) throw Error("English language not found in database. Cannot sync products.");
351
+ let d = await s(`/v1/developers/${t}/plugins/${e}.json`), p = d.plugin ?? d;
352
+ return {
353
+ success: !0,
354
+ count: await O(o, t, e, p.title || p.name || `Freemius Product ${e}`, s, u)
355
+ };
410
356
  }
411
- async function ee(e, r, t, s, c, d) {
412
- console.log(`[Freemius Sync] Fetching plans for plugin: ${s} (${t})...`);
413
- let f = 0;
414
- try {
415
- const m = `/v1/developers/${r}/plugins/${t}/plans.json`, b = await c(m), E = X(b, ["plans", "plan"]);
416
- console.log(`[Freemius Sync] Received ${E.length} plans for plugin ${t}.`);
417
- for (const a of E) {
418
- const l = a.id?.toString();
419
- if (!l) {
420
- console.warn("[Freemius Sync] Skipping plan without an id:", a);
421
- continue;
422
- }
423
- const p = a.name || a.title || l, g = a.title || p;
424
- console.log(`[Freemius Sync] Processing plan: ${g} (${l})...`);
425
- let K = a;
426
- if (K.trial_period === void 0 || K.is_require_subscription === void 0)
427
- try {
428
- const n = `/v1/developers/${r}/plugins/${t}/plans/${l}.json`, _ = await c(n), F = _.plan ?? _;
429
- K = {
430
- ...K,
431
- ...F
432
- };
433
- } catch (n) {
434
- console.warn(
435
- `[Freemius Sync] Could not fetch trial details for plan ${l}:`,
436
- n instanceof Error ? n.message : n
437
- );
438
- }
439
- const v = G(K.trial_period), j = v > 0 && pe(K.is_require_subscription);
440
- let w = 0, y = [];
441
- try {
442
- const n = `/v1/developers/${r}/plugins/${t}/plans/${l}/pricing.json`, _ = await c(n);
443
- if (y = X(_, [
444
- "pricing",
445
- "prices",
446
- "pricings"
447
- ]), y.length > 0) {
448
- const F = y[0], U = k(F.annual_price) ?? k(F.monthly_price) ?? k(F.lifetime_price);
449
- w = me(U);
450
- }
451
- console.log(`[Freemius Sync] Plan: ${g} -> Resolved Price (cents): ${w}`);
452
- } catch (n) {
453
- console.warn(`[Freemius Sync] Could not fetch pricing for plan ${l}:`, n instanceof Error ? n.message : n);
454
- }
455
- const i = `${s}-${g}`.toLowerCase().replace(/[^\w\s-]/g, "").replace(/[\s_]+/g, "-").replace(/^-+|-+$/g, ""), I = {
456
- title: `${s} - ${g}`,
457
- slug: i,
458
- short_description: a.description || "",
459
- price: w,
460
- product_type: "digital",
461
- payment_provider: "freemius",
462
- freemius_plan_id: l,
463
- freemius_product_id: t,
464
- trial_period_days: v,
465
- trial_requires_payment_method: j,
466
- status: "active",
467
- stock: 999,
468
- sku: `FM-${t}-${l}`,
469
- language_id: d
470
- }, { data: R, error: P } = await e.from("products").upsert(I, { onConflict: "language_id, sku" }).select();
471
- if (P || !R || R.length === 0) {
472
- console.error(`[Freemius Sync] Error upserting product ${I.sku}:`, P);
473
- continue;
474
- }
475
- const D = R[0].id, { data: N, error: x } = await e.from("freemius_plans").select("id").eq("product_id", D).eq("name", p).maybeSingle();
476
- x && console.warn(
477
- `[Freemius Sync] Could not check existing local plan for ${I.sku}:`,
478
- x.message || x
479
- );
480
- let S = "";
481
- if (N) {
482
- S = N.id;
483
- const { error: n } = await e.from("freemius_plans").update({ title: g, updated_at: (/* @__PURE__ */ new Date()).toISOString() }).eq("id", S);
484
- n && console.warn(
485
- `[Freemius Sync] Could not update local plan ${S}:`,
486
- n.message || n
487
- );
488
- } else {
489
- const { data: n, error: _ } = await e.from("freemius_plans").insert({
490
- product_id: D,
491
- name: p,
492
- title: g
493
- }).select("id").single();
494
- _ && console.warn(
495
- `[Freemius Sync] Could not insert local plan for ${I.sku}:`,
496
- _.message || _
497
- ), n && (S = n.id);
498
- }
499
- if (S && y.length > 0)
500
- for (const n of y) {
501
- const _ = fe(
502
- n.licenses ?? n.license_quota ?? n.quota
503
- ), { data: F, error: U } = await e.from("freemius_pricing").select("id").eq("plan_id", S).eq("license_quota", _).maybeSingle();
504
- U && console.warn(
505
- `[Freemius Sync] Could not check pricing for plan ${S}, quota ${_}:`,
506
- U.message || U
507
- );
508
- const B = {
509
- api_monthly_price: k(n.monthly_price),
510
- api_annual_price: k(n.annual_price),
511
- api_lifetime_price: k(n.lifetime_price),
512
- updated_at: (/* @__PURE__ */ new Date()).toISOString()
513
- };
514
- if (F) {
515
- const { error: h } = await e.from("freemius_pricing").update(B).eq("id", F.id);
516
- h && console.warn(
517
- `[Freemius Sync] Could not update pricing ${F.id}:`,
518
- h.message || h
519
- );
520
- } else {
521
- const { error: h } = await e.from("freemius_pricing").insert({
522
- plan_id: S,
523
- license_quota: _,
524
- ...B
525
- });
526
- h && console.warn(
527
- `[Freemius Sync] Could not insert pricing for plan ${S}, quota ${_}:`,
528
- h.message || h
529
- );
530
- }
531
- }
532
- console.log(`[Freemius Sync] Successfully fully synced product ${I.sku}.`), f++;
533
- }
534
- } catch (m) {
535
- console.error(`[Freemius Sync] Failed sync for plugin ${t}:`, m.message);
536
- }
537
- return f;
357
+ async function O(e, t, n, r, i, a) {
358
+ console.log(`[Freemius Sync] Fetching plans for plugin: ${r} (${n})...`);
359
+ let o = 0;
360
+ try {
361
+ let s = _(await i(`/v1/developers/${t}/plugins/${n}/plans.json`), ["plans", "plan"]);
362
+ console.log(`[Freemius Sync] Received ${s.length} plans for plugin ${n}.`);
363
+ for (let c of s) {
364
+ let s = c.id?.toString();
365
+ if (!s) {
366
+ console.warn("[Freemius Sync] Skipping plan without an id:", c);
367
+ continue;
368
+ }
369
+ let l = c.name || c.title || s, u = c.title || l;
370
+ console.log(`[Freemius Sync] Processing plan: ${u} (${s})...`);
371
+ let d = c;
372
+ if (d.trial_period === void 0 || d.is_require_subscription === void 0) try {
373
+ let e = await i(`/v1/developers/${t}/plugins/${n}/plans/${s}.json`), r = e.plan ?? e;
374
+ d = {
375
+ ...d,
376
+ ...r
377
+ };
378
+ } catch (e) {
379
+ console.warn(`[Freemius Sync] Could not fetch trial details for plan ${s}:`, e instanceof Error ? e.message : e);
380
+ }
381
+ let f = m(d.trial_period), p = f > 0 && h(d.is_require_subscription), g = 0, x = [];
382
+ try {
383
+ if (x = _(await i(`/v1/developers/${t}/plugins/${n}/plans/${s}/pricing.json`), [
384
+ "pricing",
385
+ "prices",
386
+ "pricings"
387
+ ]), x.length > 0) {
388
+ let e = x[0];
389
+ g = y(v(e.annual_price) ?? v(e.monthly_price) ?? v(e.lifetime_price));
390
+ }
391
+ console.log(`[Freemius Sync] Plan: ${u} -> Resolved Price (cents): ${g}`);
392
+ } catch (e) {
393
+ console.warn(`[Freemius Sync] Could not fetch pricing for plan ${s}:`, e instanceof Error ? e.message : e);
394
+ }
395
+ let S = `${r}-${u}`.toLowerCase().replace(/[^\w\s-]/g, "").replace(/[\s_]+/g, "-").replace(/^-+|-+$/g, ""), C = {
396
+ title: `${r} - ${u}`,
397
+ slug: S,
398
+ short_description: c.description || "",
399
+ price: g,
400
+ product_type: "digital",
401
+ payment_provider: "freemius",
402
+ freemius_plan_id: s,
403
+ freemius_product_id: n,
404
+ trial_period_days: f,
405
+ trial_requires_payment_method: p,
406
+ status: "active",
407
+ stock: 999,
408
+ sku: `FM-${n}-${s}`,
409
+ language_id: a
410
+ }, { data: w, error: T } = await e.from("products").upsert(C, { onConflict: "language_id, sku" }).select();
411
+ if (T || !w || w.length === 0) {
412
+ console.error(`[Freemius Sync] Error upserting product ${C.sku}:`, T);
413
+ continue;
414
+ }
415
+ let E = w[0].id, { data: D, error: O } = await e.from("freemius_plans").select("id").eq("product_id", E).eq("name", l).maybeSingle();
416
+ O && console.warn(`[Freemius Sync] Could not check existing local plan for ${C.sku}:`, O.message || O);
417
+ let k = "";
418
+ if (D) {
419
+ k = D.id;
420
+ let { error: t } = await e.from("freemius_plans").update({
421
+ title: u,
422
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
423
+ }).eq("id", k);
424
+ t && console.warn(`[Freemius Sync] Could not update local plan ${k}:`, t.message || t);
425
+ } else {
426
+ let { data: t, error: n } = await e.from("freemius_plans").insert({
427
+ product_id: E,
428
+ name: l,
429
+ title: u
430
+ }).select("id").single();
431
+ n && console.warn(`[Freemius Sync] Could not insert local plan for ${C.sku}:`, n.message || n), t && (k = t.id);
432
+ }
433
+ if (k && x.length > 0) for (let t of x) {
434
+ let n = b(t.licenses ?? t.license_quota ?? t.quota), { data: r, error: i } = await e.from("freemius_pricing").select("id").eq("plan_id", k).eq("license_quota", n).maybeSingle();
435
+ i && console.warn(`[Freemius Sync] Could not check pricing for plan ${k}, quota ${n}:`, i.message || i);
436
+ let a = {
437
+ api_monthly_price: v(t.monthly_price),
438
+ api_annual_price: v(t.annual_price),
439
+ api_lifetime_price: v(t.lifetime_price),
440
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
441
+ };
442
+ if (r) {
443
+ let { error: t } = await e.from("freemius_pricing").update(a).eq("id", r.id);
444
+ t && console.warn(`[Freemius Sync] Could not update pricing ${r.id}:`, t.message || t);
445
+ } else {
446
+ let { error: t } = await e.from("freemius_pricing").insert({
447
+ plan_id: k,
448
+ license_quota: n,
449
+ ...a
450
+ });
451
+ t && console.warn(`[Freemius Sync] Could not insert pricing for plan ${k}, quota ${n}:`, t.message || t);
452
+ }
453
+ }
454
+ console.log(`[Freemius Sync] Successfully fully synced product ${C.sku}.`), o++;
455
+ }
456
+ } catch (e) {
457
+ console.error(`[Freemius Sync] Failed sync for plugin ${n}:`, e.message);
458
+ }
459
+ return o;
538
460
  }
539
- export {
540
- Ue as FreemiusProvider,
541
- Ee as parseFreemiusCheckoutCredentialsMap,
542
- o as readFreemiusEnvValue,
543
- ge as resolveFreemiusCheckoutCredentials,
544
- Re as syncFreemiusProductsToSupabase,
545
- $e as syncSingleFreemiusProduct
546
- };
461
+ //#endregion
462
+ export { w as FreemiusProvider, x as parseFreemiusCheckoutCredentialsMap, f as readFreemiusEnvValue, S as resolveFreemiusCheckoutCredentials, E as syncFreemiusProductsToSupabase, D as syncSingleFreemiusProduct };