@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,100 +1,113 @@
1
- 'use client';
2
- import { jsxs as t, jsx as r } from "react/jsx-runtime";
3
- import { Label as c, Input as a, Button as S } from "@nextblock-cms/ui";
4
- import { useState as p, useMemo as b } from "react";
5
- import { normalizeCountryCode as i, countries as _ } from "../../../../countries.es.js";
6
- import { normalizeSubdivisionCode as N, getStatesForCountry as x, countryUsesStructuredStates as $ } from "../../../../states.es.js";
7
- import { saveTaxRateAction as F } from "../actions.es.js";
8
- function q({
9
- initialData: e,
10
- submitLabel: h = "Save tax rate",
11
- compact: u = !1
12
- }) {
13
- const m = i(e?.country_code) || "US", [o, y] = p(m), [s, n] = p(
14
- N(m, e?.state_code) || e?.state_code || ""
15
- ), f = b(() => x(o), [o]), v = $(o);
16
- return /* @__PURE__ */ t("form", { action: F, className: "space-y-4", children: [
17
- e?.id ? /* @__PURE__ */ r("input", { type: "hidden", name: "id", value: e.id }) : null,
18
- /* @__PURE__ */ t("div", { className: u ? "grid gap-4 md:grid-cols-4" : "grid gap-4 md:grid-cols-2 xl:grid-cols-4", children: [
19
- /* @__PURE__ */ t("div", { className: "space-y-2", children: [
20
- /* @__PURE__ */ r(c, { htmlFor: e?.id ? `country-${e.id}` : "tax-rate-country", children: "Country" }),
21
- /* @__PURE__ */ r(
22
- "select",
23
- {
24
- id: e?.id ? `country-${e.id}` : "tax-rate-country",
25
- name: "country_code",
26
- value: o,
27
- onChange: (d) => {
28
- const l = d.target.value, g = x(l);
29
- y(l), n(
30
- g.some((C) => C.code === s) ? s : ""
31
- );
32
- },
33
- className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
34
- children: _.map((d) => /* @__PURE__ */ r("option", { value: d.code, children: d.name }, d.code))
35
- }
36
- )
37
- ] }),
38
- /* @__PURE__ */ t("div", { className: "space-y-2", children: [
39
- /* @__PURE__ */ r(c, { htmlFor: e?.id ? `state-${e.id}` : "tax-rate-state", children: "State / Province" }),
40
- v ? /* @__PURE__ */ t(
41
- "select",
42
- {
43
- id: e?.id ? `state-${e.id}` : "tax-rate-state",
44
- name: "state_code",
45
- value: s,
46
- onChange: (d) => n(d.target.value),
47
- className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
48
- children: [
49
- /* @__PURE__ */ r("option", { value: "", children: "Country-wide / federal" }),
50
- f.map((d) => /* @__PURE__ */ r("option", { value: d.code, children: d.name }, d.code))
51
- ]
52
- }
53
- ) : /* @__PURE__ */ r(
54
- a,
55
- {
56
- id: e?.id ? `state-${e.id}` : "tax-rate-state",
57
- name: "state_code",
58
- value: s,
59
- onChange: (d) => n(d.target.value),
60
- placeholder: "Optional"
61
- }
62
- )
63
- ] }),
64
- /* @__PURE__ */ t("div", { className: "space-y-2", children: [
65
- /* @__PURE__ */ r(c, { htmlFor: e?.id ? `name-${e.id}` : "tax-rate-name", children: "Tax name" }),
66
- /* @__PURE__ */ r(
67
- a,
68
- {
69
- id: e?.id ? `name-${e.id}` : "tax-rate-name",
70
- name: "tax_name",
71
- defaultValue: e?.tax_name || "",
72
- placeholder: "GST, PST, State Sales Tax",
73
- required: !0
74
- }
75
- )
76
- ] }),
77
- /* @__PURE__ */ t("div", { className: "space-y-2", children: [
78
- /* @__PURE__ */ r(c, { htmlFor: e?.id ? `rate-${e.id}` : "tax-rate-rate", children: "Rate (%)" }),
79
- /* @__PURE__ */ r(
80
- a,
81
- {
82
- id: e?.id ? `rate-${e.id}` : "tax-rate-rate",
83
- name: "tax_rate",
84
- type: "number",
85
- min: "0",
86
- max: "100",
87
- step: "0.0001",
88
- defaultValue: typeof e?.tax_rate == "number" ? e.tax_rate.toString() : "",
89
- placeholder: "5.0000",
90
- required: !0
91
- }
92
- )
93
- ] })
94
- ] }),
95
- /* @__PURE__ */ r("div", { className: "flex justify-end", children: /* @__PURE__ */ r(S, { type: "submit", size: u ? "sm" : "default", children: h }) })
96
- ] });
1
+ "use client";
2
+ import { countries as e, normalizeCountryCode as t } from "../../../../countries.es.js";
3
+ import { countryUsesStructuredStates as n, getStatesForCountry as r, normalizeSubdivisionCode as i } from "../../../../states.es.js";
4
+ import { saveTaxRateAction as a } from "../actions.es.js";
5
+ import { useMemo as o, useState as s } from "react";
6
+ import { jsx as c, jsxs as l } from "react/jsx-runtime";
7
+ import { Button as u, Input as d, Label as f } from "@nextblock-cms/ui";
8
+ //#region libs/ecommerce/src/lib/pages/cms/taxes/components/TaxRateForm.tsx
9
+ function p({ initialData: p, submitLabel: m = "Save tax rate", compact: h = !1 }) {
10
+ let g = t(p?.country_code) || "US", [_, v] = s(g), [y, b] = s(i(g, p?.state_code) || p?.state_code || ""), x = o(() => r(_), [_]), S = n(_);
11
+ return /* @__PURE__ */ l("form", {
12
+ action: a,
13
+ className: "space-y-4",
14
+ children: [
15
+ p?.id ? /* @__PURE__ */ c("input", {
16
+ type: "hidden",
17
+ name: "id",
18
+ value: p.id
19
+ }) : null,
20
+ /* @__PURE__ */ l("div", {
21
+ className: h ? "grid gap-4 md:grid-cols-4" : "grid gap-4 md:grid-cols-2 xl:grid-cols-4",
22
+ children: [
23
+ /* @__PURE__ */ l("div", {
24
+ className: "space-y-2",
25
+ children: [/* @__PURE__ */ c(f, {
26
+ htmlFor: p?.id ? `country-${p.id}` : "tax-rate-country",
27
+ children: "Country"
28
+ }), /* @__PURE__ */ c("select", {
29
+ id: p?.id ? `country-${p.id}` : "tax-rate-country",
30
+ name: "country_code",
31
+ value: _,
32
+ onChange: (e) => {
33
+ let t = e.target.value, n = r(t);
34
+ v(t), b(n.some((e) => e.code === y) ? y : "");
35
+ },
36
+ className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
37
+ children: e.map((e) => /* @__PURE__ */ c("option", {
38
+ value: e.code,
39
+ children: e.name
40
+ }, e.code))
41
+ })]
42
+ }),
43
+ /* @__PURE__ */ l("div", {
44
+ className: "space-y-2",
45
+ children: [/* @__PURE__ */ c(f, {
46
+ htmlFor: p?.id ? `state-${p.id}` : "tax-rate-state",
47
+ children: "State / Province"
48
+ }), S ? /* @__PURE__ */ l("select", {
49
+ id: p?.id ? `state-${p.id}` : "tax-rate-state",
50
+ name: "state_code",
51
+ value: y,
52
+ onChange: (e) => b(e.target.value),
53
+ className: "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
54
+ children: [/* @__PURE__ */ c("option", {
55
+ value: "",
56
+ children: "Country-wide / federal"
57
+ }), x.map((e) => /* @__PURE__ */ c("option", {
58
+ value: e.code,
59
+ children: e.name
60
+ }, e.code))]
61
+ }) : /* @__PURE__ */ c(d, {
62
+ id: p?.id ? `state-${p.id}` : "tax-rate-state",
63
+ name: "state_code",
64
+ value: y,
65
+ onChange: (e) => b(e.target.value),
66
+ placeholder: "Optional"
67
+ })]
68
+ }),
69
+ /* @__PURE__ */ l("div", {
70
+ className: "space-y-2",
71
+ children: [/* @__PURE__ */ c(f, {
72
+ htmlFor: p?.id ? `name-${p.id}` : "tax-rate-name",
73
+ children: "Tax name"
74
+ }), /* @__PURE__ */ c(d, {
75
+ id: p?.id ? `name-${p.id}` : "tax-rate-name",
76
+ name: "tax_name",
77
+ defaultValue: p?.tax_name || "",
78
+ placeholder: "GST, PST, State Sales Tax",
79
+ required: !0
80
+ })]
81
+ }),
82
+ /* @__PURE__ */ l("div", {
83
+ className: "space-y-2",
84
+ children: [/* @__PURE__ */ c(f, {
85
+ htmlFor: p?.id ? `rate-${p.id}` : "tax-rate-rate",
86
+ children: "Rate (%)"
87
+ }), /* @__PURE__ */ c(d, {
88
+ id: p?.id ? `rate-${p.id}` : "tax-rate-rate",
89
+ name: "tax_rate",
90
+ type: "number",
91
+ min: "0",
92
+ max: "100",
93
+ step: "0.0001",
94
+ defaultValue: typeof p?.tax_rate == "number" ? p.tax_rate.toString() : "",
95
+ placeholder: "5.0000",
96
+ required: !0
97
+ })]
98
+ })
99
+ ]
100
+ }),
101
+ /* @__PURE__ */ c("div", {
102
+ className: "flex justify-end",
103
+ children: /* @__PURE__ */ c(u, {
104
+ type: "submit",
105
+ size: h ? "sm" : "default",
106
+ children: m
107
+ })
108
+ })
109
+ ]
110
+ });
97
111
  }
98
- export {
99
- q as TaxRateForm
100
- };
112
+ //#endregion
113
+ export { p as TaxRateForm };
@@ -0,0 +1 @@
1
+ const e=require("./actions.cjs.js"),t=require("./TaxesPage.cjs.js");exports.TaxesPage=t.TaxesPage,exports.deleteTaxRateAction=e.deleteTaxRateAction,exports.saveTaxRateAction=e.saveTaxRateAction,exports.updateTaxSettingsAction=e.updateTaxSettingsAction;
@@ -0,0 +1,3 @@
1
+ import { deleteTaxRateAction as e, saveTaxRateAction as t, updateTaxSettingsAction as n } from "./actions.es.js";
2
+ import { TaxesPage as r } from "./TaxesPage.es.js";
3
+ export { r as TaxesPage, e as deleteTaxRateAction, t as saveTaxRateAction, n as updateTaxSettingsAction };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@nextblock-cms/db/server"),E="payment_secret",f="payment_public",K=6e4;let u=null;function a(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}async function S(e=!1){const r=Date.now();if(!e&&u&&r-u.at<K)return{secret:u.secret,public:u.public};let i={},t={};try{const n=s.getServiceRoleSupabaseClient(),[{data:o},{data:c}]=await Promise.all([n.from("site_settings").select("value").eq("key",E).maybeSingle(),n.from("site_settings").select("value").eq("key",f).maybeSingle()]);i=a(o?.value),t=a(c?.value)}catch{}return u={at:r,secret:i,public:t},{secret:i,public:t}}function d(){u=null}function l(e,r){return s.tryDecryptWithEnvKey(e[r])}async function h(){const{secret:e}=await S();return s.resolveConfigValue(l(e,"stripeSecretKey"),"STRIPE_SECRET_KEY")}async function _(){const{secret:e}=await S();return s.resolveConfigValue(l(e,"stripeWebhookSecret"),"STRIPE_WEBHOOK_SECRET")}async function v(){const{public:e}=await S(),r=a(e.stripe).publishableKey;return s.resolveConfigValue(typeof r=="string"?r:null,"NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY")}async function C(){try{const{secret:e,public:r}=await S(),i=a(r.freemius),t=(n,o)=>{o&&o.trim()&&(process.env[n]=o.trim())};t("FREEMIUS_SECRET_KEY",l(e,"freemiusSecretKey")),t("FREEMIUS_API_KEY",l(e,"freemiusApiKey")),t("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY",l(e,"freemiusSandboxSecretKey")),t("FREEMIUS_PUBLIC_KEY",typeof i.publicKey=="string"?i.publicKey:null),t("FREEMIUS_PRODUCT_ID",typeof i.productId=="string"?i.productId:null),t("FREEMIUS_DEVELOPER_ID",typeof i.developerId=="string"?i.developerId:null)}catch(e){console.warn("[payment-config] Could not hydrate Freemius credentials from the database:",e)}}async function P(){const{secret:e,public:r}=await S(),i=a(r.freemius),t=a(r.stripe),n=[];s.resolveConfigValue(l(e,"stripeSecretKey"),"STRIPE_SECRET_KEY")||n.push("Secret key"),s.resolveConfigValue(typeof t.publishableKey=="string"?t.publishableKey:null,"NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY")||n.push("Publishable key"),s.resolveConfigValue(l(e,"stripeWebhookSecret"),"STRIPE_WEBHOOK_SECRET")||n.push("Webhook secret");const o=[];return s.resolveConfigValue(typeof i.publicKey=="string"?i.publicKey:null,"FREEMIUS_PUBLIC_KEY")||o.push("Public key"),s.resolveConfigValue(l(e,"freemiusSecretKey"),"FREEMIUS_SECRET_KEY")||o.push("Secret key"),{stripe:{hasKeys:n.length===0,missing:n},freemius:{hasKeys:o.length===0,missing:o}}}async function I(){const e=s.createClient(),[{data:r},{data:i}]=await Promise.all([e.from("site_settings").select("value").eq("key",E).maybeSingle(),e.from("site_settings").select("value").eq("key",f).maybeSingle()]),t=a(r?.value),n=a(i?.value),o=a(n.stripe),c=a(n.freemius),p=y=>typeof y=="string"?y:"";return{stripe:{publishableKey:p(o.publishableKey),hasSecretKey:s.getSecretEnvelopeStatus(t.stripeSecretKey).hasStoredValue,hasWebhookSecret:s.getSecretEnvelopeStatus(t.stripeWebhookSecret).hasStoredValue},freemius:{developerId:p(c.developerId),publicKey:p(c.publicKey),productId:p(c.productId),hasSecretKey:s.getSecretEnvelopeStatus(t.freemiusSecretKey).hasStoredValue,hasApiKey:s.getSecretEnvelopeStatus(t.freemiusApiKey).hasStoredValue},envFallbackActive:!!(!t.stripeSecretKey&&process.env.STRIPE_SECRET_KEY)}}async function R(e){const r=s.createClient(),i={stripe:{publishableKey:e.stripe.publishableKey.trim()},freemius:{developerId:e.freemius.developerId.trim(),publicKey:e.freemius.publicKey.trim(),productId:e.freemius.productId.trim(),sandboxEnabled:!1}},{error:t}=await r.from("site_settings").upsert({key:f,value:i});if(t)throw console.error("Error saving payment_public settings:",t.message),new Error("Failed to save payment settings.");const n=[["stripeSecretKey",e.stripe.secretKey],["stripeWebhookSecret",e.stripe.webhookSecret],["freemiusSecretKey",e.freemius.secretKey],["freemiusApiKey",e.freemius.apiKey]];if(n.some(([,c])=>c&&c.trim())){if(s.isSandboxEnvironment())throw new Error("The sandbox cannot store live payment credentials.");const{data:c}=await r.from("site_settings").select("value").eq("key",E).maybeSingle(),y={...a(c?.value)};for(const[g,b]of n)b&&b.trim()&&(y[g]=s.encryptWithEnvKey(b.trim()));const{error:m}=await r.from("site_settings").upsert({key:E,value:y});if(m)throw console.error("Error saving payment_secret settings:",m.message),new Error("Failed to save payment credentials.")}d()}exports.clearPaymentConfigCache=d;exports.getPaymentConfigStatus=P;exports.getPaymentCredentialsView=I;exports.hydrateFreemiusEnvFromDb=C;exports.resolveStripePublishableKey=v;exports.resolveStripeSecretKey=h;exports.resolveStripeWebhookSecret=_;exports.savePaymentCredentials=R;
1
+ let e=require("@nextblock-cms/db/server");var t=`payment_secret`,n=`payment_public`,r=6e4,i=null;function a(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}async function o(o=!1){let s=Date.now();if(!o&&i&&s-i.at<r)return{secret:i.secret,public:i.public};let c={},l={};try{let r=(0,e.getServiceRoleSupabaseClient)(),[{data:i},{data:o}]=await Promise.all([r.from(`site_settings`).select(`value`).eq(`key`,t).maybeSingle(),r.from(`site_settings`).select(`value`).eq(`key`,n).maybeSingle()]);c=a(i?.value),l=a(o?.value)}catch{}return i={at:s,secret:c,public:l},{secret:c,public:l}}function s(){i=null}function c(t,n){return(0,e.tryDecryptWithEnvKey)(t[n])}async function l(){let{secret:t}=await o();return(0,e.resolveConfigValue)(c(t,`stripeSecretKey`),`STRIPE_SECRET_KEY`)}async function u(){let{secret:t}=await o();return(0,e.resolveConfigValue)(c(t,`stripeWebhookSecret`),`STRIPE_WEBHOOK_SECRET`)}async function d(){let{public:t}=await o(),n=a(t.stripe).publishableKey;return(0,e.resolveConfigValue)(typeof n==`string`?n:null,`NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY`)}async function f(){try{let{secret:e,public:t}=await o(),n=a(t.freemius),r=(e,t)=>{t&&t.trim()&&(process.env[e]=t.trim())};r(`FREEMIUS_SECRET_KEY`,c(e,`freemiusSecretKey`)),r(`FREEMIUS_API_KEY`,c(e,`freemiusApiKey`)),r(`FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY`,c(e,`freemiusSandboxSecretKey`)),r(`FREEMIUS_PUBLIC_KEY`,typeof n.publicKey==`string`?n.publicKey:null),r(`FREEMIUS_PRODUCT_ID`,typeof n.productId==`string`?n.productId:null),r(`FREEMIUS_DEVELOPER_ID`,typeof n.developerId==`string`?n.developerId:null)}catch(e){console.warn(`[payment-config] Could not hydrate Freemius credentials from the database:`,e)}}async function p(){let{secret:t,public:n}=await o(),r=a(n.freemius),i=a(n.stripe),s=[];(0,e.resolveConfigValue)(c(t,`stripeSecretKey`),`STRIPE_SECRET_KEY`)||s.push(`Secret key`),(0,e.resolveConfigValue)(typeof i.publishableKey==`string`?i.publishableKey:null,`NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY`)||s.push(`Publishable key`),(0,e.resolveConfigValue)(c(t,`stripeWebhookSecret`),`STRIPE_WEBHOOK_SECRET`)||s.push(`Webhook secret`);let l=[];return(0,e.resolveConfigValue)(typeof r.publicKey==`string`?r.publicKey:null,`FREEMIUS_PUBLIC_KEY`)||l.push(`Public key`),(0,e.resolveConfigValue)(c(t,`freemiusSecretKey`),`FREEMIUS_SECRET_KEY`)||l.push(`Secret key`),{stripe:{hasKeys:s.length===0,missing:s},freemius:{hasKeys:l.length===0,missing:l}}}async function m(){let r=(0,e.createClient)(),[{data:i},{data:o}]=await Promise.all([r.from(`site_settings`).select(`value`).eq(`key`,t).maybeSingle(),r.from(`site_settings`).select(`value`).eq(`key`,n).maybeSingle()]),s=a(i?.value),c=a(o?.value),l=a(c.stripe),u=a(c.freemius),d=e=>typeof e==`string`?e:``;return{stripe:{publishableKey:d(l.publishableKey),hasSecretKey:(0,e.getSecretEnvelopeStatus)(s.stripeSecretKey).hasStoredValue,hasWebhookSecret:(0,e.getSecretEnvelopeStatus)(s.stripeWebhookSecret).hasStoredValue},freemius:{developerId:d(u.developerId),publicKey:d(u.publicKey),productId:d(u.productId),hasSecretKey:(0,e.getSecretEnvelopeStatus)(s.freemiusSecretKey).hasStoredValue,hasApiKey:(0,e.getSecretEnvelopeStatus)(s.freemiusApiKey).hasStoredValue},envFallbackActive:!(s.stripeSecretKey||!process.env.STRIPE_SECRET_KEY)}}async function h(r){let i=(0,e.createClient)(),o={stripe:{publishableKey:r.stripe.publishableKey.trim()},freemius:{developerId:r.freemius.developerId.trim(),publicKey:r.freemius.publicKey.trim(),productId:r.freemius.productId.trim(),sandboxEnabled:!1}},{error:c}=await i.from(`site_settings`).upsert({key:n,value:o});if(c)throw console.error(`Error saving payment_public settings:`,c.message),Error(`Failed to save payment settings.`);let l=[[`stripeSecretKey`,r.stripe.secretKey],[`stripeWebhookSecret`,r.stripe.webhookSecret],[`freemiusSecretKey`,r.freemius.secretKey],[`freemiusApiKey`,r.freemius.apiKey]];if(l.some(([,e])=>e&&e.trim())){if((0,e.isSandboxEnvironment)())throw Error(`The sandbox cannot store live payment credentials.`);let{data:n}=await i.from(`site_settings`).select(`value`).eq(`key`,t).maybeSingle(),r={...a(n?.value)};for(let[t,n]of l)n&&n.trim()&&(r[t]=(0,e.encryptWithEnvKey)(n.trim()));let{error:o}=await i.from(`site_settings`).upsert({key:t,value:r});if(o)throw console.error(`Error saving payment_secret settings:`,o.message),Error(`Failed to save payment credentials.`)}s()}exports.clearPaymentConfigCache=s,exports.getPaymentConfigStatus=p,exports.getPaymentCredentialsView=m,exports.hydrateFreemiusEnvFromDb=f,exports.resolveStripePublishableKey=d,exports.resolveStripeSecretKey=l,exports.resolveStripeWebhookSecret=u,exports.savePaymentCredentials=h;
@@ -1,137 +1,121 @@
1
- import { resolveConfigValue as o, getServiceRoleSupabaseClient as h, tryDecryptWithEnvKey as g, createClient as d, getSecretEnvelopeStatus as b, isSandboxEnvironment as I, encryptWithEnvKey as P } from "@nextblock-cms/db/server";
2
- const f = "payment_secret", S = "payment_public", v = 6e4;
3
- let u = null;
4
- function n(e) {
5
- return e && typeof e == "object" && !Array.isArray(e) ? e : {};
1
+ import { createClient as e, encryptWithEnvKey as t, getSecretEnvelopeStatus as n, getServiceRoleSupabaseClient as r, isSandboxEnvironment as i, resolveConfigValue as a, tryDecryptWithEnvKey as o } from "@nextblock-cms/db/server";
2
+ //#region libs/ecommerce/src/lib/payment-config.ts
3
+ var s = "payment_secret", c = "payment_public", l = 6e4, u = null;
4
+ function d(e) {
5
+ return e && typeof e == "object" && !Array.isArray(e) ? e : {};
6
6
  }
7
- async function E(e = !1) {
8
- const r = Date.now();
9
- if (!e && u && r - u.at < v)
10
- return { secret: u.secret, public: u.public };
11
- let s = {}, t = {};
12
- try {
13
- const i = h(), [{ data: c }, { data: a }] = await Promise.all([
14
- i.from("site_settings").select("value").eq("key", f).maybeSingle(),
15
- i.from("site_settings").select("value").eq("key", S).maybeSingle()
16
- ]);
17
- s = n(c?.value), t = n(a?.value);
18
- } catch {
19
- }
20
- return u = { at: r, secret: s, public: t }, { secret: s, public: t };
7
+ async function f(e = !1) {
8
+ let t = Date.now();
9
+ if (!e && u && t - u.at < l) return {
10
+ secret: u.secret,
11
+ public: u.public
12
+ };
13
+ let n = {}, i = {};
14
+ try {
15
+ let e = r(), [{ data: t }, { data: a }] = await Promise.all([e.from("site_settings").select("value").eq("key", s).maybeSingle(), e.from("site_settings").select("value").eq("key", c).maybeSingle()]);
16
+ n = d(t?.value), i = d(a?.value);
17
+ } catch {}
18
+ return u = {
19
+ at: t,
20
+ secret: n,
21
+ public: i
22
+ }, {
23
+ secret: n,
24
+ public: i
25
+ };
21
26
  }
22
- function R() {
23
- u = null;
27
+ function p() {
28
+ u = null;
24
29
  }
25
- function l(e, r) {
26
- return g(e[r]);
30
+ function m(e, t) {
31
+ return o(e[t]);
27
32
  }
28
- async function w() {
29
- const { secret: e } = await E();
30
- return o(l(e, "stripeSecretKey"), "STRIPE_SECRET_KEY");
33
+ async function h() {
34
+ let { secret: e } = await f();
35
+ return a(m(e, "stripeSecretKey"), "STRIPE_SECRET_KEY");
31
36
  }
32
- async function T() {
33
- const { secret: e } = await E();
34
- return o(l(e, "stripeWebhookSecret"), "STRIPE_WEBHOOK_SECRET");
37
+ async function g() {
38
+ let { secret: e } = await f();
39
+ return a(m(e, "stripeWebhookSecret"), "STRIPE_WEBHOOK_SECRET");
35
40
  }
36
- async function k() {
37
- const { public: e } = await E(), r = n(e.stripe).publishableKey;
38
- return o(
39
- typeof r == "string" ? r : null,
40
- "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY"
41
- );
41
+ async function _() {
42
+ let { public: e } = await f(), t = d(e.stripe).publishableKey;
43
+ return a(typeof t == "string" ? t : null, "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY");
42
44
  }
43
- async function U() {
44
- try {
45
- const { secret: e, public: r } = await E(), s = n(r.freemius), t = (i, c) => {
46
- c && c.trim() && (process.env[i] = c.trim());
47
- };
48
- t("FREEMIUS_SECRET_KEY", l(e, "freemiusSecretKey")), t("FREEMIUS_API_KEY", l(e, "freemiusApiKey")), t("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY", l(e, "freemiusSandboxSecretKey")), t(
49
- "FREEMIUS_PUBLIC_KEY",
50
- typeof s.publicKey == "string" ? s.publicKey : null
51
- ), t(
52
- "FREEMIUS_PRODUCT_ID",
53
- typeof s.productId == "string" ? s.productId : null
54
- ), t(
55
- "FREEMIUS_DEVELOPER_ID",
56
- typeof s.developerId == "string" ? s.developerId : null
57
- );
58
- } catch (e) {
59
- console.warn("[payment-config] Could not hydrate Freemius credentials from the database:", e);
60
- }
45
+ async function v() {
46
+ try {
47
+ let { secret: e, public: t } = await f(), n = d(t.freemius), r = (e, t) => {
48
+ t && t.trim() && (process.env[e] = t.trim());
49
+ };
50
+ r("FREEMIUS_SECRET_KEY", m(e, "freemiusSecretKey")), r("FREEMIUS_API_KEY", m(e, "freemiusApiKey")), r("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY", m(e, "freemiusSandboxSecretKey")), r("FREEMIUS_PUBLIC_KEY", typeof n.publicKey == "string" ? n.publicKey : null), r("FREEMIUS_PRODUCT_ID", typeof n.productId == "string" ? n.productId : null), r("FREEMIUS_DEVELOPER_ID", typeof n.developerId == "string" ? n.developerId : null);
51
+ } catch (e) {
52
+ console.warn("[payment-config] Could not hydrate Freemius credentials from the database:", e);
53
+ }
61
54
  }
62
- async function F() {
63
- const { secret: e, public: r } = await E(), s = n(r.freemius), t = n(r.stripe), i = [];
64
- o(l(e, "stripeSecretKey"), "STRIPE_SECRET_KEY") || i.push("Secret key"), o(
65
- typeof t.publishableKey == "string" ? t.publishableKey : null,
66
- "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY"
67
- ) || i.push("Publishable key"), o(l(e, "stripeWebhookSecret"), "STRIPE_WEBHOOK_SECRET") || i.push("Webhook secret");
68
- const c = [];
69
- return o(
70
- typeof s.publicKey == "string" ? s.publicKey : null,
71
- "FREEMIUS_PUBLIC_KEY"
72
- ) || c.push("Public key"), o(l(e, "freemiusSecretKey"), "FREEMIUS_SECRET_KEY") || c.push("Secret key"), {
73
- stripe: { hasKeys: i.length === 0, missing: i },
74
- freemius: { hasKeys: c.length === 0, missing: c }
75
- };
55
+ async function y() {
56
+ let { secret: e, public: t } = await f(), n = d(t.freemius), r = d(t.stripe), i = [];
57
+ a(m(e, "stripeSecretKey"), "STRIPE_SECRET_KEY") || i.push("Secret key"), a(typeof r.publishableKey == "string" ? r.publishableKey : null, "NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY") || i.push("Publishable key"), a(m(e, "stripeWebhookSecret"), "STRIPE_WEBHOOK_SECRET") || i.push("Webhook secret");
58
+ let o = [];
59
+ return a(typeof n.publicKey == "string" ? n.publicKey : null, "FREEMIUS_PUBLIC_KEY") || o.push("Public key"), a(m(e, "freemiusSecretKey"), "FREEMIUS_SECRET_KEY") || o.push("Secret key"), {
60
+ stripe: {
61
+ hasKeys: i.length === 0,
62
+ missing: i
63
+ },
64
+ freemius: {
65
+ hasKeys: o.length === 0,
66
+ missing: o
67
+ }
68
+ };
76
69
  }
77
- async function M() {
78
- const e = d(), [{ data: r }, { data: s }] = await Promise.all([
79
- e.from("site_settings").select("value").eq("key", f).maybeSingle(),
80
- e.from("site_settings").select("value").eq("key", S).maybeSingle()
81
- ]), t = n(r?.value), i = n(s?.value), c = n(i.stripe), a = n(i.freemius), p = (y) => typeof y == "string" ? y : "";
82
- return {
83
- stripe: {
84
- publishableKey: p(c.publishableKey),
85
- hasSecretKey: b(t.stripeSecretKey).hasStoredValue,
86
- hasWebhookSecret: b(t.stripeWebhookSecret).hasStoredValue
87
- },
88
- freemius: {
89
- developerId: p(a.developerId),
90
- publicKey: p(a.publicKey),
91
- productId: p(a.productId),
92
- hasSecretKey: b(t.freemiusSecretKey).hasStoredValue,
93
- hasApiKey: b(t.freemiusApiKey).hasStoredValue
94
- },
95
- envFallbackActive: !!(!t.stripeSecretKey && process.env.STRIPE_SECRET_KEY)
96
- };
70
+ async function b() {
71
+ let t = e(), [{ data: r }, { data: i }] = await Promise.all([t.from("site_settings").select("value").eq("key", s).maybeSingle(), t.from("site_settings").select("value").eq("key", c).maybeSingle()]), a = d(r?.value), o = d(i?.value), l = d(o.stripe), u = d(o.freemius), f = (e) => typeof e == "string" ? e : "";
72
+ return {
73
+ stripe: {
74
+ publishableKey: f(l.publishableKey),
75
+ hasSecretKey: n(a.stripeSecretKey).hasStoredValue,
76
+ hasWebhookSecret: n(a.stripeWebhookSecret).hasStoredValue
77
+ },
78
+ freemius: {
79
+ developerId: f(u.developerId),
80
+ publicKey: f(u.publicKey),
81
+ productId: f(u.productId),
82
+ hasSecretKey: n(a.freemiusSecretKey).hasStoredValue,
83
+ hasApiKey: n(a.freemiusApiKey).hasStoredValue
84
+ },
85
+ envFallbackActive: !(a.stripeSecretKey || !process.env.STRIPE_SECRET_KEY)
86
+ };
97
87
  }
98
- async function Y(e) {
99
- const r = d(), s = {
100
- stripe: { publishableKey: e.stripe.publishableKey.trim() },
101
- freemius: {
102
- developerId: e.freemius.developerId.trim(),
103
- publicKey: e.freemius.publicKey.trim(),
104
- productId: e.freemius.productId.trim(),
105
- sandboxEnabled: !1
106
- }
107
- }, { error: t } = await r.from("site_settings").upsert({ key: S, value: s });
108
- if (t)
109
- throw console.error("Error saving payment_public settings:", t.message), new Error("Failed to save payment settings.");
110
- const i = [
111
- ["stripeSecretKey", e.stripe.secretKey],
112
- ["stripeWebhookSecret", e.stripe.webhookSecret],
113
- ["freemiusSecretKey", e.freemius.secretKey],
114
- ["freemiusApiKey", e.freemius.apiKey]
115
- ];
116
- if (i.some(([, a]) => a && a.trim())) {
117
- if (I())
118
- throw new Error("The sandbox cannot store live payment credentials.");
119
- const { data: a } = await r.from("site_settings").select("value").eq("key", f).maybeSingle(), y = { ...n(a?.value) };
120
- for (const [_, m] of i)
121
- m && m.trim() && (y[_] = P(m.trim()));
122
- const { error: K } = await r.from("site_settings").upsert({ key: f, value: y });
123
- if (K)
124
- throw console.error("Error saving payment_secret settings:", K.message), new Error("Failed to save payment credentials.");
125
- }
126
- R();
88
+ async function x(n) {
89
+ let r = e(), a = {
90
+ stripe: { publishableKey: n.stripe.publishableKey.trim() },
91
+ freemius: {
92
+ developerId: n.freemius.developerId.trim(),
93
+ publicKey: n.freemius.publicKey.trim(),
94
+ productId: n.freemius.productId.trim(),
95
+ sandboxEnabled: !1
96
+ }
97
+ }, { error: o } = await r.from("site_settings").upsert({
98
+ key: c,
99
+ value: a
100
+ });
101
+ if (o) throw console.error("Error saving payment_public settings:", o.message), Error("Failed to save payment settings.");
102
+ let l = [
103
+ ["stripeSecretKey", n.stripe.secretKey],
104
+ ["stripeWebhookSecret", n.stripe.webhookSecret],
105
+ ["freemiusSecretKey", n.freemius.secretKey],
106
+ ["freemiusApiKey", n.freemius.apiKey]
107
+ ];
108
+ if (l.some(([, e]) => e && e.trim())) {
109
+ if (i()) throw Error("The sandbox cannot store live payment credentials.");
110
+ let { data: e } = await r.from("site_settings").select("value").eq("key", s).maybeSingle(), n = { ...d(e?.value) };
111
+ for (let [e, r] of l) r && r.trim() && (n[e] = t(r.trim()));
112
+ let { error: a } = await r.from("site_settings").upsert({
113
+ key: s,
114
+ value: n
115
+ });
116
+ if (a) throw console.error("Error saving payment_secret settings:", a.message), Error("Failed to save payment credentials.");
117
+ }
118
+ p();
127
119
  }
128
- export {
129
- R as clearPaymentConfigCache,
130
- F as getPaymentConfigStatus,
131
- M as getPaymentCredentialsView,
132
- U as hydrateFreemiusEnvFromDb,
133
- k as resolveStripePublishableKey,
134
- w as resolveStripeSecretKey,
135
- T as resolveStripeWebhookSecret,
136
- Y as savePaymentCredentials
137
- };
120
+ //#endregion
121
+ export { p as clearPaymentConfigCache, y as getPaymentConfigStatus, b as getPaymentCredentialsView, v as hydrateFreemiusEnvFromDb, _ as resolveStripePublishableKey, h as resolveStripeSecretKey, g as resolveStripeWebhookSecret, x as savePaymentCredentials };