@aglyn/plugins-commerce 1.0.0-beta.230 → 1.0.0-beta.232
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/package.json +13 -13
- package/src/index.d.ts +0 -1
- package/src/index.js +0 -1
- package/src/index.js.map +1 -1
- package/src/lib/barcode/barcode-decode.d.ts +71 -0
- package/src/lib/barcode/barcode-decode.js +498 -0
- package/src/lib/barcode/barcode-decode.js.map +1 -0
- package/src/lib/barcode/barcode-encode.d.ts +44 -0
- package/src/lib/barcode/barcode-encode.js +138 -0
- package/src/lib/barcode/barcode-encode.js.map +1 -0
- package/src/lib/barcode/barcode-scanner.component.d.ts +23 -0
- package/src/lib/barcode/barcode-scanner.component.js +260 -0
- package/src/lib/barcode/barcode-scanner.component.js.map +1 -0
- package/src/lib/barcode/scan-button.component.d.ts +10 -0
- package/src/lib/barcode/scan-button.component.js +62 -0
- package/src/lib/barcode/scan-button.component.js.map +1 -0
- package/src/lib/barcode/scanner-wedge.d.ts +35 -0
- package/src/lib/barcode/scanner-wedge.js +108 -0
- package/src/lib/barcode/scanner-wedge.js.map +1 -0
- package/src/lib/components/account.js +10 -1
- package/src/lib/components/account.js.map +1 -1
- package/src/lib/components/cart-extras.d.ts +45 -0
- package/src/lib/components/cart-extras.js +127 -0
- package/src/lib/components/cart-extras.js.map +1 -0
- package/src/lib/components/cart.js +82 -15
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/checkout-return-notice.d.ts +26 -0
- package/src/lib/components/checkout-return-notice.js +48 -0
- package/src/lib/components/checkout-return-notice.js.map +1 -0
- package/src/lib/components/commerce-console-page.js +124 -0
- package/src/lib/components/commerce-console-page.js.map +1 -1
- package/src/lib/components/commerce-console-sections.d.ts +1 -1
- package/src/lib/components/commerce-console-sections.js +4 -0
- package/src/lib/components/commerce-console-sections.js.map +1 -1
- package/src/lib/components/console/bulk-fulfill.d.ts +44 -0
- package/src/lib/components/console/bulk-fulfill.js +84 -0
- package/src/lib/components/console/bulk-fulfill.js.map +1 -0
- package/src/lib/components/console/catalog-organization-card.component.js +1 -0
- package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
- package/src/lib/components/console/customer-notifications-card.component.d.ts +19 -0
- package/src/lib/components/console/customer-notifications-card.component.js +149 -0
- package/src/lib/components/console/customer-notifications-card.component.js.map +1 -0
- package/src/lib/components/console/host-orders-card.component.js +88 -6
- package/src/lib/components/console/host-orders-card.component.js.map +1 -1
- package/src/lib/components/console/locations-card.component.js +164 -57
- package/src/lib/components/console/locations-card.component.js.map +1 -1
- package/src/lib/components/console/order-detail-dialog.component.js +209 -61
- package/src/lib/components/console/order-detail-dialog.component.js.map +1 -1
- package/src/lib/components/console/order-fulfillment-panel.component.d.ts +48 -0
- package/src/lib/components/console/order-fulfillment-panel.component.js +542 -0
- package/src/lib/components/console/order-fulfillment-panel.component.js.map +1 -0
- package/src/lib/components/console/order-invoice.component.d.ts +33 -0
- package/src/lib/components/console/order-invoice.component.js +81 -0
- package/src/lib/components/console/order-invoice.component.js.map +1 -0
- package/src/lib/components/console/order-receipt-resend.component.d.ts +21 -0
- package/src/lib/components/console/order-receipt-resend.component.js +203 -0
- package/src/lib/components/console/order-receipt-resend.component.js.map +1 -0
- package/src/lib/components/console/order-returns.component.d.ts +36 -0
- package/src/lib/components/console/order-returns.component.js +142 -0
- package/src/lib/components/console/order-returns.component.js.map +1 -0
- package/src/lib/components/console/order-shipping-actions.component.d.ts +54 -0
- package/src/lib/components/console/order-shipping-actions.component.js +149 -0
- package/src/lib/components/console/order-shipping-actions.component.js.map +1 -0
- package/src/lib/components/console/order-webhooks-card.component.d.ts +50 -0
- package/src/lib/components/console/order-webhooks-card.component.js +623 -0
- package/src/lib/components/console/order-webhooks-card.component.js.map +1 -0
- package/src/lib/components/console/order-zones.d.ts +155 -0
- package/src/lib/components/console/order-zones.js +40 -0
- package/src/lib/components/console/order-zones.js.map +1 -0
- package/src/lib/components/console/payment-methods-card.component.d.ts +67 -0
- package/src/lib/components/console/payment-methods-card.component.js +395 -0
- package/src/lib/components/console/payment-methods-card.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-api.d.ts +124 -0
- package/src/lib/components/console/pos/pos-api.js +101 -0
- package/src/lib/components/console/pos/pos-api.js.map +1 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.d.ts +36 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.js +160 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.d.ts +39 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.js +352 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-product-grid.component.d.ts +47 -0
- package/src/lib/components/console/pos/pos-product-grid.component.js +272 -0
- package/src/lib/components/console/pos/pos-product-grid.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-receipt-panel.component.d.ts +27 -0
- package/src/lib/components/console/pos/pos-receipt-panel.component.js +282 -0
- package/src/lib/components/console/pos/pos-receipt-panel.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +53 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js +445 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-tender-panel.component.d.ts +31 -0
- package/src/lib/components/console/pos/pos-tender-panel.component.js +640 -0
- package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -0
- package/src/lib/components/console/pos/use-pos-display.d.ts +43 -0
- package/src/lib/components/console/pos/use-pos-display.js +161 -0
- package/src/lib/components/console/pos/use-pos-display.js.map +1 -0
- package/src/lib/components/console/pos-devices-card.component.d.ts +14 -0
- package/src/lib/components/console/pos-devices-card.component.js +546 -0
- package/src/lib/components/console/pos-devices-card.component.js.map +1 -0
- package/src/lib/components/console/pos-display/brand-screen.d.ts +33 -0
- package/src/lib/components/console/pos-display/brand-screen.js +85 -0
- package/src/lib/components/console/pos-display/brand-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/cart-screen.d.ts +29 -0
- package/src/lib/components/console/pos-display/cart-screen.js +166 -0
- package/src/lib/components/console/pos-display/cart-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/pairing-screen.d.ts +24 -0
- package/src/lib/components/console/pos-display/pairing-screen.js +127 -0
- package/src/lib/components/console/pos-display/pairing-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/pos-display-api.d.ts +90 -0
- package/src/lib/components/console/pos-display/pos-display-api.js +140 -0
- package/src/lib/components/console/pos-display/pos-display-api.js.map +1 -0
- package/src/lib/components/console/pos-display/receipt-screen.d.ts +35 -0
- package/src/lib/components/console/pos-display/receipt-screen.js +200 -0
- package/src/lib/components/console/pos-display/receipt-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/tip-screen.d.ts +36 -0
- package/src/lib/components/console/pos-display/tip-screen.js +211 -0
- package/src/lib/components/console/pos-display/tip-screen.js.map +1 -0
- package/src/lib/components/console/pos-display-page.component.d.ts +16 -0
- package/src/lib/components/console/pos-display-page.component.js +407 -0
- package/src/lib/components/console/pos-display-page.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-customer-lookup.component.d.ts +40 -0
- package/src/lib/components/console/pos-ops/pos-customer-lookup.component.js +289 -0
- package/src/lib/components/console/pos-ops/pos-customer-lookup.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-last-receipt.component.d.ts +34 -0
- package/src/lib/components/console/pos-ops/pos-last-receipt.component.js +61 -0
- package/src/lib/components/console/pos-ops/pos-last-receipt.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.d.ts +38 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.js +129 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-ops-api.d.ts +37 -0
- package/src/lib/components/console/pos-ops/pos-ops-api.js +60 -0
- package/src/lib/components/console/pos-ops/pos-ops-api.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-pin-pad.component.d.ts +48 -0
- package/src/lib/components/console/pos-ops/pos-pin-pad.component.js +220 -0
- package/src/lib/components/console/pos-ops/pos-pin-pad.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-receipt-actions.component.d.ts +63 -0
- package/src/lib/components/console/pos-ops/pos-receipt-actions.component.js +186 -0
- package/src/lib/components/console/pos-ops/pos-receipt-actions.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-receipt.d.ts +39 -0
- package/src/lib/components/console/pos-ops/pos-receipt.js +182 -0
- package/src/lib/components/console/pos-ops/pos-receipt.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-return-dialog.component.d.ts +40 -0
- package/src/lib/components/console/pos-ops/pos-return-dialog.component.js +465 -0
- package/src/lib/components/console/pos-ops/pos-return-dialog.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-history-card.component.d.ts +29 -0
- package/src/lib/components/console/pos-ops/pos-shift-history-card.component.js +253 -0
- package/src/lib/components/console/pos-ops/pos-shift-history-card.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.d.ts +34 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.js +494 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-report.component.d.ts +37 -0
- package/src/lib/components/console/pos-ops/pos-shift-report.component.js +102 -0
- package/src/lib/components/console/pos-ops/pos-shift-report.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.d.ts +30 -0
- package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.js +277 -0
- package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/register-ops.d.ts +28 -0
- package/src/lib/components/console/pos-ops/register-ops.js +28 -0
- package/src/lib/components/console/pos-ops/register-ops.js.map +1 -0
- package/src/lib/components/console/pos-ops/use-pos-cashier.d.ts +46 -0
- package/src/lib/components/console/pos-ops/use-pos-cashier.js +128 -0
- package/src/lib/components/console/pos-ops/use-pos-cashier.js.map +1 -0
- package/src/lib/components/console/pos-ops/use-pos-sale-receipt.d.ts +36 -0
- package/src/lib/components/console/pos-ops/use-pos-sale-receipt.js +64 -0
- package/src/lib/components/console/pos-ops/use-pos-sale-receipt.js.map +1 -0
- package/src/lib/components/console/pos-page.component.d.ts +13 -5
- package/src/lib/components/console/pos-page.component.js +756 -654
- package/src/lib/components/console/pos-page.component.js.map +1 -1
- package/src/lib/components/console/pos-zones.d.ts +23 -0
- package/src/lib/components/console/pos-zones.js +31 -0
- package/src/lib/components/console/pos-zones.js.map +1 -0
- package/src/lib/components/console/product-editor-dialog.component.js +61 -71
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/product-labels-dialog.component.d.ts +13 -0
- package/src/lib/components/console/product-labels-dialog.component.js +197 -0
- package/src/lib/components/console/product-labels-dialog.component.js.map +1 -0
- package/src/lib/components/console/product-register-fields.component.d.ts +19 -0
- package/src/lib/components/console/product-register-fields.component.js +241 -0
- package/src/lib/components/console/product-register-fields.component.js.map +1 -0
- package/src/lib/components/console/product-zones.d.ts +44 -0
- package/src/lib/components/console/product-zones.js.map +1 -1
- package/src/lib/components/console/products-hub-card.component.js +23 -20
- package/src/lib/components/console/products-hub-card.component.js.map +1 -1
- package/src/lib/components/console/register-hardware-card.component.d.ts +33 -0
- package/src/lib/components/console/register-hardware-card.component.js +826 -0
- package/src/lib/components/console/register-hardware-card.component.js.map +1 -0
- package/src/lib/components/console/registers-card.component.js +24 -5
- package/src/lib/components/console/registers-card.component.js.map +1 -1
- package/src/lib/components/console/return-actions.d.ts +38 -0
- package/src/lib/components/console/return-actions.js +76 -0
- package/src/lib/components/console/return-actions.js.map +1 -0
- package/src/lib/components/console/return-detail-dialog.component.d.ts +34 -0
- package/src/lib/components/console/return-detail-dialog.component.js +718 -0
- package/src/lib/components/console/return-detail-dialog.component.js.map +1 -0
- package/src/lib/components/console/return-settings-card.component.d.ts +34 -0
- package/src/lib/components/console/return-settings-card.component.js +195 -0
- package/src/lib/components/console/return-settings-card.component.js.map +1 -0
- package/src/lib/components/console/return-zones.d.ts +87 -0
- package/src/lib/components/console/return-zones.js +31 -0
- package/src/lib/components/console/return-zones.js.map +1 -0
- package/src/lib/components/console/returns-card.component.d.ts +45 -0
- package/src/lib/components/console/returns-card.component.js +159 -0
- package/src/lib/components/console/returns-card.component.js.map +1 -0
- package/src/lib/components/console/shipping-settings-card.component.js +161 -5
- package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
- package/src/lib/components/console/shippingeasy-card.component.d.ts +59 -0
- package/src/lib/components/console/shippingeasy-card.component.js +378 -0
- package/src/lib/components/console/shippingeasy-card.component.js.map +1 -0
- package/src/lib/components/console/shipstation-card.component.d.ts +35 -0
- package/src/lib/components/console/shipstation-card.component.js +345 -0
- package/src/lib/components/console/shipstation-card.component.js.map +1 -0
- package/src/lib/components/console/start-return-dialog.component.d.ts +40 -0
- package/src/lib/components/console/start-return-dialog.component.js +243 -0
- package/src/lib/components/console/start-return-dialog.component.js.map +1 -0
- package/src/lib/components/console/stock-movements-card.component.js +2 -1
- package/src/lib/components/console/stock-movements-card.component.js.map +1 -1
- package/src/lib/components/console/store-settings-card.component.js +2 -66
- package/src/lib/components/console/store-settings-card.component.js.map +1 -1
- package/src/lib/components/console/store-zones.d.ts +42 -0
- package/src/lib/components/console/store-zones.js +39 -0
- package/src/lib/components/console/store-zones.js.map +1 -0
- package/src/lib/components/console/storefront-tax-summary-card.component.js +1 -0
- package/src/lib/components/console/storefront-tax-summary-card.component.js.map +1 -1
- package/src/lib/components/order-status.d.ts +36 -0
- package/src/lib/components/order-status.js +502 -0
- package/src/lib/components/order-status.js.map +1 -0
- package/src/lib/components/product-detail.js +41 -2
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/return-request.d.ts +32 -0
- package/src/lib/components/return-request.js +576 -0
- package/src/lib/components/return-request.js.map +1 -0
- package/src/lib/components/storefront-payment-appearance.d.ts +32 -0
- package/src/lib/components/storefront-payment-appearance.js +114 -0
- package/src/lib/components/storefront-payment-appearance.js.map +1 -0
- package/src/lib/components/storefront-payment-element.d.ts +57 -1
- package/src/lib/components/storefront-payment-element.js +332 -33
- package/src/lib/components/storefront-payment-element.js.map +1 -1
- package/src/lib/constants/order-status.d.ts +22 -0
- package/src/lib/constants/order-status.js +22 -0
- package/src/lib/constants/order-status.js.map +1 -0
- package/src/lib/constants/return-request.d.ts +27 -0
- package/src/lib/constants/return-request.js +32 -0
- package/src/lib/constants/return-request.js.map +1 -0
- package/src/lib/constants/stock-movement-query.js +2 -1
- package/src/lib/constants/stock-movement-query.js.map +1 -1
- package/src/lib/declarations.console-server.js +9 -0
- package/src/lib/declarations.console-server.js.map +1 -1
- package/src/lib/declarations.server.d.ts +2 -1
- package/src/lib/declarations.server.js +68 -1
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/model/buyer-notifications.d.ts +59 -0
- package/src/lib/model/buyer-notifications.js +97 -0
- package/src/lib/model/buyer-notifications.js.map +1 -0
- package/src/lib/model/commerce-orders.d.ts +171 -2
- package/src/lib/model/commerce-orders.js +26 -16
- package/src/lib/model/commerce-orders.js.map +1 -1
- package/src/lib/model/commerce-payment-methods.d.ts +146 -0
- package/src/lib/model/commerce-payment-methods.js +247 -0
- package/src/lib/model/commerce-payment-methods.js.map +1 -0
- package/src/lib/model/commerce-pos-ops.d.ts +437 -0
- package/src/lib/model/commerce-pos-ops.js +721 -0
- package/src/lib/model/commerce-pos-ops.js.map +1 -0
- package/src/lib/model/commerce-pos.d.ts +263 -0
- package/src/lib/model/commerce-pos.js +375 -0
- package/src/lib/model/commerce-pos.js.map +1 -0
- package/src/lib/model/commerce-printers.d.ts +211 -0
- package/src/lib/model/commerce-printers.js +181 -0
- package/src/lib/model/commerce-printers.js.map +1 -0
- package/src/lib/model/commerce-receipt.d.ts +97 -0
- package/src/lib/model/commerce-receipt.js +180 -0
- package/src/lib/model/commerce-receipt.js.map +1 -0
- package/src/lib/model/commerce-returns.d.ts +207 -0
- package/src/lib/model/commerce-returns.js +300 -0
- package/src/lib/model/commerce-returns.js.map +1 -0
- package/src/lib/model/commerce-shipping.d.ts +44 -1
- package/src/lib/model/commerce-shipping.js +53 -9
- package/src/lib/model/commerce-shipping.js.map +1 -1
- package/src/lib/model/commerce-tax-engine.d.ts +90 -0
- package/src/lib/model/commerce-tax-engine.js +129 -0
- package/src/lib/model/commerce-tax-engine.js.map +1 -0
- package/src/lib/model/commerce.d.ts +91 -2
- package/src/lib/model/commerce.js +89 -1
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/index.d.ts +16 -0
- package/src/lib/model/index.js +16 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/order-events.d.ts +154 -0
- package/src/lib/model/order-events.js +153 -0
- package/src/lib/model/order-events.js.map +1 -0
- package/src/lib/model/order-fulfillment.d.ts +117 -0
- package/src/lib/model/order-fulfillment.js +217 -0
- package/src/lib/model/order-fulfillment.js.map +1 -0
- package/src/lib/model/order-history.d.ts +58 -0
- package/src/lib/model/order-history.js +22 -0
- package/src/lib/model/order-history.js.map +1 -0
- package/src/lib/model/order-list-fields.d.ts +9 -1
- package/src/lib/model/order-list-fields.js +7 -1
- package/src/lib/model/order-list-fields.js.map +1 -1
- package/src/lib/model/order-shipping-export.d.ts +91 -0
- package/src/lib/model/order-shipping-export.js +192 -0
- package/src/lib/model/order-shipping-export.js.map +1 -0
- package/src/lib/model/order-status-view.d.ts +103 -0
- package/src/lib/model/order-status-view.js +156 -0
- package/src/lib/model/order-status-view.js.map +1 -0
- package/src/lib/model/order-webhooks.d.ts +142 -0
- package/src/lib/model/order-webhooks.js +91 -0
- package/src/lib/model/order-webhooks.js.map +1 -0
- package/src/lib/model/product-channel.d.ts +56 -0
- package/src/lib/model/product-channel.js +86 -0
- package/src/lib/model/product-channel.js.map +1 -0
- package/src/lib/model/product-modifiers.d.ts +80 -0
- package/src/lib/model/product-modifiers.js +140 -0
- package/src/lib/model/product-modifiers.js.map +1 -0
- package/src/lib/model/product-write.d.ts +186 -0
- package/src/lib/model/product-write.js +116 -0
- package/src/lib/model/product-write.js.map +1 -0
- package/src/lib/model/shippingeasy.d.ts +94 -0
- package/src/lib/model/shippingeasy.js +267 -0
- package/src/lib/model/shippingeasy.js.map +1 -0
- package/src/lib/model/shipstation.d.ts +125 -0
- package/src/lib/model/shipstation.js +399 -0
- package/src/lib/model/shipstation.js.map +1 -0
- package/src/lib/model/smart-collection-reads.d.ts +32 -0
- package/src/lib/model/smart-collection-reads.js +63 -0
- package/src/lib/model/smart-collection-reads.js.map +1 -0
- package/src/lib/model/tracking-url.d.ts +74 -0
- package/src/lib/model/tracking-url.js +159 -0
- package/src/lib/model/tracking-url.js.map +1 -0
- package/src/lib/plugin-config.d.ts +13 -0
- package/src/lib/plugin-config.js +77 -5
- package/src/lib/plugin-config.js.map +1 -1
- package/src/lib/plugin.js +26 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/pos-ops-config.d.ts +39 -0
- package/src/lib/pos-ops-config.js +88 -0
- package/src/lib/pos-ops-config.js.map +1 -0
- package/src/lib/printing/print-document.d.ts +106 -0
- package/src/lib/printing/print-document.js +464 -0
- package/src/lib/printing/print-document.js.map +1 -0
- package/src/lib/printing/product-labels.d.ts +58 -0
- package/src/lib/printing/product-labels.js +116 -0
- package/src/lib/printing/product-labels.js.map +1 -0
- package/src/lib/printing/render-epson.d.ts +57 -0
- package/src/lib/printing/render-epson.js +135 -0
- package/src/lib/printing/render-epson.js.map +1 -0
- package/src/lib/printing/render-star.d.ts +45 -0
- package/src/lib/printing/render-star.js +100 -0
- package/src/lib/printing/render-star.js.map +1 -0
- package/src/lib/printing/render-text.d.ts +25 -0
- package/src/lib/printing/render-text.js +53 -0
- package/src/lib/printing/render-text.js.map +1 -0
- package/src/lib/server/api-v1/openapi.js +27 -4
- package/src/lib/server/api-v1/openapi.js.map +1 -1
- package/src/lib/server/api-v1/order-view.d.ts +67 -0
- package/src/lib/server/api-v1/order-view.js +120 -0
- package/src/lib/server/api-v1/order-view.js.map +1 -0
- package/src/lib/server/api-v1/orders-and-products.js +58 -65
- package/src/lib/server/api-v1/orders-and-products.js.map +1 -1
- package/src/lib/server/billing-webhook.js +135 -28
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cancel-order.js +29 -0
- package/src/lib/server/cancel-order.js.map +1 -1
- package/src/lib/server/carrier-rates-availability.d.ts +26 -0
- package/src/lib/server/carrier-rates-availability.js +76 -0
- package/src/lib/server/carrier-rates-availability.js.map +1 -0
- package/src/lib/server/carrier-shipping.d.ts +84 -0
- package/src/lib/server/carrier-shipping.js +135 -0
- package/src/lib/server/carrier-shipping.js.map +1 -0
- package/src/lib/server/cart-checkout.d.ts +2 -0
- package/src/lib/server/cart-checkout.js +226 -22
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/channel-order-updates.d.ts +50 -0
- package/src/lib/server/channel-order-updates.js +290 -0
- package/src/lib/server/channel-order-updates.js.map +1 -0
- package/src/lib/server/channel-orders.d.ts +85 -0
- package/src/lib/server/channel-orders.js +543 -0
- package/src/lib/server/channel-orders.js.map +1 -0
- package/src/lib/server/checkout-extras.d.ts +64 -0
- package/src/lib/server/checkout-extras.js +157 -0
- package/src/lib/server/checkout-extras.js.map +1 -0
- package/src/lib/server/{feed.d.ts → checkout-status.d.ts} +2 -7
- package/src/lib/server/checkout-status.js +111 -0
- package/src/lib/server/checkout-status.js.map +1 -0
- package/src/lib/server/checkout.js +86 -9
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/draft-order.js +34 -5
- package/src/lib/server/draft-order.js.map +1 -1
- package/src/lib/server/fulfill-order.d.ts +127 -10
- package/src/lib/server/fulfill-order.js +451 -49
- package/src/lib/server/fulfill-order.js.map +1 -1
- package/src/lib/server/legacy-feed.d.ts +28 -0
- package/src/lib/server/legacy-feed.js +52 -0
- package/src/lib/server/legacy-feed.js.map +1 -0
- package/src/lib/server/native-checkout.d.ts +34 -15
- package/src/lib/server/native-checkout.js +32 -17
- package/src/lib/server/native-checkout.js.map +1 -1
- package/src/lib/server/order-event-host-emit.d.ts +23 -0
- package/src/lib/server/order-event-host-emit.js +30 -0
- package/src/lib/server/order-event-host-emit.js.map +1 -0
- package/src/lib/server/order-event-triggers.d.ts +37 -0
- package/src/lib/server/order-event-triggers.js +119 -0
- package/src/lib/server/order-event-triggers.js.map +1 -0
- package/src/lib/server/order-events.d.ts +62 -0
- package/src/lib/server/order-events.js +109 -0
- package/src/lib/server/order-events.js.map +1 -0
- package/src/lib/server/order-history.d.ts +23 -0
- package/src/lib/server/order-history.js +65 -0
- package/src/lib/server/order-history.js.map +1 -0
- package/src/lib/server/order-notifications.d.ts +185 -0
- package/src/lib/server/order-notifications.js +567 -0
- package/src/lib/server/order-notifications.js.map +1 -0
- package/src/lib/server/order-receipt-send.d.ts +39 -0
- package/src/lib/server/order-receipt-send.js +151 -0
- package/src/lib/server/order-receipt-send.js.map +1 -0
- package/src/lib/server/order-status-token.d.ts +31 -0
- package/src/lib/server/order-status-token.js +75 -0
- package/src/lib/server/order-status-token.js.map +1 -0
- package/src/lib/server/order-status.d.ts +58 -0
- package/src/lib/server/order-status.js +141 -0
- package/src/lib/server/order-status.js.map +1 -0
- package/src/lib/server/order-webhooks.d.ts +108 -0
- package/src/lib/server/order-webhooks.js +622 -0
- package/src/lib/server/order-webhooks.js.map +1 -0
- package/src/lib/server/orders-shipping-prepare.d.ts +26 -0
- package/src/lib/server/orders-shipping-prepare.js +121 -0
- package/src/lib/server/orders-shipping-prepare.js.map +1 -0
- package/src/lib/server/payment-method-domains.d.ts +209 -0
- package/src/lib/server/payment-method-domains.js +444 -0
- package/src/lib/server/payment-method-domains.js.map +1 -0
- package/src/lib/server/payment-methods.d.ts +77 -0
- package/src/lib/server/payment-methods.js +284 -0
- package/src/lib/server/payment-methods.js.map +1 -0
- package/src/lib/server/pos-auth.d.ts +50 -0
- package/src/lib/server/pos-auth.js +121 -0
- package/src/lib/server/pos-auth.js.map +1 -0
- package/src/lib/server/pos-customer.d.ts +49 -0
- package/src/lib/server/pos-customer.js +257 -0
- package/src/lib/server/pos-customer.js.map +1 -0
- package/src/lib/server/pos-display.d.ts +57 -0
- package/src/lib/server/pos-display.js +419 -0
- package/src/lib/server/pos-display.js.map +1 -0
- package/src/lib/server/pos-fee-month.d.ts +34 -0
- package/src/lib/server/pos-fee-month.js +36 -0
- package/src/lib/server/pos-fee-month.js.map +1 -0
- package/src/lib/server/pos-ops-gate.d.ts +161 -0
- package/src/lib/server/pos-ops-gate.js +295 -0
- package/src/lib/server/pos-ops-gate.js.map +1 -0
- package/src/lib/server/pos-ops-routes.d.ts +22 -0
- package/src/lib/server/pos-ops-routes.js +36 -0
- package/src/lib/server/pos-ops-routes.js.map +1 -0
- package/src/lib/server/pos-order.d.ts +1 -18
- package/src/lib/server/pos-order.js +222 -42
- package/src/lib/server/pos-order.js.map +1 -1
- package/src/lib/server/pos-payment.d.ts +39 -0
- package/src/lib/server/pos-payment.js +922 -0
- package/src/lib/server/pos-payment.js.map +1 -0
- package/src/lib/server/pos-print.d.ts +82 -0
- package/src/lib/server/pos-print.js +193 -0
- package/src/lib/server/pos-print.js.map +1 -0
- package/src/lib/server/pos-readers.d.ts +27 -0
- package/src/lib/server/pos-readers.js +276 -0
- package/src/lib/server/pos-readers.js.map +1 -0
- package/src/lib/server/pos-refund-authority.d.ts +60 -0
- package/src/lib/server/pos-refund-authority.js +72 -0
- package/src/lib/server/pos-refund-authority.js.map +1 -0
- package/src/lib/server/pos-return.d.ts +58 -0
- package/src/lib/server/pos-return.js +891 -0
- package/src/lib/server/pos-return.js.map +1 -0
- package/src/lib/server/pos-sale-stamp.d.ts +66 -0
- package/src/lib/server/pos-sale-stamp.js +84 -0
- package/src/lib/server/pos-sale-stamp.js.map +1 -0
- package/src/lib/server/pos-sale.d.ts +170 -0
- package/src/lib/server/pos-sale.js +461 -0
- package/src/lib/server/pos-sale.js.map +1 -0
- package/src/lib/server/pos-shift.d.ts +45 -0
- package/src/lib/server/pos-shift.js +484 -0
- package/src/lib/server/pos-shift.js.map +1 -0
- package/src/lib/server/pos-staff-pin.d.ts +26 -0
- package/src/lib/server/pos-staff-pin.js +339 -0
- package/src/lib/server/pos-staff-pin.js.map +1 -0
- package/src/lib/server/pos-stripe.d.ts +91 -0
- package/src/lib/server/pos-stripe.js +129 -0
- package/src/lib/server/pos-stripe.js.map +1 -0
- package/src/lib/server/pos-terminal-connection-token.d.ts +48 -0
- package/src/lib/server/pos-terminal-connection-token.js +166 -0
- package/src/lib/server/pos-terminal-connection-token.js.map +1 -0
- package/src/lib/server/pos-terminal.d.ts +218 -0
- package/src/lib/server/pos-terminal.js +1014 -0
- package/src/lib/server/pos-terminal.js.map +1 -0
- package/src/lib/server/print-queue.d.ts +124 -0
- package/src/lib/server/print-queue.js +301 -0
- package/src/lib/server/print-queue.js.map +1 -0
- package/src/lib/server/printer-poll.d.ts +75 -0
- package/src/lib/server/printer-poll.js +325 -0
- package/src/lib/server/printer-poll.js.map +1 -0
- package/src/lib/server/printer-secret.d.ts +39 -0
- package/src/lib/server/printer-secret.js +56 -0
- package/src/lib/server/printer-secret.js.map +1 -0
- package/src/lib/server/printers.d.ts +114 -0
- package/src/lib/server/printers.js +546 -0
- package/src/lib/server/printers.js.map +1 -0
- package/src/lib/server/product-catalog.d.ts +42 -0
- package/src/lib/server/product-catalog.js +309 -0
- package/src/lib/server/product-catalog.js.map +1 -0
- package/src/lib/server/product-drafts.d.ts +5 -1
- package/src/lib/server/product-drafts.js +3 -3
- package/src/lib/server/product-drafts.js.map +1 -1
- package/src/lib/server/product-writer.d.ts +19 -0
- package/src/lib/server/product-writer.js +261 -0
- package/src/lib/server/product-writer.js.map +1 -0
- package/src/lib/server/products-write.d.ts +61 -0
- package/src/lib/server/products-write.js +375 -0
- package/src/lib/server/products-write.js.map +1 -0
- package/src/lib/server/refund.js +110 -45
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/reserve.js +2 -0
- package/src/lib/server/reserve.js.map +1 -1
- package/src/lib/server/return-status-action.d.ts +37 -0
- package/src/lib/server/return-status-action.js +57 -0
- package/src/lib/server/return-status-action.js.map +1 -0
- package/src/lib/server/returns.d.ts +119 -0
- package/src/lib/server/returns.js +938 -0
- package/src/lib/server/returns.js.map +1 -0
- package/src/lib/server/shipment-records.d.ts +36 -0
- package/src/lib/server/shipment-records.js +289 -0
- package/src/lib/server/shipment-records.js.map +1 -0
- package/src/lib/server/shipping-connector-gates.d.ts +40 -0
- package/src/lib/server/shipping-connector-gates.js +97 -0
- package/src/lib/server/shipping-connector-gates.js.map +1 -0
- package/src/lib/server/shipping-connectors.d.ts +29 -0
- package/src/lib/server/shipping-connectors.js +236 -0
- package/src/lib/server/shipping-connectors.js.map +1 -0
- package/src/lib/server/shippingeasy.d.ts +238 -0
- package/src/lib/server/shippingeasy.js +787 -0
- package/src/lib/server/shippingeasy.js.map +1 -0
- package/src/lib/server/shipstation.d.ts +129 -0
- package/src/lib/server/shipstation.js +483 -0
- package/src/lib/server/shipstation.js.map +1 -0
- package/src/lib/server/site-page-resolver.d.ts +5 -0
- package/src/lib/server/site-page-resolver.js +156 -1
- package/src/lib/server/site-page-resolver.js.map +1 -1
- package/src/lib/server/stock-levels.d.ts +21 -0
- package/src/lib/server/stock-levels.js +263 -0
- package/src/lib/server/stock-levels.js.map +1 -0
- package/src/lib/server/stripe-refund.d.ts +47 -0
- package/src/lib/server/stripe-refund.js +87 -0
- package/src/lib/server/stripe-refund.js.map +1 -0
- package/src/lib/server/supplier-update.js +46 -5
- package/src/lib/server/supplier-update.js.map +1 -1
- package/src/lib/server/tax-engine-quote.d.ts +47 -0
- package/src/lib/server/tax-engine-quote.js +105 -0
- package/src/lib/server/tax-engine-quote.js.map +1 -0
- package/src/lib/server.js +143 -2
- package/src/lib/server.js.map +1 -1
- package/src/lib/site.js +12 -0
- package/src/lib/site.js.map +1 -1
- package/src/lib/subprocessors.d.ts +26 -0
- package/src/lib/subprocessors.js +50 -0
- package/src/lib/subprocessors.js.map +1 -0
- package/src/lib/tenant-emails.js +461 -3
- package/src/lib/tenant-emails.js.map +1 -1
- package/src/lib/testing/fake-firestore.d.ts +45 -0
- package/src/lib/testing/fake-firestore.js +189 -0
- package/src/lib/testing/fake-firestore.js.map +1 -0
- package/src/lib/testing/memory-firestore.d.ts +136 -0
- package/src/lib/testing/memory-firestore.js +282 -0
- package/src/lib/testing/memory-firestore.js.map +1 -0
- package/src/lib/testing/pos-ops-harness.d.ts +50 -0
- package/src/lib/testing/pos-ops-harness.js +184 -0
- package/src/lib/testing/pos-ops-harness.js.map +1 -0
- package/src/lib/testing/pos-ops-memory-firestore.d.ts +55 -0
- package/src/lib/testing/pos-ops-memory-firestore.js +376 -0
- package/src/lib/testing/pos-ops-memory-firestore.js.map +1 -0
- package/src/lib/transfer/products.server.d.ts +5 -0
- package/src/lib/transfer/products.server.js +2 -2
- package/src/lib/transfer/products.server.js.map +1 -1
- package/src/lib/transfer/records-transfer.d.ts +11 -1
- package/src/lib/transfer/records-transfer.js +127 -5
- package/src/lib/transfer/records-transfer.js.map +1 -1
- package/src/lib/transfer/records.server.d.ts +9 -2
- package/src/lib/transfer/records.server.js +58 -7
- package/src/lib/transfer/records.server.js.map +1 -1
- package/src/lib/transfer/register-transfer-resources.js +40 -1
- package/src/lib/transfer/register-transfer-resources.js.map +1 -1
- package/src/lib/transfer/register-transfer-ui.js +4 -1
- package/src/lib/transfer/register-transfer-ui.js.map +1 -1
- package/src/lib/transfer/shipping-presets.d.ts +23 -0
- package/src/lib/transfer/shipping-presets.js +156 -0
- package/src/lib/transfer/shipping-presets.js.map +1 -0
- package/src/lib/transfer/tracking-transfer.d.ts +101 -0
- package/src/lib/transfer/tracking-transfer.js +546 -0
- package/src/lib/transfer/tracking-transfer.js.map +1 -0
- package/src/lib/transfer/tracking.server.d.ts +37 -0
- package/src/lib/transfer/tracking.server.js +393 -0
- package/src/lib/transfer/tracking.server.js.map +1 -0
- package/src/lib/transfer/transfer-keys.d.ts +2 -1
- package/src/lib/transfer/transfer-keys.js +6 -2
- package/src/lib/transfer/transfer-keys.js.map +1 -1
- package/src/lib/utils/code128.d.ts +37 -0
- package/src/lib/utils/code128.js +199 -0
- package/src/lib/utils/code128.js.map +1 -0
- package/src/lib/utils/order-invoice.d.ts +55 -0
- package/src/lib/utils/order-invoice.js +127 -0
- package/src/lib/utils/order-invoice.js.map +1 -0
- package/src/lib/utils/use-checkout-return-notice.d.ts +34 -0
- package/src/lib/utils/use-checkout-return-notice.js +78 -0
- package/src/lib/utils/use-checkout-return-notice.js.map +1 -0
- package/src/lib/server/feed.js +0 -69
- package/src/lib/server/feed.js.map +0 -1
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ import { createResourceUid } from "@aglyn/aglyn/app-utils/create-resource-uid";
|
|
18
|
+
import { firebaseAdmin } from "@aglyn/tenant-data-admin/server/firebase-admin";
|
|
19
|
+
import * as CommerceModel from "../model/index.js";
|
|
20
|
+
import { ORDER_FULFILLED_EVENT, ORDER_REFUNDED_EVENT } from "../model/order-events.js";
|
|
21
|
+
import { createHash } from "node:crypto";
|
|
22
|
+
import { fulfillmentEventView, stageOrderEvent } from "./order-events.js";
|
|
23
|
+
import { restockCapKey, saleReleaseCaps } from "./restock-flag.js";
|
|
24
|
+
const DOC_ID = /^[A-Za-z0-9_-]{1,200}$/;
|
|
25
|
+
const MAX_CENTS = 10000000000;
|
|
26
|
+
const HANDOFF_KEY = 'channel-handoff';
|
|
27
|
+
/** Refund ids kept on an order: far more than any channel sends for one. */ const MAX_REFUND_IDS = 100;
|
|
28
|
+
const restockKey = restockCapKey;
|
|
29
|
+
/** The hand-off's fulfillment id: one per order, so a second report finds the first. */ const handoffFulfillmentId = (orderId)=>`f-${createHash('sha256').update(`${orderId}:${HANDOFF_KEY}`).digest('hex').slice(0, 20)}`;
|
|
30
|
+
const defaultDeps = ()=>({
|
|
31
|
+
firestore: ()=>firebaseAdmin.app().firestore(),
|
|
32
|
+
now: Date.now
|
|
33
|
+
});
|
|
34
|
+
const clip = (value, max)=>String(value != null ? value : '').trim().slice(0, max);
|
|
35
|
+
const validIds = (hostId, recordId)=>DOC_ID.test(String(hostId != null ? hostId : '')) && DOC_ID.test(String(recordId != null ? recordId : '')) && !/^__.*__$/.test(String(hostId)) && !/^__.*__$/.test(String(recordId));
|
|
36
|
+
/** The channel's courier took the order: every open unit is fulfilled, with nothing shipped from here. */ export async function completeChannelOrder(request, deps = defaultDeps()) {
|
|
37
|
+
if (!validIds(request == null ? void 0 : request.hostId, request == null ? void 0 : request.recordId)) return {
|
|
38
|
+
outcome: 'no_such_record'
|
|
39
|
+
};
|
|
40
|
+
const firestore = deps.firestore();
|
|
41
|
+
const orderRef = firestore.collection('hosts').doc(request.hostId).collection('orders').doc(request.recordId);
|
|
42
|
+
const nowMs = deps.now();
|
|
43
|
+
const fulfillmentId = handoffFulfillmentId(request.recordId);
|
|
44
|
+
return firestore.runTransaction(async (transaction)=>{
|
|
45
|
+
var _snapshot_data, _order_fulfillments, _order_fulfillments1, _snapshot_data1;
|
|
46
|
+
const snapshot = await transaction.get(orderRef);
|
|
47
|
+
if (!snapshot.exists) return {
|
|
48
|
+
outcome: 'no_such_record'
|
|
49
|
+
};
|
|
50
|
+
const order = CommerceModel.liftLegacyOrder((_snapshot_data = snapshot.data()) != null ? _snapshot_data : {});
|
|
51
|
+
if (order.channel !== 'marketplace' || !order.channelSource) return {
|
|
52
|
+
outcome: 'not_completable',
|
|
53
|
+
status: order.status
|
|
54
|
+
};
|
|
55
|
+
if (((_order_fulfillments = order.fulfillments) != null ? _order_fulfillments : []).some((entry)=>entry.id === fulfillmentId)) return {
|
|
56
|
+
outcome: 'already'
|
|
57
|
+
};
|
|
58
|
+
if (order.status === 'fulfilled' || order.status === 'delivered') return {
|
|
59
|
+
outcome: 'already'
|
|
60
|
+
};
|
|
61
|
+
if (!CommerceModel.canTransitionOrder(order.status, 'fulfilled')) {
|
|
62
|
+
return {
|
|
63
|
+
outcome: 'not_completable',
|
|
64
|
+
status: order.status
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
let lines = CommerceModel.remainingFulfillmentLines(order);
|
|
68
|
+
if (!lines.length) {
|
|
69
|
+
lines = CommerceModel.orderLineFulfillmentStates(order).filter((state)=>state.remainingQuantity > 0).map((state)=>({
|
|
70
|
+
lineItemId: state.lineItemId,
|
|
71
|
+
quantity: state.remainingQuantity
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
const carrier = clip(order.channelSource.channelLabel, 40) || 'Courier';
|
|
75
|
+
const fulfillment = {
|
|
76
|
+
id: fulfillmentId,
|
|
77
|
+
lineItemIds: lines.map((entry)=>entry.lineItemId),
|
|
78
|
+
lines,
|
|
79
|
+
carrier,
|
|
80
|
+
status: 'active',
|
|
81
|
+
// The channel tells its own buyer; nobody is emailed from here.
|
|
82
|
+
notify: false,
|
|
83
|
+
atMs: nowMs
|
|
84
|
+
};
|
|
85
|
+
const patch = {
|
|
86
|
+
status: 'fulfilled',
|
|
87
|
+
fulfillments: [
|
|
88
|
+
...(_order_fulfillments1 = order.fulfillments) != null ? _order_fulfillments1 : [],
|
|
89
|
+
fulfillment
|
|
90
|
+
],
|
|
91
|
+
updatedAtMs: nowMs,
|
|
92
|
+
timeline: CommerceModel.appendOrderEvent(order, 'fulfilled', clip(request.note, 200) || `Picked up by the ${carrier} courier`, nowMs)
|
|
93
|
+
};
|
|
94
|
+
transaction.update(orderRef, patch);
|
|
95
|
+
stageOrderEvent(transaction, ORDER_FULFILLED_EVENT, {
|
|
96
|
+
hostId: request.hostId,
|
|
97
|
+
orderId: request.recordId,
|
|
98
|
+
key: fulfillment.id,
|
|
99
|
+
order: _extends({}, (_snapshot_data1 = snapshot.data()) != null ? _snapshot_data1 : {}, patch),
|
|
100
|
+
extra: {
|
|
101
|
+
fulfillment: fulfillmentEventView(order, fulfillment)
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
outcome: 'completed'
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* What the order's sale took off each shelf, less what has gone back since
|
|
111
|
+
* (a cancel's or an earlier adjustment's rows): the most a restock may still
|
|
112
|
+
* return, by product and variant.
|
|
113
|
+
*/ function remainingReleaseCaps(rows) {
|
|
114
|
+
const caps = saleReleaseCaps(rows.filter((row)=>row.get('reason') === 'sale'));
|
|
115
|
+
for (const row of rows){
|
|
116
|
+
var _ref, _row_get, _row_get1, _row_get2, _caps_get;
|
|
117
|
+
const reason = row.get('reason');
|
|
118
|
+
if (reason !== 'refund' && reason !== 'cancellation') continue;
|
|
119
|
+
const delta = Number((_ref = (_row_get = row.get('appliedDelta')) != null ? _row_get : row.get('delta')) != null ? _ref : 0);
|
|
120
|
+
if (!(delta > 0)) continue;
|
|
121
|
+
const key = restockKey(String((_row_get1 = row.get('productId')) != null ? _row_get1 : ''), String((_row_get2 = row.get('variantId')) != null ? _row_get2 : ''));
|
|
122
|
+
if (caps.has(key)) caps.set(key, Math.max(0, ((_caps_get = caps.get(key)) != null ? _caps_get : 0) - delta));
|
|
123
|
+
}
|
|
124
|
+
return caps;
|
|
125
|
+
}
|
|
126
|
+
/** The channel refunded its buyer or took items off the order: recorded once, with the named units back on the shelf. */ export async function recordChannelOrderRefund(request, deps = defaultDeps()) {
|
|
127
|
+
if (!validIds(request == null ? void 0 : request.hostId, request == null ? void 0 : request.recordId)) return {
|
|
128
|
+
outcome: 'no_such_record'
|
|
129
|
+
};
|
|
130
|
+
const refundId = clip(request.refundId, 200);
|
|
131
|
+
if (!refundId) return {
|
|
132
|
+
outcome: 'refused',
|
|
133
|
+
reason: 'The refund has no id on its channel.'
|
|
134
|
+
};
|
|
135
|
+
const amount = Number(request.amountCents);
|
|
136
|
+
if (!Number.isInteger(amount) || amount < 0 || amount > MAX_CENTS) {
|
|
137
|
+
return {
|
|
138
|
+
outcome: 'refused',
|
|
139
|
+
reason: 'The refund is not a whole amount.'
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const asked = (Array.isArray(request.restock) ? request.restock : []).map((entry)=>({
|
|
143
|
+
lineIndex: Number(entry == null ? void 0 : entry.lineIndex),
|
|
144
|
+
quantity: Number(entry == null ? void 0 : entry.quantity)
|
|
145
|
+
})).filter((entry)=>Number.isInteger(entry.lineIndex) && entry.lineIndex >= 0 && Number.isInteger(entry.quantity) && entry.quantity > 0);
|
|
146
|
+
if (amount === 0 && !asked.length) return {
|
|
147
|
+
outcome: 'refused',
|
|
148
|
+
reason: 'The refund moves no money and no stock.'
|
|
149
|
+
};
|
|
150
|
+
const firestore = deps.firestore();
|
|
151
|
+
const hostRef = firestore.collection('hosts').doc(request.hostId);
|
|
152
|
+
const orderRef = hostRef.collection('orders').doc(request.recordId);
|
|
153
|
+
const nowMs = deps.now();
|
|
154
|
+
return firestore.runTransaction(async (transaction)=>{
|
|
155
|
+
var _snapshot_data, _source_refundIds, _order_lineItems, _ref, _ref1, _order_refundedCents, _source_refundIds1;
|
|
156
|
+
var _order_totals;
|
|
157
|
+
const snapshot = await transaction.get(orderRef);
|
|
158
|
+
if (!snapshot.exists) return {
|
|
159
|
+
outcome: 'no_such_record'
|
|
160
|
+
};
|
|
161
|
+
const order = CommerceModel.liftLegacyOrder((_snapshot_data = snapshot.data()) != null ? _snapshot_data : {});
|
|
162
|
+
const source = order.channelSource;
|
|
163
|
+
if (order.channel !== 'marketplace' || !source) return {
|
|
164
|
+
outcome: 'no_such_record'
|
|
165
|
+
};
|
|
166
|
+
if (((_source_refundIds = source.refundIds) != null ? _source_refundIds : []).includes(refundId)) return {
|
|
167
|
+
outcome: 'already'
|
|
168
|
+
};
|
|
169
|
+
// Every read before any write: the ledger, then each product a restock touches.
|
|
170
|
+
const lineItems = (_order_lineItems = order.lineItems) != null ? _order_lineItems : [];
|
|
171
|
+
const wanted = new Map();
|
|
172
|
+
for (const entry of asked){
|
|
173
|
+
var _wanted_get;
|
|
174
|
+
const line = lineItems[entry.lineIndex];
|
|
175
|
+
if (!(line == null ? void 0 : line.productId) || !line.variantId || /^__.*__$/.test(line.productId)) continue;
|
|
176
|
+
wanted.set(entry.lineIndex, Math.min(Number(line.quantity) || 0, ((_wanted_get = wanted.get(entry.lineIndex)) != null ? _wanted_get : 0) + entry.quantity));
|
|
177
|
+
}
|
|
178
|
+
const rows = wanted.size ? (await transaction.get(hostRef.collection('inventoryAdjustments').where('orderId', '==', request.recordId))).docs : [];
|
|
179
|
+
const caps = remainingReleaseCaps(rows);
|
|
180
|
+
const productIds = [
|
|
181
|
+
...new Set([
|
|
182
|
+
...wanted.keys()
|
|
183
|
+
].map((index)=>lineItems[index].productId))
|
|
184
|
+
];
|
|
185
|
+
const productSnaps = await Promise.all(productIds.map((id)=>transaction.get(hostRef.collection('products').doc(id))));
|
|
186
|
+
const products = new Map();
|
|
187
|
+
productSnaps.forEach((product, index)=>{
|
|
188
|
+
if (product.exists && !product.get('deletedAt')) {
|
|
189
|
+
products.set(productIds[index], CommerceModel.liftLegacyProduct(product.data()));
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
let restockedUnits = 0;
|
|
193
|
+
const restockedLines = [];
|
|
194
|
+
const ledger = [];
|
|
195
|
+
const changed = new Set();
|
|
196
|
+
for (const [lineIndex, quantity] of wanted){
|
|
197
|
+
var _caps_get;
|
|
198
|
+
const line = lineItems[lineIndex];
|
|
199
|
+
const product = products.get(line.productId);
|
|
200
|
+
const variantId = String(line.variantId);
|
|
201
|
+
const variant = product == null ? void 0 : product.variants.find((entry)=>entry.id === variantId);
|
|
202
|
+
if (!product || !variant || variant.inventory == null) continue;
|
|
203
|
+
const key = restockKey(line.productId, variantId);
|
|
204
|
+
// A pair the ledger never recorded a sale for gave up nothing to return.
|
|
205
|
+
const budget = (_caps_get = caps.get(key)) != null ? _caps_get : 0;
|
|
206
|
+
const back = Math.min(quantity, budget);
|
|
207
|
+
if (back <= 0) continue;
|
|
208
|
+
caps.set(key, budget - back);
|
|
209
|
+
products.set(line.productId, _extends({}, product, {
|
|
210
|
+
variants: CommerceModel.adjustVariantInventory(product, variantId, back)
|
|
211
|
+
}));
|
|
212
|
+
changed.add(line.productId);
|
|
213
|
+
restockedUnits += back;
|
|
214
|
+
restockedLines.push(lineIndex);
|
|
215
|
+
ledger.push({
|
|
216
|
+
productId: line.productId,
|
|
217
|
+
variantId,
|
|
218
|
+
delta: back,
|
|
219
|
+
reason: 'refund',
|
|
220
|
+
orderId: request.recordId,
|
|
221
|
+
source: source.channelLabel,
|
|
222
|
+
atMs: nowMs
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
const total = Number((_ref = (_ref1 = (_order_totals = order.totals) == null ? void 0 : _order_totals.totalCents) != null ? _ref1 : order.amountCents) != null ? _ref : 0);
|
|
226
|
+
const before = Number((_order_refundedCents = order.refundedCents) != null ? _order_refundedCents : 0);
|
|
227
|
+
const recorded = Math.max(0, Math.min(amount, total - before));
|
|
228
|
+
const refundedCents = before + recorded;
|
|
229
|
+
const full = total > 0 && refundedCents >= total;
|
|
230
|
+
let status = order.status;
|
|
231
|
+
if (full && status !== 'refunded' && CommerceModel.canTransitionOrder(status, 'refunded')) status = 'refunded';
|
|
232
|
+
for (const productId of changed){
|
|
233
|
+
const product = products.get(productId);
|
|
234
|
+
transaction.update(hostRef.collection('products').doc(productId), _extends({
|
|
235
|
+
variants: product.variants
|
|
236
|
+
}, CommerceModel.productStockFields(product), {
|
|
237
|
+
updatedAtMs: nowMs
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
240
|
+
for (const row of ledger)transaction.set(hostRef.collection('inventoryAdjustments').doc(createResourceUid()), row);
|
|
241
|
+
const money = (cents)=>`${(cents / 100).toFixed(2)} ${source.currency}`;
|
|
242
|
+
const reason = clip(request.reason, 200) || `Refunded on ${source.channelLabel}`;
|
|
243
|
+
const parts = [
|
|
244
|
+
recorded > 0 ? `${reason}: ${money(recorded)} refunded by ${source.channelLabel}` : reason,
|
|
245
|
+
...recorded < amount ? [
|
|
246
|
+
`${money(amount - recorded)} more than the order had left was not recorded`
|
|
247
|
+
] : [],
|
|
248
|
+
...restockedUnits > 0 ? [
|
|
249
|
+
`${restockedUnits} ${restockedUnits === 1 ? 'unit' : 'units'} returned to stock`
|
|
250
|
+
] : []
|
|
251
|
+
];
|
|
252
|
+
const patch = {
|
|
253
|
+
status,
|
|
254
|
+
refundedCents,
|
|
255
|
+
channelSource: _extends({}, source, {
|
|
256
|
+
refundIds: [
|
|
257
|
+
...(_source_refundIds1 = source.refundIds) != null ? _source_refundIds1 : [],
|
|
258
|
+
refundId
|
|
259
|
+
].slice(-MAX_REFUND_IDS)
|
|
260
|
+
}),
|
|
261
|
+
updatedAtMs: nowMs,
|
|
262
|
+
timeline: CommerceModel.appendOrderEvent(order, 'refund', `${parts.join('. ')}.`, nowMs)
|
|
263
|
+
};
|
|
264
|
+
transaction.update(orderRef, patch);
|
|
265
|
+
if (recorded > 0) {
|
|
266
|
+
var _snapshot_data1;
|
|
267
|
+
stageOrderEvent(transaction, ORDER_REFUNDED_EVENT, {
|
|
268
|
+
hostId: request.hostId,
|
|
269
|
+
orderId: request.recordId,
|
|
270
|
+
key: `refund:channel:${refundId}`,
|
|
271
|
+
order: _extends({}, (_snapshot_data1 = snapshot.data()) != null ? _snapshot_data1 : {}, patch),
|
|
272
|
+
extra: {
|
|
273
|
+
refund: {
|
|
274
|
+
id: null,
|
|
275
|
+
amountCents: recorded,
|
|
276
|
+
lineItemIds: restockedLines,
|
|
277
|
+
full
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
outcome: 'recorded',
|
|
284
|
+
refundedCents,
|
|
285
|
+
restockedUnits
|
|
286
|
+
};
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
//# sourceMappingURL=channel-order-updates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/channel-order-updates.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createResourceUid } from '@aglyn/aglyn/app-utils/create-resource-uid'\nimport type {\n PluginChannelOrderHandoff,\n PluginChannelOrderHandoffOutcome,\n PluginChannelOrderRefund,\n PluginChannelOrderRefundOutcome,\n} from '@aglyn/aglyn/plugin-manager/plugin-channel-orders'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin/server/firebase-admin'\nimport * as CommerceModel from '../model'\nimport { ORDER_FULFILLED_EVENT, ORDER_REFUNDED_EVENT } from '../model/order-events'\nimport { createHash } from 'node:crypto'\nimport { fulfillmentEventView, stageOrderEvent } from './order-events'\nimport { restockCapKey, saleReleaseCaps } from './restock-flag'\n\n/**\n * WHAT A CHANNEL SAYS AFTER ITS ORDER CAME IN (AGL-3644): commerce's half of\n * `completeOrder` and `recordRefund` on core's `core.channel-orders`.\n *\n * A delivery app's order is handed to its own courier over the counter, and\n * the app — not the store — refunds its buyer or takes an item off the order.\n * So, for an order the channel sent (`channel: 'marketplace'`):\n *\n * - **A hand-off** closes the order as fulfilled with one fulfillment for\n * every unit still open, carrying the channel as its carrier and no\n * tracking: nothing was shipped from here. Keyed, so a second report of the\n * same pickup writes nothing.\n * - **A refund or adjustment** is RECORDED: `refundedCents` grows by the\n * amount (never past the order's total), the order is `refunded` once the\n * whole of it is, and the channel's id for it is kept so the same report\n * twice records once. No money moves: the channel refunded its own buyer.\n * Units the channel names as never having left go back on the shelf, at\n * most what the order's own sale took less what was already put back —\n * the ledger bound the console's cancel uses.\n *\n * Each is ONE transaction that reads the order (and, for a restock, each\n * product) before it writes, and stages its order event in the same write.\n */\n\ntype Firestore = FirebaseFirestore.Firestore\n\nconst DOC_ID = /^[A-Za-z0-9_-]{1,200}$/\nconst MAX_CENTS = 100_000_000_00\nconst HANDOFF_KEY = 'channel-handoff'\n/** Refund ids kept on an order: far more than any channel sends for one. */\nconst MAX_REFUND_IDS = 100\n\nconst restockKey = restockCapKey\n\n/** The hand-off's fulfillment id: one per order, so a second report finds the first. */\nconst handoffFulfillmentId = (orderId: string) =>\n `f-${createHash('sha256').update(`${orderId}:${HANDOFF_KEY}`).digest('hex').slice(0, 20)}`\n\nexport interface ChannelOrderUpdateDeps {\n firestore: () => Firestore\n now: () => number\n}\n\nconst defaultDeps = (): ChannelOrderUpdateDeps => ({ firestore: () => firebaseAdmin.app().firestore(), now: Date.now })\n\nconst clip = (value: unknown, max: number): string => String(value ?? '').trim().slice(0, max)\n\nconst validIds = (hostId: unknown, recordId: unknown): boolean =>\n DOC_ID.test(String(hostId ?? '')) &&\n DOC_ID.test(String(recordId ?? '')) &&\n !/^__.*__$/.test(String(hostId)) &&\n !/^__.*__$/.test(String(recordId))\n\n/** The channel's courier took the order: every open unit is fulfilled, with nothing shipped from here. */\nexport async function completeChannelOrder(\n request: PluginChannelOrderHandoff,\n deps: ChannelOrderUpdateDeps = defaultDeps(),\n): Promise<PluginChannelOrderHandoffOutcome> {\n if (!validIds(request?.hostId, request?.recordId)) return { outcome: 'no_such_record' }\n const firestore = deps.firestore()\n const orderRef = firestore.collection('hosts').doc(request.hostId).collection('orders').doc(request.recordId)\n const nowMs = deps.now()\n const fulfillmentId = handoffFulfillmentId(request.recordId)\n return firestore.runTransaction(async (transaction): Promise<PluginChannelOrderHandoffOutcome> => {\n const snapshot = await transaction.get(orderRef)\n if (!snapshot.exists) return { outcome: 'no_such_record' }\n const order = CommerceModel.liftLegacyOrder((snapshot.data() ?? {}) as never)\n if (order.channel !== 'marketplace' || !order.channelSource) return { outcome: 'not_completable', status: order.status }\n if ((order.fulfillments ?? []).some((entry) => entry.id === fulfillmentId)) return { outcome: 'already' }\n if (order.status === 'fulfilled' || order.status === 'delivered') return { outcome: 'already' }\n if (!CommerceModel.canTransitionOrder(order.status, 'fulfilled')) {\n return { outcome: 'not_completable', status: order.status }\n }\n let lines = CommerceModel.remainingFulfillmentLines(order)\n if (!lines.length) {\n lines = CommerceModel.orderLineFulfillmentStates(order)\n .filter((state) => state.remainingQuantity > 0)\n .map((state) => ({ lineItemId: state.lineItemId, quantity: state.remainingQuantity }))\n }\n const carrier = clip(order.channelSource.channelLabel, 40) || 'Courier'\n const fulfillment: CommerceModel.OrderFulfillment = {\n id: fulfillmentId,\n lineItemIds: lines.map((entry) => entry.lineItemId),\n lines,\n carrier,\n status: 'active',\n // The channel tells its own buyer; nobody is emailed from here.\n notify: false,\n atMs: nowMs,\n }\n const patch = {\n status: 'fulfilled' as const,\n fulfillments: [...(order.fulfillments ?? []), fulfillment],\n updatedAtMs: nowMs,\n timeline: CommerceModel.appendOrderEvent(\n order,\n 'fulfilled',\n clip(request.note, 200) || `Picked up by the ${carrier} courier`,\n nowMs,\n ),\n }\n transaction.update(orderRef, patch)\n stageOrderEvent(transaction, ORDER_FULFILLED_EVENT, {\n hostId: request.hostId,\n orderId: request.recordId,\n key: fulfillment.id,\n order: { ...(snapshot.data() ?? {}), ...patch },\n extra: { fulfillment: fulfillmentEventView(order, fulfillment) },\n })\n return { outcome: 'completed' }\n })\n}\n\n/**\n * What the order's sale took off each shelf, less what has gone back since\n * (a cancel's or an earlier adjustment's rows): the most a restock may still\n * return, by product and variant.\n */\nfunction remainingReleaseCaps(rows: readonly { get: (field: string) => unknown }[]): Map<string, number> {\n const caps = saleReleaseCaps(rows.filter((row) => row.get('reason') === 'sale'))\n for (const row of rows) {\n const reason = row.get('reason')\n if (reason !== 'refund' && reason !== 'cancellation') continue\n const delta = Number(row.get('appliedDelta') ?? row.get('delta') ?? 0)\n if (!(delta > 0)) continue\n const key = restockKey(String(row.get('productId') ?? ''), String(row.get('variantId') ?? ''))\n if (caps.has(key)) caps.set(key, Math.max(0, (caps.get(key) ?? 0) - delta))\n }\n return caps\n}\n\n/** The channel refunded its buyer or took items off the order: recorded once, with the named units back on the shelf. */\nexport async function recordChannelOrderRefund(\n request: PluginChannelOrderRefund,\n deps: ChannelOrderUpdateDeps = defaultDeps(),\n): Promise<PluginChannelOrderRefundOutcome> {\n if (!validIds(request?.hostId, request?.recordId)) return { outcome: 'no_such_record' }\n const refundId = clip(request.refundId, 200)\n if (!refundId) return { outcome: 'refused', reason: 'The refund has no id on its channel.' }\n const amount = Number(request.amountCents)\n if (!Number.isInteger(amount) || amount < 0 || amount > MAX_CENTS) {\n return { outcome: 'refused', reason: 'The refund is not a whole amount.' }\n }\n const asked = (Array.isArray(request.restock) ? request.restock : [])\n .map((entry) => ({ lineIndex: Number(entry?.lineIndex), quantity: Number(entry?.quantity) }))\n .filter((entry) => Number.isInteger(entry.lineIndex) && entry.lineIndex >= 0 && Number.isInteger(entry.quantity) && entry.quantity > 0)\n if (amount === 0 && !asked.length) return { outcome: 'refused', reason: 'The refund moves no money and no stock.' }\n\n const firestore = deps.firestore()\n const hostRef = firestore.collection('hosts').doc(request.hostId)\n const orderRef = hostRef.collection('orders').doc(request.recordId)\n const nowMs = deps.now()\n return firestore.runTransaction(async (transaction): Promise<PluginChannelOrderRefundOutcome> => {\n const snapshot = await transaction.get(orderRef)\n if (!snapshot.exists) return { outcome: 'no_such_record' }\n const order = CommerceModel.liftLegacyOrder((snapshot.data() ?? {}) as never)\n const source = order.channelSource\n if (order.channel !== 'marketplace' || !source) return { outcome: 'no_such_record' }\n if ((source.refundIds ?? []).includes(refundId)) return { outcome: 'already' }\n\n // Every read before any write: the ledger, then each product a restock touches.\n const lineItems = order.lineItems ?? []\n const wanted = new Map<number, number>()\n for (const entry of asked) {\n const line = lineItems[entry.lineIndex]\n if (!line?.productId || !line.variantId || /^__.*__$/.test(line.productId)) continue\n wanted.set(entry.lineIndex, Math.min(Number(line.quantity) || 0, (wanted.get(entry.lineIndex) ?? 0) + entry.quantity))\n }\n const rows = wanted.size\n ? (await transaction.get(hostRef.collection('inventoryAdjustments').where('orderId', '==', request.recordId))).docs\n : []\n const caps = remainingReleaseCaps(rows)\n const productIds = [...new Set([...wanted.keys()].map((index) => lineItems[index].productId))]\n const productSnaps = await Promise.all(productIds.map((id) => transaction.get(hostRef.collection('products').doc(id))))\n const products = new Map<string, CommerceModel.HostProduct>()\n productSnaps.forEach((product, index) => {\n if (product.exists && !product.get('deletedAt')) {\n products.set(productIds[index], CommerceModel.liftLegacyProduct(product.data() as never))\n }\n })\n\n let restockedUnits = 0\n const restockedLines: number[] = []\n const ledger: CommerceModel.InventoryAdjustment[] = []\n const changed = new Set<string>()\n for (const [lineIndex, quantity] of wanted) {\n const line = lineItems[lineIndex]\n const product = products.get(line.productId)\n const variantId = String(line.variantId)\n const variant = product?.variants.find((entry) => entry.id === variantId)\n if (!product || !variant || variant.inventory == null) continue\n const key = restockKey(line.productId, variantId)\n // A pair the ledger never recorded a sale for gave up nothing to return.\n const budget = caps.get(key) ?? 0\n const back = Math.min(quantity, budget)\n if (back <= 0) continue\n caps.set(key, budget - back)\n products.set(line.productId, {\n ...product,\n variants: CommerceModel.adjustVariantInventory(product, variantId, back),\n })\n changed.add(line.productId)\n restockedUnits += back\n restockedLines.push(lineIndex)\n ledger.push({\n productId: line.productId,\n variantId,\n delta: back,\n reason: 'refund',\n orderId: request.recordId,\n source: source.channelLabel,\n atMs: nowMs,\n })\n }\n\n const total = Number(order.totals?.totalCents ?? order.amountCents ?? 0)\n const before = Number(order.refundedCents ?? 0)\n const recorded = Math.max(0, Math.min(amount, total - before))\n const refundedCents = before + recorded\n const full = total > 0 && refundedCents >= total\n let status = order.status\n if (full && status !== 'refunded' && CommerceModel.canTransitionOrder(status, 'refunded')) status = 'refunded'\n\n for (const productId of changed) {\n const product = products.get(productId) as CommerceModel.HostProduct\n transaction.update(hostRef.collection('products').doc(productId), {\n variants: product.variants,\n ...CommerceModel.productStockFields(product),\n updatedAtMs: nowMs,\n })\n }\n for (const row of ledger) transaction.set(hostRef.collection('inventoryAdjustments').doc(createResourceUid()), row)\n\n const money = (cents: number) => `${(cents / 100).toFixed(2)} ${source.currency}`\n const reason = clip(request.reason, 200) || `Refunded on ${source.channelLabel}`\n const parts = [\n recorded > 0 ? `${reason}: ${money(recorded)} refunded by ${source.channelLabel}` : reason,\n ...(recorded < amount ? [`${money(amount - recorded)} more than the order had left was not recorded`] : []),\n ...(restockedUnits > 0 ? [`${restockedUnits} ${restockedUnits === 1 ? 'unit' : 'units'} returned to stock`] : []),\n ]\n const patch = {\n status,\n refundedCents,\n channelSource: { ...source, refundIds: [...(source.refundIds ?? []), refundId].slice(-MAX_REFUND_IDS) },\n updatedAtMs: nowMs,\n timeline: CommerceModel.appendOrderEvent(order, 'refund', `${parts.join('. ')}.`, nowMs),\n }\n transaction.update(orderRef, patch)\n if (recorded > 0) {\n stageOrderEvent(transaction, ORDER_REFUNDED_EVENT, {\n hostId: request.hostId,\n orderId: request.recordId,\n key: `refund:channel:${refundId}`,\n order: { ...(snapshot.data() ?? {}), ...patch },\n extra: { refund: { id: null, amountCents: recorded, lineItemIds: restockedLines, full } },\n })\n }\n return { outcome: 'recorded', refundedCents, restockedUnits }\n })\n}\n"],"names":["createResourceUid","firebaseAdmin","CommerceModel","ORDER_FULFILLED_EVENT","ORDER_REFUNDED_EVENT","createHash","fulfillmentEventView","stageOrderEvent","restockCapKey","saleReleaseCaps","DOC_ID","MAX_CENTS","HANDOFF_KEY","MAX_REFUND_IDS","restockKey","handoffFulfillmentId","orderId","update","digest","slice","defaultDeps","firestore","app","now","Date","clip","value","max","String","trim","validIds","hostId","recordId","test","completeChannelOrder","request","deps","outcome","orderRef","collection","doc","nowMs","fulfillmentId","runTransaction","transaction","snapshot","order","get","exists","liftLegacyOrder","data","channel","channelSource","status","fulfillments","some","entry","id","canTransitionOrder","lines","remainingFulfillmentLines","length","orderLineFulfillmentStates","filter","state","remainingQuantity","map","lineItemId","quantity","carrier","channelLabel","fulfillment","lineItemIds","notify","atMs","patch","updatedAtMs","timeline","appendOrderEvent","note","key","extra","remainingReleaseCaps","rows","caps","row","reason","delta","Number","has","set","Math","recordChannelOrderRefund","refundId","amount","amountCents","isInteger","asked","Array","isArray","restock","lineIndex","hostRef","source","refundIds","includes","lineItems","wanted","Map","line","productId","variantId","min","size","where","docs","productIds","Set","keys","index","productSnaps","Promise","all","products","forEach","product","liftLegacyProduct","restockedUnits","restockedLines","ledger","changed","variant","variants","find","inventory","budget","back","adjustVariantInventory","add","push","total","totals","totalCents","before","refundedCents","recorded","full","productStockFields","money","cents","toFixed","currency","parts","join","refund"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,iBAAiB,QAAQ,6CAA4C;AAO9E,SAASC,aAAa,QAAQ,iDAAgD;AAC9E,YAAYC,mBAAmB,oBAAU;AACzC,SAASC,qBAAqB,EAAEC,oBAAoB,QAAQ,2BAAuB;AACnF,SA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B,IAAIsE,WAAW,GAAG;gBAKDpG;YAJftC,gBAAgBqC,aAAaxC,sBAAsB;gBACjD2B,QAAQI,QAAQJ,MAAM;gBACtBf,SAASmB,QAAQH,QAAQ;gBACzBgD,KAAK,CAAC,eAAe,EAAEa,UAAU;gBACjC/C,OAAO,cAAMD,kBAAAA,SAASK,IAAI,cAAbL,kBAAmB,CAAC,GAAO8B;gBACxCM,OAAO;oBAAEyE,QAAQ;wBAAEjG,IAAI;wBAAMsC,aAAakD;wBAAUzE,aAAawD;wBAAgBkB;oBAAK;gBAAE;YAC1F;QACF;QACA,OAAO;YAAE7G,SAAS;YAAY2G;YAAejB;QAAe;IAC9D;AACF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { PluginChannelOrder, PluginChannelOrderCancelOutcome, PluginChannelOrderFee, PluginChannelOrderOutcome, PluginChannelOrders } from '@aglyn/aglyn/plugin-manager/plugin-channel-orders';
|
|
18
|
+
/**
|
|
19
|
+
* ORDERS SOLD ON ANOTHER CHANNEL (AGL-3638): commerce's implementation of
|
|
20
|
+
* core's `core.channel-orders`, which a marketplace plugin records each
|
|
21
|
+
* order it brings in through.
|
|
22
|
+
*
|
|
23
|
+
* ## One transaction, so two channels cannot sell the last unit twice
|
|
24
|
+
*
|
|
25
|
+
* The order, its number, every product's count, every count's ledger row and
|
|
26
|
+
* the `order.paid` event are ONE Firestore transaction. Each product is read
|
|
27
|
+
* with `transaction.get`, which serializes this write with every other sale
|
|
28
|
+
* of that product (the AGL-2320 reasoning): a storefront checkout landing at
|
|
29
|
+
* the same moment decrements from the count this write left, never from the
|
|
30
|
+
* one it read. The marketplace plugin then pushes the new count to every
|
|
31
|
+
* other channel.
|
|
32
|
+
*
|
|
33
|
+
* A marketplace order is already sold and paid when it arrives, so a shelf
|
|
34
|
+
* that cannot cover it does not refuse it: the units the shelf held are
|
|
35
|
+
* taken, the order is recorded whole, and the merchant is told which units
|
|
36
|
+
* are short — the same loud oversell `reserve-stock.ts` raises.
|
|
37
|
+
*
|
|
38
|
+
* ## Once per outside order
|
|
39
|
+
*
|
|
40
|
+
* The order's id is derived from the channel and its order id
|
|
41
|
+
* ({@link channelOrderDocId}), and the transaction refuses to write over an
|
|
42
|
+
* order that exists, so a retried import answers `already` and moves nothing.
|
|
43
|
+
*
|
|
44
|
+
* ## No money moves here
|
|
45
|
+
*
|
|
46
|
+
* The buyer paid the channel. `totals.feeCents` — Aglyn's own take — is 0,
|
|
47
|
+
* the channel's charges are recorded on `channelSource.fees` for the
|
|
48
|
+
* merchant's books, the tax is the channel's to remit, and refunds happen on
|
|
49
|
+
* the channel. No buyer email is sent: a marketplace forbids contacting its
|
|
50
|
+
* buyers outside it, and none of them hands over a real address.
|
|
51
|
+
*/
|
|
52
|
+
type Firestore = FirebaseFirestore.Firestore;
|
|
53
|
+
/**
|
|
54
|
+
* The order document's id for one outside order: the channel, then a hash of
|
|
55
|
+
* the channel's own id. Deterministic, so a second import of the same order
|
|
56
|
+
* finds the first; hashed, because a channel's id may hold characters a
|
|
57
|
+
* document id may not.
|
|
58
|
+
*/
|
|
59
|
+
export declare function channelOrderDocId(channelId: string, externalOrderId: string): string;
|
|
60
|
+
/** What a seller refuses before reading anything, in the merchant's words; `null` when the order is well formed. */
|
|
61
|
+
export declare function channelOrderProblem(order: PluginChannelOrder): string | null;
|
|
62
|
+
export interface ChannelOrderDeps {
|
|
63
|
+
firestore: () => Firestore;
|
|
64
|
+
now: () => number;
|
|
65
|
+
}
|
|
66
|
+
/** Records one outside order; see the module header. */
|
|
67
|
+
export declare function importChannelOrder(order: PluginChannelOrder, deps?: ChannelOrderDeps): Promise<PluginChannelOrderOutcome>;
|
|
68
|
+
/**
|
|
69
|
+
* The channel canceled an order it sent: the order is cancelled here, and
|
|
70
|
+
* the units its sale took go back on the shelf — bounded by its own ledger,
|
|
71
|
+
* exactly as the console's cancel bounds them. Refuses once anything shipped.
|
|
72
|
+
*/
|
|
73
|
+
export declare function cancelChannelOrder(request: {
|
|
74
|
+
hostId: string;
|
|
75
|
+
recordId: string;
|
|
76
|
+
reason: string;
|
|
77
|
+
}, deps?: ChannelOrderDeps): Promise<PluginChannelOrderCancelOutcome>;
|
|
78
|
+
/** The channel's charges on a sale, recorded once it says; a later answer replaces an earlier one. */
|
|
79
|
+
export declare function recordChannelOrderFees(request: {
|
|
80
|
+
hostId: string;
|
|
81
|
+
recordId: string;
|
|
82
|
+
fees: PluginChannelOrderFee[];
|
|
83
|
+
}, deps?: ChannelOrderDeps): Promise<'recorded' | 'no_such_record'>;
|
|
84
|
+
export declare const commerceChannelOrders: PluginChannelOrders;
|
|
85
|
+
export {};
|