@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,136 +1,142 @@
1
- import { Freemius as I } from "@freemius/sdk";
2
- import { hydrateFreemiusEnvFromDb as h } from "./payment-config.es.js";
3
- import { resolveFreemiusCheckoutCredentials as k } from "./providers/freemius.es.js";
4
- const S = "A NextBlock license or trial already exists for this email. Activate that key from CMS Settings → Packages, or purchase a license at nextblock.dev.", g = "The trial could not be provisioned automatically. Start it from CMS Settings → Packages instead.";
5
- function E(e) {
6
- return e.toISOString().slice(0, 19).replace("T", " ");
1
+ import { hydrateFreemiusEnvFromDb as e } from "./payment-config.es.js";
2
+ import { resolveFreemiusCheckoutCredentials as t } from "./providers/freemius.es.js";
3
+ import { Freemius as n } from "@freemius/sdk";
4
+ //#region libs/ecommerce/src/lib/freemius-trial-provision.ts
5
+ var r = "A NextBlock license or trial already exists for this email. Activate that key from CMS Settings → Packages, or purchase a license at nextblock.dev.", i = "The trial could not be provisioned automatically. Start it from CMS Settings → Packages instead.";
6
+ function a(e) {
7
+ return e.toISOString().slice(0, 19).replace("T", " ");
7
8
  }
8
- function v(e, n) {
9
- const i = Number.isFinite(n) && n > 0 ? Math.floor(n) : 30;
10
- return new Date(e.getTime() + i * 24 * 60 * 60 * 1e3);
9
+ function o(e, t) {
10
+ let n = Number.isFinite(t) && t > 0 ? Math.floor(t) : 30;
11
+ return new Date(e.getTime() + n * 24 * 60 * 60 * 1e3);
11
12
  }
12
- function w(e) {
13
- const n = e.filter((t) => t.id !== null && t.id !== void 0);
14
- if (n.length === 0)
15
- return null;
16
- const i = n.filter((t) => !t.is_hidden);
17
- return [...i.length > 0 ? i : n].sort((t, s) => {
18
- const l = t.licenses === null || t.licenses === void 0 ? Number.POSITIVE_INFINITY : t.licenses, u = s.licenses === null || s.licenses === void 0 ? Number.POSITIVE_INFINITY : s.licenses;
19
- return l - u;
20
- })[0];
13
+ function s(e) {
14
+ let t = e.filter((e) => e.id !== null && e.id !== void 0);
15
+ if (t.length === 0) return null;
16
+ let n = t.filter((e) => !e.is_hidden);
17
+ return [...n.length > 0 ? n : t].sort((e, t) => (e.licenses === null || e.licenses === void 0 ? Infinity : e.licenses) - (t.licenses === null || t.licenses === void 0 ? Infinity : t.licenses))[0];
21
18
  }
22
- function F(e) {
23
- return e.existingLicenses.some(
24
- (i) => i.plugin_id === null || i.plugin_id === void 0 || String(i.plugin_id).trim() === String(e.productId).trim()
25
- ) ? { ok: !1, reason: "already_licensed" } : { ok: !0 };
19
+ function c(e) {
20
+ return e.existingLicenses.some((t) => t.plugin_id === null || t.plugin_id === void 0 || String(t.plugin_id).trim() === String(e.productId).trim()) ? {
21
+ ok: !1,
22
+ reason: "already_licensed"
23
+ } : { ok: !0 };
26
24
  }
27
- function b(e) {
28
- return e.trim().toLowerCase();
25
+ function l(e) {
26
+ return e.trim().toLowerCase();
29
27
  }
30
- async function x(e, n) {
31
- await h();
32
- const i = k(e.productId);
33
- if (!i.apiKey || !i.secretKey || !i.publicKey)
34
- return {
35
- error: "The license service is not configured for this product.",
36
- ok: !1,
37
- reason: "not_configured",
38
- status: 503
39
- };
40
- const c = new I({
41
- apiKey: i.apiKey,
42
- productId: Number(e.productId),
43
- publicKey: i.publicKey,
44
- secretKey: i.secretKey
45
- }), t = b(e.email), s = c.api.__unstable_ApiClient, l = { product_id: e.productId };
46
- let u = [];
47
- try {
48
- const r = await c.api.user.retrieveByEmail(t);
49
- r?.id !== null && r?.id !== void 0 && (u = await c.api.user.retrieveLicenses(r.id));
50
- } catch (r) {
51
- return console.error("[Freemius trial] user lookup failed:", r), {
52
- error: "Freemius could not be reached to verify eligibility.",
53
- ok: !1,
54
- reason: "upstream_error",
55
- status: 502
56
- };
57
- }
58
- if (!F({ existingLicenses: u, productId: e.productId }).ok)
59
- return { error: S, ok: !1, reason: "already_licensed", status: 409 };
60
- let d = null;
61
- try {
62
- const { data: r, error: a } = await s.GET("/products/{product_id}/plans/{plan_id}/pricing.json", {
63
- params: { path: { ...l, plan_id: e.planId } }
64
- });
65
- if (a)
66
- throw new Error(JSON.stringify(a));
67
- const o = w(r?.pricing ?? []);
68
- d = o?.id !== null && o?.id !== void 0 ? String(o.id) : null;
69
- } catch (r) {
70
- return console.error("[Freemius trial] pricing lookup failed:", r), {
71
- error: "Freemius could not be reached to resolve the plan pricing.",
72
- ok: !1,
73
- reason: "upstream_error",
74
- status: 502
75
- };
76
- }
77
- if (!d)
78
- return {
79
- error: g,
80
- ok: !1,
81
- reason: "no_pricing",
82
- status: 502
83
- };
84
- const y = n?.now ?? /* @__PURE__ */ new Date(), m = E(v(y, e.trialDays));
85
- let p = null, f = null;
86
- try {
87
- const { data: r, error: a } = await s.POST(
88
- "/products/{product_id}/plans/{plan_id}/pricing/{pricing_id}/licenses.json",
89
- {
90
- body: { expires_at: m, is_block_features: !0, send_email: !1 },
91
- params: { path: { ...l, plan_id: e.planId, pricing_id: d } }
92
- }
93
- );
94
- if (a)
95
- throw new Error(JSON.stringify(a));
96
- const o = r?.license;
97
- p = o?.secret_key?.trim() || null, f = o?.id !== null && o?.id !== void 0 ? String(o.id) : null;
98
- } catch (r) {
99
- return console.error("[Freemius trial] license creation failed:", r), {
100
- error: "Freemius could not create the trial license.",
101
- ok: !1,
102
- reason: "upstream_error",
103
- status: 502
104
- };
105
- }
106
- if (!p)
107
- return { error: g, ok: !1, reason: "no_key", status: 502 };
108
- let _ = !1;
109
- try {
110
- const { error: r } = await s.PUT("/products/{product_id}/licenses.json", {
111
- body: { email: t, license_key: p, name: e.name.trim() },
112
- params: { path: l }
113
- });
114
- _ = !r, r && console.warn("[Freemius trial] license assignment refused:", JSON.stringify(r));
115
- } catch (r) {
116
- console.warn("[Freemius trial] license assignment failed:", r);
117
- }
118
- return {
119
- assigned: _,
120
- expiresAt: m,
121
- licenseId: f,
122
- licenseKey: p,
123
- ok: !0,
124
- planId: e.planId,
125
- pricingId: d
126
- };
28
+ async function u(u, d) {
29
+ await e();
30
+ let f = t(u.productId);
31
+ if (!f.apiKey || !f.secretKey || !f.publicKey) return {
32
+ error: "The license service is not configured for this product.",
33
+ ok: !1,
34
+ reason: "not_configured",
35
+ status: 503
36
+ };
37
+ let p = new n({
38
+ apiKey: f.apiKey,
39
+ productId: Number(u.productId),
40
+ publicKey: f.publicKey,
41
+ secretKey: f.secretKey
42
+ }), m = l(u.email), h = p.api.__unstable_ApiClient, g = { product_id: u.productId }, _ = [];
43
+ try {
44
+ let e = await p.api.user.retrieveByEmail(m);
45
+ e?.id !== null && e?.id !== void 0 && (_ = await p.api.user.retrieveLicenses(e.id));
46
+ } catch (e) {
47
+ return console.error("[Freemius trial] user lookup failed:", e), {
48
+ error: "Freemius could not be reached to verify eligibility.",
49
+ ok: !1,
50
+ reason: "upstream_error",
51
+ status: 502
52
+ };
53
+ }
54
+ if (!c({
55
+ existingLicenses: _,
56
+ productId: u.productId
57
+ }).ok) return {
58
+ error: r,
59
+ ok: !1,
60
+ reason: "already_licensed",
61
+ status: 409
62
+ };
63
+ let v = null;
64
+ try {
65
+ let { data: e, error: t } = await h.GET("/products/{product_id}/plans/{plan_id}/pricing.json", { params: { path: {
66
+ ...g,
67
+ plan_id: u.planId
68
+ } } });
69
+ if (t) throw Error(JSON.stringify(t));
70
+ let n = s(e?.pricing ?? []);
71
+ v = n?.id !== null && n?.id !== void 0 ? String(n.id) : null;
72
+ } catch (e) {
73
+ return console.error("[Freemius trial] pricing lookup failed:", e), {
74
+ error: "Freemius could not be reached to resolve the plan pricing.",
75
+ ok: !1,
76
+ reason: "upstream_error",
77
+ status: 502
78
+ };
79
+ }
80
+ if (!v) return {
81
+ error: i,
82
+ ok: !1,
83
+ reason: "no_pricing",
84
+ status: 502
85
+ };
86
+ let y = a(o(d?.now ?? /* @__PURE__ */ new Date(), u.trialDays)), b = null, x = null;
87
+ try {
88
+ let { data: e, error: t } = await h.POST("/products/{product_id}/plans/{plan_id}/pricing/{pricing_id}/licenses.json", {
89
+ body: {
90
+ expires_at: y,
91
+ is_block_features: !0,
92
+ send_email: !1
93
+ },
94
+ params: { path: {
95
+ ...g,
96
+ plan_id: u.planId,
97
+ pricing_id: v
98
+ } }
99
+ });
100
+ if (t) throw Error(JSON.stringify(t));
101
+ let n = e?.license;
102
+ b = n?.secret_key?.trim() || null, x = n?.id !== null && n?.id !== void 0 ? String(n.id) : null;
103
+ } catch (e) {
104
+ return console.error("[Freemius trial] license creation failed:", e), {
105
+ error: "Freemius could not create the trial license.",
106
+ ok: !1,
107
+ reason: "upstream_error",
108
+ status: 502
109
+ };
110
+ }
111
+ if (!b) return {
112
+ error: i,
113
+ ok: !1,
114
+ reason: "no_key",
115
+ status: 502
116
+ };
117
+ let S = !1;
118
+ try {
119
+ let { error: e } = await h.PUT("/products/{product_id}/licenses.json", {
120
+ body: {
121
+ email: m,
122
+ license_key: b,
123
+ name: u.name.trim()
124
+ },
125
+ params: { path: g }
126
+ });
127
+ S = !e, e && console.warn("[Freemius trial] license assignment refused:", JSON.stringify(e));
128
+ } catch (e) {
129
+ console.warn("[Freemius trial] license assignment failed:", e);
130
+ }
131
+ return {
132
+ assigned: S,
133
+ expiresAt: y,
134
+ licenseId: x,
135
+ licenseKey: b,
136
+ ok: !0,
137
+ planId: u.planId,
138
+ pricingId: v
139
+ };
127
140
  }
128
- export {
129
- S as FREEMIUS_TRIAL_ALREADY_USED_MESSAGE,
130
- g as FREEMIUS_TRIAL_PROVISION_FAILED_MESSAGE,
131
- v as computeTrialExpiry,
132
- F as evaluateTrialEligibility,
133
- E as formatFreemiusTimestamp,
134
- w as pickTrialPricing,
135
- x as provisionFreemiusTrialLicense
136
- };
141
+ //#endregion
142
+ export { r as FREEMIUS_TRIAL_ALREADY_USED_MESSAGE, i as FREEMIUS_TRIAL_PROVISION_FAILED_MESSAGE, o as computeTrialExpiry, c as evaluateTrialEligibility, a as formatFreemiusTimestamp, s as pickTrialPricing, u as provisionFreemiusTrialLicense };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o="ecommerce_inventory_settings",r={trackQuantities:!0,enableTaxes:!1,taxCalculationMode:"manual"};function a(e,t=!0){if(typeof e=="boolean")return e;if(typeof e=="string"){const n=e.trim().toLowerCase();if(["true","1","yes","on"].includes(n))return!0;if(["false","0","no","off"].includes(n))return!1}return t}function c(e,t=r.taxCalculationMode){return e==="automatic"?"automatic":e==="manual"?"manual":t}function i(e){if(e&&typeof e=="object"&&!Array.isArray(e)){const t=e;return{trackQuantities:a(t.trackQuantities??t.track_quantities,r.trackQuantities),enableTaxes:a(t.enableTaxes??t.enable_taxes,r.enableTaxes),taxCalculationMode:c(t.taxCalculationMode??t.tax_calculation_mode,r.taxCalculationMode)}}return{trackQuantities:a(e,r.trackQuantities),enableTaxes:r.enableTaxes,taxCalculationMode:r.taxCalculationMode}}async function s(e){const{data:t,error:n}=await e.from("site_settings").select("value").eq("key",o).maybeSingle();return n||!t?r:i(t.value)}async function u(e,t){return e.from("site_settings").upsert({key:o,value:{track_quantities:t.trackQuantities,enable_taxes:t.enableTaxes,tax_calculation_mode:t.taxCalculationMode}})}function l(e){return{error:`${e} is no longer available.`,errorKey:"ecommerce.inventory_item_unavailable",errorParams:{item:e},errorStatus:409}}function m(e,t){return{error:`Only ${t} units remain for ${e}.`,errorKey:"ecommerce.inventory_insufficient",errorParams:{item:e,count:t},errorStatus:409}}exports.DEFAULT_ECOMMERCE_INVENTORY_SETTINGS=r;exports.ECOMMERCE_INVENTORY_SETTINGS_KEY=o;exports.createInventoryInsufficientError=m;exports.createInventoryUnavailableError=l;exports.getEcommerceInventorySettings=s;exports.normalizeEcommerceInventorySettings=i;exports.upsertEcommerceInventorySettings=u;
1
+ var e=`ecommerce_inventory_settings`,t={trackQuantities:!0,enableTaxes:!1,taxCalculationMode:`manual`};function n(e,t=!0){if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=e.trim().toLowerCase();if([`true`,`1`,`yes`,`on`].includes(t))return!0;if([`false`,`0`,`no`,`off`].includes(t))return!1}return t}function r(e,n=t.taxCalculationMode){return e===`automatic`?`automatic`:e===`manual`?`manual`:n}function i(e){if(e&&typeof e==`object`&&!Array.isArray(e)){let i=e;return{trackQuantities:n(i.trackQuantities??i.track_quantities,t.trackQuantities),enableTaxes:n(i.enableTaxes??i.enable_taxes,t.enableTaxes),taxCalculationMode:r(i.taxCalculationMode??i.tax_calculation_mode,t.taxCalculationMode)}}return{trackQuantities:n(e,t.trackQuantities),enableTaxes:t.enableTaxes,taxCalculationMode:t.taxCalculationMode}}async function a(n){let{data:r,error:a}=await n.from(`site_settings`).select(`value`).eq(`key`,e).maybeSingle();return a||!r?t:i(r.value)}async function o(t,n){return t.from(`site_settings`).upsert({key:e,value:{track_quantities:n.trackQuantities,enable_taxes:n.enableTaxes,tax_calculation_mode:n.taxCalculationMode}})}function s(e){return{error:`${e} is no longer available.`,errorKey:`ecommerce.inventory_item_unavailable`,errorParams:{item:e},errorStatus:409}}function c(e,t){return{error:`Only ${t} units remain for ${e}.`,errorKey:`ecommerce.inventory_insufficient`,errorParams:{item:e,count:t},errorStatus:409}}exports.DEFAULT_ECOMMERCE_INVENTORY_SETTINGS=t,exports.ECOMMERCE_INVENTORY_SETTINGS_KEY=e,exports.createInventoryInsufficientError=c,exports.createInventoryUnavailableError=s,exports.getEcommerceInventorySettings=a,exports.normalizeEcommerceInventorySettings=i,exports.upsertEcommerceInventorySettings=o;
@@ -1,86 +1,78 @@
1
- const o = "ecommerce_inventory_settings", a = {
2
- trackQuantities: !0,
3
- enableTaxes: !1,
4
- taxCalculationMode: "manual"
1
+ //#region libs/ecommerce/src/lib/inventory-settings.ts
2
+ var e = "ecommerce_inventory_settings", t = {
3
+ trackQuantities: !0,
4
+ enableTaxes: !1,
5
+ taxCalculationMode: "manual"
5
6
  };
6
7
  function n(e, t = !0) {
7
- if (typeof e == "boolean")
8
- return e;
9
- if (typeof e == "string") {
10
- const r = e.trim().toLowerCase();
11
- if (["true", "1", "yes", "on"].includes(r))
12
- return !0;
13
- if (["false", "0", "no", "off"].includes(r))
14
- return !1;
15
- }
16
- return t;
8
+ if (typeof e == "boolean") return e;
9
+ if (typeof e == "string") {
10
+ let t = e.trim().toLowerCase();
11
+ if ([
12
+ "true",
13
+ "1",
14
+ "yes",
15
+ "on"
16
+ ].includes(t)) return !0;
17
+ if ([
18
+ "false",
19
+ "0",
20
+ "no",
21
+ "off"
22
+ ].includes(t)) return !1;
23
+ }
24
+ return t;
17
25
  }
18
- function i(e, t = a.taxCalculationMode) {
19
- return e === "automatic" ? "automatic" : e === "manual" ? "manual" : t;
26
+ function r(e, n = t.taxCalculationMode) {
27
+ return e === "automatic" ? "automatic" : e === "manual" ? "manual" : n;
20
28
  }
21
- function c(e) {
22
- if (e && typeof e == "object" && !Array.isArray(e)) {
23
- const t = e;
24
- return {
25
- trackQuantities: n(
26
- t.trackQuantities ?? t.track_quantities,
27
- a.trackQuantities
28
- ),
29
- enableTaxes: n(
30
- t.enableTaxes ?? t.enable_taxes,
31
- a.enableTaxes
32
- ),
33
- taxCalculationMode: i(
34
- t.taxCalculationMode ?? t.tax_calculation_mode,
35
- a.taxCalculationMode
36
- )
37
- };
38
- }
39
- return {
40
- trackQuantities: n(
41
- e,
42
- a.trackQuantities
43
- ),
44
- enableTaxes: a.enableTaxes,
45
- taxCalculationMode: a.taxCalculationMode
46
- };
29
+ function i(e) {
30
+ if (e && typeof e == "object" && !Array.isArray(e)) {
31
+ let i = e;
32
+ return {
33
+ trackQuantities: n(i.trackQuantities ?? i.track_quantities, t.trackQuantities),
34
+ enableTaxes: n(i.enableTaxes ?? i.enable_taxes, t.enableTaxes),
35
+ taxCalculationMode: r(i.taxCalculationMode ?? i.tax_calculation_mode, t.taxCalculationMode)
36
+ };
37
+ }
38
+ return {
39
+ trackQuantities: n(e, t.trackQuantities),
40
+ enableTaxes: t.enableTaxes,
41
+ taxCalculationMode: t.taxCalculationMode
42
+ };
47
43
  }
48
- async function u(e) {
49
- const { data: t, error: r } = await e.from("site_settings").select("value").eq("key", o).maybeSingle();
50
- return r || !t ? a : c(t.value);
44
+ async function a(n) {
45
+ let { data: r, error: a } = await n.from("site_settings").select("value").eq("key", e).maybeSingle();
46
+ return a || !r ? t : i(r.value);
51
47
  }
52
- async function s(e, t) {
53
- return e.from("site_settings").upsert({
54
- key: o,
55
- value: {
56
- track_quantities: t.trackQuantities,
57
- enable_taxes: t.enableTaxes,
58
- tax_calculation_mode: t.taxCalculationMode
59
- }
60
- });
48
+ async function o(t, n) {
49
+ return t.from("site_settings").upsert({
50
+ key: e,
51
+ value: {
52
+ track_quantities: n.trackQuantities,
53
+ enable_taxes: n.enableTaxes,
54
+ tax_calculation_mode: n.taxCalculationMode
55
+ }
56
+ });
61
57
  }
62
- function l(e) {
63
- return {
64
- error: `${e} is no longer available.`,
65
- errorKey: "ecommerce.inventory_item_unavailable",
66
- errorParams: { item: e },
67
- errorStatus: 409
68
- };
58
+ function s(e) {
59
+ return {
60
+ error: `${e} is no longer available.`,
61
+ errorKey: "ecommerce.inventory_item_unavailable",
62
+ errorParams: { item: e },
63
+ errorStatus: 409
64
+ };
69
65
  }
70
- function f(e, t) {
71
- return {
72
- error: `Only ${t} units remain for ${e}.`,
73
- errorKey: "ecommerce.inventory_insufficient",
74
- errorParams: { item: e, count: t },
75
- errorStatus: 409
76
- };
66
+ function c(e, t) {
67
+ return {
68
+ error: `Only ${t} units remain for ${e}.`,
69
+ errorKey: "ecommerce.inventory_insufficient",
70
+ errorParams: {
71
+ item: e,
72
+ count: t
73
+ },
74
+ errorStatus: 409
75
+ };
77
76
  }
78
- export {
79
- a as DEFAULT_ECOMMERCE_INVENTORY_SETTINGS,
80
- o as ECOMMERCE_INVENTORY_SETTINGS_KEY,
81
- f as createInventoryInsufficientError,
82
- l as createInventoryUnavailableError,
83
- u as getEcommerceInventorySettings,
84
- c as normalizeEcommerceInventorySettings,
85
- s as upsertEcommerceInventorySettings
86
- };
77
+ //#endregion
78
+ export { t as DEFAULT_ECOMMERCE_INVENTORY_SETTINGS, e as ECOMMERCE_INVENTORY_SETTINGS_KEY, c as createInventoryInsufficientError, s as createInventoryUnavailableError, a as getEcommerceInventorySettings, i as normalizeEcommerceInventorySettings, o as upsertEcommerceInventorySettings };
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("@nextblock-cms/db/server"),h=require("./customer.cjs.js"),d=require("./invoice.cjs.js"),T=require("./order-tax-details.cjs.js");function w(e){return e?e.startsWith("http")||e.startsWith("/")?e:process.env.NEXT_PUBLIC_R2_BASE_URL?`${process.env.NEXT_PUBLIC_R2_BASE_URL}/${e}`:process.env.NEXT_PUBLIC_SUPABASE_URL?`${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/media/${e}`:e:null}function c(e){return e??E.getServiceRoleSupabaseClient()}function L(e){if(!e)return null;const o=e.media?.object_key??e.media?.file_path??null;return{id:e.id,name:e.name??null,url:w(o),width:e.media?.width??null,height:e.media?.height??null}}const U="active_logo_id",p=`
1
+ const e=require("./customer.cjs.js"),t=require("./invoice.cjs.js"),n=require("./order-tax-details.cjs.js");let r=require("@nextblock-cms/db/server");function i(e){return e?e.startsWith(`http`)||e.startsWith(`/`)?e:process.env.NEXT_PUBLIC_R2_BASE_URL?`${process.env.NEXT_PUBLIC_R2_BASE_URL}/${e}`:process.env.NEXT_PUBLIC_SUPABASE_URL?`${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/public/media/${e}`:e:null}function a(e){return e??(0,r.getServiceRoleSupabaseClient)()}function o(e){if(!e)return null;let t=e.media?.object_key??e.media?.file_path??null;return{id:e.id,name:e.name??null,url:i(t),width:e.media?.width??null,height:e.media?.height??null}}var s=`active_logo_id`,c=`
2
2
  id,
3
3
  name,
4
4
  media:media_id (
@@ -7,7 +7,7 @@
7
7
  width,
8
8
  height
9
9
  )
10
- `;async function k(e){const{data:o}=await e.from("site_settings").select("value").eq("key",U).maybeSingle(),n=o?.value,t=typeof n=="string"&&n.length>0?n:null;if(t){const{data:s}=await e.from("logos").select(p).eq("id",t).maybeSingle();if(s)return s}const{data:r}=await e.from("logos").select(p).order("created_at",{ascending:!1}).limit(1).maybeSingle();return r??null}async function g(e){const o=c(e),[n,t]=await Promise.all([o.from("site_settings").select("value").eq("key",d.INVOICE_SETTINGS_KEY).maybeSingle(),k(o)]);return{settings:d.normalizeInvoiceSettings(n.data?.value??d.DEFAULT_INVOICE_SETTINGS),logo:L(t)}}async function O(e){const o=c(e.client),{data:n,error:t}=await o.rpc("assign_order_invoice_metadata",{p_order_id:e.orderId,p_paid_at:e.paidAt??null}).single();if(t)throw new Error(t.message);return{invoiceNumber:n?.invoice_number??null,paidAt:n?.paid_at??null}}async function m(e,o){const n=c(o),{data:t,error:r}=await n.from("orders").select(`
10
+ `;async function l(e){let{data:t}=await e.from(`site_settings`).select(`value`).eq(`key`,s).maybeSingle(),n=t?.value,r=typeof n==`string`&&n.length>0?n:null;if(r){let{data:t}=await e.from(`logos`).select(c).eq(`id`,r).maybeSingle();if(t)return t}let{data:i}=await e.from(`logos`).select(c).order(`created_at`,{ascending:!1}).limit(1).maybeSingle();return i??null}async function u(e){let n=a(e),[r,i]=await Promise.all([n.from(`site_settings`).select(`value`).eq(`key`,t.INVOICE_SETTINGS_KEY).maybeSingle(),l(n)]);return{settings:t.normalizeInvoiceSettings(r.data?.value??t.DEFAULT_INVOICE_SETTINGS),logo:o(i)}}async function d(e){let{data:t,error:n}=await a(e.client).rpc(`assign_order_invoice_metadata`,{p_order_id:e.orderId,p_paid_at:e.paidAt??null}).single();if(n)throw Error(n.message);return{invoiceNumber:t?.invoice_number??null,paidAt:t?.paid_at??null}}async function f(t,r){let i=a(r),{data:o,error:s}=await i.from(`orders`).select(`
11
11
  id,
12
12
  invoice_number,
13
13
  paid_at,
@@ -30,4 +30,4 @@
30
30
  quantity,
31
31
  price_at_purchase
32
32
  )
33
- `).eq("id",e).single();if(r||!t)throw new Error(r?.message||"Order not found");const s=(t.order_items||[]).map(a=>a.product_id).filter(Boolean),u=(t.order_items||[]).map(a=>a.variant_id).filter(Boolean),[v,f]=await Promise.all([s.length?n.from("products").select("id, title, sku").in("id",s):Promise.resolve({data:[],error:null}),u.length?n.from("product_variants").select("id, sku").in("id",u):Promise.resolve({data:[],error:null})]),b=new Map((v.data||[]).map(a=>[a.id,a])),y=new Map((f.data||[]).map(a=>[a.id,a])),_=(t.order_items||[]).map(a=>{const i=a.product_id?b.get(a.product_id):null,l=a.variant_id?y.get(a.variant_id):null,I=i?.title||"Product",S=l?.sku?`SKU: ${l.sku}`:i?.sku?`SKU: ${i.sku}`:null;return{id:a.id,product_id:a.product_id??null,variant_id:a.variant_id??null,title:I,description:S,quantity:a.quantity,unit_amount:a.price_at_purchase,total_amount:a.price_at_purchase*a.quantity,sku:l?.sku??i?.sku??null}});return{id:t.id,invoice_number:t.invoice_number??null,paid_at:t.paid_at??null,created_at:t.created_at??null,currency:t.currency||"usd",status:t.status,provider:t.provider??null,subtotal:typeof t.subtotal=="number"?t.subtotal:_.reduce((a,i)=>a+i.total_amount,0),shipping_total:typeof t.shipping_total=="number"?t.shipping_total:0,discount_total:typeof t.discount_total=="number"?t.discount_total:0,coupon_code:t.coupon_code??null,tax_total:typeof t.tax_total=="number"?t.tax_total:0,total:t.total,customer_details:h.normalizeOrderCustomerDetails(t.customer_details??{}),tax_details:T.normalizeOrderTaxDetails(t.tax_details),items:_}}async function R(e,o){const n=c(o),[t,r]=await Promise.all([m(e,n),g(n)]);return{order:t,settings:r.settings,logo:r.logo}}exports.assignInvoiceMetadata=O;exports.getInvoiceBrandingData=g;exports.getInvoiceOrder=m;exports.getInvoicePresentationData=R;
33
+ `).eq(`id`,t).single();if(s||!o)throw Error(s?.message||`Order not found`);let c=(o.order_items||[]).map(e=>e.product_id).filter(Boolean),l=(o.order_items||[]).map(e=>e.variant_id).filter(Boolean),[u,d]=await Promise.all([c.length?i.from(`products`).select(`id, title, sku`).in(`id`,c):Promise.resolve({data:[],error:null}),l.length?i.from(`product_variants`).select(`id, sku`).in(`id`,l):Promise.resolve({data:[],error:null})]),f=new Map((u.data||[]).map(e=>[e.id,e])),p=new Map((d.data||[]).map(e=>[e.id,e])),m=(o.order_items||[]).map(e=>{let t=e.product_id?f.get(e.product_id):null,n=e.variant_id?p.get(e.variant_id):null,r=t?.title||`Product`,i=n?.sku?`SKU: ${n.sku}`:t?.sku?`SKU: ${t.sku}`:null;return{id:e.id,product_id:e.product_id??null,variant_id:e.variant_id??null,title:r,description:i,quantity:e.quantity,unit_amount:e.price_at_purchase,total_amount:e.price_at_purchase*e.quantity,sku:n?.sku??t?.sku??null}});return{id:o.id,invoice_number:o.invoice_number??null,paid_at:o.paid_at??null,created_at:o.created_at??null,currency:o.currency||`usd`,status:o.status,provider:o.provider??null,subtotal:typeof o.subtotal==`number`?o.subtotal:m.reduce((e,t)=>e+t.total_amount,0),shipping_total:typeof o.shipping_total==`number`?o.shipping_total:0,discount_total:typeof o.discount_total==`number`?o.discount_total:0,coupon_code:o.coupon_code??null,tax_total:typeof o.tax_total==`number`?o.tax_total:0,total:o.total,customer_details:e.normalizeOrderCustomerDetails(o.customer_details??{}),tax_details:n.normalizeOrderTaxDetails(o.tax_details),items:m}}async function p(e,t){let n=a(t),[r,i]=await Promise.all([f(e,n),u(n)]);return{order:r,settings:i.settings,logo:i.logo}}exports.assignInvoiceMetadata=d,exports.getInvoiceBrandingData=u,exports.getInvoiceOrder=f,exports.getInvoicePresentationData=p;