@nextblock-cms/ecom 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/_virtual/_rolldown/runtime.cjs.js +1 -0
  2. package/index.cjs.js +1 -1
  3. package/index.es.js +38 -146
  4. package/lib/CurrencyProvider.cjs.js +1 -1
  5. package/lib/CurrencyProvider.d.ts +1 -1
  6. package/lib/CurrencyProvider.es.js +85 -95
  7. package/lib/PaymentReadinessProvider.cjs.js +1 -1
  8. package/lib/PaymentReadinessProvider.d.ts +1 -1
  9. package/lib/PaymentReadinessProvider.es.js +24 -27
  10. package/lib/cart-store.cjs.js +1 -1
  11. package/lib/cart-store.es.js +109 -121
  12. package/lib/components/AccountNavigationMenu.cjs.js +1 -1
  13. package/lib/components/AccountNavigationMenu.d.ts +1 -1
  14. package/lib/components/AccountNavigationMenu.es.js +36 -50
  15. package/lib/components/AddToCartButton.cjs.js +1 -1
  16. package/lib/components/AddToCartButton.d.ts +1 -1
  17. package/lib/components/AddToCartButton.es.js +94 -89
  18. package/lib/components/Cart.cjs.js +1 -1
  19. package/lib/components/Cart.d.ts +1 -1
  20. package/lib/components/Cart.es.js +261 -180
  21. package/lib/components/CartDrawer.cjs.js +1 -1
  22. package/lib/components/CartDrawer.d.ts +1 -1
  23. package/lib/components/CartDrawer.es.js +218 -148
  24. package/lib/components/CartIcon.cjs.js +1 -1
  25. package/lib/components/CartIcon.d.ts +1 -1
  26. package/lib/components/CartIcon.es.js +33 -35
  27. package/lib/components/Checkout.cjs.js +1 -1
  28. package/lib/components/Checkout.d.ts +1 -1
  29. package/lib/components/Checkout.es.js +1092 -1108
  30. package/lib/components/CouponForm.cjs.js +1 -1
  31. package/lib/components/CouponForm.d.ts +1 -1
  32. package/lib/components/CouponForm.es.js +136 -148
  33. package/lib/components/CurrencySwitcher.cjs.js +1 -1
  34. package/lib/components/CurrencySwitcher.d.ts +1 -1
  35. package/lib/components/CurrencySwitcher.es.js +22 -18
  36. package/lib/components/CustomerProfileForm.cjs.js +1 -1
  37. package/lib/components/CustomerProfileForm.es.js +454 -313
  38. package/lib/components/FeaturedProduct.cjs.js +1 -1
  39. package/lib/components/FeaturedProduct.d.ts +1 -1
  40. package/lib/components/FeaturedProduct.es.js +98 -83
  41. package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
  42. package/lib/components/FreemiusLicensePanel.d.ts +1 -1
  43. package/lib/components/FreemiusLicensePanel.es.js +70 -65
  44. package/lib/components/InvoiceDocument.cjs.js +1 -1
  45. package/lib/components/InvoiceDocument.es.js +256 -192
  46. package/lib/components/InvoiceViewerShell.cjs.js +2 -2
  47. package/lib/components/InvoiceViewerShell.d.ts +1 -1
  48. package/lib/components/InvoiceViewerShell.es.js +75 -106
  49. package/lib/components/ProductCard.cjs.js +1 -1
  50. package/lib/components/ProductCard.d.ts +1 -1
  51. package/lib/components/ProductCard.es.js +186 -171
  52. package/lib/components/ProductDetailsLayout.cjs.js +1 -1
  53. package/lib/components/ProductDetailsLayout.es.js +405 -404
  54. package/lib/components/ProductGallery.cjs.js +1 -1
  55. package/lib/components/ProductGallery.d.ts +1 -1
  56. package/lib/components/ProductGallery.es.js +51 -54
  57. package/lib/components/ProductGrid.cjs.js +1 -1
  58. package/lib/components/ProductGrid.d.ts +1 -1
  59. package/lib/components/ProductGrid.es.js +23 -25
  60. package/lib/components/ShippingEstimator.cjs.js +1 -1
  61. package/lib/components/ShippingEstimator.d.ts +1 -1
  62. package/lib/components/ShippingEstimator.es.js +158 -153
  63. package/lib/components/ShortDescription.cjs.js +1 -1
  64. package/lib/components/ShortDescription.es.js +17 -17
  65. package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
  66. package/lib/components/SimpleTiptapRenderer.es.js +238 -211
  67. package/lib/components/SubscriptionSelector.cjs.js +1 -1
  68. package/lib/components/SubscriptionSelector.es.js +159 -154
  69. package/lib/countries.cjs.js +1 -1
  70. package/lib/countries.es.js +232 -75
  71. package/lib/coupon-server.cjs.js +1 -1
  72. package/lib/coupon-server.es.js +180 -224
  73. package/lib/coupons.cjs.js +1 -1
  74. package/lib/coupons.es.js +12 -14
  75. package/lib/currency-constants.cjs.js +1 -1
  76. package/lib/currency-constants.es.js +4 -4
  77. package/lib/currency-rest-client.cjs.js +1 -1
  78. package/lib/currency-rest-client.es.js +15 -22
  79. package/lib/currency-store.cjs.js +1 -1
  80. package/lib/currency-store.es.js +20 -27
  81. package/lib/currency-sync.cjs.js +1 -1
  82. package/lib/currency-sync.es.js +124 -170
  83. package/lib/currency.cjs.js +1 -1
  84. package/lib/currency.es.js +242 -310
  85. package/lib/customer-addresses.cjs.js +1 -1
  86. package/lib/customer-addresses.es.js +80 -109
  87. package/lib/customer-orders.cjs.js +1 -1
  88. package/lib/customer-orders.es.js +31 -43
  89. package/lib/customer.cjs.js +1 -1
  90. package/lib/customer.es.js +43 -52
  91. package/lib/export-helpers.cjs.js +1 -1
  92. package/lib/export-helpers.es.js +53 -52
  93. package/lib/factory.cjs.js +1 -1
  94. package/lib/factory.es.js +10 -7
  95. package/lib/freemius-coupons.cjs.js +1 -1
  96. package/lib/freemius-coupons.es.js +245 -262
  97. package/lib/freemius-license-claim.cjs.js +1 -1
  98. package/lib/freemius-license-claim.es.js +87 -71
  99. package/lib/freemius-license.cjs.js +1 -1
  100. package/lib/freemius-license.es.js +32 -39
  101. package/lib/freemius-order-sync.cjs.js +1 -1
  102. package/lib/freemius-order-sync.es.js +226 -290
  103. package/lib/freemius-trial-provision.cjs.js +1 -1
  104. package/lib/freemius-trial-provision.es.js +136 -130
  105. package/lib/inventory-settings.cjs.js +1 -1
  106. package/lib/inventory-settings.es.js +69 -77
  107. package/lib/invoice-server.cjs.js +3 -3
  108. package/lib/invoice-server.es.js +94 -141
  109. package/lib/invoice-ui.cjs.js +1 -1
  110. package/lib/invoice-ui.es.js +50 -66
  111. package/lib/invoice.cjs.js +1 -1
  112. package/lib/invoice.es.js +85 -94
  113. package/lib/order-inventory.cjs.js +25 -25
  114. package/lib/order-inventory.es.js +67 -79
  115. package/lib/order-tax-details.cjs.js +1 -1
  116. package/lib/order-tax-details.es.js +142 -153
  117. package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
  118. package/lib/pages/cms/coupons/CouponEditorForm.d.ts +1 -1
  119. package/lib/pages/cms/coupons/CouponEditorForm.es.js +227 -185
  120. package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
  121. package/lib/pages/cms/coupons/CouponsPage.d.ts +1 -1
  122. package/lib/pages/cms/coupons/CouponsPage.es.js +235 -166
  123. package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
  124. package/lib/pages/cms/coupons/CreateCouponDialog.d.ts +1 -1
  125. package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -34
  126. package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
  127. package/lib/pages/cms/coupons/EditCouponPage.d.ts +1 -1
  128. package/lib/pages/cms/coupons/EditCouponPage.es.js +47 -47
  129. package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
  130. package/lib/pages/cms/coupons/ProductScopePicker.d.ts +1 -1
  131. package/lib/pages/cms/coupons/ProductScopePicker.es.js +128 -117
  132. package/lib/pages/cms/coupons/actions.cjs.js +1 -1
  133. package/lib/pages/cms/coupons/actions.es.js +112 -115
  134. package/lib/pages/cms/coupons/index.cjs.js +1 -0
  135. package/lib/pages/cms/coupons/index.es.js +3 -0
  136. package/lib/pages/cms/coupons/product-options.cjs.js +1 -1
  137. package/lib/pages/cms/coupons/product-options.es.js +21 -23
  138. package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
  139. package/lib/pages/cms/orders/ExportReportsDialog.es.js +135 -129
  140. package/lib/pages/cms/orders/MarkPaidButton.d.ts +1 -1
  141. package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
  142. package/lib/pages/cms/orders/OrderDetailPage.d.ts +1 -1
  143. package/lib/pages/cms/orders/OrderDetailPage.es.js +186 -134
  144. package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
  145. package/lib/pages/cms/orders/OrderPrintButton.d.ts +1 -1
  146. package/lib/pages/cms/orders/OrderPrintButton.es.js +15 -21
  147. package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
  148. package/lib/pages/cms/orders/OrderStatusForm.d.ts +1 -1
  149. package/lib/pages/cms/orders/OrderStatusForm.es.js +85 -69
  150. package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
  151. package/lib/pages/cms/orders/OrdersPage.d.ts +1 -1
  152. package/lib/pages/cms/orders/OrdersPage.es.js +170 -102
  153. package/lib/pages/cms/orders/actions.cjs.js +3 -3
  154. package/lib/pages/cms/orders/actions.es.js +53 -69
  155. package/lib/pages/cms/orders/export-actions.cjs.js +1 -1
  156. package/lib/pages/cms/orders/export-actions.es.js +23 -26
  157. package/lib/pages/cms/orders/index.cjs.js +1 -0
  158. package/lib/pages/cms/orders/index.es.js +6 -0
  159. package/lib/pages/cms/orders/server-actions.cjs.js +1 -1
  160. package/lib/pages/cms/orders/server-actions.es.js +60 -51
  161. package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
  162. package/lib/pages/cms/payments/PaymentsClient.d.ts +1 -1
  163. package/lib/pages/cms/payments/PaymentsClient.es.js +316 -346
  164. package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
  165. package/lib/pages/cms/payments/PaymentsPage.d.ts +1 -1
  166. package/lib/pages/cms/payments/PaymentsPage.es.js +29 -32
  167. package/lib/pages/cms/payments/actions.cjs.js +1 -1
  168. package/lib/pages/cms/payments/actions.es.js +38 -48
  169. package/lib/pages/cms/payments/index.cjs.js +1 -0
  170. package/lib/pages/cms/payments/index.es.js +3 -0
  171. package/lib/pages/cms/payments/queries.cjs.js +1 -1
  172. package/lib/pages/cms/payments/queries.es.js +38 -48
  173. package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
  174. package/lib/pages/cms/products/ProductsPage.d.ts +1 -1
  175. package/lib/pages/cms/products/ProductsPage.es.js +63 -66
  176. package/lib/pages/cms/products/[id]/edit/EditProductPage.d.ts +1 -1
  177. package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
  178. package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +138 -155
  179. package/lib/pages/cms/products/actions.cjs.js +4 -4
  180. package/lib/pages/cms/products/actions.es.js +121 -162
  181. package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
  182. package/lib/pages/cms/products/attributes/AttributeManagementPage.d.ts +1 -1
  183. package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +55 -47
  184. package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
  185. package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +1 -1
  186. package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +285 -290
  187. package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
  188. package/lib/pages/cms/products/categories/CategoryManagementPage.d.ts +1 -1
  189. package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +43 -35
  190. package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
  191. package/lib/pages/cms/products/categories/components/CategoryManager.es.js +315 -262
  192. package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
  193. package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +115 -113
  194. package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
  195. package/lib/pages/cms/products/components/CurrencyPriceFields.d.ts +1 -1
  196. package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +136 -145
  197. package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
  198. package/lib/pages/cms/products/components/DeleteProductButton.d.ts +1 -1
  199. package/lib/pages/cms/products/components/DeleteProductButton.es.js +35 -47
  200. package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
  201. package/lib/pages/cms/products/components/FreemiusPricingDashboard.d.ts +1 -1
  202. package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +106 -84
  203. package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
  204. package/lib/pages/cms/products/components/ProductCategorySelector.es.js +156 -159
  205. package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
  206. package/lib/pages/cms/products/components/ProductForm.es.js +872 -693
  207. package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
  208. package/lib/pages/cms/products/components/ProductMediaManager.es.js +106 -103
  209. package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
  210. package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +1 -1
  211. package/lib/pages/cms/products/components/ProductsBulkTable.es.js +303 -294
  212. package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
  213. package/lib/pages/cms/products/components/SaleScheduleFields.d.ts +1 -1
  214. package/lib/pages/cms/products/components/SaleScheduleFields.es.js +111 -134
  215. package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
  216. package/lib/pages/cms/products/components/SyncFreemiusButton.d.ts +1 -1
  217. package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +29 -35
  218. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
  219. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.d.ts +1 -1
  220. package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +36 -48
  221. package/lib/pages/cms/products/components/SyncProductForm.d.ts +1 -1
  222. package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
  223. package/lib/pages/cms/products/components/VariationsEditor.d.ts +1 -1
  224. package/lib/pages/cms/products/components/VariationsEditor.es.js +396 -405
  225. package/lib/pages/cms/products/index.cjs.js +1 -0
  226. package/lib/pages/cms/products/index.es.js +8 -0
  227. package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
  228. package/lib/pages/cms/products/inventory/InventoryPage.d.ts +1 -1
  229. package/lib/pages/cms/products/inventory/InventoryPage.es.js +21 -15
  230. package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
  231. package/lib/pages/cms/products/inventory/InventoryTableClient.d.ts +1 -1
  232. package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +230 -209
  233. package/lib/pages/cms/products/inventory/actions.cjs.js +3 -3
  234. package/lib/pages/cms/products/inventory/actions.es.js +83 -91
  235. package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
  236. package/lib/pages/cms/products/new/NewProductPage.d.ts +1 -1
  237. package/lib/pages/cms/products/new/NewProductPage.es.js +58 -74
  238. package/lib/pages/cms/products/product-price-sync.cjs.js +1 -1
  239. package/lib/pages/cms/products/product-price-sync.es.js +74 -89
  240. package/lib/pages/cms/products/server-actions.cjs.js +1 -1
  241. package/lib/pages/cms/products/server-actions.es.js +250 -233
  242. package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
  243. package/lib/pages/cms/shipping/ShippingPage.es.js +287 -209
  244. package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
  245. package/lib/pages/cms/shipping/components/RateForm.d.ts +1 -1
  246. package/lib/pages/cms/shipping/components/RateForm.es.js +439 -436
  247. package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
  248. package/lib/pages/cms/shipping/components/ZoneForm.es.js +245 -224
  249. package/lib/pages/cms/shipping/index.cjs.js +1 -0
  250. package/lib/pages/cms/shipping/index.es.js +3 -0
  251. package/lib/pages/cms/shipping/server-actions.cjs.js +1 -1
  252. package/lib/pages/cms/shipping/server-actions.es.js +131 -149
  253. package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
  254. package/lib/pages/cms/taxes/TaxesPage.d.ts +1 -1
  255. package/lib/pages/cms/taxes/TaxesPage.es.js +211 -169
  256. package/lib/pages/cms/taxes/actions.cjs.js +1 -1
  257. package/lib/pages/cms/taxes/actions.es.js +41 -53
  258. package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
  259. package/lib/pages/cms/taxes/components/TaxRateForm.d.ts +1 -1
  260. package/lib/pages/cms/taxes/components/TaxRateForm.es.js +112 -99
  261. package/lib/pages/cms/taxes/index.cjs.js +1 -0
  262. package/lib/pages/cms/taxes/index.es.js +3 -0
  263. package/lib/payment-config.cjs.js +1 -1
  264. package/lib/payment-config.es.js +110 -126
  265. package/lib/product-actions.cjs.js +4 -4
  266. package/lib/product-actions.es.js +289 -544
  267. package/lib/product-context.cjs.js +1 -1
  268. package/lib/product-context.es.js +13 -15
  269. package/lib/product-schema.cjs.js +1 -1
  270. package/lib/product-schema.es.js +99 -134
  271. package/lib/providers/freemius.cjs.js +1 -5
  272. package/lib/providers/freemius.es.js +446 -530
  273. package/lib/providers/stripe.cjs.js +1 -1
  274. package/lib/providers/stripe.es.js +417 -477
  275. package/lib/server-actions/coupon-actions.cjs.js +1 -1
  276. package/lib/server-actions/coupon-actions.es.js +22 -22
  277. package/lib/server-actions/customer-actions.cjs.js +1 -1
  278. package/lib/server-actions/customer-actions.es.js +26 -28
  279. package/lib/server-actions/product-actions.cjs.js +1 -1
  280. package/lib/server-actions/product-actions.es.js +9 -15
  281. package/lib/server-actions/shipping-actions.cjs.js +1 -1
  282. package/lib/server-actions/shipping-actions.es.js +27 -24
  283. package/lib/server-actions/tax-actions.cjs.js +1 -1
  284. package/lib/server-actions/tax-actions.es.js +33 -39
  285. package/lib/shared-inventory.cjs.js +2 -2
  286. package/lib/shared-inventory.es.js +111 -160
  287. package/lib/shipping/resolver.cjs.js +2 -2
  288. package/lib/shipping/resolver.es.js +44 -61
  289. package/lib/shipping-rate-currency.cjs.js +1 -1
  290. package/lib/shipping-rate-currency.es.js +52 -67
  291. package/lib/states.cjs.js +1 -1
  292. package/lib/states.es.js +333 -154
  293. package/lib/stripe/checkout.cjs.js +1 -1
  294. package/lib/stripe/checkout.es.js +125 -181
  295. package/lib/stripe/client.cjs.js +1 -1
  296. package/lib/stripe/client.es.js +14 -19
  297. package/lib/stripe/order-sync.cjs.js +1 -1
  298. package/lib/stripe/order-sync.es.js +106 -126
  299. package/lib/stripe/webhooks.cjs.js +1 -1
  300. package/lib/stripe/webhooks.es.js +37 -31
  301. package/lib/tax-calculation.cjs.js +1 -1
  302. package/lib/tax-calculation.es.js +84 -98
  303. package/lib/trials.cjs.js +1 -1
  304. package/lib/trials.es.js +24 -30
  305. package/lib/types.cjs.js +1 -1
  306. package/lib/types.es.js +21 -27
  307. package/lib/use-cart.cjs.js +1 -1
  308. package/lib/use-cart.es.js +38 -40
  309. package/lib/use-price-formatter.cjs.js +1 -1
  310. package/lib/use-price-formatter.es.js +10 -11
  311. package/lib/variation-utils.cjs.js +1 -1
  312. package/lib/variation-utils.es.js +199 -261
  313. package/lib/zod-config.cjs.js +1 -1
  314. package/lib/zod-config.es.js +5 -6
  315. package/package.json +16 -16
  316. package/server.cjs.js +1 -1
  317. package/server.es.js +56 -211
@@ -1,61 +1,61 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("server-only");const l=require("postgres"),c=require("./inventory-settings.cjs.js");function y(){return process.env.POSTGRES_URL||process.env.DATABASE_URL||null}async function _(r){const n=y();if(!n)throw new Error("Missing POSTGRES_URL or DATABASE_URL for inventory fallback");const e=l(n,{ssl:"require",onnotice:()=>{}});try{await e.begin(async o=>{const t=o,s=(await t`
1
+ const e=require("../_virtual/_rolldown/runtime.cjs.js"),t=require("./inventory-settings.cjs.js");require("server-only");let n=require("postgres");n=e.__toESM(n,1);function r(){return process.env.POSTGRES_URL||process.env.DATABASE_URL||null}async function i(e){let i=r();if(!i)throw Error(`Missing POSTGRES_URL or DATABASE_URL for inventory fallback`);let a=(0,n.default)(i,{ssl:`require`,onnotice:()=>{}});try{await a.begin(async n=>{let r=n,i=(await r`
2
2
  SELECT inventory_deducted_at
3
3
  FROM public.orders
4
- WHERE id = ${r}
4
+ WHERE id = ${e}
5
5
  FOR UPDATE
6
- `)[0];if(!s||s.inventory_deducted_at)return;const u=await t`
6
+ `)[0];if(!i||i.inventory_deducted_at)return;let a=await r`
7
7
  SELECT value
8
8
  FROM public.site_settings
9
- WHERE key = ${c.ECOMMERCE_INVENTORY_SETTINGS_KEY}
9
+ WHERE key = ${t.ECOMMERCE_INVENTORY_SETTINGS_KEY}
10
10
  LIMIT 1
11
- `;if(!c.normalizeEcommerceInventorySettings(u[0]?.value).trackQuantities){await t`
11
+ `;if(!t.normalizeEcommerceInventorySettings(a[0]?.value).trackQuantities){await r`
12
12
  UPDATE public.orders
13
13
  SET inventory_deducted_at = now()
14
- WHERE id = ${r}
15
- `;return}const E=await t`
14
+ WHERE id = ${e}
15
+ `;return}let o=await r`
16
16
  SELECT
17
17
  product_id,
18
18
  variant_id,
19
19
  SUM(quantity)::integer AS quantity
20
20
  FROM public.order_items
21
- WHERE order_id = ${r}
21
+ WHERE order_id = ${e}
22
22
  GROUP BY product_id, variant_id
23
- `;for(const a of E){if(a.variant_id){const i=(await t`
23
+ `;for(let e of o){if(e.variant_id){let t=(await r`
24
24
  SELECT
25
25
  sku,
26
26
  stock_quantity
27
27
  FROM public.product_variants
28
- WHERE id = ${a.variant_id}
28
+ WHERE id = ${e.variant_id}
29
29
  LIMIT 1
30
- `)[0];if(!i?.sku)continue;await t`
30
+ `)[0];if(!t?.sku)continue;await r`
31
31
  INSERT INTO public.inventory_items (sku, quantity)
32
- VALUES (${i.sku}, ${Math.max(0,i.stock_quantity??0)})
32
+ VALUES (${t.sku}, ${Math.max(0,t.stock_quantity??0)})
33
33
  ON CONFLICT (sku) DO NOTHING
34
- `,await t`
34
+ `,await r`
35
35
  UPDATE public.inventory_items
36
36
  SET
37
- quantity = GREATEST(COALESCE(quantity, 0) - ${a.quantity}, 0),
37
+ quantity = GREATEST(COALESCE(quantity, 0) - ${e.quantity}, 0),
38
38
  updated_at = now()
39
- WHERE sku = ${i.sku}
40
- `;continue}if(a.product_id){const i=(await t`
39
+ WHERE sku = ${t.sku}
40
+ `;continue}if(e.product_id){let t=(await r`
41
41
  SELECT
42
42
  sku,
43
43
  stock
44
44
  FROM public.products
45
- WHERE id = ${a.product_id}
45
+ WHERE id = ${e.product_id}
46
46
  LIMIT 1
47
- `)[0];if(!i?.sku)continue;await t`
47
+ `)[0];if(!t?.sku)continue;await r`
48
48
  INSERT INTO public.inventory_items (sku, quantity)
49
- VALUES (${i.sku}, ${Math.max(0,i.stock??0)})
49
+ VALUES (${t.sku}, ${Math.max(0,t.stock??0)})
50
50
  ON CONFLICT (sku) DO NOTHING
51
- `,await t`
51
+ `,await r`
52
52
  UPDATE public.inventory_items
53
53
  SET
54
- quantity = GREATEST(COALESCE(quantity, 0) - ${a.quantity}, 0),
54
+ quantity = GREATEST(COALESCE(quantity, 0) - ${e.quantity}, 0),
55
55
  updated_at = now()
56
- WHERE sku = ${i.sku}
57
- `}}await t`
56
+ WHERE sku = ${t.sku}
57
+ `}}await r`
58
58
  UPDATE public.orders
59
59
  SET inventory_deducted_at = now()
60
- WHERE id = ${r}
61
- `})}finally{await e.end()}}async function p(r,n){const{error:e}=await r.rpc("apply_order_inventory_deduction",{p_order_id:n});if(!e)return{method:"rpc"};console.error(`[Inventory] RPC deduction failed for order ${n}:`,e);try{return await _(n),{method:"sql-fallback"}}catch(o){const t=o instanceof Error?o.message:String(o);throw new Error(`Failed to reconcile inventory for order ${n}. RPC error: ${e.message}. Fallback error: ${t}`)}}exports.applyOrderInventoryDeduction=p;
60
+ WHERE id = ${e}
61
+ `})}finally{await a.end()}}async function a(e,t){let{error:n}=await e.rpc(`apply_order_inventory_deduction`,{p_order_id:t});if(!n)return{method:`rpc`};console.error(`[Inventory] RPC deduction failed for order ${t}:`,n);try{return await i(t),{method:`sql-fallback`}}catch(e){let r=e instanceof Error?e.message:String(e);throw Error(`Failed to reconcile inventory for order ${t}. RPC error: ${n.message}. Fallback error: ${r}`)}}exports.applyOrderInventoryDeduction=a;
@@ -1,128 +1,116 @@
1
+ import { ECOMMERCE_INVENTORY_SETTINGS_KEY as e, normalizeEcommerceInventorySettings as t } from "./inventory-settings.es.js";
1
2
  import "server-only";
2
- import d from "postgres";
3
- import { ECOMMERCE_INVENTORY_SETTINGS_KEY as l, normalizeEcommerceInventorySettings as _ } from "./inventory-settings.es.js";
4
- function p() {
5
- return process.env.POSTGRES_URL || process.env.DATABASE_URL || null;
3
+ import n from "postgres";
4
+ //#region libs/ecommerce/src/lib/order-inventory.ts
5
+ function r() {
6
+ return process.env.POSTGRES_URL || process.env.DATABASE_URL || null;
6
7
  }
7
- async function y(r) {
8
- const n = p();
9
- if (!n)
10
- throw new Error("Missing POSTGRES_URL or DATABASE_URL for inventory fallback");
11
- const a = d(n, {
12
- ssl: "require",
13
- onnotice: () => {
14
- }
15
- });
16
- try {
17
- await a.begin(async (e) => {
18
- const t = e, s = (await t`
8
+ async function i(i) {
9
+ let a = r();
10
+ if (!a) throw Error("Missing POSTGRES_URL or DATABASE_URL for inventory fallback");
11
+ let o = n(a, {
12
+ ssl: "require",
13
+ onnotice: () => {}
14
+ });
15
+ try {
16
+ await o.begin(async (n) => {
17
+ let r = n, a = (await r`
19
18
  SELECT inventory_deducted_at
20
19
  FROM public.orders
21
- WHERE id = ${r}
20
+ WHERE id = ${i}
22
21
  FOR UPDATE
23
22
  `)[0];
24
- if (!s || s.inventory_deducted_at)
25
- return;
26
- const c = await t`
23
+ if (!a || a.inventory_deducted_at) return;
24
+ let o = await r`
27
25
  SELECT value
28
26
  FROM public.site_settings
29
- WHERE key = ${l}
27
+ WHERE key = ${e}
30
28
  LIMIT 1
31
29
  `;
32
- if (!_(
33
- c[0]?.value
34
- ).trackQuantities) {
35
- await t`
30
+ if (!t(o[0]?.value).trackQuantities) {
31
+ await r`
36
32
  UPDATE public.orders
37
33
  SET inventory_deducted_at = now()
38
- WHERE id = ${r}
34
+ WHERE id = ${i}
39
35
  `;
40
- return;
41
- }
42
- const u = await t`
36
+ return;
37
+ }
38
+ let s = await r`
43
39
  SELECT
44
40
  product_id,
45
41
  variant_id,
46
42
  SUM(quantity)::integer AS quantity
47
43
  FROM public.order_items
48
- WHERE order_id = ${r}
44
+ WHERE order_id = ${i}
49
45
  GROUP BY product_id, variant_id
50
46
  `;
51
- for (const o of u) {
52
- if (o.variant_id) {
53
- const i = (await t`
47
+ for (let e of s) {
48
+ if (e.variant_id) {
49
+ let t = (await r`
54
50
  SELECT
55
51
  sku,
56
52
  stock_quantity
57
53
  FROM public.product_variants
58
- WHERE id = ${o.variant_id}
54
+ WHERE id = ${e.variant_id}
59
55
  LIMIT 1
60
56
  `)[0];
61
- if (!i?.sku)
62
- continue;
63
- await t`
57
+ if (!t?.sku) continue;
58
+ await r`
64
59
  INSERT INTO public.inventory_items (sku, quantity)
65
- VALUES (${i.sku}, ${Math.max(0, i.stock_quantity ?? 0)})
60
+ VALUES (${t.sku}, ${Math.max(0, t.stock_quantity ?? 0)})
66
61
  ON CONFLICT (sku) DO NOTHING
67
- `, await t`
62
+ `, await r`
68
63
  UPDATE public.inventory_items
69
64
  SET
70
- quantity = GREATEST(COALESCE(quantity, 0) - ${o.quantity}, 0),
65
+ quantity = GREATEST(COALESCE(quantity, 0) - ${e.quantity}, 0),
71
66
  updated_at = now()
72
- WHERE sku = ${i.sku}
67
+ WHERE sku = ${t.sku}
73
68
  `;
74
- continue;
75
- }
76
- if (o.product_id) {
77
- const i = (await t`
69
+ continue;
70
+ }
71
+ if (e.product_id) {
72
+ let t = (await r`
78
73
  SELECT
79
74
  sku,
80
75
  stock
81
76
  FROM public.products
82
- WHERE id = ${o.product_id}
77
+ WHERE id = ${e.product_id}
83
78
  LIMIT 1
84
79
  `)[0];
85
- if (!i?.sku)
86
- continue;
87
- await t`
80
+ if (!t?.sku) continue;
81
+ await r`
88
82
  INSERT INTO public.inventory_items (sku, quantity)
89
- VALUES (${i.sku}, ${Math.max(0, i.stock ?? 0)})
83
+ VALUES (${t.sku}, ${Math.max(0, t.stock ?? 0)})
90
84
  ON CONFLICT (sku) DO NOTHING
91
- `, await t`
85
+ `, await r`
92
86
  UPDATE public.inventory_items
93
87
  SET
94
- quantity = GREATEST(COALESCE(quantity, 0) - ${o.quantity}, 0),
88
+ quantity = GREATEST(COALESCE(quantity, 0) - ${e.quantity}, 0),
95
89
  updated_at = now()
96
- WHERE sku = ${i.sku}
90
+ WHERE sku = ${t.sku}
97
91
  `;
98
- }
99
- }
100
- await t`
92
+ }
93
+ }
94
+ await r`
101
95
  UPDATE public.orders
102
96
  SET inventory_deducted_at = now()
103
- WHERE id = ${r}
97
+ WHERE id = ${i}
104
98
  `;
105
- });
106
- } finally {
107
- await a.end();
108
- }
99
+ });
100
+ } finally {
101
+ await o.end();
102
+ }
109
103
  }
110
- async function v(r, n) {
111
- const { error: a } = await r.rpc("apply_order_inventory_deduction", {
112
- p_order_id: n
113
- });
114
- if (!a)
115
- return { method: "rpc" };
116
- console.error(`[Inventory] RPC deduction failed for order ${n}:`, a);
117
- try {
118
- return await y(n), { method: "sql-fallback" };
119
- } catch (e) {
120
- const t = e instanceof Error ? e.message : String(e);
121
- throw new Error(
122
- `Failed to reconcile inventory for order ${n}. RPC error: ${a.message}. Fallback error: ${t}`
123
- );
124
- }
104
+ async function a(e, t) {
105
+ let { error: n } = await e.rpc("apply_order_inventory_deduction", { p_order_id: t });
106
+ if (!n) return { method: "rpc" };
107
+ console.error(`[Inventory] RPC deduction failed for order ${t}:`, n);
108
+ try {
109
+ return await i(t), { method: "sql-fallback" };
110
+ } catch (e) {
111
+ let r = e instanceof Error ? e.message : String(e);
112
+ throw Error(`Failed to reconcile inventory for order ${t}. RPC error: ${n.message}. Fallback error: ${r}`);
113
+ }
125
114
  }
126
- export {
127
- v as applyOrderInventoryDeduction
128
- };
115
+ //#endregion
116
+ export { a as applyOrderInventoryDeduction };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m={gst:"GST",qst:"QST",hst:"HST",pst:"PST",vat:"VAT",sales_tax:"Sales Tax",amusement_tax:"Amusement Tax",retail_delivery_fee:"Retail Delivery Fee"};function c(){return new Date().toISOString()}function l(t){const e=t.tax_type?.trim().toLowerCase();return e&&m[e]?m[e]:t.display_name||"Tax"}function s(t){return typeof t.effective_percentage=="number"?t.effective_percentage:typeof t.percentage=="number"?t.percentage:null}function f(t){return t.jurisdiction?t.jurisdiction:[t.state,t.country].filter(Boolean).join(", ")||null}function p(t){return JSON.stringify({source:t.source,rate_id:t.rate.id??null,display_name:l(t.rate),percentage:s(t.rate),jurisdiction:f(t.rate),jurisdiction_level:t.rate.jurisdiction_level??null,country:t.rate.country??null,state:t.rate.state??null,tax_type:t.rate.tax_type??null,inclusive:t.rate.inclusive??null})}function u(t){const e=new Map;for(const o of t){const n=p(o),a=e.get(n);if(!a){e.set(n,{...o,scope:"aggregate",line_item_id:null});continue}a.amount+=o.amount,typeof a.taxable_amount=="number"||typeof o.taxable_amount=="number"?a.taxable_amount=(typeof a.taxable_amount=="number"?a.taxable_amount:0)+(typeof o.taxable_amount=="number"?o.taxable_amount:0):a.taxable_amount=null,a.description!==o.description&&(a.description=null),a.taxability_reason!==o.taxability_reason&&(a.taxability_reason=null)}return[...e.values()].sort((o,n)=>{const a=l(o.rate).localeCompare(l(n.rate));return a!==0?a:(s(o.rate)??0)-(s(n.rate)??0)})}function x(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const e=t;return typeof e.currency!="string"?null:{source:e.source==="manual"||e.source==="stripe_checkout"||e.source==="none"?e.source:"none",mode:e.mode==="automatic"?"automatic":"manual",currency:e.currency,subtotal:typeof e.subtotal=="number"?e.subtotal:0,shipping_total:typeof e.shipping_total=="number"?e.shipping_total:0,tax_total:typeof e.tax_total=="number"?e.tax_total:0,total:typeof e.total=="number"?e.total:0,is_finalized:!!e.is_finalized,lines:Array.isArray(e.lines)?u(e.lines):[],updated_at:typeof e.updated_at=="string"?e.updated_at:c()}}function g(t){const e=t.currency||"usd",o=t.calculation.mode==="manual"&&!t.calculation.isPendingExternalCalculation;return{source:t.calculation.enabled&&t.calculation.mode==="manual"?"manual":t.calculation.mode==="automatic"?"stripe_checkout":"none",mode:t.calculation.mode,currency:e,subtotal:t.subtotal,shipping_total:t.shippingTotal,tax_total:t.calculation.amount,total:t.total,is_finalized:o,lines:t.calculation.enabled&&t.calculation.mode==="manual"?t.calculation.lines.map(n=>({scope:"aggregate",source:"manual",amount:n.amount,taxable_amount:t.calculation.taxableSubtotal,description:n.name,rate:{id:n.id??null,display_name:n.name,percentage:n.rate,country:n.country_code,state:n.state_code??null}})):[],updated_at:c()}}function _(t){return{id:t.id,display_name:t.display_name,percentage:t.percentage,effective_percentage:t.effective_percentage,jurisdiction:t.jurisdiction,jurisdiction_level:t.jurisdiction_level,country:t.country,state:t.state,tax_type:t.tax_type,inclusive:t.inclusive,description:t.description}}function y(t){const e=t.currency||t.session.currency||"usd",o=typeof t.session.amount_total=="number"?t.session.amount_total:0,n=t.session.total_details?.amount_tax??0,a=[];for(const r of t.lineItems)for(const i of r.taxes||[])a.push({scope:"line_item",source:"stripe_checkout",amount:i.amount,taxable_amount:i.taxable_amount,description:r.description||void 0,line_item_id:r.id,taxability_reason:i.taxability_reason,rate:_(i.rate)});if(a.length===0)for(const r of t.session.total_details?.breakdown?.taxes||[])a.push({scope:"aggregate",source:"stripe_checkout",amount:r.amount,taxable_amount:r.taxable_amount,description:r.rate.display_name,taxability_reason:r.taxability_reason,rate:_(r.rate)});const d=u(a);return{source:n>0||d.length>0?"stripe_checkout":"none",mode:t.fallbackMode==="manual"?"manual":"automatic",currency:e,subtotal:t.subtotal,shipping_total:t.shippingTotal,tax_total:n,total:o,is_finalized:!0,lines:d,updated_at:c()}}exports.aggregateOrderTaxLines=u;exports.buildOrderTaxDetailsFromCalculation=g;exports.buildOrderTaxDetailsFromStripeSession=y;exports.getOrderTaxRateJurisdiction=f;exports.getOrderTaxRateLabel=l;exports.getOrderTaxRatePercentage=s;exports.normalizeOrderTaxDetails=x;
1
+ var e={gst:`GST`,qst:`QST`,hst:`HST`,pst:`PST`,vat:`VAT`,sales_tax:`Sales Tax`,amusement_tax:`Amusement Tax`,retail_delivery_fee:`Retail Delivery Fee`};function t(){return new Date().toISOString()}function n(t){let n=t.tax_type?.trim().toLowerCase();return n&&e[n]?e[n]:t.display_name||`Tax`}function r(e){return typeof e.effective_percentage==`number`?e.effective_percentage:typeof e.percentage==`number`?e.percentage:null}function i(e){return e.jurisdiction?e.jurisdiction:[e.state,e.country].filter(Boolean).join(`, `)||null}function a(e){return JSON.stringify({source:e.source,rate_id:e.rate.id??null,display_name:n(e.rate),percentage:r(e.rate),jurisdiction:i(e.rate),jurisdiction_level:e.rate.jurisdiction_level??null,country:e.rate.country??null,state:e.rate.state??null,tax_type:e.rate.tax_type??null,inclusive:e.rate.inclusive??null})}function o(e){let t=new Map;for(let n of e){let e=a(n),r=t.get(e);if(!r){t.set(e,{...n,scope:`aggregate`,line_item_id:null});continue}r.amount+=n.amount,r.taxable_amount=typeof r.taxable_amount==`number`||typeof n.taxable_amount==`number`?(typeof r.taxable_amount==`number`?r.taxable_amount:0)+(typeof n.taxable_amount==`number`?n.taxable_amount:0):null,r.description!==n.description&&(r.description=null),r.taxability_reason!==n.taxability_reason&&(r.taxability_reason=null)}return[...t.values()].sort((e,t)=>{let i=n(e.rate).localeCompare(n(t.rate));return i===0?(r(e.rate)??0)-(r(t.rate)??0):i})}function s(e){if(!e||typeof e!=`object`||Array.isArray(e))return null;let n=e;return typeof n.currency==`string`?{source:n.source===`manual`||n.source===`stripe_checkout`||n.source===`none`?n.source:`none`,mode:n.mode===`automatic`?`automatic`:`manual`,currency:n.currency,subtotal:typeof n.subtotal==`number`?n.subtotal:0,shipping_total:typeof n.shipping_total==`number`?n.shipping_total:0,tax_total:typeof n.tax_total==`number`?n.tax_total:0,total:typeof n.total==`number`?n.total:0,is_finalized:!!n.is_finalized,lines:Array.isArray(n.lines)?o(n.lines):[],updated_at:typeof n.updated_at==`string`?n.updated_at:t()}:null}function c(e){let n=e.currency||`usd`,r=e.calculation.mode===`manual`&&!e.calculation.isPendingExternalCalculation;return{source:e.calculation.enabled&&e.calculation.mode===`manual`?`manual`:e.calculation.mode===`automatic`?`stripe_checkout`:`none`,mode:e.calculation.mode,currency:n,subtotal:e.subtotal,shipping_total:e.shippingTotal,tax_total:e.calculation.amount,total:e.total,is_finalized:r,lines:e.calculation.enabled&&e.calculation.mode===`manual`?e.calculation.lines.map(t=>({scope:`aggregate`,source:`manual`,amount:t.amount,taxable_amount:e.calculation.taxableSubtotal,description:t.name,rate:{id:t.id??null,display_name:t.name,percentage:t.rate,country:t.country_code,state:t.state_code??null}})):[],updated_at:t()}}function l(e){return{id:e.id,display_name:e.display_name,percentage:e.percentage,effective_percentage:e.effective_percentage,jurisdiction:e.jurisdiction,jurisdiction_level:e.jurisdiction_level,country:e.country,state:e.state,tax_type:e.tax_type,inclusive:e.inclusive,description:e.description}}function u(e){let n=e.currency||e.session.currency||`usd`,r=typeof e.session.amount_total==`number`?e.session.amount_total:0,i=e.session.total_details?.amount_tax??0,a=[];for(let t of e.lineItems)for(let e of t.taxes||[])a.push({scope:`line_item`,source:`stripe_checkout`,amount:e.amount,taxable_amount:e.taxable_amount,description:t.description||void 0,line_item_id:t.id,taxability_reason:e.taxability_reason,rate:l(e.rate)});if(a.length===0)for(let t of e.session.total_details?.breakdown?.taxes||[])a.push({scope:`aggregate`,source:`stripe_checkout`,amount:t.amount,taxable_amount:t.taxable_amount,description:t.rate.display_name,taxability_reason:t.taxability_reason,rate:l(t.rate)});let s=o(a);return{source:i>0||s.length>0?`stripe_checkout`:`none`,mode:e.fallbackMode===`manual`?`manual`:`automatic`,currency:n,subtotal:e.subtotal,shipping_total:e.shippingTotal,tax_total:i,total:r,is_finalized:!0,lines:s,updated_at:t()}}exports.aggregateOrderTaxLines=o,exports.buildOrderTaxDetailsFromCalculation=c,exports.buildOrderTaxDetailsFromStripeSession=u,exports.getOrderTaxRateJurisdiction=i,exports.getOrderTaxRateLabel=n,exports.getOrderTaxRatePercentage=r,exports.normalizeOrderTaxDetails=s;
@@ -1,164 +1,153 @@
1
- const d = {
2
- gst: "GST",
3
- qst: "QST",
4
- hst: "HST",
5
- pst: "PST",
6
- vat: "VAT",
7
- sales_tax: "Sales Tax",
8
- amusement_tax: "Amusement Tax",
9
- retail_delivery_fee: "Retail Delivery Fee"
1
+ //#region libs/ecommerce/src/lib/order-tax-details.ts
2
+ var e = {
3
+ gst: "GST",
4
+ qst: "QST",
5
+ hst: "HST",
6
+ pst: "PST",
7
+ vat: "VAT",
8
+ sales_tax: "Sales Tax",
9
+ amusement_tax: "Amusement Tax",
10
+ retail_delivery_fee: "Retail Delivery Fee"
10
11
  };
11
- function c() {
12
- return (/* @__PURE__ */ new Date()).toISOString();
12
+ function t() {
13
+ return (/* @__PURE__ */ new Date()).toISOString();
13
14
  }
14
- function l(t) {
15
- const e = t.tax_type?.trim().toLowerCase();
16
- return e && d[e] ? d[e] : t.display_name || "Tax";
15
+ function n(t) {
16
+ let n = t.tax_type?.trim().toLowerCase();
17
+ return n && e[n] ? e[n] : t.display_name || "Tax";
17
18
  }
18
- function s(t) {
19
- return typeof t.effective_percentage == "number" ? t.effective_percentage : typeof t.percentage == "number" ? t.percentage : null;
19
+ function r(e) {
20
+ return typeof e.effective_percentage == "number" ? e.effective_percentage : typeof e.percentage == "number" ? e.percentage : null;
20
21
  }
21
- function f(t) {
22
- return t.jurisdiction ? t.jurisdiction : [t.state, t.country].filter(Boolean).join(", ") || null;
22
+ function i(e) {
23
+ return e.jurisdiction ? e.jurisdiction : [e.state, e.country].filter(Boolean).join(", ") || null;
23
24
  }
24
- function p(t) {
25
- return JSON.stringify({
26
- source: t.source,
27
- rate_id: t.rate.id ?? null,
28
- display_name: l(t.rate),
29
- percentage: s(t.rate),
30
- jurisdiction: f(t.rate),
31
- jurisdiction_level: t.rate.jurisdiction_level ?? null,
32
- country: t.rate.country ?? null,
33
- state: t.rate.state ?? null,
34
- tax_type: t.rate.tax_type ?? null,
35
- inclusive: t.rate.inclusive ?? null
36
- });
25
+ function a(e) {
26
+ return JSON.stringify({
27
+ source: e.source,
28
+ rate_id: e.rate.id ?? null,
29
+ display_name: n(e.rate),
30
+ percentage: r(e.rate),
31
+ jurisdiction: i(e.rate),
32
+ jurisdiction_level: e.rate.jurisdiction_level ?? null,
33
+ country: e.rate.country ?? null,
34
+ state: e.rate.state ?? null,
35
+ tax_type: e.rate.tax_type ?? null,
36
+ inclusive: e.rate.inclusive ?? null
37
+ });
37
38
  }
38
- function _(t) {
39
- const e = /* @__PURE__ */ new Map();
40
- for (const o of t) {
41
- const n = p(o), a = e.get(n);
42
- if (!a) {
43
- e.set(n, {
44
- ...o,
45
- scope: "aggregate",
46
- line_item_id: null
47
- });
48
- continue;
49
- }
50
- a.amount += o.amount, typeof a.taxable_amount == "number" || typeof o.taxable_amount == "number" ? a.taxable_amount = (typeof a.taxable_amount == "number" ? a.taxable_amount : 0) + (typeof o.taxable_amount == "number" ? o.taxable_amount : 0) : a.taxable_amount = null, a.description !== o.description && (a.description = null), a.taxability_reason !== o.taxability_reason && (a.taxability_reason = null);
51
- }
52
- return [...e.values()].sort((o, n) => {
53
- const a = l(o.rate).localeCompare(l(n.rate));
54
- return a !== 0 ? a : (s(o.rate) ?? 0) - (s(n.rate) ?? 0);
55
- });
39
+ function o(e) {
40
+ let t = /* @__PURE__ */ new Map();
41
+ for (let n of e) {
42
+ let e = a(n), r = t.get(e);
43
+ if (!r) {
44
+ t.set(e, {
45
+ ...n,
46
+ scope: "aggregate",
47
+ line_item_id: null
48
+ });
49
+ continue;
50
+ }
51
+ r.amount += n.amount, r.taxable_amount = typeof r.taxable_amount == "number" || typeof n.taxable_amount == "number" ? (typeof r.taxable_amount == "number" ? r.taxable_amount : 0) + (typeof n.taxable_amount == "number" ? n.taxable_amount : 0) : null, r.description !== n.description && (r.description = null), r.taxability_reason !== n.taxability_reason && (r.taxability_reason = null);
52
+ }
53
+ return [...t.values()].sort((e, t) => {
54
+ let i = n(e.rate).localeCompare(n(t.rate));
55
+ return i === 0 ? (r(e.rate) ?? 0) - (r(t.rate) ?? 0) : i;
56
+ });
56
57
  }
57
- function y(t) {
58
- if (!t || typeof t != "object" || Array.isArray(t))
59
- return null;
60
- const e = t;
61
- return typeof e.currency != "string" ? null : {
62
- source: e.source === "manual" || e.source === "stripe_checkout" || e.source === "none" ? e.source : "none",
63
- mode: e.mode === "automatic" ? "automatic" : "manual",
64
- currency: e.currency,
65
- subtotal: typeof e.subtotal == "number" ? e.subtotal : 0,
66
- shipping_total: typeof e.shipping_total == "number" ? e.shipping_total : 0,
67
- tax_total: typeof e.tax_total == "number" ? e.tax_total : 0,
68
- total: typeof e.total == "number" ? e.total : 0,
69
- is_finalized: !!e.is_finalized,
70
- lines: Array.isArray(e.lines) ? _(e.lines) : [],
71
- updated_at: typeof e.updated_at == "string" ? e.updated_at : c()
72
- };
58
+ function s(e) {
59
+ if (!e || typeof e != "object" || Array.isArray(e)) return null;
60
+ let n = e;
61
+ return typeof n.currency == "string" ? {
62
+ source: n.source === "manual" || n.source === "stripe_checkout" || n.source === "none" ? n.source : "none",
63
+ mode: n.mode === "automatic" ? "automatic" : "manual",
64
+ currency: n.currency,
65
+ subtotal: typeof n.subtotal == "number" ? n.subtotal : 0,
66
+ shipping_total: typeof n.shipping_total == "number" ? n.shipping_total : 0,
67
+ tax_total: typeof n.tax_total == "number" ? n.tax_total : 0,
68
+ total: typeof n.total == "number" ? n.total : 0,
69
+ is_finalized: !!n.is_finalized,
70
+ lines: Array.isArray(n.lines) ? o(n.lines) : [],
71
+ updated_at: typeof n.updated_at == "string" ? n.updated_at : t()
72
+ } : null;
73
73
  }
74
- function x(t) {
75
- const e = t.currency || "usd", o = t.calculation.mode === "manual" && !t.calculation.isPendingExternalCalculation;
76
- return {
77
- source: t.calculation.enabled && t.calculation.mode === "manual" ? "manual" : t.calculation.mode === "automatic" ? "stripe_checkout" : "none",
78
- mode: t.calculation.mode,
79
- currency: e,
80
- subtotal: t.subtotal,
81
- shipping_total: t.shippingTotal,
82
- tax_total: t.calculation.amount,
83
- total: t.total,
84
- is_finalized: o,
85
- lines: t.calculation.enabled && t.calculation.mode === "manual" ? t.calculation.lines.map((n) => ({
86
- scope: "aggregate",
87
- source: "manual",
88
- amount: n.amount,
89
- taxable_amount: t.calculation.taxableSubtotal,
90
- description: n.name,
91
- rate: {
92
- id: n.id ?? null,
93
- display_name: n.name,
94
- percentage: n.rate,
95
- country: n.country_code,
96
- state: n.state_code ?? null
97
- }
98
- })) : [],
99
- updated_at: c()
100
- };
74
+ function c(e) {
75
+ let n = e.currency || "usd", r = e.calculation.mode === "manual" && !e.calculation.isPendingExternalCalculation;
76
+ return {
77
+ source: e.calculation.enabled && e.calculation.mode === "manual" ? "manual" : e.calculation.mode === "automatic" ? "stripe_checkout" : "none",
78
+ mode: e.calculation.mode,
79
+ currency: n,
80
+ subtotal: e.subtotal,
81
+ shipping_total: e.shippingTotal,
82
+ tax_total: e.calculation.amount,
83
+ total: e.total,
84
+ is_finalized: r,
85
+ lines: e.calculation.enabled && e.calculation.mode === "manual" ? e.calculation.lines.map((t) => ({
86
+ scope: "aggregate",
87
+ source: "manual",
88
+ amount: t.amount,
89
+ taxable_amount: e.calculation.taxableSubtotal,
90
+ description: t.name,
91
+ rate: {
92
+ id: t.id ?? null,
93
+ display_name: t.name,
94
+ percentage: t.rate,
95
+ country: t.country_code,
96
+ state: t.state_code ?? null
97
+ }
98
+ })) : [],
99
+ updated_at: t()
100
+ };
101
101
  }
102
- function m(t) {
103
- return {
104
- id: t.id,
105
- display_name: t.display_name,
106
- percentage: t.percentage,
107
- effective_percentage: t.effective_percentage,
108
- jurisdiction: t.jurisdiction,
109
- jurisdiction_level: t.jurisdiction_level,
110
- country: t.country,
111
- state: t.state,
112
- tax_type: t.tax_type,
113
- inclusive: t.inclusive,
114
- description: t.description
115
- };
102
+ function l(e) {
103
+ return {
104
+ id: e.id,
105
+ display_name: e.display_name,
106
+ percentage: e.percentage,
107
+ effective_percentage: e.effective_percentage,
108
+ jurisdiction: e.jurisdiction,
109
+ jurisdiction_level: e.jurisdiction_level,
110
+ country: e.country,
111
+ state: e.state,
112
+ tax_type: e.tax_type,
113
+ inclusive: e.inclusive,
114
+ description: e.description
115
+ };
116
116
  }
117
- function b(t) {
118
- const e = t.currency || t.session.currency || "usd", o = typeof t.session.amount_total == "number" ? t.session.amount_total : 0, n = t.session.total_details?.amount_tax ?? 0, a = [];
119
- for (const i of t.lineItems)
120
- for (const r of i.taxes || [])
121
- a.push({
122
- scope: "line_item",
123
- source: "stripe_checkout",
124
- amount: r.amount,
125
- taxable_amount: r.taxable_amount,
126
- description: i.description || void 0,
127
- line_item_id: i.id,
128
- taxability_reason: r.taxability_reason,
129
- rate: m(r.rate)
130
- });
131
- if (a.length === 0)
132
- for (const i of t.session.total_details?.breakdown?.taxes || [])
133
- a.push({
134
- scope: "aggregate",
135
- source: "stripe_checkout",
136
- amount: i.amount,
137
- taxable_amount: i.taxable_amount,
138
- description: i.rate.display_name,
139
- taxability_reason: i.taxability_reason,
140
- rate: m(i.rate)
141
- });
142
- const u = _(a);
143
- return {
144
- source: n > 0 || u.length > 0 ? "stripe_checkout" : "none",
145
- mode: t.fallbackMode === "manual" ? "manual" : "automatic",
146
- currency: e,
147
- subtotal: t.subtotal,
148
- shipping_total: t.shippingTotal,
149
- tax_total: n,
150
- total: o,
151
- is_finalized: !0,
152
- lines: u,
153
- updated_at: c()
154
- };
117
+ function u(e) {
118
+ let n = e.currency || e.session.currency || "usd", r = typeof e.session.amount_total == "number" ? e.session.amount_total : 0, i = e.session.total_details?.amount_tax ?? 0, a = [];
119
+ for (let t of e.lineItems) for (let e of t.taxes || []) a.push({
120
+ scope: "line_item",
121
+ source: "stripe_checkout",
122
+ amount: e.amount,
123
+ taxable_amount: e.taxable_amount,
124
+ description: t.description || void 0,
125
+ line_item_id: t.id,
126
+ taxability_reason: e.taxability_reason,
127
+ rate: l(e.rate)
128
+ });
129
+ if (a.length === 0) for (let t of e.session.total_details?.breakdown?.taxes || []) a.push({
130
+ scope: "aggregate",
131
+ source: "stripe_checkout",
132
+ amount: t.amount,
133
+ taxable_amount: t.taxable_amount,
134
+ description: t.rate.display_name,
135
+ taxability_reason: t.taxability_reason,
136
+ rate: l(t.rate)
137
+ });
138
+ let s = o(a);
139
+ return {
140
+ source: i > 0 || s.length > 0 ? "stripe_checkout" : "none",
141
+ mode: e.fallbackMode === "manual" ? "manual" : "automatic",
142
+ currency: n,
143
+ subtotal: e.subtotal,
144
+ shipping_total: e.shippingTotal,
145
+ tax_total: i,
146
+ total: r,
147
+ is_finalized: !0,
148
+ lines: s,
149
+ updated_at: t()
150
+ };
155
151
  }
156
- export {
157
- _ as aggregateOrderTaxLines,
158
- x as buildOrderTaxDetailsFromCalculation,
159
- b as buildOrderTaxDetailsFromStripeSession,
160
- f as getOrderTaxRateJurisdiction,
161
- l as getOrderTaxRateLabel,
162
- s as getOrderTaxRatePercentage,
163
- y as normalizeOrderTaxDetails
164
- };
152
+ //#endregion
153
+ export { o as aggregateOrderTaxLines, c as buildOrderTaxDetailsFromCalculation, u as buildOrderTaxDetailsFromStripeSession, i as getOrderTaxRateJurisdiction, n as getOrderTaxRateLabel, r as getOrderTaxRatePercentage, s as normalizeOrderTaxDetails };