@nextblock-cms/ecom 0.20.3 → 0.21.1

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 (446) hide show
  1. package/README.md +43 -0
  2. package/_virtual/_rolldown/runtime.cjs +1 -0
  3. package/index.cjs +1 -0
  4. package/index.es.js +38 -146
  5. package/lib/CurrencyProvider.cjs +1 -0
  6. package/lib/CurrencyProvider.d.ts +1 -1
  7. package/lib/CurrencyProvider.es.js +85 -95
  8. package/lib/PaymentReadinessProvider.cjs +1 -0
  9. package/lib/PaymentReadinessProvider.d.ts +1 -1
  10. package/lib/PaymentReadinessProvider.es.js +24 -27
  11. package/lib/cart-store.cjs +1 -0
  12. package/lib/cart-store.es.js +109 -121
  13. package/lib/components/AccountNavigationMenu.cjs +1 -0
  14. package/lib/components/AccountNavigationMenu.d.ts +1 -1
  15. package/lib/components/AccountNavigationMenu.es.js +36 -50
  16. package/lib/components/AddToCartButton.cjs +1 -0
  17. package/lib/components/AddToCartButton.d.ts +1 -1
  18. package/lib/components/AddToCartButton.es.js +94 -89
  19. package/lib/components/Cart.cjs +1 -0
  20. package/lib/components/Cart.d.ts +1 -1
  21. package/lib/components/Cart.es.js +261 -180
  22. package/lib/components/CartDrawer.cjs +1 -0
  23. package/lib/components/CartDrawer.d.ts +1 -1
  24. package/lib/components/CartDrawer.es.js +218 -148
  25. package/lib/components/CartIcon.cjs +1 -0
  26. package/lib/components/CartIcon.d.ts +1 -1
  27. package/lib/components/CartIcon.es.js +33 -35
  28. package/lib/components/Checkout.cjs +1 -0
  29. package/lib/components/Checkout.d.ts +1 -1
  30. package/lib/components/Checkout.es.js +1092 -1108
  31. package/lib/components/CouponForm.cjs +1 -0
  32. package/lib/components/CouponForm.d.ts +1 -1
  33. package/lib/components/CouponForm.es.js +136 -148
  34. package/lib/components/CurrencySwitcher.cjs +1 -0
  35. package/lib/components/CurrencySwitcher.d.ts +1 -1
  36. package/lib/components/CurrencySwitcher.es.js +22 -18
  37. package/lib/components/CustomerProfileForm.cjs +1 -0
  38. package/lib/components/CustomerProfileForm.es.js +454 -313
  39. package/lib/components/FeaturedProduct.cjs +1 -0
  40. package/lib/components/FeaturedProduct.d.ts +1 -1
  41. package/lib/components/FeaturedProduct.es.js +98 -83
  42. package/lib/components/FreemiusLicensePanel.cjs +1 -0
  43. package/lib/components/FreemiusLicensePanel.d.ts +1 -1
  44. package/lib/components/FreemiusLicensePanel.es.js +70 -65
  45. package/lib/components/InvoiceDocument.cjs +1 -0
  46. package/lib/components/InvoiceDocument.es.js +256 -192
  47. package/lib/components/InvoiceViewerShell.cjs +29 -0
  48. package/lib/components/InvoiceViewerShell.d.ts +1 -1
  49. package/lib/components/InvoiceViewerShell.es.js +75 -106
  50. package/lib/components/ProductCard.cjs +1 -0
  51. package/lib/components/ProductCard.d.ts +1 -1
  52. package/lib/components/ProductCard.es.js +186 -171
  53. package/lib/components/ProductDetailsLayout.cjs +1 -0
  54. package/lib/components/ProductDetailsLayout.es.js +405 -404
  55. package/lib/components/ProductGallery.cjs +1 -0
  56. package/lib/components/ProductGallery.d.ts +1 -1
  57. package/lib/components/ProductGallery.es.js +51 -54
  58. package/lib/components/ProductGrid.cjs +1 -0
  59. package/lib/components/ProductGrid.d.ts +1 -1
  60. package/lib/components/ProductGrid.es.js +23 -25
  61. package/lib/components/ShippingEstimator.cjs +1 -0
  62. package/lib/components/ShippingEstimator.d.ts +1 -1
  63. package/lib/components/ShippingEstimator.es.js +158 -153
  64. package/lib/components/ShortDescription.cjs +1 -0
  65. package/lib/components/ShortDescription.es.js +17 -17
  66. package/lib/components/SimpleTiptapRenderer.cjs +1 -0
  67. package/lib/components/SimpleTiptapRenderer.es.js +238 -211
  68. package/lib/components/SubscriptionSelector.cjs +1 -0
  69. package/lib/components/SubscriptionSelector.es.js +159 -154
  70. package/lib/countries.cjs +1 -0
  71. package/lib/countries.es.js +232 -75
  72. package/lib/coupon-server.cjs +1 -0
  73. package/lib/coupon-server.es.js +180 -224
  74. package/lib/coupons.cjs +1 -0
  75. package/lib/coupons.es.js +12 -14
  76. package/lib/currency-constants.cjs +1 -0
  77. package/lib/currency-constants.es.js +4 -4
  78. package/lib/currency-rest-client.cjs +1 -0
  79. package/lib/currency-rest-client.es.js +15 -22
  80. package/lib/currency-store.cjs +1 -0
  81. package/lib/currency-store.es.js +20 -27
  82. package/lib/currency-sync.cjs +1 -0
  83. package/lib/currency-sync.es.js +124 -170
  84. package/lib/currency.cjs +1 -0
  85. package/lib/currency.es.js +242 -310
  86. package/lib/customer-addresses.cjs +1 -0
  87. package/lib/customer-addresses.es.js +80 -109
  88. package/lib/customer-orders.cjs +1 -0
  89. package/lib/customer-orders.es.js +31 -43
  90. package/lib/customer.cjs +1 -0
  91. package/lib/customer.es.js +43 -52
  92. package/lib/export-helpers.cjs +1 -0
  93. package/lib/export-helpers.es.js +53 -52
  94. package/lib/factory.cjs +1 -0
  95. package/lib/factory.es.js +10 -7
  96. package/lib/freemius-coupons.cjs +1 -0
  97. package/lib/freemius-coupons.es.js +245 -262
  98. package/lib/freemius-license-claim.cjs +1 -0
  99. package/lib/freemius-license-claim.es.js +87 -71
  100. package/lib/freemius-license.cjs +1 -0
  101. package/lib/freemius-license.es.js +32 -39
  102. package/lib/freemius-order-sync.cjs +1 -0
  103. package/lib/freemius-order-sync.es.js +226 -290
  104. package/lib/freemius-trial-provision.cjs +1 -0
  105. package/lib/freemius-trial-provision.es.js +136 -130
  106. package/lib/inventory-settings.cjs +1 -0
  107. package/lib/inventory-settings.es.js +69 -77
  108. package/lib/invoice-server.cjs +33 -0
  109. package/lib/invoice-server.es.js +94 -141
  110. package/lib/invoice-ui.cjs +1 -0
  111. package/lib/invoice-ui.es.js +50 -66
  112. package/lib/invoice.cjs +1 -0
  113. package/lib/invoice.es.js +85 -94
  114. package/lib/order-inventory.cjs +61 -0
  115. package/lib/order-inventory.es.js +67 -79
  116. package/lib/order-tax-details.cjs +1 -0
  117. package/lib/order-tax-details.es.js +142 -153
  118. package/lib/pages/cms/coupons/CouponEditorForm.cjs +1 -0
  119. package/lib/pages/cms/coupons/CouponEditorForm.d.ts +1 -1
  120. package/lib/pages/cms/coupons/CouponEditorForm.es.js +227 -185
  121. package/lib/pages/cms/coupons/CouponsPage.cjs +5 -0
  122. package/lib/pages/cms/coupons/CouponsPage.d.ts +1 -1
  123. package/lib/pages/cms/coupons/CouponsPage.es.js +235 -166
  124. package/lib/pages/cms/coupons/CreateCouponDialog.cjs +1 -0
  125. package/lib/pages/cms/coupons/CreateCouponDialog.d.ts +1 -1
  126. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -34
  127. package/lib/pages/cms/coupons/EditCouponPage.cjs +1 -0
  128. package/lib/pages/cms/coupons/EditCouponPage.d.ts +1 -1
  129. package/lib/pages/cms/coupons/EditCouponPage.es.js +47 -47
  130. package/lib/pages/cms/coupons/ProductScopePicker.cjs +1 -0
  131. package/lib/pages/cms/coupons/ProductScopePicker.d.ts +1 -1
  132. package/lib/pages/cms/coupons/ProductScopePicker.es.js +128 -117
  133. package/lib/pages/cms/coupons/actions.cjs +1 -0
  134. package/lib/pages/cms/coupons/actions.es.js +112 -115
  135. package/lib/pages/cms/coupons/index.cjs +1 -0
  136. package/lib/pages/cms/coupons/index.es.js +3 -0
  137. package/lib/pages/cms/coupons/product-options.cjs +1 -0
  138. package/lib/pages/cms/coupons/product-options.es.js +21 -23
  139. package/lib/pages/cms/orders/ExportReportsDialog.cjs +1 -0
  140. package/lib/pages/cms/orders/ExportReportsDialog.es.js +135 -129
  141. package/lib/pages/cms/orders/MarkPaidButton.d.ts +1 -1
  142. package/lib/pages/cms/orders/OrderDetailPage.cjs +1 -0
  143. package/lib/pages/cms/orders/OrderDetailPage.d.ts +1 -1
  144. package/lib/pages/cms/orders/OrderDetailPage.es.js +186 -134
  145. package/lib/pages/cms/orders/OrderPrintButton.cjs +1 -0
  146. package/lib/pages/cms/orders/OrderPrintButton.d.ts +1 -1
  147. package/lib/pages/cms/orders/OrderPrintButton.es.js +15 -21
  148. package/lib/pages/cms/orders/OrderStatusForm.cjs +1 -0
  149. package/lib/pages/cms/orders/OrderStatusForm.d.ts +1 -1
  150. package/lib/pages/cms/orders/OrderStatusForm.es.js +85 -69
  151. package/lib/pages/cms/orders/OrdersPage.cjs +1 -0
  152. package/lib/pages/cms/orders/OrdersPage.d.ts +1 -1
  153. package/lib/pages/cms/orders/OrdersPage.es.js +170 -102
  154. package/lib/pages/cms/orders/actions.cjs +7 -0
  155. package/lib/pages/cms/orders/actions.es.js +53 -69
  156. package/lib/pages/cms/orders/export-actions.cjs +1 -0
  157. package/lib/pages/cms/orders/export-actions.es.js +23 -26
  158. package/lib/pages/cms/orders/index.cjs +1 -0
  159. package/lib/pages/cms/orders/index.es.js +6 -0
  160. package/lib/pages/cms/orders/server-actions.cjs +1 -0
  161. package/lib/pages/cms/orders/server-actions.es.js +60 -51
  162. package/lib/pages/cms/payments/PaymentsClient.cjs +1 -0
  163. package/lib/pages/cms/payments/PaymentsClient.d.ts +1 -1
  164. package/lib/pages/cms/payments/PaymentsClient.es.js +316 -346
  165. package/lib/pages/cms/payments/PaymentsPage.cjs +1 -0
  166. package/lib/pages/cms/payments/PaymentsPage.d.ts +1 -1
  167. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -32
  168. package/lib/pages/cms/payments/actions.cjs +1 -0
  169. package/lib/pages/cms/payments/actions.es.js +38 -48
  170. package/lib/pages/cms/payments/index.cjs +1 -0
  171. package/lib/pages/cms/payments/index.es.js +3 -0
  172. package/lib/pages/cms/payments/queries.cjs +1 -0
  173. package/lib/pages/cms/payments/queries.es.js +38 -48
  174. package/lib/pages/cms/products/ProductsPage.cjs +1 -0
  175. package/lib/pages/cms/products/ProductsPage.d.ts +1 -1
  176. package/lib/pages/cms/products/ProductsPage.es.js +63 -66
  177. package/lib/pages/cms/products/[id]/edit/EditProductPage.cjs +1 -0
  178. package/lib/pages/cms/products/[id]/edit/EditProductPage.d.ts +1 -1
  179. package/lib/pages/cms/products/[id]/edit/EditProductPage.es.js +139 -0
  180. package/lib/pages/cms/products/actions.cjs +44 -0
  181. package/lib/pages/cms/products/actions.es.js +121 -162
  182. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs +1 -0
  183. package/lib/pages/cms/products/attributes/AttributeManagementPage.d.ts +1 -1
  184. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +55 -47
  185. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs +1 -0
  186. package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +1 -1
  187. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +285 -290
  188. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs +1 -0
  189. package/lib/pages/cms/products/categories/CategoryManagementPage.d.ts +1 -1
  190. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +43 -35
  191. package/lib/pages/cms/products/categories/components/CategoryManager.cjs +1 -0
  192. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +315 -262
  193. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs +1 -0
  194. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +115 -113
  195. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs +1 -0
  196. package/lib/pages/cms/products/components/CurrencyPriceFields.d.ts +1 -1
  197. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +136 -145
  198. package/lib/pages/cms/products/components/DeleteProductButton.cjs +1 -0
  199. package/lib/pages/cms/products/components/DeleteProductButton.d.ts +1 -1
  200. package/lib/pages/cms/products/components/DeleteProductButton.es.js +35 -47
  201. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs +1 -0
  202. package/lib/pages/cms/products/components/FreemiusPricingDashboard.d.ts +1 -1
  203. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +106 -84
  204. package/lib/pages/cms/products/components/ProductCategorySelector.cjs +1 -0
  205. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +156 -159
  206. package/lib/pages/cms/products/components/ProductForm.cjs +1 -0
  207. package/lib/pages/cms/products/components/ProductForm.es.js +872 -693
  208. package/lib/pages/cms/products/components/ProductMediaManager.cjs +1 -0
  209. package/lib/pages/cms/products/components/ProductMediaManager.es.js +106 -103
  210. package/lib/pages/cms/products/components/ProductsBulkTable.cjs +1 -0
  211. package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +1 -1
  212. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +303 -294
  213. package/lib/pages/cms/products/components/SaleScheduleFields.cjs +1 -0
  214. package/lib/pages/cms/products/components/SaleScheduleFields.d.ts +1 -1
  215. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +111 -134
  216. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs +1 -0
  217. package/lib/pages/cms/products/components/SyncFreemiusButton.d.ts +1 -1
  218. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +29 -35
  219. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs +5 -0
  220. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.d.ts +1 -1
  221. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +36 -48
  222. package/lib/pages/cms/products/components/SyncProductForm.d.ts +1 -1
  223. package/lib/pages/cms/products/components/VariationsEditor.cjs +1 -0
  224. package/lib/pages/cms/products/components/VariationsEditor.d.ts +1 -1
  225. package/lib/pages/cms/products/components/VariationsEditor.es.js +396 -405
  226. package/lib/pages/cms/products/index.cjs +1 -0
  227. package/lib/pages/cms/products/index.es.js +8 -0
  228. package/lib/pages/cms/products/inventory/InventoryPage.cjs +1 -0
  229. package/lib/pages/cms/products/inventory/InventoryPage.d.ts +1 -1
  230. package/lib/pages/cms/products/inventory/InventoryPage.es.js +21 -15
  231. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs +2 -0
  232. package/lib/pages/cms/products/inventory/InventoryTableClient.d.ts +1 -1
  233. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +230 -209
  234. package/lib/pages/cms/products/inventory/actions.cjs +3 -0
  235. package/lib/pages/cms/products/inventory/actions.es.js +83 -91
  236. package/lib/pages/cms/products/new/NewProductPage.cjs +1 -0
  237. package/lib/pages/cms/products/new/NewProductPage.d.ts +1 -1
  238. package/lib/pages/cms/products/new/NewProductPage.es.js +58 -74
  239. package/lib/pages/cms/products/product-price-sync.cjs +1 -0
  240. package/lib/pages/cms/products/product-price-sync.es.js +74 -89
  241. package/lib/pages/cms/products/server-actions.cjs +1 -0
  242. package/lib/pages/cms/products/server-actions.es.js +250 -233
  243. package/lib/pages/cms/shipping/ShippingPage.cjs +5 -0
  244. package/lib/pages/cms/shipping/ShippingPage.es.js +287 -209
  245. package/lib/pages/cms/shipping/components/RateForm.cjs +1 -0
  246. package/lib/pages/cms/shipping/components/RateForm.d.ts +1 -1
  247. package/lib/pages/cms/shipping/components/RateForm.es.js +439 -436
  248. package/lib/pages/cms/shipping/components/ZoneForm.cjs +1 -0
  249. package/lib/pages/cms/shipping/components/ZoneForm.es.js +245 -224
  250. package/lib/pages/cms/shipping/index.cjs +1 -0
  251. package/lib/pages/cms/shipping/index.es.js +3 -0
  252. package/lib/pages/cms/shipping/server-actions.cjs +1 -0
  253. package/lib/pages/cms/shipping/server-actions.es.js +131 -149
  254. package/lib/pages/cms/taxes/TaxesPage.cjs +1 -0
  255. package/lib/pages/cms/taxes/TaxesPage.d.ts +1 -1
  256. package/lib/pages/cms/taxes/TaxesPage.es.js +211 -169
  257. package/lib/pages/cms/taxes/actions.cjs +1 -0
  258. package/lib/pages/cms/taxes/actions.es.js +41 -53
  259. package/lib/pages/cms/taxes/components/TaxRateForm.cjs +1 -0
  260. package/lib/pages/cms/taxes/components/TaxRateForm.d.ts +1 -1
  261. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +112 -99
  262. package/lib/pages/cms/taxes/index.cjs +1 -0
  263. package/lib/pages/cms/taxes/index.es.js +3 -0
  264. package/lib/payment-config.cjs +1 -0
  265. package/lib/payment-config.es.js +110 -126
  266. package/lib/product-actions.cjs +238 -0
  267. package/lib/product-actions.es.js +289 -544
  268. package/lib/product-context.cjs +1 -0
  269. package/lib/product-context.es.js +13 -15
  270. package/lib/product-schema.cjs +1 -0
  271. package/lib/product-schema.es.js +99 -134
  272. package/lib/providers/freemius.cjs +1 -0
  273. package/lib/providers/freemius.es.js +446 -530
  274. package/lib/providers/stripe.cjs +1 -0
  275. package/lib/providers/stripe.es.js +417 -477
  276. package/lib/server-actions/coupon-actions.cjs +1 -0
  277. package/lib/server-actions/coupon-actions.es.js +22 -22
  278. package/lib/server-actions/customer-actions.cjs +1 -0
  279. package/lib/server-actions/customer-actions.es.js +26 -28
  280. package/lib/server-actions/product-actions.cjs +1 -0
  281. package/lib/server-actions/product-actions.es.js +9 -15
  282. package/lib/server-actions/shipping-actions.cjs +1 -0
  283. package/lib/server-actions/shipping-actions.es.js +27 -24
  284. package/lib/server-actions/tax-actions.cjs +1 -0
  285. package/lib/server-actions/tax-actions.es.js +33 -39
  286. package/lib/shared-inventory.cjs +15 -0
  287. package/lib/shared-inventory.es.js +111 -160
  288. package/lib/shipping/resolver.cjs +7 -0
  289. package/lib/shipping/resolver.es.js +44 -61
  290. package/lib/shipping-rate-currency.cjs +1 -0
  291. package/lib/shipping-rate-currency.es.js +52 -67
  292. package/lib/states.cjs +1 -0
  293. package/lib/states.es.js +333 -154
  294. package/lib/stripe/checkout.cjs +1 -0
  295. package/lib/stripe/checkout.es.js +125 -181
  296. package/lib/stripe/client.cjs +1 -0
  297. package/lib/stripe/client.es.js +14 -19
  298. package/lib/stripe/order-sync.cjs +1 -0
  299. package/lib/stripe/order-sync.es.js +106 -126
  300. package/lib/stripe/webhooks.cjs +1 -0
  301. package/lib/stripe/webhooks.es.js +37 -31
  302. package/lib/tax-calculation.cjs +1 -0
  303. package/lib/tax-calculation.es.js +84 -98
  304. package/lib/trials.cjs +1 -0
  305. package/lib/trials.es.js +24 -30
  306. package/lib/types.cjs +1 -0
  307. package/lib/types.es.js +21 -27
  308. package/lib/use-cart.cjs +1 -0
  309. package/lib/use-cart.es.js +38 -40
  310. package/lib/use-price-formatter.cjs +1 -0
  311. package/lib/use-price-formatter.es.js +10 -11
  312. package/lib/variation-utils.cjs +1 -0
  313. package/lib/variation-utils.es.js +199 -261
  314. package/lib/zod-config.cjs +1 -0
  315. package/lib/zod-config.es.js +5 -6
  316. package/package.json +22 -21
  317. package/server.cjs +1 -0
  318. package/server.es.js +56 -211
  319. package/index.cjs.js +0 -1
  320. package/lib/CurrencyProvider.cjs.js +0 -1
  321. package/lib/PaymentReadinessProvider.cjs.js +0 -1
  322. package/lib/cart-store.cjs.js +0 -1
  323. package/lib/components/AccountNavigationMenu.cjs.js +0 -1
  324. package/lib/components/AddToCartButton.cjs.js +0 -1
  325. package/lib/components/Cart.cjs.js +0 -1
  326. package/lib/components/CartDrawer.cjs.js +0 -1
  327. package/lib/components/CartIcon.cjs.js +0 -1
  328. package/lib/components/Checkout.cjs.js +0 -1
  329. package/lib/components/CouponForm.cjs.js +0 -1
  330. package/lib/components/CurrencySwitcher.cjs.js +0 -1
  331. package/lib/components/CustomerProfileForm.cjs.js +0 -1
  332. package/lib/components/FeaturedProduct.cjs.js +0 -1
  333. package/lib/components/FreemiusLicensePanel.cjs.js +0 -1
  334. package/lib/components/InvoiceDocument.cjs.js +0 -1
  335. package/lib/components/InvoiceViewerShell.cjs.js +0 -29
  336. package/lib/components/ProductCard.cjs.js +0 -1
  337. package/lib/components/ProductDetailsLayout.cjs.js +0 -1
  338. package/lib/components/ProductGallery.cjs.js +0 -1
  339. package/lib/components/ProductGrid.cjs.js +0 -1
  340. package/lib/components/ShippingEstimator.cjs.js +0 -1
  341. package/lib/components/ShortDescription.cjs.js +0 -1
  342. package/lib/components/SimpleTiptapRenderer.cjs.js +0 -1
  343. package/lib/components/SubscriptionSelector.cjs.js +0 -1
  344. package/lib/countries.cjs.js +0 -1
  345. package/lib/coupon-server.cjs.js +0 -1
  346. package/lib/coupons.cjs.js +0 -1
  347. package/lib/currency-constants.cjs.js +0 -1
  348. package/lib/currency-rest-client.cjs.js +0 -1
  349. package/lib/currency-store.cjs.js +0 -1
  350. package/lib/currency-sync.cjs.js +0 -1
  351. package/lib/currency.cjs.js +0 -1
  352. package/lib/customer-addresses.cjs.js +0 -1
  353. package/lib/customer-orders.cjs.js +0 -1
  354. package/lib/customer.cjs.js +0 -1
  355. package/lib/export-helpers.cjs.js +0 -1
  356. package/lib/factory.cjs.js +0 -1
  357. package/lib/freemius-coupons.cjs.js +0 -1
  358. package/lib/freemius-license-claim.cjs.js +0 -1
  359. package/lib/freemius-license.cjs.js +0 -1
  360. package/lib/freemius-order-sync.cjs.js +0 -1
  361. package/lib/freemius-trial-provision.cjs.js +0 -1
  362. package/lib/inventory-settings.cjs.js +0 -1
  363. package/lib/invoice-server.cjs.js +0 -33
  364. package/lib/invoice-ui.cjs.js +0 -1
  365. package/lib/invoice.cjs.js +0 -1
  366. package/lib/order-inventory.cjs.js +0 -61
  367. package/lib/order-tax-details.cjs.js +0 -1
  368. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +0 -1
  369. package/lib/pages/cms/coupons/CouponsPage.cjs.js +0 -5
  370. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +0 -1
  371. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +0 -1
  372. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +0 -1
  373. package/lib/pages/cms/coupons/actions.cjs.js +0 -1
  374. package/lib/pages/cms/coupons/product-options.cjs.js +0 -1
  375. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +0 -1
  376. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +0 -1
  377. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +0 -1
  378. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +0 -1
  379. package/lib/pages/cms/orders/OrdersPage.cjs.js +0 -1
  380. package/lib/pages/cms/orders/actions.cjs.js +0 -7
  381. package/lib/pages/cms/orders/export-actions.cjs.js +0 -1
  382. package/lib/pages/cms/orders/server-actions.cjs.js +0 -1
  383. package/lib/pages/cms/payments/PaymentsClient.cjs.js +0 -1
  384. package/lib/pages/cms/payments/PaymentsPage.cjs.js +0 -1
  385. package/lib/pages/cms/payments/actions.cjs.js +0 -1
  386. package/lib/pages/cms/payments/queries.cjs.js +0 -1
  387. package/lib/pages/cms/products/ProductsPage.cjs.js +0 -1
  388. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +0 -1
  389. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +0 -156
  390. package/lib/pages/cms/products/actions.cjs.js +0 -44
  391. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +0 -1
  392. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +0 -1
  393. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +0 -1
  394. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +0 -1
  395. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +0 -1
  396. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +0 -1
  397. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +0 -1
  398. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +0 -1
  399. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +0 -1
  400. package/lib/pages/cms/products/components/ProductForm.cjs.js +0 -1
  401. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +0 -1
  402. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +0 -1
  403. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +0 -1
  404. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +0 -1
  405. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +0 -5
  406. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +0 -1
  407. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +0 -1
  408. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +0 -2
  409. package/lib/pages/cms/products/inventory/actions.cjs.js +0 -3
  410. package/lib/pages/cms/products/new/NewProductPage.cjs.js +0 -1
  411. package/lib/pages/cms/products/product-price-sync.cjs.js +0 -1
  412. package/lib/pages/cms/products/server-actions.cjs.js +0 -1
  413. package/lib/pages/cms/shipping/ShippingPage.cjs.js +0 -5
  414. package/lib/pages/cms/shipping/components/RateForm.cjs.js +0 -1
  415. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +0 -1
  416. package/lib/pages/cms/shipping/server-actions.cjs.js +0 -1
  417. package/lib/pages/cms/taxes/TaxesPage.cjs.js +0 -1
  418. package/lib/pages/cms/taxes/actions.cjs.js +0 -1
  419. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +0 -1
  420. package/lib/payment-config.cjs.js +0 -1
  421. package/lib/product-actions.cjs.js +0 -238
  422. package/lib/product-context.cjs.js +0 -1
  423. package/lib/product-schema.cjs.js +0 -1
  424. package/lib/providers/freemius.cjs.js +0 -5
  425. package/lib/providers/stripe.cjs.js +0 -1
  426. package/lib/server-actions/coupon-actions.cjs.js +0 -1
  427. package/lib/server-actions/customer-actions.cjs.js +0 -1
  428. package/lib/server-actions/product-actions.cjs.js +0 -1
  429. package/lib/server-actions/shipping-actions.cjs.js +0 -1
  430. package/lib/server-actions/tax-actions.cjs.js +0 -1
  431. package/lib/shared-inventory.cjs.js +0 -15
  432. package/lib/shipping/resolver.cjs.js +0 -7
  433. package/lib/shipping-rate-currency.cjs.js +0 -1
  434. package/lib/states.cjs.js +0 -1
  435. package/lib/stripe/checkout.cjs.js +0 -1
  436. package/lib/stripe/client.cjs.js +0 -1
  437. package/lib/stripe/order-sync.cjs.js +0 -1
  438. package/lib/stripe/webhooks.cjs.js +0 -1
  439. package/lib/tax-calculation.cjs.js +0 -1
  440. package/lib/trials.cjs.js +0 -1
  441. package/lib/types.cjs.js +0 -1
  442. package/lib/use-cart.cjs.js +0 -1
  443. package/lib/use-price-formatter.cjs.js +0 -1
  444. package/lib/variation-utils.cjs.js +0 -1
  445. package/lib/zod-config.cjs.js +0 -1
  446. package/server.cjs.js +0 -1
@@ -1,482 +1,422 @@
1
- import { getStripeClient as _e } from "../stripe/client.es.js";
2
- import { createClient as we } from "@supabase/supabase-js";
3
- import { countries as Pe } from "../countries.es.js";
4
- import { normalizeOrderCustomerDetails as be } from "../customer.es.js";
5
- import { getCouponQuote as qe, getQuoteLineDiscountMap as Te, recordCouponRedemption as Ae } from "../coupon-server.es.js";
6
- import { getCartLineCouponKey as Ie } from "../coupons.es.js";
7
- import { upsertDefaultUserAddresses as De, fillMissingUserProfileCheckoutDetails as Ue } from "../customer-addresses.es.js";
8
- import { getEcommerceInventorySettings as Le, createInventoryUnavailableError as se, createInventoryInsufficientError as ue } from "../inventory-settings.es.js";
9
- import { calculateCheckoutTaxes as Me, STRIPE_TAX_CODE_SHIPPING as Fe, STRIPE_TAX_CODE_NONTAXABLE as le, getStripeTaxCodeForProduct as Re } from "../tax-calculation.es.js";
10
- import { getDefaultCurrency as Ne, resolveEffectivePriceForCurrency as de, normalizePriceMap as I, convertMinorUnitAmount as Ke } from "../currency.es.js";
11
- import { buildOrderTaxDetailsFromCalculation as Be } from "../order-tax-details.es.js";
12
- import { isDigitalItem as Oe } from "../types.es.js";
13
- import { resolveTranslatedText as Qe } from "../variation-utils.es.js";
14
- const ze = Pe.map((r) => r.code), $e = /* @__PURE__ */ new Set([
15
- "bg",
16
- "cs",
17
- "da",
18
- "de",
19
- "el",
20
- "en",
21
- "en-GB",
22
- "es",
23
- "es-419",
24
- "et",
25
- "fi",
26
- "fil",
27
- "fr",
28
- "hr",
29
- "hu",
30
- "id",
31
- "it",
32
- "ja",
33
- "ko",
34
- "lt",
35
- "lv",
36
- "ms",
37
- "mt",
38
- "nb",
39
- "nl",
40
- "pl",
41
- "pt",
42
- "pt-BR",
43
- "ro",
44
- "ru",
45
- "sk",
46
- "sl",
47
- "sv",
48
- "th",
49
- "tr",
50
- "vi",
51
- "zh",
52
- "zh-HK",
53
- "zh-TW"
54
- ]);
55
- function pe(r) {
56
- if (r)
57
- return {
58
- line1: r.line1 || void 0,
59
- line2: r.line2 || void 0,
60
- city: r.city || void 0,
61
- state: r.state || void 0,
62
- postal_code: r.postal_code || void 0,
63
- country: r.country_code || void 0
64
- };
1
+ import { isDigitalItem as e } from "../types.es.js";
2
+ import { convertMinorUnitAmount as t, getDefaultCurrency as n, normalizePriceMap as r, resolveEffectivePriceForCurrency as i } from "../currency.es.js";
3
+ import { getCartLineCouponKey as a } from "../coupons.es.js";
4
+ import { getCouponQuote as o, getQuoteLineDiscountMap as s, recordCouponRedemption as c } from "../coupon-server.es.js";
5
+ import { countries as l } from "../countries.es.js";
6
+ import { resolveTranslatedText as u } from "../variation-utils.es.js";
7
+ import { createInventoryInsufficientError as d, createInventoryUnavailableError as f, getEcommerceInventorySettings as ee } from "../inventory-settings.es.js";
8
+ import { STRIPE_TAX_CODE_NONTAXABLE as p, STRIPE_TAX_CODE_SHIPPING as te, calculateCheckoutTaxes as ne, getStripeTaxCodeForProduct as re } from "../tax-calculation.es.js";
9
+ import { normalizeOrderCustomerDetails as ie } from "../customer.es.js";
10
+ import { fillMissingUserProfileCheckoutDetails as ae, upsertDefaultUserAddresses as oe } from "../customer-addresses.es.js";
11
+ import { buildOrderTaxDetailsFromCalculation as se } from "../order-tax-details.es.js";
12
+ import { getStripeClient as m } from "../stripe/client.es.js";
13
+ import { createClient as ce } from "@supabase/supabase-js";
14
+ //#region src/lib/providers/stripe.ts
15
+ var le = l.map((e) => e.code), h = /* @__PURE__ */ new Set(/* @__PURE__ */ "bg.cs.da.de.el.en.en-GB.es.es-419.et.fi.fil.fr.hr.hu.id.it.ja.ko.lt.lv.ms.mt.nb.nl.pl.pt.pt-BR.ro.ru.sk.sl.sv.th.tr.vi.zh.zh-HK.zh-TW".split("."));
16
+ function g(e) {
17
+ if (e) return {
18
+ line1: e.line1 || void 0,
19
+ line2: e.line2 || void 0,
20
+ city: e.city || void 0,
21
+ state: e.state || void 0,
22
+ postal_code: e.postal_code || void 0,
23
+ country: e.country_code || void 0
24
+ };
65
25
  }
66
- function Xe(r) {
67
- const i = r?.trim().replace("_", "-");
68
- if (!i)
69
- return;
70
- const l = [i, i.toLowerCase(), i.split("-")[0].toLowerCase()];
71
- for (const d of l)
72
- if ($e.has(d))
73
- return d;
26
+ function ue(e) {
27
+ let t = e?.trim().replace("_", "-");
28
+ if (!t) return;
29
+ let n = [
30
+ t,
31
+ t.toLowerCase(),
32
+ t.split("-")[0].toLowerCase()
33
+ ];
34
+ for (let e of n) if (h.has(e)) return e;
74
35
  }
75
- function He(r, i) {
76
- return Qe(
77
- r.name,
78
- r.name_translations || null,
79
- i
80
- );
36
+ function de(e, t) {
37
+ return u(e.name, e.name_translations || null, t);
81
38
  }
82
- async function Ge(r) {
83
- if (!r.email)
84
- return null;
85
- const i = await _e(), l = pe(r.shippingAddress), d = r.shippingAddress?.recipient_name || r.billingAddress?.recipient_name || void 0, p = {
86
- email: r.email,
87
- name: r.billingAddress?.recipient_name || r.shippingAddress?.recipient_name || void 0,
88
- phone: r.phone || void 0,
89
- address: pe(r.billingAddress),
90
- metadata: r.userId ? { userId: r.userId } : void 0,
91
- ...l && d ? {
92
- shipping: {
93
- name: d,
94
- phone: r.phone || void 0,
95
- address: l
96
- }
97
- } : {}
98
- };
99
- try {
100
- const _ = (await i.customers.list({
101
- email: r.email,
102
- limit: 1
103
- })).data[0];
104
- return _ ? (await i.customers.update(_.id, p), _.id) : (await i.customers.create(p)).id;
105
- } catch (u) {
106
- return console.error("Failed to upsert Stripe customer for checkout prefill:", u), null;
107
- }
39
+ async function fe(e) {
40
+ if (!e.email) return null;
41
+ let t = await m(), n = g(e.shippingAddress), r = e.shippingAddress?.recipient_name || e.billingAddress?.recipient_name || void 0, i = {
42
+ email: e.email,
43
+ name: e.billingAddress?.recipient_name || e.shippingAddress?.recipient_name || void 0,
44
+ phone: e.phone || void 0,
45
+ address: g(e.billingAddress),
46
+ metadata: e.userId ? { userId: e.userId } : void 0,
47
+ ...n && r ? { shipping: {
48
+ name: r,
49
+ phone: e.phone || void 0,
50
+ address: n
51
+ } } : {}
52
+ };
53
+ try {
54
+ let n = (await t.customers.list({
55
+ email: e.email,
56
+ limit: 1
57
+ })).data[0];
58
+ return n ? (await t.customers.update(n.id, i), n.id) : (await t.customers.create(i)).id;
59
+ } catch (e) {
60
+ return console.error("Failed to upsert Stripe customer for checkout prefill:", e), null;
61
+ }
108
62
  }
109
- class ct {
110
- getProviderName() {
111
- return "Stripe";
112
- }
113
- async createCheckoutSession({
114
- items: i,
115
- customerEmail: l,
116
- customerPhone: d,
117
- userId: p,
118
- billingAddress: u,
119
- shippingAddress: _,
120
- shippingMethodId: D,
121
- currencyCode: me,
122
- locale: R,
123
- couponCode: N,
124
- couponContextItems: U
125
- }) {
126
- const he = await _e(), K = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, B = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY;
127
- if (!K || !B)
128
- return console.error("Missing Supabase credentials for checkout (Service Key required)."), { error: "Internal Server Error", url: null };
129
- const a = we(K, B), O = process.env.NEXT_PUBLIC_URL || "http://localhost:4200", Q = i.some((e) => !Oe(e));
130
- if (!i.length)
131
- return { error: "Cart is empty", url: null };
132
- const { data: fe, error: z } = await a.from("currencies").select(
133
- "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"
134
- ).eq("is_active", !0).order("code", { ascending: !0 }), y = fe ?? [];
135
- if (z || y.length === 0)
136
- return console.error("Error fetching currencies for checkout:", z), { error: "Failed to resolve store currencies", url: null };
137
- const $ = Ne(y), m = y.find((e) => e.code === (me || "").toUpperCase()) ?? $, L = m.code.toLowerCase(), X = await Le(a), ve = i.map((e) => e.product_id), H = i.map((e) => e.variant_id).filter((e) => !!e), { data: G, error: V } = await a.from("products").select("id, title, sku, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, stock, is_taxable").in("id", ve);
138
- if (V || !G)
139
- return console.error("Error fetching products for validation:", V), { error: "Failed to validate product prices", url: null };
140
- const { data: ye, error: W } = H.length ? await a.from("product_variants").select("id, product_id, sku, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, stock_quantity").in("id", H) : { data: [], error: null };
141
- if (W)
142
- return console.error("Error fetching variants for validation:", W), { error: "Failed to validate product variants", url: null };
143
- const Y = new Map(G.map((e) => [e.id, e])), j = new Map((ye || []).map((e) => [e.id, e])), M = /* @__PURE__ */ new Set(), b = /* @__PURE__ */ new Map();
144
- for (const e of i) {
145
- const t = Y.get(e.product_id);
146
- if (!t)
147
- continue;
148
- const n = (e.variant_id ? j.get(e.variant_id) : null)?.sku || t.sku;
149
- n && (M.add(n), b.set(
150
- n,
151
- (b.get(n) ?? 0) + e.quantity
152
- ));
153
- }
154
- const { data: ge, error: J } = M.size ? await a.from("inventory_items").select("sku, quantity").in("sku", [...M]) : { data: [], error: null };
155
- if (J)
156
- return console.error("Error fetching SKU inventory for validation:", J), { error: "Failed to validate SKU inventory", url: null };
157
- const q = new Map(
158
- (ge || []).map((e) => [
159
- e.sku,
160
- Math.max(0, e.quantity ?? 0)
161
- ])
162
- ), g = [], Z = [], ee = [];
163
- let f = 0, S = 0, c = null;
164
- if (N) {
165
- const e = await qe({
166
- client: a,
167
- code: N,
168
- items: U && U.length > 0 ? U : i,
169
- currencyCode: m.code
170
- });
171
- if (!e.success)
172
- return {
173
- error: e.error,
174
- errorKey: e.errorKey,
175
- errorStatus: 400,
176
- url: null
177
- };
178
- c = e.quote;
179
- }
180
- const Se = Te(c), Ce = (e) => {
181
- const t = e.unitAmount * e.quantity, v = Math.max(0, t - e.lineDiscount);
182
- if (v <= 0)
183
- return;
184
- const n = Math.floor(v / e.quantity), w = v - n * e.quantity, E = (P, x) => {
185
- x <= 0 || P <= 0 || g.push({
186
- price_data: {
187
- currency: e.currency,
188
- product_data: {
189
- name: e.name,
190
- tax_code: Re(e.isTaxable),
191
- metadata: {
192
- productId: e.productId,
193
- variantId: e.variantId || ""
194
- }
195
- },
196
- tax_behavior: "exclusive",
197
- unit_amount: P
198
- },
199
- quantity: x
200
- });
201
- };
202
- E(n, e.quantity - w), E(n + 1, w);
203
- };
204
- for (const e of i) {
205
- const t = Y.get(e.product_id);
206
- if (!t)
207
- return console.warn(`Product ${e.product_id} not found in DB.`), {
208
- url: null,
209
- ...se(e.title)
210
- };
211
- const v = de({
212
- prices: I(t.prices),
213
- salePrices: t.sale_prices || {},
214
- fallbackPrice: t.price,
215
- fallbackSalePrice: t.sale_price,
216
- saleStartAt: t.sale_start_at,
217
- saleEndAt: t.sale_end_at,
218
- scheduledPrice: t.scheduled_price,
219
- scheduledPrices: I(t.scheduled_prices),
220
- scheduledPriceAt: t.scheduled_price_at,
221
- currencyCode: m.code,
222
- currencies: y
223
- });
224
- let n = v.sale_price ?? v.price, w = t.title, E = null;
225
- if (e.variant_id) {
226
- const o = j.get(e.variant_id);
227
- if (!o || o.product_id !== e.product_id)
228
- return {
229
- url: null,
230
- ...se(e.title)
231
- };
232
- const A = b.get(o.sku) ?? e.quantity, ne = q.has(o.sku) ? q.get(o.sku) ?? 0 : Math.max(0, o.stock_quantity ?? 0);
233
- if (X.trackQuantities && A > ne)
234
- return {
235
- url: null,
236
- ...ue(e.title, ne)
237
- };
238
- const ce = de({
239
- prices: I(o.prices),
240
- salePrices: o.sale_prices || {},
241
- fallbackPrice: o.price,
242
- fallbackSalePrice: o.sale_price,
243
- saleStartAt: o.sale_start_at,
244
- saleEndAt: o.sale_end_at,
245
- scheduledPrice: o.scheduled_price,
246
- scheduledPrices: I(o.scheduled_prices),
247
- scheduledPriceAt: o.scheduled_price_at,
248
- currencyCode: m.code,
249
- currencies: y
250
- });
251
- n = ce.sale_price ?? ce.price, E = o.id, w = e.variant_label ? `${t.title} - ${e.variant_label}` : `${t.title} - ${o.sku}`;
252
- } else {
253
- const o = b.get(t.sku) ?? e.quantity, A = q.has(t.sku) ? q.get(t.sku) ?? 0 : Math.max(0, t.stock ?? 0);
254
- if (X.trackQuantities && o > A)
255
- return {
256
- url: null,
257
- ...ue(e.title, A)
258
- };
259
- }
260
- const P = t.is_taxable ?? !0;
261
- if (n < 0)
262
- return { error: "A product variation produced an invalid price.", url: null };
263
- const x = Math.min(
264
- n * e.quantity,
265
- Se.get(Ie(e)) ?? 0
266
- );
267
- Ce({
268
- name: w,
269
- currency: L,
270
- productId: t.id,
271
- variantId: E,
272
- isTaxable: P,
273
- unitAmount: n,
274
- quantity: e.quantity,
275
- lineDiscount: x
276
- }), f += n * e.quantity, S += x, ee.push({
277
- product_id: t.id,
278
- quantity: e.quantity,
279
- price_at_purchase: n,
280
- variant_id: E
281
- }), Z.push({
282
- product_id: t.id,
283
- quantity: e.quantity,
284
- unit_amount: n,
285
- discount_amount: x,
286
- is_taxable: P
287
- });
288
- }
289
- if (g.length === 0 && S >= f)
290
- return {
291
- error: "This coupon would reduce the Stripe order to zero. Use a smaller discount for Stripe checkout.",
292
- errorKey: "ecommerce.coupon_zero_total_not_supported",
293
- errorStatus: 400,
294
- url: null
295
- };
296
- if (g.length === 0)
297
- return { error: "No valid items in cart", url: null };
298
- let h = 0, F = null;
299
- if (D) {
300
- const { data: e, error: t } = await a.from("shipping_zone_methods").select("id, name, name_translations, cost_amount, cost_currency").eq("id", D).single();
301
- if (t)
302
- return console.error("Failed to load shipping method:", t), { error: "Failed to load shipping method", url: null };
303
- h = Ke({
304
- amount: e.cost_amount ?? 0,
305
- fromCurrencyCode: e.cost_currency || $.code,
306
- toCurrencyCode: m.code,
307
- currencies: y
308
- }), F = He(e, R);
309
- }
310
- const te = Q ? _ ?? u : u;
311
- let s;
312
- try {
313
- s = await Me(a, {
314
- items: Z,
315
- destination: {
316
- country_code: te?.country_code,
317
- state: te?.state
318
- }
319
- });
320
- } catch (e) {
321
- return console.error("Failed to calculate checkout taxes:", e), { error: "Failed to calculate taxes", url: null };
322
- }
323
- h > 0 && F && g.push({
324
- price_data: {
325
- currency: L,
326
- product_data: {
327
- name: F,
328
- tax_code: s.enabled && s.mode === "automatic" ? Fe : le
329
- },
330
- tax_behavior: "exclusive",
331
- unit_amount: h
332
- },
333
- quantity: 1
334
- });
335
- const C = s.enabled && s.mode === "manual" && !s.isPendingExternalCalculation ? s.amount : 0;
336
- C > 0 && g.push({
337
- price_data: {
338
- currency: L,
339
- product_data: {
340
- name: "Tax",
341
- tax_code: le
342
- },
343
- tax_behavior: "exclusive",
344
- unit_amount: C
345
- },
346
- quantity: 1
347
- });
348
- const ke = be({
349
- email: l,
350
- phone: d,
351
- name: u?.recipient_name,
352
- billing: u,
353
- shipping: _
354
- }), re = m.code, Ee = Be({
355
- calculation: s,
356
- subtotal: f,
357
- shippingTotal: h,
358
- total: Math.max(0, f - S) + h + C,
359
- currency: re
360
- }), xe = Math.max(0, f - S) + h + C, { data: oe, error: ie } = await a.from("orders").insert({
361
- status: "pending",
362
- total: xe,
363
- currency: re,
364
- exchange_rate_at_purchase: m.exchange_rate,
365
- subtotal: f,
366
- shipping_total: h,
367
- tax_total: C,
368
- tax_details: Ee,
369
- coupon_id: c?.couponId ?? null,
370
- coupon_code: c?.code ?? null,
371
- discount_total: S,
372
- discount_details: c ? {
373
- code: c.code,
374
- discount_type: c.discountType,
375
- discount_amount: c.discountAmount,
376
- provider: "stripe",
377
- provider_discounts: c.providerDiscounts,
378
- line_discounts: c.lineDiscounts
379
- } : null,
380
- provider: "stripe",
381
- user_id: p,
382
- customer_details: ke
383
- }).select("id").single();
384
- if (ie || !oe)
385
- return console.error("Failed to create pending order:", ie), { error: "Failed to initiate order", url: null };
386
- const k = oe.id, { error: ae } = await a.from("order_items").insert(
387
- ee.map((e) => ({
388
- order_id: k,
389
- product_id: e.product_id,
390
- variant_id: e.variant_id ?? null,
391
- quantity: e.quantity,
392
- price_at_purchase: e.price_at_purchase
393
- }))
394
- );
395
- if (ae)
396
- return console.error("Failed to insert order items:", ae), await a.from("orders").update({ status: "failed" }).eq("id", k), { error: "Failed to record order items", url: null };
397
- if (p)
398
- try {
399
- await De({
400
- userId: p,
401
- billingAddress: u,
402
- shippingAddress: _,
403
- client: a
404
- }), await Ue({
405
- userId: p,
406
- fullName: u?.recipient_name ?? _?.recipient_name ?? null,
407
- phone: d,
408
- client: a
409
- });
410
- } catch (e) {
411
- console.error(
412
- "Failed to sync checkout profile defaults before checkout:",
413
- e
414
- );
415
- }
416
- c && await Ae({
417
- client: a,
418
- quote: c,
419
- orderId: k,
420
- provider: "stripe",
421
- discountTotal: S,
422
- userId: p,
423
- customerEmail: l,
424
- metadata: {
425
- currency: m.code,
426
- subtotal: f,
427
- shipping_total: h,
428
- tax_total: C
429
- }
430
- });
431
- const T = await Ge({
432
- email: l,
433
- phone: d,
434
- userId: p,
435
- billingAddress: u,
436
- shippingAddress: _
437
- });
438
- try {
439
- const e = await he.checkout.sessions.create({
440
- mode: "payment",
441
- success_url: `${O}/checkout/success?session_id={CHECKOUT_SESSION_ID}`,
442
- cancel_url: `${O}/checkout`,
443
- locale: Xe(R),
444
- line_items: g,
445
- automatic_tax: s.enabled && s.mode === "automatic" ? { enabled: !0 } : void 0,
446
- billing_address_collection: "auto",
447
- customer: T || void 0,
448
- customer_email: T ? void 0 : l || void 0,
449
- customer_creation: T ? void 0 : "if_required",
450
- customer_update: T ? {
451
- name: "auto",
452
- address: "auto",
453
- shipping: "auto"
454
- } : void 0,
455
- shipping_address_collection: Q ? {
456
- allowed_countries: ze
457
- } : void 0,
458
- metadata: {
459
- orderId: k,
460
- taxMode: s.mode,
461
- currencyCode: m.code,
462
- couponCode: c?.code || ""
463
- }
464
- }), { error: t } = await a.from("orders").update({ stripe_session_id: e.id }).eq("id", k);
465
- return t && console.error("Failed to save Stripe session ID on order:", t), { url: e.url };
466
- } catch (e) {
467
- return console.error("Stripe session creation failed:", e), await a.from("orders").update({ status: "failed" }).eq("id", k), e?.name === "StripeNotConfiguredError" || e?.type === "StripeAuthenticationError" ? {
468
- error: "This store is not able to take payments right now. Please contact the seller to complete your purchase.",
469
- errorKey: "ecommerce.checkout_payments_unavailable",
470
- errorStatus: 503,
471
- url: null
472
- } : {
473
- error: "Something went wrong while preparing your checkout. Please try again.",
474
- errorKey: "ecommerce.checkout_internal_server_error",
475
- url: null
476
- };
477
- }
478
- }
479
- }
480
- export {
481
- ct as StripeProvider
63
+ var _ = class {
64
+ getProviderName() {
65
+ return "Stripe";
66
+ }
67
+ async createCheckoutSession({ items: l, customerEmail: u, customerPhone: h, userId: g, billingAddress: _, shippingAddress: v, shippingMethodId: pe, currencyCode: me, locale: he, couponCode: y, couponContextItems: b }) {
68
+ let ge = await m(), x = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, S = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY;
69
+ if (!x || !S) return console.error("Missing Supabase credentials for checkout (Service Key required)."), {
70
+ error: "Internal Server Error",
71
+ url: null
72
+ };
73
+ let C = ce(x, S), w = process.env.NEXT_PUBLIC_URL || "http://localhost:4200", T = l.some((t) => !e(t));
74
+ if (!l.length) return {
75
+ error: "Cart is empty",
76
+ url: null
77
+ };
78
+ let { data: _e, error: E } = await C.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 }), D = _e ?? [];
79
+ if (E || D.length === 0) return console.error("Error fetching currencies for checkout:", E), {
80
+ error: "Failed to resolve store currencies",
81
+ url: null
82
+ };
83
+ let O = n(D), k = D.find((e) => e.code === (me || "").toUpperCase()) ?? O, A = k.code.toLowerCase(), j = await ee(C), ve = l.map((e) => e.product_id), M = l.map((e) => e.variant_id).filter((e) => !!e), { data: N, error: P } = await C.from("products").select("id, title, sku, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, stock, is_taxable").in("id", ve);
84
+ if (P || !N) return console.error("Error fetching products for validation:", P), {
85
+ error: "Failed to validate product prices",
86
+ url: null
87
+ };
88
+ let { data: ye, error: F } = M.length ? await C.from("product_variants").select("id, product_id, sku, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, stock_quantity").in("id", M) : {
89
+ data: [],
90
+ error: null
91
+ };
92
+ if (F) return console.error("Error fetching variants for validation:", F), {
93
+ error: "Failed to validate product variants",
94
+ url: null
95
+ };
96
+ let I = new Map(N.map((e) => [e.id, e])), L = new Map((ye || []).map((e) => [e.id, e])), R = /* @__PURE__ */ new Set(), z = /* @__PURE__ */ new Map();
97
+ for (let e of l) {
98
+ let t = I.get(e.product_id);
99
+ if (!t) continue;
100
+ let n = (e.variant_id ? L.get(e.variant_id) : null)?.sku || t.sku;
101
+ n && (R.add(n), z.set(n, (z.get(n) ?? 0) + e.quantity));
102
+ }
103
+ let { data: be, error: B } = R.size ? await C.from("inventory_items").select("sku, quantity").in("sku", [...R]) : {
104
+ data: [],
105
+ error: null
106
+ };
107
+ if (B) return console.error("Error fetching SKU inventory for validation:", B), {
108
+ error: "Failed to validate SKU inventory",
109
+ url: null
110
+ };
111
+ let V = new Map((be || []).map((e) => [e.sku, Math.max(0, e.quantity ?? 0)])), H = [], U = [], W = [], G = 0, K = 0, q = null;
112
+ if (y) {
113
+ let e = await o({
114
+ client: C,
115
+ code: y,
116
+ items: b && b.length > 0 ? b : l,
117
+ currencyCode: k.code
118
+ });
119
+ if (!e.success) return {
120
+ error: e.error,
121
+ errorKey: e.errorKey,
122
+ errorStatus: 400,
123
+ url: null
124
+ };
125
+ q = e.quote;
126
+ }
127
+ let xe = s(q), Se = (e) => {
128
+ let t = e.unitAmount * e.quantity, n = Math.max(0, t - e.lineDiscount);
129
+ if (n <= 0) return;
130
+ let r = Math.floor(n / e.quantity), i = n - r * e.quantity, a = (t, n) => {
131
+ n <= 0 || t <= 0 || H.push({
132
+ price_data: {
133
+ currency: e.currency,
134
+ product_data: {
135
+ name: e.name,
136
+ tax_code: re(e.isTaxable),
137
+ metadata: {
138
+ productId: e.productId,
139
+ variantId: e.variantId || ""
140
+ }
141
+ },
142
+ tax_behavior: "exclusive",
143
+ unit_amount: t
144
+ },
145
+ quantity: n
146
+ });
147
+ };
148
+ a(r, e.quantity - i), a(r + 1, i);
149
+ };
150
+ for (let e of l) {
151
+ let t = I.get(e.product_id);
152
+ if (!t) return console.warn(`Product ${e.product_id} not found in DB.`), {
153
+ url: null,
154
+ ...f(e.title)
155
+ };
156
+ let n = i({
157
+ prices: r(t.prices),
158
+ salePrices: t.sale_prices || {},
159
+ fallbackPrice: t.price,
160
+ fallbackSalePrice: t.sale_price,
161
+ saleStartAt: t.sale_start_at,
162
+ saleEndAt: t.sale_end_at,
163
+ scheduledPrice: t.scheduled_price,
164
+ scheduledPrices: r(t.scheduled_prices),
165
+ scheduledPriceAt: t.scheduled_price_at,
166
+ currencyCode: k.code,
167
+ currencies: D
168
+ }), o = n.sale_price ?? n.price, s = t.title, c = null;
169
+ if (e.variant_id) {
170
+ let n = L.get(e.variant_id);
171
+ if (!n || n.product_id !== e.product_id) return {
172
+ url: null,
173
+ ...f(e.title)
174
+ };
175
+ let a = z.get(n.sku) ?? e.quantity, l = V.has(n.sku) ? V.get(n.sku) ?? 0 : Math.max(0, n.stock_quantity ?? 0);
176
+ if (j.trackQuantities && a > l) return {
177
+ url: null,
178
+ ...d(e.title, l)
179
+ };
180
+ let u = i({
181
+ prices: r(n.prices),
182
+ salePrices: n.sale_prices || {},
183
+ fallbackPrice: n.price,
184
+ fallbackSalePrice: n.sale_price,
185
+ saleStartAt: n.sale_start_at,
186
+ saleEndAt: n.sale_end_at,
187
+ scheduledPrice: n.scheduled_price,
188
+ scheduledPrices: r(n.scheduled_prices),
189
+ scheduledPriceAt: n.scheduled_price_at,
190
+ currencyCode: k.code,
191
+ currencies: D
192
+ });
193
+ o = u.sale_price ?? u.price, c = n.id, s = e.variant_label ? `${t.title} - ${e.variant_label}` : `${t.title} - ${n.sku}`;
194
+ } else {
195
+ let n = z.get(t.sku) ?? e.quantity, r = V.has(t.sku) ? V.get(t.sku) ?? 0 : Math.max(0, t.stock ?? 0);
196
+ if (j.trackQuantities && n > r) return {
197
+ url: null,
198
+ ...d(e.title, r)
199
+ };
200
+ }
201
+ let l = t.is_taxable ?? !0;
202
+ if (o < 0) return {
203
+ error: "A product variation produced an invalid price.",
204
+ url: null
205
+ };
206
+ let u = Math.min(o * e.quantity, xe.get(a(e)) ?? 0);
207
+ Se({
208
+ name: s,
209
+ currency: A,
210
+ productId: t.id,
211
+ variantId: c,
212
+ isTaxable: l,
213
+ unitAmount: o,
214
+ quantity: e.quantity,
215
+ lineDiscount: u
216
+ }), G += o * e.quantity, K += u, W.push({
217
+ product_id: t.id,
218
+ quantity: e.quantity,
219
+ price_at_purchase: o,
220
+ variant_id: c
221
+ }), U.push({
222
+ product_id: t.id,
223
+ quantity: e.quantity,
224
+ unit_amount: o,
225
+ discount_amount: u,
226
+ is_taxable: l
227
+ });
228
+ }
229
+ if (H.length === 0 && K >= G) return {
230
+ error: "This coupon would reduce the Stripe order to zero. Use a smaller discount for Stripe checkout.",
231
+ errorKey: "ecommerce.coupon_zero_total_not_supported",
232
+ errorStatus: 400,
233
+ url: null
234
+ };
235
+ if (H.length === 0) return {
236
+ error: "No valid items in cart",
237
+ url: null
238
+ };
239
+ let J = 0, Y = null;
240
+ if (pe) {
241
+ let { data: e, error: n } = await C.from("shipping_zone_methods").select("id, name, name_translations, cost_amount, cost_currency").eq("id", pe).single();
242
+ if (n) return console.error("Failed to load shipping method:", n), {
243
+ error: "Failed to load shipping method",
244
+ url: null
245
+ };
246
+ J = t({
247
+ amount: e.cost_amount ?? 0,
248
+ fromCurrencyCode: e.cost_currency || O.code,
249
+ toCurrencyCode: k.code,
250
+ currencies: D
251
+ }), Y = de(e, he);
252
+ }
253
+ let Ce = T ? v ?? _ : _, X;
254
+ try {
255
+ X = await ne(C, {
256
+ items: U,
257
+ destination: {
258
+ country_code: Ce?.country_code,
259
+ state: Ce?.state
260
+ }
261
+ });
262
+ } catch (e) {
263
+ return console.error("Failed to calculate checkout taxes:", e), {
264
+ error: "Failed to calculate taxes",
265
+ url: null
266
+ };
267
+ }
268
+ J > 0 && Y && H.push({
269
+ price_data: {
270
+ currency: A,
271
+ product_data: {
272
+ name: Y,
273
+ tax_code: X.enabled && X.mode === "automatic" ? te : p
274
+ },
275
+ tax_behavior: "exclusive",
276
+ unit_amount: J
277
+ },
278
+ quantity: 1
279
+ });
280
+ let Z = X.enabled && X.mode === "manual" && !X.isPendingExternalCalculation ? X.amount : 0;
281
+ Z > 0 && H.push({
282
+ price_data: {
283
+ currency: A,
284
+ product_data: {
285
+ name: "Tax",
286
+ tax_code: p
287
+ },
288
+ tax_behavior: "exclusive",
289
+ unit_amount: Z
290
+ },
291
+ quantity: 1
292
+ });
293
+ let we = ie({
294
+ email: u,
295
+ phone: h,
296
+ name: _?.recipient_name,
297
+ billing: _,
298
+ shipping: v
299
+ }), Te = k.code, Ee = se({
300
+ calculation: X,
301
+ subtotal: G,
302
+ shippingTotal: J,
303
+ total: Math.max(0, G - K) + J + Z,
304
+ currency: Te
305
+ }), De = Math.max(0, G - K) + J + Z, { data: Oe, error: ke } = await C.from("orders").insert({
306
+ status: "pending",
307
+ total: De,
308
+ currency: Te,
309
+ exchange_rate_at_purchase: k.exchange_rate,
310
+ subtotal: G,
311
+ shipping_total: J,
312
+ tax_total: Z,
313
+ tax_details: Ee,
314
+ coupon_id: q?.couponId ?? null,
315
+ coupon_code: q?.code ?? null,
316
+ discount_total: K,
317
+ discount_details: q ? {
318
+ code: q.code,
319
+ discount_type: q.discountType,
320
+ discount_amount: q.discountAmount,
321
+ provider: "stripe",
322
+ provider_discounts: q.providerDiscounts,
323
+ line_discounts: q.lineDiscounts
324
+ } : null,
325
+ provider: "stripe",
326
+ user_id: g,
327
+ customer_details: we
328
+ }).select("id").single();
329
+ if (ke || !Oe) return console.error("Failed to create pending order:", ke), {
330
+ error: "Failed to initiate order",
331
+ url: null
332
+ };
333
+ let Q = Oe.id, { error: Ae } = await C.from("order_items").insert(W.map((e) => ({
334
+ order_id: Q,
335
+ product_id: e.product_id,
336
+ variant_id: e.variant_id ?? null,
337
+ quantity: e.quantity,
338
+ price_at_purchase: e.price_at_purchase
339
+ })));
340
+ if (Ae) return console.error("Failed to insert order items:", Ae), await C.from("orders").update({ status: "failed" }).eq("id", Q), {
341
+ error: "Failed to record order items",
342
+ url: null
343
+ };
344
+ if (g) try {
345
+ await oe({
346
+ userId: g,
347
+ billingAddress: _,
348
+ shippingAddress: v,
349
+ client: C
350
+ }), await ae({
351
+ userId: g,
352
+ fullName: _?.recipient_name ?? v?.recipient_name ?? null,
353
+ phone: h,
354
+ client: C
355
+ });
356
+ } catch (e) {
357
+ console.error("Failed to sync checkout profile defaults before checkout:", e);
358
+ }
359
+ q && await c({
360
+ client: C,
361
+ quote: q,
362
+ orderId: Q,
363
+ provider: "stripe",
364
+ discountTotal: K,
365
+ userId: g,
366
+ customerEmail: u,
367
+ metadata: {
368
+ currency: k.code,
369
+ subtotal: G,
370
+ shipping_total: J,
371
+ tax_total: Z
372
+ }
373
+ });
374
+ let $ = await fe({
375
+ email: u,
376
+ phone: h,
377
+ userId: g,
378
+ billingAddress: _,
379
+ shippingAddress: v
380
+ });
381
+ try {
382
+ let e = await ge.checkout.sessions.create({
383
+ mode: "payment",
384
+ success_url: `${w}/checkout/success?session_id={CHECKOUT_SESSION_ID}`,
385
+ cancel_url: `${w}/checkout`,
386
+ locale: ue(he),
387
+ line_items: H,
388
+ automatic_tax: X.enabled && X.mode === "automatic" ? { enabled: !0 } : void 0,
389
+ billing_address_collection: "auto",
390
+ customer: $ || void 0,
391
+ customer_email: $ ? void 0 : u || void 0,
392
+ customer_creation: $ ? void 0 : "if_required",
393
+ customer_update: $ ? {
394
+ name: "auto",
395
+ address: "auto",
396
+ shipping: "auto"
397
+ } : void 0,
398
+ shipping_address_collection: T ? { allowed_countries: le } : void 0,
399
+ metadata: {
400
+ orderId: Q,
401
+ taxMode: X.mode,
402
+ currencyCode: k.code,
403
+ couponCode: q?.code || ""
404
+ }
405
+ }), { error: t } = await C.from("orders").update({ stripe_session_id: e.id }).eq("id", Q);
406
+ return t && console.error("Failed to save Stripe session ID on order:", t), { url: e.url };
407
+ } catch (e) {
408
+ return console.error("Stripe session creation failed:", e), await C.from("orders").update({ status: "failed" }).eq("id", Q), e?.name === "StripeNotConfiguredError" || e?.type === "StripeAuthenticationError" ? {
409
+ error: "This store is not able to take payments right now. Please contact the seller to complete your purchase.",
410
+ errorKey: "ecommerce.checkout_payments_unavailable",
411
+ errorStatus: 503,
412
+ url: null
413
+ } : {
414
+ error: "Something went wrong while preparing your checkout. Please try again.",
415
+ errorKey: "ecommerce.checkout_internal_server_error",
416
+ url: null
417
+ };
418
+ }
419
+ }
482
420
  };
421
+ //#endregion
422
+ export { _ as StripeProvider };