@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.
- package/_virtual/_rolldown/runtime.cjs.js +1 -0
- package/index.cjs.js +1 -1
- package/index.es.js +38 -146
- package/lib/CurrencyProvider.cjs.js +1 -1
- package/lib/CurrencyProvider.d.ts +1 -1
- package/lib/CurrencyProvider.es.js +85 -95
- package/lib/PaymentReadinessProvider.cjs.js +1 -1
- package/lib/PaymentReadinessProvider.d.ts +1 -1
- package/lib/PaymentReadinessProvider.es.js +24 -27
- package/lib/cart-store.cjs.js +1 -1
- package/lib/cart-store.es.js +109 -121
- package/lib/components/AccountNavigationMenu.cjs.js +1 -1
- package/lib/components/AccountNavigationMenu.d.ts +1 -1
- package/lib/components/AccountNavigationMenu.es.js +36 -50
- package/lib/components/AddToCartButton.cjs.js +1 -1
- package/lib/components/AddToCartButton.d.ts +1 -1
- package/lib/components/AddToCartButton.es.js +94 -89
- package/lib/components/Cart.cjs.js +1 -1
- package/lib/components/Cart.d.ts +1 -1
- package/lib/components/Cart.es.js +261 -180
- package/lib/components/CartDrawer.cjs.js +1 -1
- package/lib/components/CartDrawer.d.ts +1 -1
- package/lib/components/CartDrawer.es.js +218 -148
- package/lib/components/CartIcon.cjs.js +1 -1
- package/lib/components/CartIcon.d.ts +1 -1
- package/lib/components/CartIcon.es.js +33 -35
- package/lib/components/Checkout.cjs.js +1 -1
- package/lib/components/Checkout.d.ts +1 -1
- package/lib/components/Checkout.es.js +1092 -1108
- package/lib/components/CouponForm.cjs.js +1 -1
- package/lib/components/CouponForm.d.ts +1 -1
- package/lib/components/CouponForm.es.js +136 -148
- package/lib/components/CurrencySwitcher.cjs.js +1 -1
- package/lib/components/CurrencySwitcher.d.ts +1 -1
- package/lib/components/CurrencySwitcher.es.js +22 -18
- package/lib/components/CustomerProfileForm.cjs.js +1 -1
- package/lib/components/CustomerProfileForm.es.js +454 -313
- package/lib/components/FeaturedProduct.cjs.js +1 -1
- package/lib/components/FeaturedProduct.d.ts +1 -1
- package/lib/components/FeaturedProduct.es.js +98 -83
- package/lib/components/FreemiusLicensePanel.cjs.js +1 -1
- package/lib/components/FreemiusLicensePanel.d.ts +1 -1
- package/lib/components/FreemiusLicensePanel.es.js +70 -65
- package/lib/components/InvoiceDocument.cjs.js +1 -1
- package/lib/components/InvoiceDocument.es.js +256 -192
- package/lib/components/InvoiceViewerShell.cjs.js +2 -2
- package/lib/components/InvoiceViewerShell.d.ts +1 -1
- package/lib/components/InvoiceViewerShell.es.js +75 -106
- package/lib/components/ProductCard.cjs.js +1 -1
- package/lib/components/ProductCard.d.ts +1 -1
- package/lib/components/ProductCard.es.js +186 -171
- package/lib/components/ProductDetailsLayout.cjs.js +1 -1
- package/lib/components/ProductDetailsLayout.es.js +405 -404
- package/lib/components/ProductGallery.cjs.js +1 -1
- package/lib/components/ProductGallery.d.ts +1 -1
- package/lib/components/ProductGallery.es.js +51 -54
- package/lib/components/ProductGrid.cjs.js +1 -1
- package/lib/components/ProductGrid.d.ts +1 -1
- package/lib/components/ProductGrid.es.js +23 -25
- package/lib/components/ShippingEstimator.cjs.js +1 -1
- package/lib/components/ShippingEstimator.d.ts +1 -1
- package/lib/components/ShippingEstimator.es.js +158 -153
- package/lib/components/ShortDescription.cjs.js +1 -1
- package/lib/components/ShortDescription.es.js +17 -17
- package/lib/components/SimpleTiptapRenderer.cjs.js +1 -1
- package/lib/components/SimpleTiptapRenderer.es.js +238 -211
- package/lib/components/SubscriptionSelector.cjs.js +1 -1
- package/lib/components/SubscriptionSelector.es.js +159 -154
- package/lib/countries.cjs.js +1 -1
- package/lib/countries.es.js +232 -75
- package/lib/coupon-server.cjs.js +1 -1
- package/lib/coupon-server.es.js +180 -224
- package/lib/coupons.cjs.js +1 -1
- package/lib/coupons.es.js +12 -14
- package/lib/currency-constants.cjs.js +1 -1
- package/lib/currency-constants.es.js +4 -4
- package/lib/currency-rest-client.cjs.js +1 -1
- package/lib/currency-rest-client.es.js +15 -22
- package/lib/currency-store.cjs.js +1 -1
- package/lib/currency-store.es.js +20 -27
- package/lib/currency-sync.cjs.js +1 -1
- package/lib/currency-sync.es.js +124 -170
- package/lib/currency.cjs.js +1 -1
- package/lib/currency.es.js +242 -310
- package/lib/customer-addresses.cjs.js +1 -1
- package/lib/customer-addresses.es.js +80 -109
- package/lib/customer-orders.cjs.js +1 -1
- package/lib/customer-orders.es.js +31 -43
- package/lib/customer.cjs.js +1 -1
- package/lib/customer.es.js +43 -52
- package/lib/export-helpers.cjs.js +1 -1
- package/lib/export-helpers.es.js +53 -52
- package/lib/factory.cjs.js +1 -1
- package/lib/factory.es.js +10 -7
- package/lib/freemius-coupons.cjs.js +1 -1
- package/lib/freemius-coupons.es.js +245 -262
- package/lib/freemius-license-claim.cjs.js +1 -1
- package/lib/freemius-license-claim.es.js +87 -71
- package/lib/freemius-license.cjs.js +1 -1
- package/lib/freemius-license.es.js +32 -39
- package/lib/freemius-order-sync.cjs.js +1 -1
- package/lib/freemius-order-sync.es.js +226 -290
- package/lib/freemius-trial-provision.cjs.js +1 -1
- package/lib/freemius-trial-provision.es.js +136 -130
- package/lib/inventory-settings.cjs.js +1 -1
- package/lib/inventory-settings.es.js +69 -77
- package/lib/invoice-server.cjs.js +3 -3
- package/lib/invoice-server.es.js +94 -141
- package/lib/invoice-ui.cjs.js +1 -1
- package/lib/invoice-ui.es.js +50 -66
- package/lib/invoice.cjs.js +1 -1
- package/lib/invoice.es.js +85 -94
- package/lib/order-inventory.cjs.js +25 -25
- package/lib/order-inventory.es.js +67 -79
- package/lib/order-tax-details.cjs.js +1 -1
- package/lib/order-tax-details.es.js +142 -153
- package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -1
- package/lib/pages/cms/coupons/CouponEditorForm.d.ts +1 -1
- package/lib/pages/cms/coupons/CouponEditorForm.es.js +227 -185
- package/lib/pages/cms/coupons/CouponsPage.cjs.js +2 -2
- package/lib/pages/cms/coupons/CouponsPage.d.ts +1 -1
- package/lib/pages/cms/coupons/CouponsPage.es.js +235 -166
- package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -1
- package/lib/pages/cms/coupons/CreateCouponDialog.d.ts +1 -1
- package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -34
- package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -1
- package/lib/pages/cms/coupons/EditCouponPage.d.ts +1 -1
- package/lib/pages/cms/coupons/EditCouponPage.es.js +47 -47
- package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -1
- package/lib/pages/cms/coupons/ProductScopePicker.d.ts +1 -1
- package/lib/pages/cms/coupons/ProductScopePicker.es.js +128 -117
- package/lib/pages/cms/coupons/actions.cjs.js +1 -1
- package/lib/pages/cms/coupons/actions.es.js +112 -115
- package/lib/pages/cms/coupons/index.cjs.js +1 -0
- package/lib/pages/cms/coupons/index.es.js +3 -0
- package/lib/pages/cms/coupons/product-options.cjs.js +1 -1
- package/lib/pages/cms/coupons/product-options.es.js +21 -23
- package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -1
- package/lib/pages/cms/orders/ExportReportsDialog.es.js +135 -129
- package/lib/pages/cms/orders/MarkPaidButton.d.ts +1 -1
- package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderDetailPage.d.ts +1 -1
- package/lib/pages/cms/orders/OrderDetailPage.es.js +186 -134
- package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderPrintButton.d.ts +1 -1
- package/lib/pages/cms/orders/OrderPrintButton.es.js +15 -21
- package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -1
- package/lib/pages/cms/orders/OrderStatusForm.d.ts +1 -1
- package/lib/pages/cms/orders/OrderStatusForm.es.js +85 -69
- package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -1
- package/lib/pages/cms/orders/OrdersPage.d.ts +1 -1
- package/lib/pages/cms/orders/OrdersPage.es.js +170 -102
- package/lib/pages/cms/orders/actions.cjs.js +3 -3
- package/lib/pages/cms/orders/actions.es.js +53 -69
- package/lib/pages/cms/orders/export-actions.cjs.js +1 -1
- package/lib/pages/cms/orders/export-actions.es.js +23 -26
- package/lib/pages/cms/orders/index.cjs.js +1 -0
- package/lib/pages/cms/orders/index.es.js +6 -0
- package/lib/pages/cms/orders/server-actions.cjs.js +1 -1
- package/lib/pages/cms/orders/server-actions.es.js +60 -51
- package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -1
- package/lib/pages/cms/payments/PaymentsClient.d.ts +1 -1
- package/lib/pages/cms/payments/PaymentsClient.es.js +316 -346
- package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -1
- package/lib/pages/cms/payments/PaymentsPage.d.ts +1 -1
- package/lib/pages/cms/payments/PaymentsPage.es.js +29 -32
- package/lib/pages/cms/payments/actions.cjs.js +1 -1
- package/lib/pages/cms/payments/actions.es.js +38 -48
- package/lib/pages/cms/payments/index.cjs.js +1 -0
- package/lib/pages/cms/payments/index.es.js +3 -0
- package/lib/pages/cms/payments/queries.cjs.js +1 -1
- package/lib/pages/cms/payments/queries.es.js +38 -48
- package/lib/pages/cms/products/ProductsPage.cjs.js +1 -1
- package/lib/pages/cms/products/ProductsPage.d.ts +1 -1
- package/lib/pages/cms/products/ProductsPage.es.js +63 -66
- package/lib/pages/cms/products/[id]/edit/EditProductPage.d.ts +1 -1
- package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -1
- package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +138 -155
- package/lib/pages/cms/products/actions.cjs.js +4 -4
- package/lib/pages/cms/products/actions.es.js +121 -162
- package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -1
- package/lib/pages/cms/products/attributes/AttributeManagementPage.d.ts +1 -1
- package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +55 -47
- package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -1
- package/lib/pages/cms/products/attributes/components/AttributeManager.d.ts +1 -1
- package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +285 -290
- package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -1
- package/lib/pages/cms/products/categories/CategoryManagementPage.d.ts +1 -1
- package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +43 -35
- package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -1
- package/lib/pages/cms/products/categories/components/CategoryManager.es.js +315 -262
- package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -1
- package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +115 -113
- package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -1
- package/lib/pages/cms/products/components/CurrencyPriceFields.d.ts +1 -1
- package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +136 -145
- package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -1
- package/lib/pages/cms/products/components/DeleteProductButton.d.ts +1 -1
- package/lib/pages/cms/products/components/DeleteProductButton.es.js +35 -47
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -1
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.d.ts +1 -1
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +106 -84
- package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductCategorySelector.es.js +156 -159
- package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductForm.es.js +872 -693
- package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductMediaManager.es.js +106 -103
- package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -1
- package/lib/pages/cms/products/components/ProductsBulkTable.d.ts +1 -1
- package/lib/pages/cms/products/components/ProductsBulkTable.es.js +303 -294
- package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -1
- package/lib/pages/cms/products/components/SaleScheduleFields.d.ts +1 -1
- package/lib/pages/cms/products/components/SaleScheduleFields.es.js +111 -134
- package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -1
- package/lib/pages/cms/products/components/SyncFreemiusButton.d.ts +1 -1
- package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +29 -35
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +2 -2
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.d.ts +1 -1
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +36 -48
- package/lib/pages/cms/products/components/SyncProductForm.d.ts +1 -1
- package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -1
- package/lib/pages/cms/products/components/VariationsEditor.d.ts +1 -1
- package/lib/pages/cms/products/components/VariationsEditor.es.js +396 -405
- package/lib/pages/cms/products/index.cjs.js +1 -0
- package/lib/pages/cms/products/index.es.js +8 -0
- package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -1
- package/lib/pages/cms/products/inventory/InventoryPage.d.ts +1 -1
- package/lib/pages/cms/products/inventory/InventoryPage.es.js +21 -15
- package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -2
- package/lib/pages/cms/products/inventory/InventoryTableClient.d.ts +1 -1
- package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +230 -209
- package/lib/pages/cms/products/inventory/actions.cjs.js +3 -3
- package/lib/pages/cms/products/inventory/actions.es.js +83 -91
- package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -1
- package/lib/pages/cms/products/new/NewProductPage.d.ts +1 -1
- package/lib/pages/cms/products/new/NewProductPage.es.js +58 -74
- package/lib/pages/cms/products/product-price-sync.cjs.js +1 -1
- package/lib/pages/cms/products/product-price-sync.es.js +74 -89
- package/lib/pages/cms/products/server-actions.cjs.js +1 -1
- package/lib/pages/cms/products/server-actions.es.js +250 -233
- package/lib/pages/cms/shipping/ShippingPage.cjs.js +2 -2
- package/lib/pages/cms/shipping/ShippingPage.es.js +287 -209
- package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -1
- package/lib/pages/cms/shipping/components/RateForm.d.ts +1 -1
- package/lib/pages/cms/shipping/components/RateForm.es.js +439 -436
- package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -1
- package/lib/pages/cms/shipping/components/ZoneForm.es.js +245 -224
- package/lib/pages/cms/shipping/index.cjs.js +1 -0
- package/lib/pages/cms/shipping/index.es.js +3 -0
- package/lib/pages/cms/shipping/server-actions.cjs.js +1 -1
- package/lib/pages/cms/shipping/server-actions.es.js +131 -149
- package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -1
- package/lib/pages/cms/taxes/TaxesPage.d.ts +1 -1
- package/lib/pages/cms/taxes/TaxesPage.es.js +211 -169
- package/lib/pages/cms/taxes/actions.cjs.js +1 -1
- package/lib/pages/cms/taxes/actions.es.js +41 -53
- package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -1
- package/lib/pages/cms/taxes/components/TaxRateForm.d.ts +1 -1
- package/lib/pages/cms/taxes/components/TaxRateForm.es.js +112 -99
- package/lib/pages/cms/taxes/index.cjs.js +1 -0
- package/lib/pages/cms/taxes/index.es.js +3 -0
- package/lib/payment-config.cjs.js +1 -1
- package/lib/payment-config.es.js +110 -126
- package/lib/product-actions.cjs.js +4 -4
- package/lib/product-actions.es.js +289 -544
- package/lib/product-context.cjs.js +1 -1
- package/lib/product-context.es.js +13 -15
- package/lib/product-schema.cjs.js +1 -1
- package/lib/product-schema.es.js +99 -134
- package/lib/providers/freemius.cjs.js +1 -5
- package/lib/providers/freemius.es.js +446 -530
- package/lib/providers/stripe.cjs.js +1 -1
- package/lib/providers/stripe.es.js +417 -477
- package/lib/server-actions/coupon-actions.cjs.js +1 -1
- package/lib/server-actions/coupon-actions.es.js +22 -22
- package/lib/server-actions/customer-actions.cjs.js +1 -1
- package/lib/server-actions/customer-actions.es.js +26 -28
- package/lib/server-actions/product-actions.cjs.js +1 -1
- package/lib/server-actions/product-actions.es.js +9 -15
- package/lib/server-actions/shipping-actions.cjs.js +1 -1
- package/lib/server-actions/shipping-actions.es.js +27 -24
- package/lib/server-actions/tax-actions.cjs.js +1 -1
- package/lib/server-actions/tax-actions.es.js +33 -39
- package/lib/shared-inventory.cjs.js +2 -2
- package/lib/shared-inventory.es.js +111 -160
- package/lib/shipping/resolver.cjs.js +2 -2
- package/lib/shipping/resolver.es.js +44 -61
- package/lib/shipping-rate-currency.cjs.js +1 -1
- package/lib/shipping-rate-currency.es.js +52 -67
- package/lib/states.cjs.js +1 -1
- package/lib/states.es.js +333 -154
- package/lib/stripe/checkout.cjs.js +1 -1
- package/lib/stripe/checkout.es.js +125 -181
- package/lib/stripe/client.cjs.js +1 -1
- package/lib/stripe/client.es.js +14 -19
- package/lib/stripe/order-sync.cjs.js +1 -1
- package/lib/stripe/order-sync.es.js +106 -126
- package/lib/stripe/webhooks.cjs.js +1 -1
- package/lib/stripe/webhooks.es.js +37 -31
- package/lib/tax-calculation.cjs.js +1 -1
- package/lib/tax-calculation.es.js +84 -98
- package/lib/trials.cjs.js +1 -1
- package/lib/trials.es.js +24 -30
- package/lib/types.cjs.js +1 -1
- package/lib/types.es.js +21 -27
- package/lib/use-cart.cjs.js +1 -1
- package/lib/use-cart.es.js +38 -40
- package/lib/use-price-formatter.cjs.js +1 -1
- package/lib/use-price-formatter.es.js +10 -11
- package/lib/variation-utils.cjs.js +1 -1
- package/lib/variation-utils.es.js +199 -261
- package/lib/zod-config.cjs.js +1 -1
- package/lib/zod-config.es.js +5 -6
- package/package.json +16 -16
- package/server.cjs.js +1 -1
- package/server.es.js +56 -211
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require("../_virtual/_rolldown/runtime.cjs.js"),t=require("./inventory-settings.cjs.js");require("server-only");let n=require("postgres");n=e.__toESM(n,1);function r(){return process.env.POSTGRES_URL||process.env.DATABASE_URL||null}async function i(e){let i=r();if(!i)throw Error(`Missing POSTGRES_URL or DATABASE_URL for inventory fallback`);let a=(0,n.default)(i,{ssl:`require`,onnotice:()=>{}});try{await a.begin(async n=>{let r=n,i=(await r`
|
|
2
2
|
SELECT inventory_deducted_at
|
|
3
3
|
FROM public.orders
|
|
4
|
-
WHERE id = ${
|
|
4
|
+
WHERE id = ${e}
|
|
5
5
|
FOR UPDATE
|
|
6
|
-
`)[0];if(!
|
|
6
|
+
`)[0];if(!i||i.inventory_deducted_at)return;let a=await r`
|
|
7
7
|
SELECT value
|
|
8
8
|
FROM public.site_settings
|
|
9
|
-
WHERE key = ${
|
|
9
|
+
WHERE key = ${t.ECOMMERCE_INVENTORY_SETTINGS_KEY}
|
|
10
10
|
LIMIT 1
|
|
11
|
-
`;if(!
|
|
11
|
+
`;if(!t.normalizeEcommerceInventorySettings(a[0]?.value).trackQuantities){await r`
|
|
12
12
|
UPDATE public.orders
|
|
13
13
|
SET inventory_deducted_at = now()
|
|
14
|
-
WHERE id = ${
|
|
15
|
-
`;return}
|
|
14
|
+
WHERE id = ${e}
|
|
15
|
+
`;return}let o=await r`
|
|
16
16
|
SELECT
|
|
17
17
|
product_id,
|
|
18
18
|
variant_id,
|
|
19
19
|
SUM(quantity)::integer AS quantity
|
|
20
20
|
FROM public.order_items
|
|
21
|
-
WHERE order_id = ${
|
|
21
|
+
WHERE order_id = ${e}
|
|
22
22
|
GROUP BY product_id, variant_id
|
|
23
|
-
`;for(
|
|
23
|
+
`;for(let e of o){if(e.variant_id){let t=(await r`
|
|
24
24
|
SELECT
|
|
25
25
|
sku,
|
|
26
26
|
stock_quantity
|
|
27
27
|
FROM public.product_variants
|
|
28
|
-
WHERE id = ${
|
|
28
|
+
WHERE id = ${e.variant_id}
|
|
29
29
|
LIMIT 1
|
|
30
|
-
`)[0];if(!
|
|
30
|
+
`)[0];if(!t?.sku)continue;await r`
|
|
31
31
|
INSERT INTO public.inventory_items (sku, quantity)
|
|
32
|
-
VALUES (${
|
|
32
|
+
VALUES (${t.sku}, ${Math.max(0,t.stock_quantity??0)})
|
|
33
33
|
ON CONFLICT (sku) DO NOTHING
|
|
34
|
-
`,await
|
|
34
|
+
`,await r`
|
|
35
35
|
UPDATE public.inventory_items
|
|
36
36
|
SET
|
|
37
|
-
quantity = GREATEST(COALESCE(quantity, 0) - ${
|
|
37
|
+
quantity = GREATEST(COALESCE(quantity, 0) - ${e.quantity}, 0),
|
|
38
38
|
updated_at = now()
|
|
39
|
-
WHERE sku = ${
|
|
40
|
-
`;continue}if(
|
|
39
|
+
WHERE sku = ${t.sku}
|
|
40
|
+
`;continue}if(e.product_id){let t=(await r`
|
|
41
41
|
SELECT
|
|
42
42
|
sku,
|
|
43
43
|
stock
|
|
44
44
|
FROM public.products
|
|
45
|
-
WHERE id = ${
|
|
45
|
+
WHERE id = ${e.product_id}
|
|
46
46
|
LIMIT 1
|
|
47
|
-
`)[0];if(!
|
|
47
|
+
`)[0];if(!t?.sku)continue;await r`
|
|
48
48
|
INSERT INTO public.inventory_items (sku, quantity)
|
|
49
|
-
VALUES (${
|
|
49
|
+
VALUES (${t.sku}, ${Math.max(0,t.stock??0)})
|
|
50
50
|
ON CONFLICT (sku) DO NOTHING
|
|
51
|
-
`,await
|
|
51
|
+
`,await r`
|
|
52
52
|
UPDATE public.inventory_items
|
|
53
53
|
SET
|
|
54
|
-
quantity = GREATEST(COALESCE(quantity, 0) - ${
|
|
54
|
+
quantity = GREATEST(COALESCE(quantity, 0) - ${e.quantity}, 0),
|
|
55
55
|
updated_at = now()
|
|
56
|
-
WHERE sku = ${
|
|
57
|
-
`}}await
|
|
56
|
+
WHERE sku = ${t.sku}
|
|
57
|
+
`}}await r`
|
|
58
58
|
UPDATE public.orders
|
|
59
59
|
SET inventory_deducted_at = now()
|
|
60
|
-
WHERE id = ${
|
|
61
|
-
`})}finally{await
|
|
60
|
+
WHERE id = ${e}
|
|
61
|
+
`})}finally{await a.end()}}async function a(e,t){let{error:n}=await e.rpc(`apply_order_inventory_deduction`,{p_order_id:t});if(!n)return{method:`rpc`};console.error(`[Inventory] RPC deduction failed for order ${t}:`,n);try{return await i(t),{method:`sql-fallback`}}catch(e){let r=e instanceof Error?e.message:String(e);throw Error(`Failed to reconcile inventory for order ${t}. RPC error: ${n.message}. Fallback error: ${r}`)}}exports.applyOrderInventoryDeduction=a;
|
|
@@ -1,128 +1,116 @@
|
|
|
1
|
+
import { ECOMMERCE_INVENTORY_SETTINGS_KEY as e, normalizeEcommerceInventorySettings as t } from "./inventory-settings.es.js";
|
|
1
2
|
import "server-only";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
function
|
|
5
|
-
|
|
3
|
+
import n from "postgres";
|
|
4
|
+
//#region libs/ecommerce/src/lib/order-inventory.ts
|
|
5
|
+
function r() {
|
|
6
|
+
return process.env.POSTGRES_URL || process.env.DATABASE_URL || null;
|
|
6
7
|
}
|
|
7
|
-
async function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
await a.begin(async (e) => {
|
|
18
|
-
const t = e, s = (await t`
|
|
8
|
+
async function i(i) {
|
|
9
|
+
let a = r();
|
|
10
|
+
if (!a) throw Error("Missing POSTGRES_URL or DATABASE_URL for inventory fallback");
|
|
11
|
+
let o = n(a, {
|
|
12
|
+
ssl: "require",
|
|
13
|
+
onnotice: () => {}
|
|
14
|
+
});
|
|
15
|
+
try {
|
|
16
|
+
await o.begin(async (n) => {
|
|
17
|
+
let r = n, a = (await r`
|
|
19
18
|
SELECT inventory_deducted_at
|
|
20
19
|
FROM public.orders
|
|
21
|
-
WHERE id = ${
|
|
20
|
+
WHERE id = ${i}
|
|
22
21
|
FOR UPDATE
|
|
23
22
|
`)[0];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const c = await t`
|
|
23
|
+
if (!a || a.inventory_deducted_at) return;
|
|
24
|
+
let o = await r`
|
|
27
25
|
SELECT value
|
|
28
26
|
FROM public.site_settings
|
|
29
|
-
WHERE key = ${
|
|
27
|
+
WHERE key = ${e}
|
|
30
28
|
LIMIT 1
|
|
31
29
|
`;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
).trackQuantities) {
|
|
35
|
-
await t`
|
|
30
|
+
if (!t(o[0]?.value).trackQuantities) {
|
|
31
|
+
await r`
|
|
36
32
|
UPDATE public.orders
|
|
37
33
|
SET inventory_deducted_at = now()
|
|
38
|
-
WHERE id = ${
|
|
34
|
+
WHERE id = ${i}
|
|
39
35
|
`;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
let s = await r`
|
|
43
39
|
SELECT
|
|
44
40
|
product_id,
|
|
45
41
|
variant_id,
|
|
46
42
|
SUM(quantity)::integer AS quantity
|
|
47
43
|
FROM public.order_items
|
|
48
|
-
WHERE order_id = ${
|
|
44
|
+
WHERE order_id = ${i}
|
|
49
45
|
GROUP BY product_id, variant_id
|
|
50
46
|
`;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
for (let e of s) {
|
|
48
|
+
if (e.variant_id) {
|
|
49
|
+
let t = (await r`
|
|
54
50
|
SELECT
|
|
55
51
|
sku,
|
|
56
52
|
stock_quantity
|
|
57
53
|
FROM public.product_variants
|
|
58
|
-
WHERE id = ${
|
|
54
|
+
WHERE id = ${e.variant_id}
|
|
59
55
|
LIMIT 1
|
|
60
56
|
`)[0];
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
await t`
|
|
57
|
+
if (!t?.sku) continue;
|
|
58
|
+
await r`
|
|
64
59
|
INSERT INTO public.inventory_items (sku, quantity)
|
|
65
|
-
VALUES (${
|
|
60
|
+
VALUES (${t.sku}, ${Math.max(0, t.stock_quantity ?? 0)})
|
|
66
61
|
ON CONFLICT (sku) DO NOTHING
|
|
67
|
-
`, await
|
|
62
|
+
`, await r`
|
|
68
63
|
UPDATE public.inventory_items
|
|
69
64
|
SET
|
|
70
|
-
quantity = GREATEST(COALESCE(quantity, 0) - ${
|
|
65
|
+
quantity = GREATEST(COALESCE(quantity, 0) - ${e.quantity}, 0),
|
|
71
66
|
updated_at = now()
|
|
72
|
-
WHERE sku = ${
|
|
67
|
+
WHERE sku = ${t.sku}
|
|
73
68
|
`;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (e.product_id) {
|
|
72
|
+
let t = (await r`
|
|
78
73
|
SELECT
|
|
79
74
|
sku,
|
|
80
75
|
stock
|
|
81
76
|
FROM public.products
|
|
82
|
-
WHERE id = ${
|
|
77
|
+
WHERE id = ${e.product_id}
|
|
83
78
|
LIMIT 1
|
|
84
79
|
`)[0];
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
await t`
|
|
80
|
+
if (!t?.sku) continue;
|
|
81
|
+
await r`
|
|
88
82
|
INSERT INTO public.inventory_items (sku, quantity)
|
|
89
|
-
VALUES (${
|
|
83
|
+
VALUES (${t.sku}, ${Math.max(0, t.stock ?? 0)})
|
|
90
84
|
ON CONFLICT (sku) DO NOTHING
|
|
91
|
-
`, await
|
|
85
|
+
`, await r`
|
|
92
86
|
UPDATE public.inventory_items
|
|
93
87
|
SET
|
|
94
|
-
quantity = GREATEST(COALESCE(quantity, 0) - ${
|
|
88
|
+
quantity = GREATEST(COALESCE(quantity, 0) - ${e.quantity}, 0),
|
|
95
89
|
updated_at = now()
|
|
96
|
-
WHERE sku = ${
|
|
90
|
+
WHERE sku = ${t.sku}
|
|
97
91
|
`;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
await r`
|
|
101
95
|
UPDATE public.orders
|
|
102
96
|
SET inventory_deducted_at = now()
|
|
103
|
-
WHERE id = ${
|
|
97
|
+
WHERE id = ${i}
|
|
104
98
|
`;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
});
|
|
100
|
+
} finally {
|
|
101
|
+
await o.end();
|
|
102
|
+
}
|
|
109
103
|
}
|
|
110
|
-
async function
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const t = e instanceof Error ? e.message : String(e);
|
|
121
|
-
throw new Error(
|
|
122
|
-
`Failed to reconcile inventory for order ${n}. RPC error: ${a.message}. Fallback error: ${t}`
|
|
123
|
-
);
|
|
124
|
-
}
|
|
104
|
+
async function a(e, t) {
|
|
105
|
+
let { error: n } = await e.rpc("apply_order_inventory_deduction", { p_order_id: t });
|
|
106
|
+
if (!n) return { method: "rpc" };
|
|
107
|
+
console.error(`[Inventory] RPC deduction failed for order ${t}:`, n);
|
|
108
|
+
try {
|
|
109
|
+
return await i(t), { method: "sql-fallback" };
|
|
110
|
+
} catch (e) {
|
|
111
|
+
let r = e instanceof Error ? e.message : String(e);
|
|
112
|
+
throw Error(`Failed to reconcile inventory for order ${t}. RPC error: ${n.message}. Fallback error: ${r}`);
|
|
113
|
+
}
|
|
125
114
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
};
|
|
115
|
+
//#endregion
|
|
116
|
+
export { a as applyOrderInventoryDeduction };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var e={gst:`GST`,qst:`QST`,hst:`HST`,pst:`PST`,vat:`VAT`,sales_tax:`Sales Tax`,amusement_tax:`Amusement Tax`,retail_delivery_fee:`Retail Delivery Fee`};function t(){return new Date().toISOString()}function n(t){let n=t.tax_type?.trim().toLowerCase();return n&&e[n]?e[n]:t.display_name||`Tax`}function r(e){return typeof e.effective_percentage==`number`?e.effective_percentage:typeof e.percentage==`number`?e.percentage:null}function i(e){return e.jurisdiction?e.jurisdiction:[e.state,e.country].filter(Boolean).join(`, `)||null}function a(e){return JSON.stringify({source:e.source,rate_id:e.rate.id??null,display_name:n(e.rate),percentage:r(e.rate),jurisdiction:i(e.rate),jurisdiction_level:e.rate.jurisdiction_level??null,country:e.rate.country??null,state:e.rate.state??null,tax_type:e.rate.tax_type??null,inclusive:e.rate.inclusive??null})}function o(e){let t=new Map;for(let n of e){let e=a(n),r=t.get(e);if(!r){t.set(e,{...n,scope:`aggregate`,line_item_id:null});continue}r.amount+=n.amount,r.taxable_amount=typeof r.taxable_amount==`number`||typeof n.taxable_amount==`number`?(typeof r.taxable_amount==`number`?r.taxable_amount:0)+(typeof n.taxable_amount==`number`?n.taxable_amount:0):null,r.description!==n.description&&(r.description=null),r.taxability_reason!==n.taxability_reason&&(r.taxability_reason=null)}return[...t.values()].sort((e,t)=>{let i=n(e.rate).localeCompare(n(t.rate));return i===0?(r(e.rate)??0)-(r(t.rate)??0):i})}function s(e){if(!e||typeof e!=`object`||Array.isArray(e))return null;let n=e;return typeof n.currency==`string`?{source:n.source===`manual`||n.source===`stripe_checkout`||n.source===`none`?n.source:`none`,mode:n.mode===`automatic`?`automatic`:`manual`,currency:n.currency,subtotal:typeof n.subtotal==`number`?n.subtotal:0,shipping_total:typeof n.shipping_total==`number`?n.shipping_total:0,tax_total:typeof n.tax_total==`number`?n.tax_total:0,total:typeof n.total==`number`?n.total:0,is_finalized:!!n.is_finalized,lines:Array.isArray(n.lines)?o(n.lines):[],updated_at:typeof n.updated_at==`string`?n.updated_at:t()}:null}function c(e){let n=e.currency||`usd`,r=e.calculation.mode===`manual`&&!e.calculation.isPendingExternalCalculation;return{source:e.calculation.enabled&&e.calculation.mode===`manual`?`manual`:e.calculation.mode===`automatic`?`stripe_checkout`:`none`,mode:e.calculation.mode,currency:n,subtotal:e.subtotal,shipping_total:e.shippingTotal,tax_total:e.calculation.amount,total:e.total,is_finalized:r,lines:e.calculation.enabled&&e.calculation.mode===`manual`?e.calculation.lines.map(t=>({scope:`aggregate`,source:`manual`,amount:t.amount,taxable_amount:e.calculation.taxableSubtotal,description:t.name,rate:{id:t.id??null,display_name:t.name,percentage:t.rate,country:t.country_code,state:t.state_code??null}})):[],updated_at:t()}}function l(e){return{id:e.id,display_name:e.display_name,percentage:e.percentage,effective_percentage:e.effective_percentage,jurisdiction:e.jurisdiction,jurisdiction_level:e.jurisdiction_level,country:e.country,state:e.state,tax_type:e.tax_type,inclusive:e.inclusive,description:e.description}}function u(e){let n=e.currency||e.session.currency||`usd`,r=typeof e.session.amount_total==`number`?e.session.amount_total:0,i=e.session.total_details?.amount_tax??0,a=[];for(let t of e.lineItems)for(let e of t.taxes||[])a.push({scope:`line_item`,source:`stripe_checkout`,amount:e.amount,taxable_amount:e.taxable_amount,description:t.description||void 0,line_item_id:t.id,taxability_reason:e.taxability_reason,rate:l(e.rate)});if(a.length===0)for(let t of e.session.total_details?.breakdown?.taxes||[])a.push({scope:`aggregate`,source:`stripe_checkout`,amount:t.amount,taxable_amount:t.taxable_amount,description:t.rate.display_name,taxability_reason:t.taxability_reason,rate:l(t.rate)});let s=o(a);return{source:i>0||s.length>0?`stripe_checkout`:`none`,mode:e.fallbackMode===`manual`?`manual`:`automatic`,currency:n,subtotal:e.subtotal,shipping_total:e.shippingTotal,tax_total:i,total:r,is_finalized:!0,lines:s,updated_at:t()}}exports.aggregateOrderTaxLines=o,exports.buildOrderTaxDetailsFromCalculation=c,exports.buildOrderTaxDetailsFromStripeSession=u,exports.getOrderTaxRateJurisdiction=i,exports.getOrderTaxRateLabel=n,exports.getOrderTaxRatePercentage=r,exports.normalizeOrderTaxDetails=s;
|
|
@@ -1,164 +1,153 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//#region libs/ecommerce/src/lib/order-tax-details.ts
|
|
2
|
+
var e = {
|
|
3
|
+
gst: "GST",
|
|
4
|
+
qst: "QST",
|
|
5
|
+
hst: "HST",
|
|
6
|
+
pst: "PST",
|
|
7
|
+
vat: "VAT",
|
|
8
|
+
sales_tax: "Sales Tax",
|
|
9
|
+
amusement_tax: "Amusement Tax",
|
|
10
|
+
retail_delivery_fee: "Retail Delivery Fee"
|
|
10
11
|
};
|
|
11
|
-
function
|
|
12
|
-
|
|
12
|
+
function t() {
|
|
13
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
function n(t) {
|
|
16
|
+
let n = t.tax_type?.trim().toLowerCase();
|
|
17
|
+
return n && e[n] ? e[n] : t.display_name || "Tax";
|
|
17
18
|
}
|
|
18
|
-
function
|
|
19
|
-
|
|
19
|
+
function r(e) {
|
|
20
|
+
return typeof e.effective_percentage == "number" ? e.effective_percentage : typeof e.percentage == "number" ? e.percentage : null;
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
-
|
|
22
|
+
function i(e) {
|
|
23
|
+
return e.jurisdiction ? e.jurisdiction : [e.state, e.country].filter(Boolean).join(", ") || null;
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
function a(e) {
|
|
26
|
+
return JSON.stringify({
|
|
27
|
+
source: e.source,
|
|
28
|
+
rate_id: e.rate.id ?? null,
|
|
29
|
+
display_name: n(e.rate),
|
|
30
|
+
percentage: r(e.rate),
|
|
31
|
+
jurisdiction: i(e.rate),
|
|
32
|
+
jurisdiction_level: e.rate.jurisdiction_level ?? null,
|
|
33
|
+
country: e.rate.country ?? null,
|
|
34
|
+
state: e.rate.state ?? null,
|
|
35
|
+
tax_type: e.rate.tax_type ?? null,
|
|
36
|
+
inclusive: e.rate.inclusive ?? null
|
|
37
|
+
});
|
|
37
38
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
39
|
+
function o(e) {
|
|
40
|
+
let t = /* @__PURE__ */ new Map();
|
|
41
|
+
for (let n of e) {
|
|
42
|
+
let e = a(n), r = t.get(e);
|
|
43
|
+
if (!r) {
|
|
44
|
+
t.set(e, {
|
|
45
|
+
...n,
|
|
46
|
+
scope: "aggregate",
|
|
47
|
+
line_item_id: null
|
|
48
|
+
});
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
r.amount += n.amount, r.taxable_amount = typeof r.taxable_amount == "number" || typeof n.taxable_amount == "number" ? (typeof r.taxable_amount == "number" ? r.taxable_amount : 0) + (typeof n.taxable_amount == "number" ? n.taxable_amount : 0) : null, r.description !== n.description && (r.description = null), r.taxability_reason !== n.taxability_reason && (r.taxability_reason = null);
|
|
52
|
+
}
|
|
53
|
+
return [...t.values()].sort((e, t) => {
|
|
54
|
+
let i = n(e.rate).localeCompare(n(t.rate));
|
|
55
|
+
return i === 0 ? (r(e.rate) ?? 0) - (r(t.rate) ?? 0) : i;
|
|
56
|
+
});
|
|
56
57
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
};
|
|
58
|
+
function s(e) {
|
|
59
|
+
if (!e || typeof e != "object" || Array.isArray(e)) return null;
|
|
60
|
+
let n = e;
|
|
61
|
+
return typeof n.currency == "string" ? {
|
|
62
|
+
source: n.source === "manual" || n.source === "stripe_checkout" || n.source === "none" ? n.source : "none",
|
|
63
|
+
mode: n.mode === "automatic" ? "automatic" : "manual",
|
|
64
|
+
currency: n.currency,
|
|
65
|
+
subtotal: typeof n.subtotal == "number" ? n.subtotal : 0,
|
|
66
|
+
shipping_total: typeof n.shipping_total == "number" ? n.shipping_total : 0,
|
|
67
|
+
tax_total: typeof n.tax_total == "number" ? n.tax_total : 0,
|
|
68
|
+
total: typeof n.total == "number" ? n.total : 0,
|
|
69
|
+
is_finalized: !!n.is_finalized,
|
|
70
|
+
lines: Array.isArray(n.lines) ? o(n.lines) : [],
|
|
71
|
+
updated_at: typeof n.updated_at == "string" ? n.updated_at : t()
|
|
72
|
+
} : null;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
74
|
+
function c(e) {
|
|
75
|
+
let n = e.currency || "usd", r = e.calculation.mode === "manual" && !e.calculation.isPendingExternalCalculation;
|
|
76
|
+
return {
|
|
77
|
+
source: e.calculation.enabled && e.calculation.mode === "manual" ? "manual" : e.calculation.mode === "automatic" ? "stripe_checkout" : "none",
|
|
78
|
+
mode: e.calculation.mode,
|
|
79
|
+
currency: n,
|
|
80
|
+
subtotal: e.subtotal,
|
|
81
|
+
shipping_total: e.shippingTotal,
|
|
82
|
+
tax_total: e.calculation.amount,
|
|
83
|
+
total: e.total,
|
|
84
|
+
is_finalized: r,
|
|
85
|
+
lines: e.calculation.enabled && e.calculation.mode === "manual" ? e.calculation.lines.map((t) => ({
|
|
86
|
+
scope: "aggregate",
|
|
87
|
+
source: "manual",
|
|
88
|
+
amount: t.amount,
|
|
89
|
+
taxable_amount: e.calculation.taxableSubtotal,
|
|
90
|
+
description: t.name,
|
|
91
|
+
rate: {
|
|
92
|
+
id: t.id ?? null,
|
|
93
|
+
display_name: t.name,
|
|
94
|
+
percentage: t.rate,
|
|
95
|
+
country: t.country_code,
|
|
96
|
+
state: t.state_code ?? null
|
|
97
|
+
}
|
|
98
|
+
})) : [],
|
|
99
|
+
updated_at: t()
|
|
100
|
+
};
|
|
101
101
|
}
|
|
102
|
-
function
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
102
|
+
function l(e) {
|
|
103
|
+
return {
|
|
104
|
+
id: e.id,
|
|
105
|
+
display_name: e.display_name,
|
|
106
|
+
percentage: e.percentage,
|
|
107
|
+
effective_percentage: e.effective_percentage,
|
|
108
|
+
jurisdiction: e.jurisdiction,
|
|
109
|
+
jurisdiction_level: e.jurisdiction_level,
|
|
110
|
+
country: e.country,
|
|
111
|
+
state: e.state,
|
|
112
|
+
tax_type: e.tax_type,
|
|
113
|
+
inclusive: e.inclusive,
|
|
114
|
+
description: e.description
|
|
115
|
+
};
|
|
116
116
|
}
|
|
117
|
-
function
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
is_finalized: !0,
|
|
152
|
-
lines: u,
|
|
153
|
-
updated_at: c()
|
|
154
|
-
};
|
|
117
|
+
function u(e) {
|
|
118
|
+
let n = e.currency || e.session.currency || "usd", r = typeof e.session.amount_total == "number" ? e.session.amount_total : 0, i = e.session.total_details?.amount_tax ?? 0, a = [];
|
|
119
|
+
for (let t of e.lineItems) for (let e of t.taxes || []) a.push({
|
|
120
|
+
scope: "line_item",
|
|
121
|
+
source: "stripe_checkout",
|
|
122
|
+
amount: e.amount,
|
|
123
|
+
taxable_amount: e.taxable_amount,
|
|
124
|
+
description: t.description || void 0,
|
|
125
|
+
line_item_id: t.id,
|
|
126
|
+
taxability_reason: e.taxability_reason,
|
|
127
|
+
rate: l(e.rate)
|
|
128
|
+
});
|
|
129
|
+
if (a.length === 0) for (let t of e.session.total_details?.breakdown?.taxes || []) a.push({
|
|
130
|
+
scope: "aggregate",
|
|
131
|
+
source: "stripe_checkout",
|
|
132
|
+
amount: t.amount,
|
|
133
|
+
taxable_amount: t.taxable_amount,
|
|
134
|
+
description: t.rate.display_name,
|
|
135
|
+
taxability_reason: t.taxability_reason,
|
|
136
|
+
rate: l(t.rate)
|
|
137
|
+
});
|
|
138
|
+
let s = o(a);
|
|
139
|
+
return {
|
|
140
|
+
source: i > 0 || s.length > 0 ? "stripe_checkout" : "none",
|
|
141
|
+
mode: e.fallbackMode === "manual" ? "manual" : "automatic",
|
|
142
|
+
currency: n,
|
|
143
|
+
subtotal: e.subtotal,
|
|
144
|
+
shipping_total: e.shippingTotal,
|
|
145
|
+
tax_total: i,
|
|
146
|
+
total: r,
|
|
147
|
+
is_finalized: !0,
|
|
148
|
+
lines: s,
|
|
149
|
+
updated_at: t()
|
|
150
|
+
};
|
|
155
151
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
x as buildOrderTaxDetailsFromCalculation,
|
|
159
|
-
b as buildOrderTaxDetailsFromStripeSession,
|
|
160
|
-
f as getOrderTaxRateJurisdiction,
|
|
161
|
-
l as getOrderTaxRateLabel,
|
|
162
|
-
s as getOrderTaxRatePercentage,
|
|
163
|
-
y as normalizeOrderTaxDetails
|
|
164
|
-
};
|
|
152
|
+
//#endregion
|
|
153
|
+
export { o as aggregateOrderTaxLines, c as buildOrderTaxDetailsFromCalculation, u as buildOrderTaxDetailsFromStripeSession, i as getOrderTaxRateJurisdiction, n as getOrderTaxRateLabel, r as getOrderTaxRatePercentage, s as normalizeOrderTaxDetails };
|