@nextblock-cms/ecom 0.8.6 → 0.8.7

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 (277) hide show
  1. package/index.cjs.js +1 -1
  2. package/index.es.js +136 -533
  3. package/lib/CurrencyProvider.cjs.js +1 -0
  4. package/lib/CurrencyProvider.es.js +99 -0
  5. package/lib/cart-store.cjs.js +1 -0
  6. package/{cart-store.es.js → lib/cart-store.es.js} +13 -13
  7. package/lib/components/AccountNavigationMenu.cjs.js +1 -0
  8. package/lib/components/AccountNavigationMenu.es.js +44 -0
  9. package/lib/components/AddToCartButton.cjs.js +1 -0
  10. package/{AddToCartButton-ffE0DhHu.js → lib/components/AddToCartButton.es.js} +14 -13
  11. package/lib/components/Cart.cjs.js +1 -0
  12. package/lib/components/Cart.es.js +148 -0
  13. package/lib/components/CartDrawer.cjs.js +1 -0
  14. package/{components → lib/components}/CartDrawer.es.js +15 -14
  15. package/{components → lib/components}/CartIcon.cjs.js +1 -1
  16. package/{components → lib/components}/CartIcon.es.js +1 -0
  17. package/lib/components/Checkout.cjs.js +1 -0
  18. package/{components → lib/components}/Checkout.es.js +330 -363
  19. package/lib/components/CouponForm.cjs.js +1 -0
  20. package/lib/components/CouponForm.es.js +136 -0
  21. package/lib/components/CurrencySwitcher.cjs.js +1 -0
  22. package/{components → lib/components}/CurrencySwitcher.es.js +5 -4
  23. package/lib/components/CustomerProfileForm.cjs.js +1 -0
  24. package/lib/components/CustomerProfileForm.es.js +355 -0
  25. package/lib/components/FeaturedProduct.cjs.js +1 -0
  26. package/{components → lib/components}/FeaturedProduct.es.js +9 -8
  27. package/lib/components/InvoiceDocument.cjs.js +1 -0
  28. package/lib/components/InvoiceDocument.es.js +196 -0
  29. package/lib/components/InvoiceViewerShell.cjs.js +29 -0
  30. package/lib/components/InvoiceViewerShell.es.js +100 -0
  31. package/lib/components/ProductCard.cjs.js +1 -0
  32. package/lib/components/ProductCard.es.js +119 -0
  33. package/lib/components/ProductDetailsLayout.cjs.js +1 -0
  34. package/lib/components/ProductDetailsLayout.es.js +361 -0
  35. package/lib/components/ProductGallery.cjs.js +1 -0
  36. package/lib/components/ProductGallery.es.js +41 -0
  37. package/lib/components/ProductGrid.cjs.js +1 -0
  38. package/lib/components/ProductGrid.es.js +19 -0
  39. package/lib/components/ShippingEstimator.cjs.js +1 -0
  40. package/lib/components/ShippingEstimator.es.js +125 -0
  41. package/lib/components/SubscriptionSelector.cjs.js +1 -0
  42. package/lib/components/SubscriptionSelector.es.js +140 -0
  43. package/lib/countries.cjs.js +1 -0
  44. package/lib/countries.es.js +77 -0
  45. package/lib/coupon-server.cjs.js +1 -0
  46. package/{coupon-server-DUKVtyYs.js → lib/coupon-server.es.js} +68 -82
  47. package/lib/coupons.cjs.js +1 -0
  48. package/lib/coupons.es.js +17 -0
  49. package/lib/currency-store.cjs.js +1 -0
  50. package/lib/currency-store.es.js +27 -0
  51. package/lib/currency-sync.cjs.js +1 -0
  52. package/lib/currency-sync.es.js +180 -0
  53. package/lib/customer-addresses.cjs.js +1 -0
  54. package/lib/customer-addresses.es.js +116 -0
  55. package/lib/customer-orders.cjs.js +1 -0
  56. package/lib/customer-orders.es.js +45 -0
  57. package/lib/customer.cjs.js +1 -0
  58. package/{customer-C3xccjUg.js → lib/customer.es.js} +15 -14
  59. package/lib/export-helpers.cjs.js +1 -0
  60. package/lib/export-helpers.es.js +56 -0
  61. package/lib/factory.cjs.js +1 -0
  62. package/lib/factory.es.js +8 -0
  63. package/lib/freemius-coupons.cjs.js +1 -0
  64. package/lib/freemius-coupons.es.js +272 -0
  65. package/lib/freemius-order-sync.cjs.js +1 -0
  66. package/lib/freemius-order-sync.es.js +284 -0
  67. package/lib/inventory-settings.cjs.js +1 -0
  68. package/lib/inventory-settings.es.js +86 -0
  69. package/lib/invoice-server.cjs.js +33 -0
  70. package/lib/invoice-server.es.js +141 -0
  71. package/lib/invoice-ui.cjs.js +1 -0
  72. package/lib/invoice-ui.es.js +71 -0
  73. package/lib/invoice.cjs.js +1 -0
  74. package/lib/invoice.es.js +102 -0
  75. package/lib/order-inventory.cjs.js +61 -0
  76. package/lib/order-inventory.es.js +128 -0
  77. package/lib/order-tax-details.cjs.js +1 -0
  78. package/lib/order-tax-details.es.js +164 -0
  79. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -0
  80. package/lib/pages/cms/coupons/CouponEditorForm.es.js +189 -0
  81. package/lib/pages/cms/coupons/CouponsPage.cjs.js +5 -0
  82. package/lib/pages/cms/coupons/CouponsPage.es.js +171 -0
  83. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -0
  84. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -0
  85. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -0
  86. package/lib/pages/cms/coupons/EditCouponPage.es.js +48 -0
  87. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -0
  88. package/lib/pages/cms/coupons/ProductScopePicker.es.js +120 -0
  89. package/lib/pages/cms/coupons/actions.cjs.js +1 -0
  90. package/lib/pages/cms/coupons/actions.es.js +128 -0
  91. package/lib/pages/cms/coupons/product-options.cjs.js +1 -0
  92. package/lib/pages/cms/coupons/product-options.es.js +27 -0
  93. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -0
  94. package/lib/pages/cms/orders/ExportReportsDialog.es.js +130 -0
  95. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -0
  96. package/lib/pages/cms/orders/OrderDetailPage.es.js +137 -0
  97. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -0
  98. package/lib/pages/cms/orders/OrderPrintButton.es.js +22 -0
  99. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -0
  100. package/lib/pages/cms/orders/OrderStatusForm.es.js +71 -0
  101. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -0
  102. package/lib/pages/cms/orders/OrdersPage.es.js +104 -0
  103. package/lib/pages/cms/orders/actions.cjs.js +7 -0
  104. package/lib/pages/cms/orders/actions.es.js +71 -0
  105. package/lib/pages/cms/orders/export-actions.cjs.js +1 -0
  106. package/lib/pages/cms/orders/export-actions.es.js +27 -0
  107. package/lib/pages/cms/orders/server-actions.cjs.js +1 -0
  108. package/lib/pages/cms/orders/server-actions.es.js +55 -0
  109. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -0
  110. package/lib/pages/cms/payments/PaymentsClient.es.js +188 -0
  111. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -0
  112. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -0
  113. package/lib/pages/cms/payments/actions.cjs.js +1 -0
  114. package/lib/pages/cms/payments/actions.es.js +23 -0
  115. package/lib/pages/cms/payments/queries.cjs.js +1 -0
  116. package/lib/pages/cms/payments/queries.es.js +30 -0
  117. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -0
  118. package/lib/pages/cms/products/ProductsPage.es.js +46 -0
  119. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -0
  120. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +156 -0
  121. package/lib/pages/cms/products/actions.cjs.js +44 -0
  122. package/lib/pages/cms/products/actions.es.js +175 -0
  123. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -0
  124. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +48 -0
  125. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -0
  126. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +291 -0
  127. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -0
  128. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +36 -0
  129. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -0
  130. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +263 -0
  131. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -0
  132. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +114 -0
  133. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -0
  134. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +107 -0
  135. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -0
  136. package/lib/pages/cms/products/components/DeleteProductButton.es.js +48 -0
  137. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -0
  138. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +86 -0
  139. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -0
  140. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +160 -0
  141. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -0
  142. package/lib/pages/cms/products/components/ProductForm.es.js +702 -0
  143. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -0
  144. package/lib/pages/cms/products/components/ProductMediaManager.es.js +104 -0
  145. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -0
  146. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +228 -0
  147. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -0
  148. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +137 -0
  149. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -0
  150. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +36 -0
  151. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +1 -0
  152. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +40 -0
  153. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -0
  154. package/lib/pages/cms/products/components/VariationsEditor.es.js +408 -0
  155. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -0
  156. package/lib/pages/cms/products/inventory/InventoryPage.es.js +16 -0
  157. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -0
  158. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +214 -0
  159. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -0
  160. package/lib/pages/cms/products/inventory/actions.es.js +95 -0
  161. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -0
  162. package/lib/pages/cms/products/new/NewProductPage.es.js +76 -0
  163. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -0
  164. package/lib/pages/cms/products/product-price-sync.es.js +98 -0
  165. package/lib/pages/cms/products/server-actions.cjs.js +1 -0
  166. package/lib/pages/cms/products/server-actions.es.js +193 -0
  167. package/lib/pages/cms/shipping/ShippingPage.cjs.js +5 -0
  168. package/lib/pages/cms/shipping/ShippingPage.es.js +211 -0
  169. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -0
  170. package/lib/pages/cms/shipping/components/RateForm.es.js +441 -0
  171. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -0
  172. package/lib/pages/cms/shipping/components/ZoneForm.es.js +228 -0
  173. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -0
  174. package/lib/pages/cms/shipping/server-actions.es.js +159 -0
  175. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -0
  176. package/lib/pages/cms/taxes/TaxesPage.es.js +172 -0
  177. package/lib/pages/cms/taxes/actions.cjs.js +1 -0
  178. package/lib/pages/cms/taxes/actions.es.js +57 -0
  179. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -0
  180. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +100 -0
  181. package/lib/product-actions.cjs.js +237 -0
  182. package/lib/product-actions.es.js +524 -0
  183. package/lib/product-context.cjs.js +1 -0
  184. package/lib/product-context.es.js +16 -0
  185. package/lib/product-schema.cjs.js +1 -0
  186. package/lib/product-schema.es.js +134 -0
  187. package/lib/providers/freemius.cjs.js +5 -0
  188. package/lib/providers/freemius.es.js +538 -0
  189. package/lib/providers/stripe.cjs.js +1 -0
  190. package/lib/providers/stripe.es.js +473 -0
  191. package/lib/server-actions/coupon-actions.cjs.js +1 -0
  192. package/lib/server-actions/coupon-actions.es.js +23 -0
  193. package/lib/server-actions/customer-actions.cjs.js +1 -0
  194. package/lib/server-actions/customer-actions.es.js +30 -0
  195. package/lib/server-actions/product-actions.cjs.js +1 -0
  196. package/{server-actions → lib/server-actions}/product-actions.es.js +5 -4
  197. package/lib/server-actions/shipping-actions.cjs.js +1 -0
  198. package/{shipping-actions-BnHjlo2q.js → lib/server-actions/shipping-actions.es.js} +9 -7
  199. package/lib/server-actions/tax-actions.cjs.js +1 -0
  200. package/lib/server-actions/tax-actions.es.js +40 -0
  201. package/lib/shared-inventory.cjs.js +15 -0
  202. package/lib/shared-inventory.es.js +171 -0
  203. package/lib/shipping/resolver.cjs.js +7 -0
  204. package/lib/shipping/resolver.es.js +62 -0
  205. package/lib/shipping-rate-currency.cjs.js +1 -0
  206. package/lib/shipping-rate-currency.es.js +72 -0
  207. package/lib/states.cjs.js +1 -0
  208. package/{states-DlHJezQ1.js → lib/states.es.js} +27 -100
  209. package/lib/stripe/checkout.cjs.js +1 -0
  210. package/lib/stripe/checkout.es.js +182 -0
  211. package/lib/stripe/client.cjs.js +1 -0
  212. package/lib/stripe/client.es.js +7 -0
  213. package/lib/stripe/order-sync.cjs.js +1 -0
  214. package/lib/stripe/order-sync.es.js +130 -0
  215. package/lib/stripe/webhooks.cjs.js +1 -0
  216. package/lib/stripe/webhooks.es.js +30 -0
  217. package/lib/tax-calculation.cjs.js +1 -0
  218. package/lib/tax-calculation.es.js +101 -0
  219. package/lib/trials.cjs.js +1 -0
  220. package/{trials-RDcRAZKx.js → lib/trials.es.js} +9 -9
  221. package/{use-cart.es.js → lib/use-cart.es.js} +1 -0
  222. package/lib/zod-config.cjs.js +1 -0
  223. package/lib/zod-config.es.js +6 -0
  224. package/package.json +4 -4
  225. package/server.cjs.js +1 -110
  226. package/server.es.js +178 -6052
  227. package/AddToCartButton-DsSEH9yp.cjs +0 -1
  228. package/CouponForm-BI_5SBHQ.js +0 -152
  229. package/CouponForm-D_uu2bLP.cjs +0 -1
  230. package/CurrencyProvider-Cg-Q6ucj.cjs +0 -1
  231. package/CurrencyProvider-OzlRN96V.js +0 -120
  232. package/CurrencyProvider.cjs.js +0 -1
  233. package/CurrencyProvider.es.js +0 -10
  234. package/ProductDetailsLayout-BxJH_BxR.cjs +0 -1
  235. package/ProductDetailsLayout-Dg8dRTYp.js +0 -530
  236. package/ProductGrid-BdL7iglO.cjs +0 -1
  237. package/ProductGrid-D3AWM8sr.js +0 -130
  238. package/actions-AHmBrS5e.cjs +0 -48
  239. package/actions-j5fuSZX-.js +0 -820
  240. package/cart-store.cjs.js +0 -1
  241. package/components/Cart.cjs.js +0 -1
  242. package/components/Cart.es.js +0 -259
  243. package/components/CartDrawer.cjs.js +0 -1
  244. package/components/Checkout.cjs.js +0 -1
  245. package/components/CurrencySwitcher.cjs.js +0 -1
  246. package/components/FeaturedProduct.cjs.js +0 -1
  247. package/components/ProductDetailsLayout.cjs.js +0 -1
  248. package/components/ProductDetailsLayout.es.js +0 -19
  249. package/components/ProductGrid.cjs.js +0 -1
  250. package/components/ProductGrid.es.js +0 -6
  251. package/coupon-server-C9ySm3I5.cjs +0 -1
  252. package/customer-C-UPvrYN.cjs +0 -1
  253. package/invoice-ui-CAnJPu6n.cjs +0 -29
  254. package/invoice-ui-DtpbTJE1.js +0 -2886
  255. package/product-actions-CONBF8i6.cjs +0 -251
  256. package/product-actions-DjlIWCMH.js +0 -691
  257. package/resolver-Fz_FKsfX.cjs +0 -7
  258. package/resolver-cfrCaHpE.js +0 -128
  259. package/server-actions/product-actions.cjs.js +0 -1
  260. package/shipping-actions-D6zt20gg.cjs +0 -1
  261. package/states-CWYRxV4B.cjs +0 -1
  262. package/tax-calculation-Dab89aHd.js +0 -181
  263. package/tax-calculation-MkDKOEkL.cjs +0 -1
  264. package/trials-DvZaOtNy.cjs +0 -1
  265. /package/{components → lib/components}/SimpleTiptapRenderer.cjs.js +0 -0
  266. /package/{components → lib/components}/SimpleTiptapRenderer.es.js +0 -0
  267. /package/{currency-constants.cjs.js → lib/currency-constants.cjs.js} +0 -0
  268. /package/{currency-constants.es.js → lib/currency-constants.es.js} +0 -0
  269. /package/{currency-rest-client-uolJxUkL.cjs → lib/currency-rest-client.cjs.js} +0 -0
  270. /package/{currency-rest-client-CwoqdgAP.js → lib/currency-rest-client.es.js} +0 -0
  271. /package/{currency.cjs.js → lib/currency.cjs.js} +0 -0
  272. /package/{currency.es.js → lib/currency.es.js} +0 -0
  273. /package/{types.cjs.js → lib/types.cjs.js} +0 -0
  274. /package/{types.es.js → lib/types.es.js} +0 -0
  275. /package/{use-cart.cjs.js → lib/use-cart.cjs.js} +0 -0
  276. /package/{variation-utils.cjs.js → lib/variation-utils.cjs.js} +0 -0
  277. /package/{variation-utils.es.js → lib/variation-utils.es.js} +0 -0
@@ -1,48 +0,0 @@
1
- "use strict";const P=require("@nextblock-cms/db/server"),G=require("./product-actions-CONBF8i6.cjs"),J=require("@supabase/supabase-js"),oe=require("crypto"),ye=require("@freemius/sdk"),Q=require("./customer-C-UPvrYN.cjs"),te=require("./coupon-server-C9ySm3I5.cjs"),V=require("./currency.cjs.js"),j=require("next/cache");function D(e){const r=e?.trim();return r||null}function ne(e){return e?Q.normalizeCustomerAddress({company_name:e.company_name,recipient_name:e.recipient_name,line1:e.line1,line2:e.line2,city:e.city,state:e.state,postal_code:e.postal_code,country_code:e.country_code}):null}function se(e,r){return e?.find(t=>t.address_type===r&&t.is_default)??e?.find(t=>t.address_type===r)??null}async function ie(e,r,t,n){const s=Q.normalizeCustomerAddress(n),{data:o,error:l}=await e.from("user_addresses").select("*").eq("user_id",r).eq("address_type",t).order("is_default",{ascending:!1}).order("updated_at",{ascending:!1});if(l)throw new Error(l.message);const c=o?.[0]??null,u=(o??[]).slice(1).map(a=>a.id);if(!s){if(o?.length){const a=o.map(m=>m.id),{error:d}=await e.from("user_addresses").delete().in("id",a);if(d)throw new Error(d.message)}return}const y={user_id:r,address_type:t,is_default:!0,company_name:s.company_name??null,recipient_name:s.recipient_name??null,line1:s.line1??null,line2:s.line2??null,city:s.city??null,state:s.state??null,postal_code:s.postal_code??null,country_code:s.country_code??null,updated_at:new Date().toISOString()};if(c){const{error:a}=await e.from("user_addresses").update(y).eq("id",c.id);if(a)throw new Error(a.message)}else{const{error:a}=await e.from("user_addresses").insert(y);if(a)throw new Error(a.message)}if(u.length){const{error:a}=await e.from("user_addresses").delete().in("id",u);if(a)throw new Error(a.message)}}async function Ee(e,r){const t=r??P.createClient(),{data:n,error:s}=await t.from("user_addresses").select("*").eq("user_id",e).in("address_type",["billing","shipping"]).order("is_default",{ascending:!1}).order("updated_at",{ascending:!1});if(s)throw new Error(s.message);const o=ne(se(n??[],"billing")),l=ne(se(n??[],"shipping"));return{billingAddress:o,shippingAddress:l}}async function ae(e){const r=e.client??P.createClient();await ie(r,e.userId,"billing",e.billingAddress??null),await ie(r,e.userId,"shipping",e.shippingAddress??null)}async function ce(e){const r=e.client??P.createClient(),t=D(e.fullName),n=D(e.phone);if(!t&&!n)return;const{data:s,error:o}=await r.from("profiles").select("full_name, phone").eq("id",e.userId).maybeSingle();if(o)throw new Error(o.message);if(!s)return;const l=D(s.full_name)||t,c=D(s.phone)||n;if(D(s.full_name)===l&&D(s.phone)===c)return;const{error:u}=await r.from("profiles").update({full_name:l,phone:c,updated_at:new Date().toISOString()}).eq("id",e.userId);if(u)throw new Error(u.message)}function p(e){const r=process.env[e];if(!r)return null;const t=r.trim();return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1).trim():t}function he(e){const r=e?.trim();if(!r)return{firstName:null,lastName:null};const[t,...n]=r.split(/\s+/);return{firstName:t||null,lastName:n.length>0?n.join(" "):null}}function ue(e){if(e==null||e==="")return 0;const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.round(r)}function Se(e){return e===!0||e===1||e==="1"||e==="true"}function we(e,r){const t=e?.[r];return Array.isArray(t)?t:t&&typeof t=="object"?[t]:[]}function W(e,r){for(const t of r){const n=we(e,t);if(n.length>0)return n}return Array.isArray(e)?e:[]}function k(e){if(e==null||e==="")return null;const r=Number(e);return Number.isFinite(r)?r:null}function Pe(e){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)}function Fe(e){const r=Number(e);return!Number.isFinite(r)||r<1?1:Math.round(r)}function le(){const e=p("FREEMIUS_CHECKOUT_PRODUCTS_JSON");if(!e)return null;try{const r=JSON.parse(e);return r&&typeof r=="object"?r:null}catch(r){return console.error("[Freemius Checkout] Failed to parse FREEMIUS_CHECKOUT_PRODUCTS_JSON:",r),null}}function de(e){const r=le(),t=String(e),n=r?.[t],s=p("FREEMIUS_PRODUCT_ID"),o=p("FREEMIUS_ECOMMERCE_SANDBOX_PUBLIC_KEY"),l=p("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY");return n?.publicKey?{publicKey:n.publicKey,secretKey:n.secretKey??null,apiKey:n.apiKey??null,source:"product-map"}:process.env.FREEMIUS_SANDBOX_ENABLED==="true"&&s&&s===t&&o?{publicKey:o,secretKey:l,apiKey:p("FREEMIUS_API_KEY"),source:"single-product-sandbox-env"}:s&&s===t&&p("FREEMIUS_PUBLIC_KEY")?{publicKey:p("FREEMIUS_PUBLIC_KEY"),secretKey:p("FREEMIUS_SECRET_KEY"),apiKey:p("FREEMIUS_API_KEY"),source:"single-product-env"}:{publicKey:p("FREEMIUS_PUBLIC_KEY"),secretKey:p("FREEMIUS_SECRET_KEY"),apiKey:p("FREEMIUS_API_KEY"),source:"legacy-env"}}async function Ce(e){if(!e.apiKey)throw new Error("Missing Freemius API key for SDK sandbox generation.");return new ye.Freemius({productId:Number(e.productId),apiKey:e.apiKey,secretKey:e.secretKey,publicKey:e.publicKey}).checkout.getSandboxParams()}class be{getProviderName(){return"Freemius"}async createCheckoutSession({items:r,customerEmail:t,customerPhone:n,userId:s,billingAddress:o,shippingAddress:l,currencyCode:c,couponCode:u,couponContextItems:y}){const a=process.env.NEXT_PUBLIC_SUPABASE_URL,d=process.env.SUPABASE_SERVICE_ROLE_KEY;if(!a||!d)return{error:"Missing Supabase credentials for checkout (Service Key required).",url:null};const m=J.createClient(a,d);if(!r||r.length===0)return{error:"Cart is empty",url:null};if(r.length!==1)return{error:"Freemius items must be checked out one at a time.",url:null};const{data:E,error:v}=await m.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}),I=E??[];if(v||I.length===0)return{error:"Failed to resolve store currencies",url:null};const H=V.getDefaultCurrency(I),K=I.find(f=>f.code===(c||"").toUpperCase())??H,h=r[0],{data:_,error:$}=await m.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",h.product_id).single();if($||!_)return{error:"Product not found",url:null};const U=_.freemius_plan_id,F=_.freemius_product_id;if(!U||!F)return{error:"Product is not configured for Freemius checkout (missing Plan ID or Product ID)",url:null};const N=V.resolveEffectivePriceForCurrency({prices:_.prices||{},salePrices:_.sale_prices||{},fallbackPrice:_.price,fallbackSalePrice:_.sale_price,saleStartAt:_.sale_start_at,saleEndAt:_.sale_end_at,scheduledPrice:_.scheduled_price,scheduledPrices:_.scheduled_prices||{},scheduledPriceAt:_.scheduled_price_at,currencyCode:K.code,currencies:I}),O=N.sale_price??N.price,x=V.isSaleWindowActive({saleStartAt:_.sale_start_at,saleEndAt:_.sale_end_at}),S=O*h.quantity;let i=null,g=0;if(u){const f=await te.getCouponQuote({client:m,code:u,items:y&&y.length>0?y:r,currencyCode:K.code});if(!f.success)return{error:f.error,errorKey:f.errorKey,errorStatus:400,url:null};i=f.quote,g=Math.min(S,i.lineDiscounts.filter(A=>A.product_id===_.id).reduce((A,X)=>A+X.discount,0))}const C=ue(_.trial_period_days),R=C>0?h.trial_preference?h.trial_preference:_.trial_requires_payment_method?"paid":"free":null,B="pending",w=he(o?.recipient_name??null),{data:z,error:Z}=await m.from("orders").insert({status:B,total:Math.max(0,S-g),currency:K.code,exchange_rate_at_purchase:K.exchange_rate,subtotal:S,discount_total:g,coupon_id:i?.couponId??null,coupon_code:i?.code??null,discount_details:i?{code:i.code,discount_type:i.discountType,discount_amount:i.discountAmount,provider:"freemius",provider_discounts:i.providerDiscounts,line_discounts:i.lineDiscounts,final_amount_owned_by:"freemius"}:null,provider:"freemius",freemius_product_id:String(F),freemius_plan_id:String(U),user_id:s||null,customer_details:Q.normalizeOrderCustomerDetails({email:t,phone:n,name:o?.recipient_name,billing:o,shipping:l})}).select("id").single();if(Z||!z)return console.error("Failed to create pending order:",Z),{error:"Failed to initiate order",url:null};const{error:ee}=await m.from("order_items").insert([{order_id:z.id,product_id:_.id,quantity:h.quantity,price_at_purchase:O}]);if(ee&&console.error("Failed to insert order items:",ee),s)try{await ae({userId:s,billingAddress:o,shippingAddress:l,client:m}),await ce({userId:s,fullName:o?.recipient_name??l?.recipient_name??null,phone:n,client:m})}catch(f){console.error("Failed to sync checkout profile defaults before checkout:",f)}i&&await te.recordCouponRedemption({client:m,quote:i,orderId:z.id,provider:"freemius",discountTotal:g,userId:s,customerEmail:t,metadata:{currency:K.code,subtotal:S,final_amount_owned_by:"freemius"}});const T=process.env.FREEMIUS_SANDBOX_ENABLED==="true",M=de(F),q=M.publicKey,L=M.secretKey,re=M.apiKey;if(!q||T&&!L)return{error:"Missing FREEMIUS credentials (PUBLIC_KEY or SECRET_KEY) in environment variables.",url:null};if(T&&M.source==="legacy-env"){const f=p("FREEMIUS_PRODUCT_ID"),A=!!p("FREEMIUS_ECOMMERCE_SANDBOX_PUBLIC_KEY"),X=!!p("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY");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.`,{configuredProductId:f,productIdsMatch:f===String(F),hasSandboxOverridePublicKey:A,hasSandboxOverrideSecretKey:X,hasCheckoutProductsJson:!!p("FREEMIUS_CHECKOUT_PRODUCTS_JSON")})}let Y=!1;if(T&&L&&q)try{Y=await Ce({productId:F,publicKey:q,secretKey:L,apiKey:re})}catch(f){console.warn("Freemius Checkout - SDK sandbox generation failed. Falling back to manual token generation.",f,{credentialSource:M.source,hasApiKey:!!re});const A=Math.floor(Date.now()/1e3).toString(),X=`${A}${F}${L}${q}checkout`,ge=oe.createHash("md5").update(X).digest("hex");Y={ctx:A,token:ge}}const b=new URL(`https://checkout.freemius.com/app/${F}/plan/${U}/`);if(T&&L&&q?(b.searchParams.append("sandbox",Y.token),b.searchParams.append("s_ctx_ts",Y.ctx)):T&&b.searchParams.append("sandbox","true"),t&&b.searchParams.append("user_email",t),w.firstName&&b.searchParams.append("user_firstname",w.firstName),w.lastName&&b.searchParams.append("user_lastname",w.lastName),b.searchParams.append("currency",K.code.toLowerCase()),h.billing_cycle&&b.searchParams.append("billing_cycle",h.billing_cycle),R&&b.searchParams.append("trial",R),i)b.searchParams.append("coupon",i.code);else if(x){const{data:f}=await m.from("product_freemius_sale_coupons").select("freemius_coupon_code, is_active, starts_at, ends_at, sync_status").eq("product_id",_.id).maybeSingle();f?.is_active&&f.sync_status==="synced"&&f.freemius_coupon_code&&V.isSaleWindowActive({saleStartAt:f.starts_at,saleEndAt:f.ends_at})&&b.searchParams.append("coupon",f.freemius_coupon_code)}return{url:b.toString(),customProps:{provider:"freemius",plugin_id:F,plan_id:U,public_key:q,user_email:t,user_firstname:w.firstName,user_lastname:w.lastName,credential_source:M.source,sandbox:Y,billing_cycle:h.billing_cycle,trial:R,trial_period_days:C,trial_requires_payment_method:_.trial_requires_payment_method,initial_order_status:B,coupon:i?.code??null,order_id:z.id}}}}async function pe(e,r,t,n){const o=new Date().toUTCString().replace("GMT","+0000"),l=`GET
2
-
3
-
4
- ${o}
5
- ${e}`,c=oe.createHmac("sha256",n).update(l).digest("hex"),u=Buffer.from(c).toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,""),y=`FS ${r}:${t}:${u}`,a=await fetch(`https://api.freemius.com${e}`,{headers:{Authorization:y,Date:o,Accept:"application/json"}});if(!a.ok){const d=await a.text();throw console.error(`[Freemius API] [ERROR] ${e} returned ${a.status}: ${d}`),new Error(`Freemius API failed on ${e}: ${a.status} - ${d}`)}return a.json()}async function _e(){const e=p("FREEMIUS_DEVELOPER_ID"),r=p("FREEMIUS_PUBLIC_KEY"),t=p("FREEMIUS_SECRET_KEY"),n=process.env.NEXT_PUBLIC_SUPABASE_URL,s=process.env.SUPABASE_SERVICE_ROLE_KEY;if(!e||!r||!t||!n||!s)throw new Error("Missing necessary environment variables for Freemius Sync.");const o=J.createClient(n,s,{auth:{autoRefreshToken:!1,persistSession:!1}}),l=c=>pe(c,e,r,t);try{console.log(`[Freemius Sync] Fetching all plugins for developer ${e}...`);const c=await l(`/v1/developers/${e}/plugins.json`),u=W(c,["plugins","plugin"]);console.log(`[Freemius Sync] Found ${u.length} plugins. Syncing plans...`);let y=0;const{data:a}=await o.from("languages").select("id").eq("code","en").single(),d=a?.id;if(!d)throw new Error("English language not found in database. Cannot sync products.");for(const m of u){const E=m.id?.toString();if(!E){console.warn("[Freemius Sync] Skipping plugin without an id:",m);continue}const v=await fe(o,e,E,m.title||m.name||`Freemius Product ${E}`,l,d);y+=v}return{success:!0,count:y}}catch(c){throw console.error("[Freemius Sync] Global Error:",c),c}}async function me(e){const r=p("FREEMIUS_DEVELOPER_ID"),t=p("FREEMIUS_PUBLIC_KEY"),n=p("FREEMIUS_SECRET_KEY"),s=process.env.NEXT_PUBLIC_SUPABASE_URL,o=process.env.SUPABASE_SERVICE_ROLE_KEY;if(!r||!t||!n||!s||!o)throw new Error("Missing environment variables for Freemius Sync.");const l=J.createClient(s,o),c=E=>pe(E,r,t,n),{data:u}=await l.from("languages").select("id").eq("code","en").single(),y=u?.id;if(!y)throw new Error("English language not found in database. Cannot sync products.");const a=await c(`/v1/developers/${r}/plugins/${e}.json`),d=a.plugin??a;return{success:!0,count:await fe(l,r,e,d.title||d.name||`Freemius Product ${e}`,c,y)}}async function fe(e,r,t,n,s,o){console.log(`[Freemius Sync] Fetching plans for plugin: ${n} (${t})...`);let l=0;try{const c=`/v1/developers/${r}/plugins/${t}/plans.json`,u=await s(c),y=W(u,["plans","plan"]);console.log(`[Freemius Sync] Received ${y.length} plans for plugin ${t}.`);for(const a of y){const d=a.id?.toString();if(!d){console.warn("[Freemius Sync] Skipping plan without an id:",a);continue}const m=a.name||a.title||d,E=a.title||m;console.log(`[Freemius Sync] Processing plan: ${E} (${d})...`);let v=a;if(v.trial_period===void 0||v.is_require_subscription===void 0)try{const i=`/v1/developers/${r}/plugins/${t}/plans/${d}.json`,g=await s(i),C=g.plan??g;v={...v,...C}}catch(i){console.warn(`[Freemius Sync] Could not fetch trial details for plan ${d}:`,i instanceof Error?i.message:i)}const I=ue(v.trial_period),H=I>0&&Se(v.is_require_subscription);let K=0,h=[];try{const i=`/v1/developers/${r}/plugins/${t}/plans/${d}/pricing.json`,g=await s(i);if(h=W(g,["pricing","prices","pricings"]),h.length>0){const C=h[0],R=k(C.annual_price)??k(C.monthly_price)??k(C.lifetime_price);K=Pe(R)}console.log(`[Freemius Sync] Plan: ${E} -> Resolved Price (cents): ${K}`)}catch(i){console.warn(`[Freemius Sync] Could not fetch pricing for plan ${d}:`,i instanceof Error?i.message:i)}const _=`${n}-${E}`.toLowerCase().replace(/[^\w\s-]/g,"").replace(/[\s_]+/g,"-").replace(/^-+|-+$/g,""),$={title:`${n} - ${E}`,slug:_,short_description:a.description||"",price:K,product_type:"digital",payment_provider:"freemius",freemius_plan_id:d,freemius_product_id:t,trial_period_days:I,trial_requires_payment_method:H,status:"active",stock:999,sku:`FM-${t}-${d}`,language_id:o},{data:U,error:F}=await e.from("products").upsert($,{onConflict:"language_id, sku"}).select();if(F||!U||U.length===0){console.error(`[Freemius Sync] Error upserting product ${$.sku}:`,F);continue}const N=U[0].id,{data:O,error:x}=await e.from("freemius_plans").select("id").eq("product_id",N).eq("name",m).maybeSingle();x&&console.warn(`[Freemius Sync] Could not check existing local plan for ${$.sku}:`,x.message||x);let S="";if(O){S=O.id;const{error:i}=await e.from("freemius_plans").update({title:E,updated_at:new Date().toISOString()}).eq("id",S);i&&console.warn(`[Freemius Sync] Could not update local plan ${S}:`,i.message||i)}else{const{data:i,error:g}=await e.from("freemius_plans").insert({product_id:N,name:m,title:E}).select("id").single();g&&console.warn(`[Freemius Sync] Could not insert local plan for ${$.sku}:`,g.message||g),i&&(S=i.id)}if(S&&h.length>0)for(const i of h){const g=Fe(i.licenses??i.license_quota??i.quota),{data:C,error:R}=await e.from("freemius_pricing").select("id").eq("plan_id",S).eq("license_quota",g).maybeSingle();R&&console.warn(`[Freemius Sync] Could not check pricing for plan ${S}, quota ${g}:`,R.message||R);const B={api_monthly_price:k(i.monthly_price),api_annual_price:k(i.annual_price),api_lifetime_price:k(i.lifetime_price),updated_at:new Date().toISOString()};if(C){const{error:w}=await e.from("freemius_pricing").update(B).eq("id",C.id);w&&console.warn(`[Freemius Sync] Could not update pricing ${C.id}:`,w.message||w)}else{const{error:w}=await e.from("freemius_pricing").insert({plan_id:S,license_quota:g,...B});w&&console.warn(`[Freemius Sync] Could not insert pricing for plan ${S}, quota ${g}:`,w.message||w)}}console.log(`[Freemius Sync] Successfully fully synced product ${$.sku}.`),l++}}catch(c){console.error(`[Freemius Sync] Failed sync for plugin ${t}:`,c.message)}return l}async function ve(e){const r=P.createClient(),{data:t,count:n,error:s}=await await G.getProducts(r,e);if(s)throw new Error(s.message);return{data:t,count:n}}async function Ke(e){const r=P.createClient(),{data:t,error:n}=await G.getProduct(r,e);if(n)throw new Error(n.message);return t}async function Re(){try{const e=await _e();return j.revalidatePath("/cms/products","page"),{success:!0,data:e}}catch(e){return{error:e.message||"Failed to sync with Freemius"}}}async function Ue(e){try{const r=await me(e);return j.revalidatePath("/cms/products","page"),{success:!0,data:r}}catch(r){return{error:r.message||"Failed to sync product with Freemius"}}}async function Ae(e,r){try{const t=P.createClient();return await G.copyProductFromLanguage(t,e,r),j.revalidatePath("/cms/products"),j.revalidatePath(`/cms/products/${e}/edit`),{success:!0}}catch(t){return{success:!1,error:t.message||"Failed to copy product content"}}}async function Ie(e){const r=P.createClient(),{data:t,error:n}=await r.from("products").select("id, title, language_id, slug").eq("translation_group_id",e);if(n)throw new Error(n.message);return t}async function $e(){const e=P.getServiceRoleSupabaseClient(),{data:r,error:t}=await e.from("product_attributes").select(`
6
- id,
7
- name,
8
- name_translations,
9
- slug,
10
- product_attribute_terms (
11
- id,
12
- attribute_id,
13
- value,
14
- slug,
15
- sort_order,
16
- value_translations
17
- )
18
- `);if(t)throw new Error(t.message);return(r||[]).map(n=>({...n,product_attribute_terms:(n.product_attribute_terms||[]).sort((s,o)=>(s.sort_order??Number.MAX_SAFE_INTEGER)-(o.sort_order??Number.MAX_SAFE_INTEGER)||s.value.localeCompare(o.value))})).sort((n,s)=>n.name.localeCompare(s.name))}async function Me(e){const r=P.createClient(),{data:t,error:n}=await r.from("freemius_plans").select(`
19
- id,
20
- name,
21
- title,
22
- freemius_pricing (
23
- id,
24
- license_quota,
25
- api_monthly_price,
26
- api_annual_price,
27
- api_lifetime_price,
28
- override_monthly_price,
29
- override_annual_price,
30
- override_lifetime_price,
31
- is_active
32
- )
33
- `).eq("product_id",e);if(n)throw new Error(n.message);return t}async function qe(e,r){const t=P.createClient(),{error:n}=await t.from("freemius_pricing").update({...r,updated_at:new Date().toISOString()}).eq("id",e);return n?{success:!1,error:n.message}:(j.revalidatePath("/cms/products"),{success:!0})}async function De(e){const r=P.createClient(),{data:t}=await r.from("products").select("translation_group_id").eq("id",e).maybeSingle();let n=[e];if(t?.translation_group_id){const{data:c}=await r.from("products").select("id").eq("translation_group_id",t.translation_group_id);c&&c.length>0&&(n=c.map(u=>u.id))}const{data:s,error:o}=await r.from("freemius_plans").select(`
34
- id,
35
- name,
36
- title,
37
- freemius_pricing (
38
- id,
39
- license_quota,
40
- api_monthly_price,
41
- api_annual_price,
42
- api_lifetime_price,
43
- override_monthly_price,
44
- override_annual_price,
45
- override_lifetime_price,
46
- is_active
47
- )
48
- `).in("product_id",n);if(o)throw new Error(o.message);return(s||[]).map(c=>({id:c.id,name:c.name,title:c.title,pricing:(c.freemius_pricing||[]).filter(u=>u.is_active!==!1).map(u=>({id:u.id,license_quota:u.license_quota,monthly_price:u.override_monthly_price??u.api_monthly_price,annual_price:u.override_annual_price??u.api_annual_price,lifetime_price:u.override_lifetime_price??u.api_lifetime_price,is_active:u.is_active}))}))}async function ke(){const e=P.createClient(),{data:r,error:t}=await e.from("categories").select("id, name, slug, description, created_at, name_translations, description_translations, product_categories(count)").order("name",{ascending:!0});if(t)throw new Error(t.message);return(r||[]).map(n=>{const s=n.product_categories?.[0]?.count??n.product_categories?.count??0;return{id:n.id,name:n.name,slug:n.slug,description:n.description??"",created_at:n.created_at,productCount:Number(s),name_translations:n.name_translations||{},description_translations:n.description_translations||{}}})}async function Ne(e){const r=P.createClient(),{data:t,error:n}=await r.from("categories").select("id, name, slug, description, created_at").eq("slug",e).maybeSingle();if(n)throw new Error(n.message);return t}async function Oe(e){const r=P.createClient(),{data:t,error:n}=await r.from("product_categories").select("category:categories(id, name, slug, description, name_translations, description_translations, created_at)").eq("product_id",e);if(n)throw new Error(n.message);return(t||[]).map(s=>s.category).filter(Boolean)}exports.FreemiusProvider=be;exports.copyProductFromLanguageAction=Ae;exports.fillMissingUserProfileCheckoutDetails=ce;exports.getCategoriesWithCount=ke;exports.getCategoryBySlug=Ne;exports.getDefaultUserAddresses=Ee;exports.getFreemiusPricingByProductId=Me;exports.getGlobalProductAttributes=$e;exports.getProduct=Ke;exports.getProductCategories=Oe;exports.getProductTranslations=Ie;exports.getProducts=ve;exports.getPublicFreemiusPricing=De;exports.parseFreemiusCheckoutCredentialsMap=le;exports.readFreemiusEnvValue=p;exports.resolveFreemiusCheckoutCredentials=de;exports.syncFreemiusProductsToSupabase=_e;exports.syncSingleFreemiusProduct=me;exports.triggerFreemiusSync=Re;exports.triggerSingleProductSync=Ue;exports.updateFreemiusOverride=qe;exports.upsertDefaultUserAddresses=ae;