@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
@@ -0,0 +1,473 @@
1
+ import { stripe as D } from "../stripe/client.es.js";
2
+ import { createClient as Ee } from "@supabase/supabase-js";
3
+ import { countries as qe } from "../countries.es.js";
4
+ import { normalizeOrderCustomerDetails as Pe } from "../customer.es.js";
5
+ import { getCouponQuote as be, getQuoteLineDiscountMap as we, recordCouponRedemption as Te } from "../coupon-server.es.js";
6
+ import { getCartLineCouponKey as Ie } from "../coupons.es.js";
7
+ import { upsertDefaultUserAddresses as Ae, fillMissingUserProfileCheckoutDetails as De } from "../customer-addresses.es.js";
8
+ import { getEcommerceInventorySettings as Me, createInventoryUnavailableError as ue, createInventoryInsufficientError as le } from "../inventory-settings.es.js";
9
+ import { calculateCheckoutTaxes as Le, STRIPE_TAX_CODE_SHIPPING as Ue, STRIPE_TAX_CODE_NONTAXABLE as de, getStripeTaxCodeForProduct as Fe } from "../tax-calculation.es.js";
10
+ import { getDefaultCurrency as Re, resolveEffectivePriceForCurrency as pe, normalizePriceMap as A, convertMinorUnitAmount as Ne } from "../currency.es.js";
11
+ import { buildOrderTaxDetailsFromCalculation as Oe } from "../order-tax-details.es.js";
12
+ import { isDigitalItem as Be } from "../types.es.js";
13
+ import { resolveTranslatedText as Ke } from "../variation-utils.es.js";
14
+ const Qe = qe.map((r) => r.code), ze = /* @__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 _e(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
+ };
65
+ }
66
+ function $e(r) {
67
+ const a = r?.trim().replace("_", "-");
68
+ if (!a)
69
+ return;
70
+ const l = [a, a.toLowerCase(), a.split("-")[0].toLowerCase()];
71
+ for (const d of l)
72
+ if (ze.has(d))
73
+ return d;
74
+ }
75
+ function Xe(r, a) {
76
+ return Ke(
77
+ r.name,
78
+ r.name_translations || null,
79
+ a
80
+ );
81
+ }
82
+ async function He(r) {
83
+ if (!r.email)
84
+ return null;
85
+ const a = _e(r.shippingAddress), l = r.shippingAddress?.recipient_name || r.billingAddress?.recipient_name || void 0, d = {
86
+ email: r.email,
87
+ name: r.billingAddress?.recipient_name || r.shippingAddress?.recipient_name || void 0,
88
+ phone: r.phone || void 0,
89
+ address: _e(r.billingAddress),
90
+ metadata: r.userId ? { userId: r.userId } : void 0,
91
+ ...a && l ? {
92
+ shipping: {
93
+ name: l,
94
+ phone: r.phone || void 0,
95
+ address: a
96
+ }
97
+ } : {}
98
+ };
99
+ try {
100
+ const s = (await D.customers.list({
101
+ email: r.email,
102
+ limit: 1
103
+ })).data[0];
104
+ return s ? (await D.customers.update(s.id, d), s.id) : (await D.customers.create(d)).id;
105
+ } catch (p) {
106
+ return console.error("Failed to upsert Stripe customer for checkout prefill:", p), null;
107
+ }
108
+ }
109
+ class nt {
110
+ getProviderName() {
111
+ return "Stripe";
112
+ }
113
+ async createCheckoutSession({
114
+ items: a,
115
+ customerEmail: l,
116
+ customerPhone: d,
117
+ userId: p,
118
+ billingAddress: s,
119
+ shippingAddress: v,
120
+ shippingMethodId: R,
121
+ currencyCode: me,
122
+ locale: N,
123
+ couponCode: O,
124
+ couponContextItems: M
125
+ }) {
126
+ const B = process.env.NEXT_PUBLIC_SUPABASE_URL, K = process.env.SUPABASE_SERVICE_ROLE_KEY;
127
+ if (!B || !K)
128
+ return console.error("Missing Supabase credentials for checkout (Service Key required)."), { error: "Internal Server Error", url: null };
129
+ const i = Ee(B, K), Q = process.env.NEXT_PUBLIC_URL || "http://localhost:4200", z = a.some((e) => !Be(e));
130
+ if (!a.length)
131
+ return { error: "Cart is empty", url: null };
132
+ const { data: he, error: $ } = await i.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 = he ?? [];
135
+ if ($ || y.length === 0)
136
+ return console.error("Error fetching currencies for checkout:", $), { error: "Failed to resolve store currencies", url: null };
137
+ const X = Re(y), _ = y.find((e) => e.code === (me || "").toUpperCase()) ?? X, L = _.code.toLowerCase(), H = await Me(i), fe = a.map((e) => e.product_id), G = a.map((e) => e.variant_id).filter((e) => !!e), { data: V, error: W } = await i.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", fe);
138
+ if (W || !V)
139
+ return console.error("Error fetching products for validation:", W), { error: "Failed to validate product prices", url: null };
140
+ const { data: ve, error: j } = G.length ? await i.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", G) : { data: [], error: null };
141
+ if (j)
142
+ return console.error("Error fetching variants for validation:", j), { error: "Failed to validate product variants", url: null };
143
+ const Y = new Map(V.map((e) => [e.id, e])), J = new Map((ve || []).map((e) => [e.id, e])), U = /* @__PURE__ */ new Set(), b = /* @__PURE__ */ new Map();
144
+ for (const e of a) {
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 && (U.add(n), b.set(
150
+ n,
151
+ (b.get(n) ?? 0) + e.quantity
152
+ ));
153
+ }
154
+ const { data: ye, error: Z } = U.size ? await i.from("inventory_items").select("sku, quantity").in("sku", [...U]) : { data: [], error: null };
155
+ if (Z)
156
+ return console.error("Error fetching SKU inventory for validation:", Z), { error: "Failed to validate SKU inventory", url: null };
157
+ const w = new Map(
158
+ (ye || []).map((e) => [
159
+ e.sku,
160
+ Math.max(0, e.quantity ?? 0)
161
+ ])
162
+ ), g = [], ee = [], te = [];
163
+ let h = 0, S = 0, c = null;
164
+ if (O) {
165
+ const e = await be({
166
+ client: i,
167
+ code: O,
168
+ items: M && M.length > 0 ? M : a,
169
+ currencyCode: _.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 ge = we(c), Se = (e) => {
181
+ const t = e.unitAmount * e.quantity, f = Math.max(0, t - e.lineDiscount);
182
+ if (f <= 0)
183
+ return;
184
+ const n = Math.floor(f / e.quantity), q = f - n * e.quantity, k = (P, E) => {
185
+ E <= 0 || P <= 0 || g.push({
186
+ price_data: {
187
+ currency: e.currency,
188
+ product_data: {
189
+ name: e.name,
190
+ tax_code: Fe(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: E
200
+ });
201
+ };
202
+ k(n, e.quantity - q), k(n + 1, q);
203
+ };
204
+ for (const e of a) {
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
+ ...ue(e.title)
210
+ };
211
+ const f = pe({
212
+ prices: A(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: A(t.scheduled_prices),
220
+ scheduledPriceAt: t.scheduled_price_at,
221
+ currencyCode: _.code,
222
+ currencies: y
223
+ });
224
+ let n = f.sale_price ?? f.price, q = t.title, k = 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
+ ...ue(e.title)
231
+ };
232
+ const I = b.get(o.sku) ?? e.quantity, ce = w.has(o.sku) ? w.get(o.sku) ?? 0 : Math.max(0, o.stock_quantity ?? 0);
233
+ if (H.trackQuantities && I > ce)
234
+ return {
235
+ url: null,
236
+ ...le(e.title, ce)
237
+ };
238
+ const se = pe({
239
+ prices: A(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: A(o.scheduled_prices),
247
+ scheduledPriceAt: o.scheduled_price_at,
248
+ currencyCode: _.code,
249
+ currencies: y
250
+ });
251
+ n = se.sale_price ?? se.price, k = o.id, q = e.variant_label ? `${t.title} - ${e.variant_label}` : `${t.title} - ${o.sku}`;
252
+ } else {
253
+ const o = b.get(t.sku) ?? e.quantity, I = w.has(t.sku) ? w.get(t.sku) ?? 0 : Math.max(0, t.stock ?? 0);
254
+ if (H.trackQuantities && o > I)
255
+ return {
256
+ url: null,
257
+ ...le(e.title, I)
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 E = Math.min(
264
+ n * e.quantity,
265
+ ge.get(Ie(e)) ?? 0
266
+ );
267
+ Se({
268
+ name: q,
269
+ currency: L,
270
+ productId: t.id,
271
+ variantId: k,
272
+ isTaxable: P,
273
+ unitAmount: n,
274
+ quantity: e.quantity,
275
+ lineDiscount: E
276
+ }), h += n * e.quantity, S += E, te.push({
277
+ product_id: t.id,
278
+ quantity: e.quantity,
279
+ price_at_purchase: n,
280
+ variant_id: k
281
+ }), ee.push({
282
+ product_id: t.id,
283
+ quantity: e.quantity,
284
+ unit_amount: n,
285
+ discount_amount: E,
286
+ is_taxable: P
287
+ });
288
+ }
289
+ if (g.length === 0 && S >= h)
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 m = 0, F = null;
299
+ if (R) {
300
+ const { data: e, error: t } = await i.from("shipping_zone_methods").select("id, name, name_translations, cost_amount, cost_currency").eq("id", R).single();
301
+ if (t)
302
+ return console.error("Failed to load shipping method:", t), { error: "Failed to load shipping method", url: null };
303
+ m = Ne({
304
+ amount: e.cost_amount ?? 0,
305
+ fromCurrencyCode: e.cost_currency || X.code,
306
+ toCurrencyCode: _.code,
307
+ currencies: y
308
+ }), F = Xe(e, N);
309
+ }
310
+ const re = z ? v ?? s : s;
311
+ let u;
312
+ try {
313
+ u = await Le(i, {
314
+ items: ee,
315
+ destination: {
316
+ country_code: re?.country_code,
317
+ state: re?.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
+ m > 0 && F && g.push({
324
+ price_data: {
325
+ currency: L,
326
+ product_data: {
327
+ name: F,
328
+ tax_code: u.enabled && u.mode === "automatic" ? Ue : de
329
+ },
330
+ tax_behavior: "exclusive",
331
+ unit_amount: m
332
+ },
333
+ quantity: 1
334
+ });
335
+ const C = u.enabled && u.mode === "manual" && !u.isPendingExternalCalculation ? u.amount : 0;
336
+ C > 0 && g.push({
337
+ price_data: {
338
+ currency: L,
339
+ product_data: {
340
+ name: "Tax",
341
+ tax_code: de
342
+ },
343
+ tax_behavior: "exclusive",
344
+ unit_amount: C
345
+ },
346
+ quantity: 1
347
+ });
348
+ const Ce = Pe({
349
+ email: l,
350
+ phone: d,
351
+ name: s?.recipient_name,
352
+ billing: s,
353
+ shipping: v
354
+ }), oe = _.code, xe = Oe({
355
+ calculation: u,
356
+ subtotal: h,
357
+ shippingTotal: m,
358
+ total: Math.max(0, h - S) + m + C,
359
+ currency: oe
360
+ }), ke = Math.max(0, h - S) + m + C, { data: ae, error: ie } = await i.from("orders").insert({
361
+ status: "pending",
362
+ total: ke,
363
+ currency: oe,
364
+ exchange_rate_at_purchase: _.exchange_rate,
365
+ subtotal: h,
366
+ shipping_total: m,
367
+ tax_total: C,
368
+ tax_details: xe,
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: Ce
383
+ }).select("id").single();
384
+ if (ie || !ae)
385
+ return console.error("Failed to create pending order:", ie), { error: "Failed to initiate order", url: null };
386
+ const x = ae.id, { error: ne } = await i.from("order_items").insert(
387
+ te.map((e) => ({
388
+ order_id: x,
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 (ne)
396
+ return console.error("Failed to insert order items:", ne), await i.from("orders").update({ status: "failed" }).eq("id", x), { error: "Failed to record order items", url: null };
397
+ if (p)
398
+ try {
399
+ await Ae({
400
+ userId: p,
401
+ billingAddress: s,
402
+ shippingAddress: v,
403
+ client: i
404
+ }), await De({
405
+ userId: p,
406
+ fullName: s?.recipient_name ?? v?.recipient_name ?? null,
407
+ phone: d,
408
+ client: i
409
+ });
410
+ } catch (e) {
411
+ console.error(
412
+ "Failed to sync checkout profile defaults before checkout:",
413
+ e
414
+ );
415
+ }
416
+ c && await Te({
417
+ client: i,
418
+ quote: c,
419
+ orderId: x,
420
+ provider: "stripe",
421
+ discountTotal: S,
422
+ userId: p,
423
+ customerEmail: l,
424
+ metadata: {
425
+ currency: _.code,
426
+ subtotal: h,
427
+ shipping_total: m,
428
+ tax_total: C
429
+ }
430
+ });
431
+ const T = await He({
432
+ email: l,
433
+ phone: d,
434
+ userId: p,
435
+ billingAddress: s,
436
+ shippingAddress: v
437
+ });
438
+ try {
439
+ const e = await D.checkout.sessions.create({
440
+ mode: "payment",
441
+ success_url: `${Q}/checkout/success?session_id={CHECKOUT_SESSION_ID}`,
442
+ cancel_url: `${Q}/checkout`,
443
+ locale: $e(N),
444
+ line_items: g,
445
+ automatic_tax: u.enabled && u.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: z ? {
456
+ allowed_countries: Qe
457
+ } : void 0,
458
+ metadata: {
459
+ orderId: x,
460
+ taxMode: u.mode,
461
+ currencyCode: _.code,
462
+ couponCode: c?.code || ""
463
+ }
464
+ }), { error: t } = await i.from("orders").update({ stripe_session_id: e.id }).eq("id", x);
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 i.from("orders").update({ status: "failed" }).eq("id", x), { error: e.message, url: null };
468
+ }
469
+ }
470
+ }
471
+ export {
472
+ nt as StripeProvider
473
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@nextblock-cms/db/server"),t=require("../coupon-server.cjs.js");async function c(e){try{const o=r.getServiceRoleSupabaseClient();return await t.getCouponQuote({client:o,code:e.code,items:Array.isArray(e.items)?e.items:[],currencyCode:e.currencyCode})}catch(o){return console.error("Failed to validate coupon:",o),{success:!1,error:o.message||"Failed to validate coupon.",errorKey:"ecommerce.coupon_validation_failed"}}}exports.getCouponQuoteAction=c;
@@ -0,0 +1,23 @@
1
+ 'use server';
2
+ import { getServiceRoleSupabaseClient as r } from "@nextblock-cms/db/server";
3
+ import { getCouponQuote as t } from "../coupon-server.es.js";
4
+ async function i(e) {
5
+ try {
6
+ const o = r();
7
+ return await t({
8
+ client: o,
9
+ code: e.code,
10
+ items: Array.isArray(e.items) ? e.items : [],
11
+ currencyCode: e.currencyCode
12
+ });
13
+ } catch (o) {
14
+ return console.error("Failed to validate coupon:", o), {
15
+ success: !1,
16
+ error: o.message || "Failed to validate coupon.",
17
+ errorKey: "ecommerce.coupon_validation_failed"
18
+ };
19
+ }
20
+ }
21
+ export {
22
+ i as getCouponQuoteAction
23
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@nextblock-cms/db/server"),o=require("next/cache"),n=require("../customer.cjs.js"),c=require("../customer-addresses.cjs.js");async function p(e){const r=d.createClient(),{data:{user:s},error:u}=await r.auth.getUser();if(u||!s)throw new Error("Unauthorized");const l={full_name:e.full_name||null,avatar_url:e.avatar_url||null,website:e.website||null,github_username:e.github_username||null,phone:e.phone||null,updated_at:new Date().toISOString()},{error:t}=await r.from("profiles").update(l).eq("id",s.id);if(t)throw console.error("Error updating profile:",t),new Error("Failed to update profile");const i=n.normalizeCustomerAddress(e.billing_address),a=e.use_billing_for_shipping?i:n.normalizeCustomerAddress(e.shipping_address);return await c.upsertDefaultUserAddresses({userId:s.id,billingAddress:i,shippingAddress:a,client:r}),o.revalidatePath("/profile"),o.revalidatePath("/checkout"),{success:!0}}exports.updateProfile=p;
@@ -0,0 +1,30 @@
1
+ 'use server';
2
+ import { createClient as p } from "@nextblock-cms/db/server";
3
+ import { revalidatePath as s } from "next/cache";
4
+ import { normalizeCustomerAddress as n } from "../customer.es.js";
5
+ import { upsertDefaultUserAddresses as d } from "../customer-addresses.es.js";
6
+ async function _(r) {
7
+ const e = p(), { data: { user: i }, error: l } = await e.auth.getUser();
8
+ if (l || !i)
9
+ throw new Error("Unauthorized");
10
+ const u = {
11
+ full_name: r.full_name || null,
12
+ avatar_url: r.avatar_url || null,
13
+ website: r.website || null,
14
+ github_username: r.github_username || null,
15
+ phone: r.phone || null,
16
+ updated_at: (/* @__PURE__ */ new Date()).toISOString()
17
+ }, { error: o } = await e.from("profiles").update(u).eq("id", i.id);
18
+ if (o)
19
+ throw console.error("Error updating profile:", o), new Error("Failed to update profile");
20
+ const t = n(r.billing_address), a = r.use_billing_for_shipping ? t : n(r.shipping_address);
21
+ return await d({
22
+ userId: i.id,
23
+ billingAddress: t,
24
+ shippingAddress: a,
25
+ client: e
26
+ }), s("/profile"), s("/checkout"), { success: !0 };
27
+ }
28
+ export {
29
+ _ as updateProfile
30
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@nextblock-cms/db/server"),u=require("../product-actions.cjs.js");async function d(t,e,o=[],a=[]){const n=c.createClient(),{data:s,error:r}=await u.fetchTranslatedProductsForCartInternal(n,t,e,o,a);return r?(console.error("[getTranslatedProductsForCart] Error:",r),[]):s||[]}exports.getTranslatedProductsForCart=d;
@@ -1,15 +1,16 @@
1
+ 'use server';
1
2
  import { createClient as c } from "@nextblock-cms/db/server";
2
- import { f as d } from "../product-actions-DjlIWCMH.js";
3
- async function i(t, a, o = [], e = []) {
3
+ import { fetchTranslatedProductsForCartInternal as d } from "../product-actions.es.js";
4
+ async function l(t, o, a = [], e = []) {
4
5
  const n = c(), { data: s, error: r } = await d(
5
6
  n,
6
7
  t,
7
- a,
8
8
  o,
9
+ a,
9
10
  e
10
11
  );
11
12
  return r ? (console.error("[getTranslatedProductsForCart] Error:", r), []) : s || [];
12
13
  }
13
14
  export {
14
- i as getTranslatedProductsForCart
15
+ l as getTranslatedProductsForCart
15
16
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../shipping/resolver.cjs.js"),n=require("../countries.cjs.js"),c=require("../states.cjs.js");async function u(o,r,s,t){try{const e=n.normalizeCountryCode(r.country);return e?{success:!0,methods:await i.resolveShippingOptions(o,{...r,country:e,state:c.normalizeSubdivisionCode(e,r.state)||void 0},s,t)}:{success:!1,error:"Country is required for shipping calculation",errorKey:"ecommerce.shipping_country_required"}}catch(e){return console.error("Failed to resolve shipping options:",e),{success:!1,error:e.message||"Failed to calculate shipping",errorKey:"ecommerce.shipping_calculation_failed"}}}exports.getShippingEstimates=u;
@@ -1,13 +1,15 @@
1
- import { r as t } from "./resolver-cfrCaHpE.js";
2
- import { n, b as c } from "./states-DlHJezQ1.js";
3
- async function l(o, e, s, i) {
1
+ 'use server';
2
+ import { resolveShippingOptions as t } from "../shipping/resolver.es.js";
3
+ import { normalizeCountryCode as c } from "../countries.es.js";
4
+ import { normalizeSubdivisionCode as n } from "../states.es.js";
5
+ async function m(o, e, i, s) {
4
6
  try {
5
- const r = n(e.country);
7
+ const r = c(e.country);
6
8
  return r ? { success: !0, methods: await t(o, {
7
9
  ...e,
8
10
  country: r,
9
- state: c(r, e.state) || void 0
10
- }, s, i) } : {
11
+ state: n(r, e.state) || void 0
12
+ }, i, s) } : {
11
13
  success: !1,
12
14
  error: "Country is required for shipping calculation",
13
15
  errorKey: "ecommerce.shipping_country_required"
@@ -21,5 +23,5 @@ async function l(o, e, s, i) {
21
23
  }
22
24
  }
23
25
  export {
24
- l as g
26
+ m as getShippingEstimates
25
27
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@nextblock-cms/db/server"),n=require("../tax-calculation.cjs.js"),o=require("../coupon-server.cjs.js");async function x(a,l,s="USD",c,t){try{const e=u.createClient(),_=u.getServiceRoleSupabaseClient(),{data:d}=await e.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}),g=d??[];let r;if(c){const i=await o.getCouponQuote({client:_,code:c,items:t&&t.length>0?t:a,currencyCode:s});i.success&&(r=o.getQuoteLineDiscountMap(i.quote))}const m=await n.buildCheckoutTaxableItemsFromCart(e,a,s,g,r);return{success:!0,tax:await n.calculateCheckoutTaxes(e,{items:m,destination:l})}}catch(e){return console.error("Failed to estimate taxes:",e),{success:!1,error:e.message||"Failed to calculate taxes"}}}exports.getTaxEstimate=x;
@@ -0,0 +1,40 @@
1
+ 'use server';
2
+ import { createClient as d, getServiceRoleSupabaseClient as m } from "@nextblock-cms/db/server";
3
+ import { buildCheckoutTaxableItemsFromCart as g, calculateCheckoutTaxes as p } from "../tax-calculation.es.js";
4
+ import { getCouponQuote as x, getQuoteLineDiscountMap as f } from "../coupon-server.es.js";
5
+ async function S(a, o, s = "USD", c, t) {
6
+ try {
7
+ const e = d(), u = m(), { data: n } = await e.from("currencies").select(
8
+ "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"
9
+ ).eq("is_active", !0).order("code", { ascending: !0 }), l = n ?? [];
10
+ let r;
11
+ if (c) {
12
+ const i = await x({
13
+ client: u,
14
+ code: c,
15
+ items: t && t.length > 0 ? t : a,
16
+ currencyCode: s
17
+ });
18
+ i.success && (r = f(i.quote));
19
+ }
20
+ const _ = await g(
21
+ e,
22
+ a,
23
+ s,
24
+ l,
25
+ r
26
+ );
27
+ return { success: !0, tax: await p(e, {
28
+ items: _,
29
+ destination: o
30
+ }) };
31
+ } catch (e) {
32
+ return console.error("Failed to estimate taxes:", e), {
33
+ success: !1,
34
+ error: e.message || "Failed to calculate taxes"
35
+ };
36
+ }
37
+ }
38
+ export {
39
+ S as getTaxEstimate
40
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("server-only");const w=require("@nextblock-cms/db/server");function p(a){return a??w.getServiceRoleSupabaseClient()}function S(a){return a?(Array.isArray(a)?a:[a]).map(r=>r?.code?.toUpperCase().trim()).filter(r=>!!r):[]}function d(a){return[...new Set(a)].sort((n,r)=>n.localeCompare(r))}function v(a,n){return!a||a===n?n:"mixed"}async function y(a,n){const r=Array.from(n.reduce((u,s)=>{const t=s.sku.trim();return t&&u.set(t,{sku:t,quantity:Math.max(0,Math.trunc(s.quantity))}),u},new Map).values());if(r.length===0)return;const{error:o}=await a.from("inventory_items").upsert(r,{onConflict:"sku"});if(o)throw new Error(o.message)}async function k(a,n){const r=d(n.map(s=>s.trim()).filter(Boolean));if(r.length===0)return new Map;const{data:o,error:u}=await a.from("inventory_items").select("sku, quantity").in("sku",r);if(u)throw new Error(u.message);return new Map((o||[]).map(s=>[s.sku,Math.max(0,s.quantity??0)]))}async function m(a){const{data:n,error:r}=await a.from("products").select(`
2
+ id,
3
+ title,
4
+ sku,
5
+ stock,
6
+ status,
7
+ languages (
8
+ code
9
+ ),
10
+ product_variants (
11
+ id,
12
+ sku,
13
+ stock_quantity
14
+ )
15
+ `).order("title",{ascending:!0});if(r)throw new Error(r.message);const o=new Map,u=(s,t,e,c,g)=>{const l=s.trim();if(!l)return;const f=S(c.languages),i=o.get(l);if(i){i.usageType=v(i.usageType,t),i.stockFallback=Math.min(i.stockFallback,e),i.productTitles.add(c.title),i.parentProductSkus.add(c.sku),i.languages=new Set([...i.languages,...f]),i.statuses.add(c.status),i.productIds.add(c.id),g&&i.variantIds.add(g);return}o.set(l,{sku:l,stockFallback:e,usageType:t,productTitles:new Set([c.title]),parentProductSkus:new Set([c.sku]),languages:new Set(f),statuses:new Set([c.status]),productIds:new Set([c.id]),variantIds:g?new Set([g]):new Set})};for(const s of n||[]){const t=s.product_variants||[];if(t.length>0){for(const e of t)u(e.sku,"variant",Math.max(0,e.stock_quantity??0),s,e.id);continue}u(s.sku,"product",Math.max(0,s.stock??0),s)}return o}async function h(a){const n=p(a),r=await m(n),o=[...r.keys()];if(o.length===0)return[];let u=await k(n,o);const s=o.filter(t=>!u.has(t)).flatMap(t=>{const e=r.get(t);return e?[{sku:t,quantity:e.stockFallback}]:[]});return s.length>0&&(await y(n,s),u=await k(n,o)),o.flatMap(t=>{const e=r.get(t);return e?{key:t,sku:t,stock:u.get(t)??e.stockFallback,usageType:e.usageType,productTitles:d(e.productTitles),parentProductSkus:d(e.parentProductSkus),languages:d(e.languages),statuses:d(e.statuses),productIds:d(e.productIds),variantIds:d(e.variantIds)}:[]}).sort((t,e)=>t.sku.localeCompare(e.sku)||t.usageType.localeCompare(e.usageType)||t.productTitles.join(", ").localeCompare(e.productTitles.join(", ")))}async function M(a,n){const r=p(n),o=a.sku.trim(),u=Math.max(0,Math.trunc(a.stock));if(!o)throw new Error("SKU is required to update inventory.");await y(r,[{sku:o,quantity:u}]);const t=(await m(r)).get(o),e=(t?.productIds.size??0)+(t?.variantIds.size??0);return{stock:u,affectedCount:e}}async function I(a,n,r){const o=p(r);if(n.variants&&n.variants.length>0){const u=Array.from(n.variants.reduce((s,t)=>(s.set(t.sku.trim(),Math.max(0,Math.trunc(t.stock_quantity))),s),new Map).entries()).map(([s,t])=>({sku:s,quantity:t}));await y(o,u);return}await y(o,[{sku:n.sku,quantity:Math.max(0,Math.trunc(n.stock))}])}exports.getInventoryItems=h;exports.setSharedInventoryQuantity=M;exports.syncSharedInventoryForSavedProduct=I;