@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 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/order-fulfillment.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\n/**\n * Quantity-level fulfillment (AGL-3611).\n *\n * A fulfillment used to name whole lines (`lineItemIds`), so \"ship 2 of the 5\n * mugs now, the rest next week\" could not be said. A fulfillment now carries\n * `lines: [{ lineItemId, quantity }]`; one written before that reads as every\n * unit of each line it named, which is what it meant when it was written.\n *\n * Every figure here is computed from the order's own fulfillments, so the\n * server's transaction and the console's panel ask the same question of the\n * same record and cannot disagree about what is left to ship.\n */\n\nimport type {\n HostOrder,\n OrderFulfillment,\n OrderLineItem,\n OrderStatus,\n} from './commerce-orders'\n\n/** One line of a fulfillment: which order line, and how many of its units. */\nexport interface OrderFulfillmentLine {\n /** The line's index in `order.lineItems`. */\n lineItemId: number\n quantity: number\n}\n\n/** A fulfillment's lifecycle; absent reads as `active`. */\nexport type OrderFulfillmentStatus = 'active' | 'cancelled'\n\n/**\n * Whether a line has to be shipped at all. Digital goods and services are\n * delivered by other means, so they never hold an order in\n * `partially_fulfilled`. A line with no recorded type predates types and is\n * treated as physical, the only reading that cannot close an order early.\n */\nexport function lineRequiresShipping(line: Pick<OrderLineItem, 'productType'>): boolean {\n return line.productType !== 'digital' && line.productType !== 'service'\n}\n\nconst wholeUnits = (value: unknown): number => {\n const units = Math.floor(Number(value ?? 0))\n return Number.isFinite(units) && units > 0 ? units : 0\n}\n\n/** Whether a fulfillment still counts: a cancelled one ships nothing. */\nexport function fulfillmentIsActive(fulfillment: Partial<OrderFulfillment> | null | undefined): boolean {\n return Boolean(fulfillment) && fulfillment?.status !== 'cancelled'\n}\n\n/**\n * The units one fulfillment covers, per line. A legacy fulfillment (no\n * `lines`) covers every unit of each line it names.\n */\nexport function fulfillmentLineQuantities(\n order: Pick<HostOrder, 'lineItems'>,\n fulfillment: Partial<OrderFulfillment>,\n): OrderFulfillmentLine[] {\n const lines = order.lineItems ?? []\n if (Array.isArray(fulfillment.lines) && fulfillment.lines.length > 0) {\n return fulfillment.lines\n .map((entry) => ({\n lineItemId: Math.round(Number(entry?.lineItemId)),\n quantity: wholeUnits(entry?.quantity),\n }))\n .filter(\n (entry) =>\n Number.isInteger(entry.lineItemId) &&\n entry.lineItemId >= 0 &&\n entry.lineItemId < lines.length &&\n entry.quantity > 0,\n )\n }\n return (fulfillment.lineItemIds ?? [])\n .map((index) => Math.round(Number(index)))\n .filter((index) => Number.isInteger(index) && index >= 0 && index < lines.length)\n .map((index) => ({ lineItemId: index, quantity: wholeUnits(lines[index]?.quantity) }))\n .filter((entry) => entry.quantity > 0)\n}\n\n/** Units already fulfilled per line index, over every active fulfillment. */\nexport function fulfilledQuantities(order: Pick<HostOrder, 'lineItems' | 'fulfillments'>): Map<number, number> {\n const totals = new Map<number, number>()\n for (const fulfillment of order.fulfillments ?? []) {\n if (!fulfillmentIsActive(fulfillment)) continue\n for (const entry of fulfillmentLineQuantities(order, fulfillment)) {\n totals.set(entry.lineItemId, (totals.get(entry.lineItemId) ?? 0) + entry.quantity)\n }\n }\n return totals\n}\n\n/** A line as the fulfillment panel and the server both reason about it. */\nexport interface OrderLineFulfillmentState {\n lineItemId: number\n quantity: number\n fulfilledQuantity: number\n remainingQuantity: number\n requiresShipping: boolean\n}\n\n/** Every line's fulfilled and remaining units. */\nexport function orderLineFulfillmentStates(\n order: Pick<HostOrder, 'lineItems' | 'fulfillments'>,\n): OrderLineFulfillmentState[] {\n const fulfilled = fulfilledQuantities(order)\n return (order.lineItems ?? []).map((line, index) => {\n const quantity = wholeUnits(line.quantity)\n const done = Math.min(quantity, fulfilled.get(index) ?? 0)\n return {\n lineItemId: index,\n quantity,\n fulfilledQuantity: done,\n remainingQuantity: quantity - done,\n requiresShipping: lineRequiresShipping(line),\n }\n })\n}\n\n/**\n * What is left to ship: every shippable line's remaining units. This is what\n * a \"fulfill everything\" request covers.\n */\nexport function remainingFulfillmentLines(\n order: Pick<HostOrder, 'lineItems' | 'fulfillments'>,\n): OrderFulfillmentLine[] {\n return orderLineFulfillmentStates(order)\n .filter((state) => state.requiresShipping && state.remainingQuantity > 0)\n .map((state) => ({ lineItemId: state.lineItemId, quantity: state.remainingQuantity }))\n}\n\n/** Why a requested set of fulfillment lines was refused. */\nexport type FulfillmentLinesProblem =\n | { problem: 'empty' }\n | { problem: 'unknown_line'; lineItemId: number }\n | { problem: 'bad_quantity'; lineItemId: number }\n | { problem: 'over_fulfilled'; lineItemId: number; remaining: number; requested: number }\n\n/**\n * Validates and merges a requested set of lines against what is left.\n *\n * Duplicate entries for one line are summed before the check, so a request\n * cannot slip past the remaining count by naming the line twice. A digital\n * or service line may be fulfilled (a merchant marking a service done), but\n * never beyond its quantity.\n */\nexport function resolveFulfillmentLines(\n order: Pick<HostOrder, 'lineItems' | 'fulfillments'>,\n requested: ReadonlyArray<{ lineItemId: unknown; quantity: unknown }>,\n): { lines: OrderFulfillmentLine[] } | FulfillmentLinesProblem {\n const states = orderLineFulfillmentStates(order)\n const merged = new Map<number, number>()\n for (const entry of requested) {\n const lineItemId = Number(entry?.lineItemId)\n if (!Number.isInteger(lineItemId) || lineItemId < 0 || lineItemId >= states.length) {\n return { problem: 'unknown_line', lineItemId: Number.isFinite(lineItemId) ? lineItemId : -1 }\n }\n const quantity = Number(entry?.quantity)\n if (!Number.isInteger(quantity) || quantity <= 0) {\n return { problem: 'bad_quantity', lineItemId }\n }\n merged.set(lineItemId, (merged.get(lineItemId) ?? 0) + quantity)\n }\n if (merged.size === 0) return { problem: 'empty' }\n const lines: OrderFulfillmentLine[] = []\n for (const [lineItemId, quantity] of [...merged.entries()].sort((a, b) => a[0] - b[0])) {\n const remaining = states[lineItemId].remainingQuantity\n if (quantity > remaining) {\n return { problem: 'over_fulfilled', lineItemId, remaining, requested: quantity }\n }\n lines.push({ lineItemId, quantity })\n }\n return { lines }\n}\n\n/** Words for a refused request, for the console and the API. */\nexport function describeFulfillmentLinesProblem(problem: FulfillmentLinesProblem): string {\n switch (problem.problem) {\n case 'empty':\n return 'Choose at least one item to fulfill'\n case 'unknown_line':\n return `Line ${problem.lineItemId} is not on this order`\n case 'bad_quantity':\n return `The quantity for line ${problem.lineItemId} must be a whole number above zero`\n case 'over_fulfilled':\n return problem.remaining === 0\n ? `Line ${problem.lineItemId} is already fully fulfilled`\n : `Line ${problem.lineItemId} has only ${problem.remaining} left to fulfill, not ${problem.requested}`\n }\n}\n\n/**\n * The status an order's fulfillments put it in: `fulfilled` once every\n * shippable unit is covered, `partially_fulfilled` while some are, and\n * `paid` when none are. An order with nothing to ship reads as `fulfilled`\n * once anything at all was recorded against it, and as `paid` before.\n */\nexport function statusFromFulfillments(\n order: Pick<HostOrder, 'lineItems' | 'fulfillments'>,\n): Extract<OrderStatus, 'paid' | 'partially_fulfilled' | 'fulfilled'> {\n const states = orderLineFulfillmentStates(order)\n const shippable = states.filter((state) => state.requiresShipping)\n const anything = states.some((state) => state.fulfilledQuantity > 0)\n if (shippable.length === 0) return anything ? 'fulfilled' : 'paid'\n if (shippable.every((state) => state.remainingQuantity === 0)) return 'fulfilled'\n return shippable.some((state) => state.fulfilledQuantity > 0) || anything\n ? 'partially_fulfilled'\n : 'paid'\n}\n\n/** Statuses whose fulfillments may still be added to, edited or cancelled. */\nconst FULFILLMENT_OPEN_STATUSES: readonly OrderStatus[] = ['paid', 'partially_fulfilled', 'fulfilled']\n\n/**\n * Whether a fulfillment on this order may be edited or cancelled. A delivered,\n * refunded or cancelled order is history: its fulfillments are what happened.\n */\nexport function orderFulfillmentsEditable(order: Pick<HostOrder, 'status'>): boolean {\n return FULFILLMENT_OPEN_STATUSES.includes(order.status)\n}\n\n/** A short \"2× Mug, 1× Shirt\" for a fulfillment, for timelines and emails. */\nexport function describeFulfillmentLines(\n order: Pick<HostOrder, 'lineItems'>,\n lines: readonly OrderFulfillmentLine[],\n): string {\n return lines\n .map((entry) => `${entry.quantity}× ${order.lineItems?.[entry.lineItemId]?.name ?? `line ${entry.lineItemId}`}`)\n .join(', ')\n}\n\n/** The carriers the console offers by name; anything else is typed under Other. */\nexport const FULFILLMENT_CARRIER_CHOICES: readonly string[] = [\n 'USPS',\n 'UPS',\n 'FedEx',\n 'DHL',\n 'Canada Post',\n 'Royal Mail',\n 'Australia Post',\n]\n\n/** What a merchant reads for a carrier's tracking status (AGL-3612). */\nconst TRACKING_STATUS_LABELS: Readonly<Record<string, string>> = {\n pre_transit: 'Label created',\n in_transit: 'In transit',\n out_for_delivery: 'Out for delivery',\n delivered: 'Delivered',\n exception: 'Delivery problem',\n returned: 'Returned to sender',\n}\n\n/** The words for a fulfillment's `trackingStatus`, or the status itself. */\nexport function trackingStatusLabel(status: string | undefined | null): string {\n return status ? TRACKING_STATUS_LABELS[status] ?? status : ''\n}\n"],"names":["lineRequiresShipping","line","productType","wholeUnits","value","units","Math","floor","Number","isFinite","fulfillmentIsActive","fulfillment","Boolean","status","fulfillmentLineQuantities","order","lines","lineItems","Array","isArray","length","map","entry","lineItemId","round","quantity","filter","isInteger","lineItemIds","index","fulfilledQuantities","totals","Map","fulfillments","set","get","orderLineFulfillmentStates","fulfilled","done","min","fulfilledQuantity","remainingQuantity","requiresShipping","remainingFulfillmentLines","state","resolveFulfillmentLines","requested","states","merged","problem","size","entries","sort","a","b","remaining","push","describeFulfillmentLinesProblem","statusFromFulfillments","shippable","anything","some","every","FULFILLMENT_OPEN_STATUSES","orderFulfillmentsEditable","includes","describeFulfillmentLines","name","join","FULFILLMENT_CARRIER_CHOICES","TRACKING_STATUS_LABELS","pre_transit","in_transit","out_for_delivery","delivered","exception","returned","trackingStatusLabel"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;CAWC,GAmBD;;;;;CAKC,GACD,OAAO,SAASA,qBAAqBC,IAAwC;IAC3E,OAAOA,KAAKC,WAAW,KAAK,aAAaD,KAAKC,WAAW,KAAK;AAChE;AAEA,MAAMC,aAAa,CAACC;IAClB,MAAMC,QAAQC,KAAKC,KAAK,CAACC,OAAOJ,gBAAAA,QAAS;IACzC,OAAOI,OAAOC,QAAQ,CAACJ,UAAUA,QAAQ,IAAIA,QAAQ;AACvD;AAEA,uEAAuE,GACvE,OAAO,SAASK,oBAAoBC,WAAyD;IAC3F,OAAOC,QAAQD,gBAAgBA,CAAAA,+BAAAA,YAAaE,MAAM,MAAK;AACzD;AAEA;;;CAGC,GACD,OAAO,SAASC,0BACdC,KAAmC,EACnCJ,WAAsC;QAExBI,kBAeNJ;IAfR,MAAMK,SAAQD,mBAAAA,MAAME,SAAS,YAAfF,mBAAmB,EAAE;IACnC,IAAIG,MAAMC,OAAO,CAACR,YAAYK,KAAK,KAAKL,YAAYK,KAAK,CAACI,MAAM,GAAG,GAA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
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { OrderEventOrder } from './order-events';
|
|
18
|
+
/**
|
|
19
|
+
* A site's order HISTORY, for another plugin (AGL-3614).
|
|
20
|
+
*
|
|
21
|
+
* The order events (`order-events.ts`) bring every order from the moment a
|
|
22
|
+
* subscriber listens. A plugin that must also read the orders BEFORE that —
|
|
23
|
+
* accounting, posting a merchant's earlier sales from a start date — reads
|
|
24
|
+
* them through this service, in the same public shape the events carry, and
|
|
25
|
+
* never through commerce's storage. Commerce registers the one
|
|
26
|
+
* implementation from its console server declarations; a reader in another
|
|
27
|
+
* plugin restates this contract under the same id, as an event subscriber
|
|
28
|
+
* restates an event.
|
|
29
|
+
*/
|
|
30
|
+
/** One stored order, as the history hands it out. */
|
|
31
|
+
export interface OrderHistoryEntry {
|
|
32
|
+
id: string;
|
|
33
|
+
createdAtMs: number;
|
|
34
|
+
/** When it was paid; `null` for one never paid. */
|
|
35
|
+
paidAtMs: number | null;
|
|
36
|
+
/** The newest refund on its timeline, or `null`. */
|
|
37
|
+
lastRefundAtMs: number | null;
|
|
38
|
+
/** Whether its prices include the tax. */
|
|
39
|
+
taxInclusive: boolean;
|
|
40
|
+
/** The tax rate it was charged under, when one was named. */
|
|
41
|
+
taxRateId: string | null;
|
|
42
|
+
/** The order in the public API's shape. */
|
|
43
|
+
order: OrderEventOrder;
|
|
44
|
+
}
|
|
45
|
+
export interface OrderHistoryPageRequest {
|
|
46
|
+
hostId: string;
|
|
47
|
+
/** Orders created at or after this… */
|
|
48
|
+
fromMs: number;
|
|
49
|
+
/** …and before this. */
|
|
50
|
+
untilMs: number;
|
|
51
|
+
/** At most this many, oldest first; capped at 200. */
|
|
52
|
+
limit: number;
|
|
53
|
+
}
|
|
54
|
+
export interface OrderHistoryReader {
|
|
55
|
+
listOrders(request: OrderHistoryPageRequest): Promise<OrderHistoryEntry[]>;
|
|
56
|
+
}
|
|
57
|
+
export declare const ORDER_HISTORY_CONTRACT_ID = "commerce.orderHistory";
|
|
58
|
+
export declare const ORDER_HISTORY_CONTRACT: import("@aglyn/aglyn/src").PluginServiceContract<OrderHistoryReader>;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
*/ import { definePluginServiceContract } from "@aglyn/aglyn/plugin-manager/plugin-services";
|
|
17
|
+
export const ORDER_HISTORY_CONTRACT_ID = 'commerce.orderHistory';
|
|
18
|
+
export const ORDER_HISTORY_CONTRACT = definePluginServiceContract(ORDER_HISTORY_CONTRACT_ID, {
|
|
19
|
+
multiple: false
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=order-history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/order-history.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 { definePluginServiceContract } from '@aglyn/aglyn/plugin-manager/plugin-services'\nimport type { OrderEventOrder } from './order-events'\n\n/**\n * A site's order HISTORY, for another plugin (AGL-3614).\n *\n * The order events (`order-events.ts`) bring every order from the moment a\n * subscriber listens. A plugin that must also read the orders BEFORE that —\n * accounting, posting a merchant's earlier sales from a start date — reads\n * them through this service, in the same public shape the events carry, and\n * never through commerce's storage. Commerce registers the one\n * implementation from its console server declarations; a reader in another\n * plugin restates this contract under the same id, as an event subscriber\n * restates an event.\n */\n\n/** One stored order, as the history hands it out. */\nexport interface OrderHistoryEntry {\n id: string\n createdAtMs: number\n /** When it was paid; `null` for one never paid. */\n paidAtMs: number | null\n /** The newest refund on its timeline, or `null`. */\n lastRefundAtMs: number | null\n /** Whether its prices include the tax. */\n taxInclusive: boolean\n /** The tax rate it was charged under, when one was named. */\n taxRateId: string | null\n /** The order in the public API's shape. */\n order: OrderEventOrder\n}\n\nexport interface OrderHistoryPageRequest {\n hostId: string\n /** Orders created at or after this… */\n fromMs: number\n /** …and before this. */\n untilMs: number\n /** At most this many, oldest first; capped at 200. */\n limit: number\n}\n\nexport interface OrderHistoryReader {\n listOrders(request: OrderHistoryPageRequest): Promise<OrderHistoryEntry[]>\n}\n\nexport const ORDER_HISTORY_CONTRACT_ID = 'commerce.orderHistory'\n\nexport const ORDER_HISTORY_CONTRACT = definePluginServiceContract<OrderHistoryReader>(ORDER_HISTORY_CONTRACT_ID, {\n multiple: false,\n})\n"],"names":["definePluginServiceContract","ORDER_HISTORY_CONTRACT_ID","ORDER_HISTORY_CONTRACT","multiple"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,2BAA2B,QAAQ,8CAA6C;AA8CzF,OAAO,MAAMC,4BAA4B,wBAAuB;AAEhE,OAAO,MAAMC,yBAAyBF,4BAAgDC,2BAA2B;IAC/GE,UAAU;AACZ,GAAE"}
|
|
@@ -76,5 +76,13 @@ export declare function orderListFields(order: object, docId: string, options?:
|
|
|
76
76
|
* An order document with its list fields spread over it — what a creator
|
|
77
77
|
* writes. The document's own `status` and `channel` win where it names them,
|
|
78
78
|
* which every creator does; the rest is derived from it.
|
|
79
|
+
*
|
|
80
|
+
* A creator also stamps whether the order ships and when it last changed
|
|
81
|
+
* (`orderSyncFields`, AGL-3613): the query the shipping export and the
|
|
82
|
+
* ShipStation feed ask. Those stay OFF `orderListFields`, which the orders
|
|
83
|
+
* backfill restates field for field — they are not list columns.
|
|
79
84
|
*/
|
|
80
|
-
export declare function withOrderListFields<T extends object>(docId: string, doc: T): T & OrderListFields
|
|
85
|
+
export declare function withOrderListFields<T extends object>(docId: string, doc: T): T & OrderListFields & {
|
|
86
|
+
requiresShipping: boolean;
|
|
87
|
+
updatedAtMs?: number;
|
|
88
|
+
};
|
|
@@ -17,6 +17,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
|
17
17
|
*/ import { emailSearchTokens } from "@aglyn/aglyn/app-utils/email-search";
|
|
18
18
|
import { nameSearchKey, nameSearchTokens } from "@aglyn/aglyn/app-utils/name-search";
|
|
19
19
|
import { describeOrderDispute } from "./commerce-dispute.js";
|
|
20
|
+
import { orderSyncFields } from "./order-shipping-export.js";
|
|
20
21
|
import { formatOrderNumber } from "./commerce-orders.js";
|
|
21
22
|
/*
|
|
22
23
|
* WHAT THE ORDERS LIST ASKS ITS QUERY, WRITTEN ON THE ORDER (AGL-3321).
|
|
@@ -105,8 +106,13 @@ const text = (value)=>typeof value === 'string' ? value : '';
|
|
|
105
106
|
* An order document with its list fields spread over it — what a creator
|
|
106
107
|
* writes. The document's own `status` and `channel` win where it names them,
|
|
107
108
|
* which every creator does; the rest is derived from it.
|
|
109
|
+
*
|
|
110
|
+
* A creator also stamps whether the order ships and when it last changed
|
|
111
|
+
* (`orderSyncFields`, AGL-3613): the query the shipping export and the
|
|
112
|
+
* ShipStation feed ask. Those stay OFF `orderListFields`, which the orders
|
|
113
|
+
* backfill restates field for field — they are not list columns.
|
|
108
114
|
*/ export function withOrderListFields(docId, doc) {
|
|
109
|
-
return _extends({}, doc, orderListFields(doc, docId));
|
|
115
|
+
return _extends({}, doc, orderListFields(doc, docId), orderSyncFields(doc));
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
//# sourceMappingURL=order-list-fields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/order-list-fields.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 { emailSearchTokens } from '@aglyn/aglyn/app-utils/email-search'\nimport {\n nameSearchKey,\n nameSearchTokens,\n} from '@aglyn/aglyn/app-utils/name-search'\nimport { describeOrderDispute, type OrderDisputeTone } from './commerce-dispute'\nimport {\n formatOrderNumber,\n type HostOrder,\n type OrderChannel,\n type OrderDispute,\n type OrderStatus,\n} from './commerce-orders'\n\n/*\n * WHAT THE ORDERS LIST ASKS ITS QUERY, WRITTEN ON THE ORDER (AGL-3321).\n *\n * The orders list puts every filter and its search on the Firestore query,\n * and a query can only ask about a field a document stores. The list used to\n * derive five of its columns in the browser — a legacy order's status and\n * channel, the products in a cart, the dispute badge, the order number — and\n * match them over the two hundred rows it had read, which answered \"none\"\n * for an order on the next page.\n *\n * So every writer of `hosts/{hostId}/orders` spreads `orderListFields` over\n * the document it writes, computed from the whole document as it will stand:\n * the creators (cart, buy-now, subscription renewal, POS, draft) and every\n * write that moves an input — the dispute record, the address a paid draft\n * learns. A write that moves none of them (a status flip, a fulfillment, a\n * refund, a timeline note) moves none of these either: `status` is its own\n * field and is what the Status filter reads.\n *\n * `tools/scripts/backfill-orders-list-fields.mjs` restates this for the\n * orders written before it; the two answer the same worked examples,\n * `tools/scripts/lib/order-list-fields.fixtures.json`.\n */\n\n/** Tokens past this many are dropped from the quick search's array. */\nexport const ORDER_SEARCH_TOKEN_LIMIT = 200\n\n/** The fields the orders list's query reads, as every writer stamps them. */\nexport interface OrderListFields {\n /**\n * Always present. A Commerce Starter order (AGL-90) carried none and was\n * read as `paid` (`liftLegacyOrder`); the lift is written down so the\n * Status filter finds it.\n */\n status: OrderStatus\n /** Always present; absent was always read as `online`. */\n channel: OrderChannel\n /**\n * Every product the order holds, line items first and the legacy flat\n * `productId` after — the Product filter's `array-contains-any`.\n */\n productIds: string[]\n /**\n * The dispute badge's tone (`describeOrderDispute`), or null with no\n * dispute. `open` is a case with a deadline; `lost` a chargeback; `won` and\n * `settled` closed with no money reversed. What the Disputes filter and the\n * open-dispute banner ask.\n */\n disputeKey: OrderDisputeTone | null\n /** The buyer's address, lower-cased — the Customer filter's `equals`. */\n customerEmailLower: string | null\n /** The address's search prefixes (`emailSearchTokens`) — its `contains`. */\n customerEmailTokens: string[]\n /** The order number's prefixes, with and without its `#` — Order `contains`. */\n orderLabelTokens: string[]\n /**\n * The quick search: the order number's, the buyer's address's and every\n * line item name's word prefixes, capped at {@link ORDER_SEARCH_TOKEN_LIMIT}\n * with the item names cut first.\n */\n searchTokens: string[]\n}\n\n/** The dispute badge's tone, stored — see {@link OrderListFields.disputeKey}. */\nexport function orderDisputeKey(\n dispute: OrderDispute | null | undefined,\n): OrderDisputeTone | null {\n if (!dispute || typeof dispute !== 'object') return null\n return describeOrderDispute({ dispute })?.tone ?? null\n}\n\n/**\n * The order number's prefixes, as `#1042` and as `1042`, so a reader who\n * types either finds it. An order with no number is labelled by its document\n * id (`formatOrderNumber`), and is found by that label the same way.\n */\nexport function orderLabelTokens(\n order: Pick<Partial<HostOrder>, 'number'>,\n docId: string,\n): string[] {\n const label = nameSearchKey(formatOrderNumber({ number: order.number }, docId))\n const bare = label.replace(/^#+/, '')\n return nameSearchTokens(bare && bare !== label ? `${label} ${bare}` : label)\n}\n\nconst text = (value: unknown): string =>\n typeof value === 'string' ? value : ''\n\n/**\n * The fields the orders list's query reads, from an order as it will be\n * stored — see {@link OrderListFields}. Pure: the same answer on the server,\n * in a spec and (restated) in the backfill.\n *\n * `legacyProductName` names the product of a Commerce Starter order, which\n * stored an id and no line items; only the backfill has it to give.\n */\nexport function orderListFields(\n order: object,\n docId: string,\n options: { legacyProductName?: string } = {},\n): OrderListFields {\n const source = order as Partial<HostOrder> & Record<string, unknown>\n const lineItems = Array.isArray(source.lineItems) ? source.lineItems : []\n const productIds = [\n ...new Set(\n [...lineItems.map((line) => line?.productId), source.productId].filter(\n (id): id is string => typeof id === 'string' && id !== '',\n ),\n ),\n ]\n const email = text(source.customerEmail)\n const emailTokens = emailSearchTokens(email)\n const labelTokens = orderLabelTokens(source, docId)\n const names = lineItems.map((line) => text(line?.name)).filter(Boolean)\n if (!names.length && options.legacyProductName) {\n names.push(options.legacyProductName)\n }\n const searchTokens = [\n ...new Set([\n ...labelTokens,\n ...emailTokens,\n ...names.flatMap((name) => nameSearchTokens(name)),\n ]),\n ].slice(0, ORDER_SEARCH_TOKEN_LIMIT)\n return {\n status: (text(source.status) || 'paid') as OrderStatus,\n channel: (text(source.channel) || 'online') as OrderChannel,\n productIds,\n disputeKey: orderDisputeKey(source.dispute),\n customerEmailLower: nameSearchKey(email) || null,\n customerEmailTokens: emailTokens,\n orderLabelTokens: labelTokens,\n searchTokens,\n }\n}\n\n/**\n * An order document with its list fields spread over it — what a creator\n * writes. The document's own `status` and `channel` win where it names them,\n * which every creator does; the rest is derived from it.\n */\nexport function withOrderListFields<T extends object>(\n docId: string,\n doc: T,\n): T & OrderListFields {\n return { ...doc, ...orderListFields(doc, docId) }\n}\n"],"names":["emailSearchTokens","nameSearchKey","nameSearchTokens","describeOrderDispute","formatOrderNumber","ORDER_SEARCH_TOKEN_LIMIT","orderDisputeKey","dispute","tone","orderLabelTokens","order","docId","label","number","bare","replace","text","value","orderListFields","options","source","lineItems","Array","isArray","productIds","Set","map","line","productId","filter","id","email","customerEmail","emailTokens","labelTokens","names","name","Boolean","length","legacyProductName","push","searchTokens","flatMap","slice","status","channel","disputeKey","customerEmailLower","customerEmailTokens","withOrderListFields","doc"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,iBAAiB,QAAQ,sCAAqC;AACvE,SACEC,aAAa,EACbC,gBAAgB,QACX,qCAAoC;AAC3C,SAASC,oBAAoB,QAA+B,wBAAoB;AAChF,SACEC,iBAAiB,QAKZ,uBAAmB;AAE1B;;;;;;;;;;;;;;;;;;;;;CAqBC,GAED,qEAAqE,GACrE,OAAO,MAAMC,2BAA2B,IAAG;AAsC3C,+EAA+E,GAC/E,OAAO,SAASC,gBACdC,OAAwC;;
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/order-list-fields.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 { emailSearchTokens } from '@aglyn/aglyn/app-utils/email-search'\nimport {\n nameSearchKey,\n nameSearchTokens,\n} from '@aglyn/aglyn/app-utils/name-search'\nimport { describeOrderDispute, type OrderDisputeTone } from './commerce-dispute'\nimport { orderSyncFields } from './order-shipping-export'\nimport {\n formatOrderNumber,\n type HostOrder,\n type OrderChannel,\n type OrderDispute,\n type OrderStatus,\n} from './commerce-orders'\n\n/*\n * WHAT THE ORDERS LIST ASKS ITS QUERY, WRITTEN ON THE ORDER (AGL-3321).\n *\n * The orders list puts every filter and its search on the Firestore query,\n * and a query can only ask about a field a document stores. The list used to\n * derive five of its columns in the browser — a legacy order's status and\n * channel, the products in a cart, the dispute badge, the order number — and\n * match them over the two hundred rows it had read, which answered \"none\"\n * for an order on the next page.\n *\n * So every writer of `hosts/{hostId}/orders` spreads `orderListFields` over\n * the document it writes, computed from the whole document as it will stand:\n * the creators (cart, buy-now, subscription renewal, POS, draft) and every\n * write that moves an input — the dispute record, the address a paid draft\n * learns. A write that moves none of them (a status flip, a fulfillment, a\n * refund, a timeline note) moves none of these either: `status` is its own\n * field and is what the Status filter reads.\n *\n * `tools/scripts/backfill-orders-list-fields.mjs` restates this for the\n * orders written before it; the two answer the same worked examples,\n * `tools/scripts/lib/order-list-fields.fixtures.json`.\n */\n\n/** Tokens past this many are dropped from the quick search's array. */\nexport const ORDER_SEARCH_TOKEN_LIMIT = 200\n\n/** The fields the orders list's query reads, as every writer stamps them. */\nexport interface OrderListFields {\n /**\n * Always present. A Commerce Starter order (AGL-90) carried none and was\n * read as `paid` (`liftLegacyOrder`); the lift is written down so the\n * Status filter finds it.\n */\n status: OrderStatus\n /** Always present; absent was always read as `online`. */\n channel: OrderChannel\n /**\n * Every product the order holds, line items first and the legacy flat\n * `productId` after — the Product filter's `array-contains-any`.\n */\n productIds: string[]\n /**\n * The dispute badge's tone (`describeOrderDispute`), or null with no\n * dispute. `open` is a case with a deadline; `lost` a chargeback; `won` and\n * `settled` closed with no money reversed. What the Disputes filter and the\n * open-dispute banner ask.\n */\n disputeKey: OrderDisputeTone | null\n /** The buyer's address, lower-cased — the Customer filter's `equals`. */\n customerEmailLower: string | null\n /** The address's search prefixes (`emailSearchTokens`) — its `contains`. */\n customerEmailTokens: string[]\n /** The order number's prefixes, with and without its `#` — Order `contains`. */\n orderLabelTokens: string[]\n /**\n * The quick search: the order number's, the buyer's address's and every\n * line item name's word prefixes, capped at {@link ORDER_SEARCH_TOKEN_LIMIT}\n * with the item names cut first.\n */\n searchTokens: string[]\n}\n\n/** The dispute badge's tone, stored — see {@link OrderListFields.disputeKey}. */\nexport function orderDisputeKey(\n dispute: OrderDispute | null | undefined,\n): OrderDisputeTone | null {\n if (!dispute || typeof dispute !== 'object') return null\n return describeOrderDispute({ dispute })?.tone ?? null\n}\n\n/**\n * The order number's prefixes, as `#1042` and as `1042`, so a reader who\n * types either finds it. An order with no number is labelled by its document\n * id (`formatOrderNumber`), and is found by that label the same way.\n */\nexport function orderLabelTokens(\n order: Pick<Partial<HostOrder>, 'number'>,\n docId: string,\n): string[] {\n const label = nameSearchKey(formatOrderNumber({ number: order.number }, docId))\n const bare = label.replace(/^#+/, '')\n return nameSearchTokens(bare && bare !== label ? `${label} ${bare}` : label)\n}\n\nconst text = (value: unknown): string =>\n typeof value === 'string' ? value : ''\n\n/**\n * The fields the orders list's query reads, from an order as it will be\n * stored — see {@link OrderListFields}. Pure: the same answer on the server,\n * in a spec and (restated) in the backfill.\n *\n * `legacyProductName` names the product of a Commerce Starter order, which\n * stored an id and no line items; only the backfill has it to give.\n */\nexport function orderListFields(\n order: object,\n docId: string,\n options: { legacyProductName?: string } = {},\n): OrderListFields {\n const source = order as Partial<HostOrder> & Record<string, unknown>\n const lineItems = Array.isArray(source.lineItems) ? source.lineItems : []\n const productIds = [\n ...new Set(\n [...lineItems.map((line) => line?.productId), source.productId].filter(\n (id): id is string => typeof id === 'string' && id !== '',\n ),\n ),\n ]\n const email = text(source.customerEmail)\n const emailTokens = emailSearchTokens(email)\n const labelTokens = orderLabelTokens(source, docId)\n const names = lineItems.map((line) => text(line?.name)).filter(Boolean)\n if (!names.length && options.legacyProductName) {\n names.push(options.legacyProductName)\n }\n const searchTokens = [\n ...new Set([\n ...labelTokens,\n ...emailTokens,\n ...names.flatMap((name) => nameSearchTokens(name)),\n ]),\n ].slice(0, ORDER_SEARCH_TOKEN_LIMIT)\n return {\n status: (text(source.status) || 'paid') as OrderStatus,\n channel: (text(source.channel) || 'online') as OrderChannel,\n productIds,\n disputeKey: orderDisputeKey(source.dispute),\n customerEmailLower: nameSearchKey(email) || null,\n customerEmailTokens: emailTokens,\n orderLabelTokens: labelTokens,\n searchTokens,\n }\n}\n\n/**\n * An order document with its list fields spread over it — what a creator\n * writes. The document's own `status` and `channel` win where it names them,\n * which every creator does; the rest is derived from it.\n *\n * A creator also stamps whether the order ships and when it last changed\n * (`orderSyncFields`, AGL-3613): the query the shipping export and the\n * ShipStation feed ask. Those stay OFF `orderListFields`, which the orders\n * backfill restates field for field — they are not list columns.\n */\nexport function withOrderListFields<T extends object>(\n docId: string,\n doc: T,\n): T & OrderListFields & { requiresShipping: boolean; updatedAtMs?: number } {\n return { ...doc, ...orderListFields(doc, docId), ...orderSyncFields(doc) }\n}\n"],"names":["emailSearchTokens","nameSearchKey","nameSearchTokens","describeOrderDispute","orderSyncFields","formatOrderNumber","ORDER_SEARCH_TOKEN_LIMIT","orderDisputeKey","dispute","tone","orderLabelTokens","order","docId","label","number","bare","replace","text","value","orderListFields","options","source","lineItems","Array","isArray","productIds","Set","map","line","productId","filter","id","email","customerEmail","emailTokens","labelTokens","names","name","Boolean","length","legacyProductName","push","searchTokens","flatMap","slice","status","channel","disputeKey","customerEmailLower","customerEmailTokens","withOrderListFields","doc"],"mappings":";AAAA;;;;;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AAa;IACvC,MAAMC,cAAclC,kBAAkBgC;IACtC,MAAMG,cAAczB,iBAAiBW,QAAQT;IAC7C,MAAMwB,QAAQd,UAAUK,GAAG,CAAC,CAACC,OAASX,KAAKW,wBAAAA,KAAMS,IAAI,GAAGP,MAAM,CAACQ;IAC/D,IAAI,CAACF,MAAMG,MAAM,IAAInB,QAAQoB,iBAAiB,EAAE;QAC9CJ,MAAMK,IAAI,CAACrB,QAAQoB,iBAAiB;IACtC;IACA,MAAME,eAAe;WAChB,IAAIhB,IAAI;eACNS;eACAD;eACAE,MAAMO,OAAO,CAAC,CAACN,OAASnC,iBAAiBmC;SAC7C;KACF,CAACO,KAAK,CAAC,GAAGtC;IACX,OAAO;QACLuC,QAAS5B,KAAKI,OAAOwB,MAAM,KAAK;QAChCC,SAAU7B,KAAKI,OAAOyB,OAAO,KAAK;QAClCrB;QACAsB,YAAYxC,gBAAgBc,OAAOb,OAAO;QAC1CwC,oBAAoB/C,cAAc+B,UAAU;QAC5CiB,qBAAqBf;QACrBxB,kBAAkByB;QAClBO;IACF;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,SAASQ,oBACdtC,KAAa,EACbuC,GAAM;IAEN,OAAO,aAAKA,KAAQhC,gBAAgBgC,KAAKvC,QAAWR,gBAAgB+C;AACtE"}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 { HostOrder, OrderFulfillment, OrderLineItem } from './commerce-orders';
|
|
18
|
+
/** Grams in one avoirdupois ounce. */
|
|
19
|
+
export declare const GRAMS_PER_OUNCE = 28.349523125;
|
|
20
|
+
/** Ounces in one pound. */
|
|
21
|
+
export declare const OUNCES_PER_POUND = 16;
|
|
22
|
+
/** A weight in grams as ounces, to two places. */
|
|
23
|
+
export declare function gramsToOunces(grams: number): number;
|
|
24
|
+
/** A weight in ounces as pounds, to two places. */
|
|
25
|
+
export declare function ouncesToPounds(ounces: number): number;
|
|
26
|
+
/**
|
|
27
|
+
* Whether an order has anything to put in a box.
|
|
28
|
+
*
|
|
29
|
+
* A line with no recorded type predates types and counts as physical, the
|
|
30
|
+
* reading that never hides an order a merchant has to ship. A register sale
|
|
31
|
+
* left the shop in the buyer's hands, so a POS order ships only when it was
|
|
32
|
+
* given a shipping address. A legacy Commerce Starter order with no lines
|
|
33
|
+
* ships when it carries an address.
|
|
34
|
+
*/
|
|
35
|
+
export declare function orderRequiresShipping(order: Partial<HostOrder>): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The fields a CREATOR of an order stamps beside its list fields: whether it
|
|
38
|
+
* ships, and when it last changed — its creation, for a new order. Writers
|
|
39
|
+
* that change an order afterwards stamp `updatedAtMs` themselves; nothing
|
|
40
|
+
* else here moves after creation, because an order's lines never do.
|
|
41
|
+
*/
|
|
42
|
+
export declare function orderSyncFields(order: object): {
|
|
43
|
+
requiresShipping: boolean;
|
|
44
|
+
updatedAtMs?: number;
|
|
45
|
+
};
|
|
46
|
+
/** The number a shipping tool shows and sends back: `1042`, or the document id for an unnumbered order. */
|
|
47
|
+
export declare function shippingOrderNumber(order: Pick<HostOrder, 'number'>, docId: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Every spelling of an order a file or a ShipNotice may name it by: `1042`,
|
|
50
|
+
* `#1042` and the document id. What `parseShippingOrderRef` reads back.
|
|
51
|
+
*/
|
|
52
|
+
export declare function shippingOrderRefs(order: Pick<HostOrder, 'number'>, docId: string): string[];
|
|
53
|
+
/** What a reference a tool sent back names: an order number, or a document id. */
|
|
54
|
+
export declare function parseShippingOrderRef(value: unknown): {
|
|
55
|
+
number?: number;
|
|
56
|
+
id?: string;
|
|
57
|
+
} | null;
|
|
58
|
+
/** A product's weights, keyed by variant id (`''` for a product with no variant named). */
|
|
59
|
+
export type ProductWeights = Readonly<Record<string, Readonly<Record<string, number>>>>;
|
|
60
|
+
/** One unit of a line's weight in grams, or `null` when the product records none. */
|
|
61
|
+
export declare function lineUnitGrams(line: Pick<OrderLineItem, 'productId' | 'variantId'>, weights: ProductWeights): number | null;
|
|
62
|
+
/** One line still to ship: which line, how many units, and what one weighs. */
|
|
63
|
+
export interface ShippingLine {
|
|
64
|
+
lineItemId: number;
|
|
65
|
+
line: OrderLineItem;
|
|
66
|
+
quantity: number;
|
|
67
|
+
unitGrams: number | null;
|
|
68
|
+
}
|
|
69
|
+
/** The lines still to ship, with their remaining units. */
|
|
70
|
+
export declare function shippingLines(order: Pick<HostOrder, 'lineItems' | 'fulfillments'>, weights?: ProductWeights): ShippingLine[];
|
|
71
|
+
/**
|
|
72
|
+
* The parcel's weight in ounces: every remaining unit's recorded weight.
|
|
73
|
+
* `null` when no line records one, so a tool falls back to the default
|
|
74
|
+
* package the merchant set there rather than a weight of zero.
|
|
75
|
+
*/
|
|
76
|
+
export declare function shippingWeightOunces(lines: readonly ShippingLine[]): number | null;
|
|
77
|
+
/** A line as a packing list names it: `2 × Mug (Blue), SKU MUG-B`. */
|
|
78
|
+
export declare function describeShippingLine(entry: Pick<ShippingLine, 'line' | 'quantity'>): string;
|
|
79
|
+
/**
|
|
80
|
+
* The shipping columns of one order, as the orders export writes them
|
|
81
|
+
* (`ORDER_SHIPPING_FIELDS`). Every value is what the order holds; nothing is
|
|
82
|
+
* invented — an order with no phone exports no phone.
|
|
83
|
+
*/
|
|
84
|
+
export declare function orderShippingRecord(docId: string, order: Partial<HostOrder>, weights?: ProductWeights): Record<string, unknown>;
|
|
85
|
+
/**
|
|
86
|
+
* A tracking number as a parcel's identity: spaces and dashes dropped,
|
|
87
|
+
* upper-cased. `9400 1000 0000` and `94001000000` are one parcel.
|
|
88
|
+
*/
|
|
89
|
+
export declare function normalizeTrackingNumber(value: unknown): string;
|
|
90
|
+
/** The active fulfillment already carrying this tracking number, if any. */
|
|
91
|
+
export declare function fulfillmentWithTracking(order: Pick<HostOrder, 'fulfillments'>, trackingNumber: unknown): OrderFulfillment | undefined;
|
|
@@ -0,0 +1,192 @@
|
|
|
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
|
+
*/ import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
17
|
+
import { fulfillmentIsActive, lineRequiresShipping, remainingFulfillmentLines } from "./order-fulfillment.js";
|
|
18
|
+
/*
|
|
19
|
+
* AN ORDER AS A SHIPPING TOOL READS IT (AGL-3613).
|
|
20
|
+
*
|
|
21
|
+
* ShipStation's Custom Store feed, Pirate Ship's spreadsheet upload and the
|
|
22
|
+
* Shippo and EasyPost CSVs all want the same facts about an order: who it
|
|
23
|
+
* goes to, what is still to be packed, and what that weighs. This module is
|
|
24
|
+
* that one reading, pure, so the XML feed and the CSV export cannot disagree
|
|
25
|
+
* about an order's weight or which units are still owed.
|
|
26
|
+
*
|
|
27
|
+
* WHAT IS STILL TO SHIP, NOT WHAT WAS BOUGHT. A partially fulfilled order
|
|
28
|
+
* exports its remaining units (`remainingFulfillmentLines`), so a label tool
|
|
29
|
+
* that imports it again after the first parcel left asks for the rest and
|
|
30
|
+
* not the whole order a second time. Digital and service lines never ship.
|
|
31
|
+
*
|
|
32
|
+
* WHICH ORDERS SHIP AT ALL is stamped on the order as `requiresShipping`
|
|
33
|
+
* when it is written (`withOrderListFields`), so the export and the
|
|
34
|
+
* ShipStation feed ask it of their Firestore query instead of reading every
|
|
35
|
+
* order and dropping the downloads afterwards.
|
|
36
|
+
*/ /** Grams in one avoirdupois ounce. */ export const GRAMS_PER_OUNCE = 28.349523125;
|
|
37
|
+
/** Ounces in one pound. */ export const OUNCES_PER_POUND = 16;
|
|
38
|
+
/** A weight in grams as ounces, to two places. */ export function gramsToOunces(grams) {
|
|
39
|
+
return Math.round(grams / GRAMS_PER_OUNCE * 100) / 100;
|
|
40
|
+
}
|
|
41
|
+
/** A weight in ounces as pounds, to two places. */ export function ouncesToPounds(ounces) {
|
|
42
|
+
return Math.round(ounces / OUNCES_PER_POUND * 100) / 100;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether an order has anything to put in a box.
|
|
46
|
+
*
|
|
47
|
+
* A line with no recorded type predates types and counts as physical, the
|
|
48
|
+
* reading that never hides an order a merchant has to ship. A register sale
|
|
49
|
+
* left the shop in the buyer's hands, so a POS order ships only when it was
|
|
50
|
+
* given a shipping address. A legacy Commerce Starter order with no lines
|
|
51
|
+
* ships when it carries an address.
|
|
52
|
+
*/ export function orderRequiresShipping(order) {
|
|
53
|
+
const lines = Array.isArray(order.lineItems) ? order.lineItems : [];
|
|
54
|
+
const address = hasShippingAddress(order.shippingAddress);
|
|
55
|
+
if (!lines.length) return address;
|
|
56
|
+
if (!lines.some((line)=>line && lineRequiresShipping(line))) return false;
|
|
57
|
+
return order.channel === 'pos' ? address : true;
|
|
58
|
+
}
|
|
59
|
+
function hasShippingAddress(address) {
|
|
60
|
+
var _address_line1;
|
|
61
|
+
return Boolean(address && String((_address_line1 = address.line1) != null ? _address_line1 : '').trim());
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The fields a CREATOR of an order stamps beside its list fields: whether it
|
|
65
|
+
* ships, and when it last changed — its creation, for a new order. Writers
|
|
66
|
+
* that change an order afterwards stamp `updatedAtMs` themselves; nothing
|
|
67
|
+
* else here moves after creation, because an order's lines never do.
|
|
68
|
+
*/ export function orderSyncFields(order) {
|
|
69
|
+
var _source_updatedAtMs;
|
|
70
|
+
const source = order;
|
|
71
|
+
const at = Number((_source_updatedAtMs = source.updatedAtMs) != null ? _source_updatedAtMs : source.createdAtMs);
|
|
72
|
+
return _extends({
|
|
73
|
+
requiresShipping: orderRequiresShipping(source)
|
|
74
|
+
}, Number.isFinite(at) && at > 0 ? {
|
|
75
|
+
updatedAtMs: at
|
|
76
|
+
} : {});
|
|
77
|
+
}
|
|
78
|
+
/** The number a shipping tool shows and sends back: `1042`, or the document id for an unnumbered order. */ export function shippingOrderNumber(order, docId) {
|
|
79
|
+
return typeof order.number === 'number' && Number.isFinite(order.number) ? String(order.number) : docId;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Every spelling of an order a file or a ShipNotice may name it by: `1042`,
|
|
83
|
+
* `#1042` and the document id. What `parseShippingOrderRef` reads back.
|
|
84
|
+
*/ export function shippingOrderRefs(order, docId) {
|
|
85
|
+
const refs = [
|
|
86
|
+
docId
|
|
87
|
+
];
|
|
88
|
+
if (typeof order.number === 'number' && Number.isFinite(order.number)) {
|
|
89
|
+
refs.unshift(String(order.number), `#${order.number}`);
|
|
90
|
+
}
|
|
91
|
+
return refs;
|
|
92
|
+
}
|
|
93
|
+
/** What a reference a tool sent back names: an order number, or a document id. */ export function parseShippingOrderRef(value) {
|
|
94
|
+
const text = String(value != null ? value : '').trim();
|
|
95
|
+
if (!text) return null;
|
|
96
|
+
const numbered = /^#?\s*(\d{1,12})$/.exec(text);
|
|
97
|
+
if (numbered) return {
|
|
98
|
+
number: Number(numbered[1]),
|
|
99
|
+
id: text.replace(/^#\s*/, '')
|
|
100
|
+
};
|
|
101
|
+
// Document ids are what Firestore accepts: no slash, not reserved.
|
|
102
|
+
if (/[/]/.test(text) || /^__.*__$/.test(text) || text.length > 200) return null;
|
|
103
|
+
return {
|
|
104
|
+
id: text
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/** One unit of a line's weight in grams, or `null` when the product records none. */ export function lineUnitGrams(line, weights) {
|
|
108
|
+
const byVariant = weights[line.productId];
|
|
109
|
+
if (!byVariant) return null;
|
|
110
|
+
const grams = line.variantId ? byVariant[line.variantId] : undefined;
|
|
111
|
+
const value = grams != null ? grams : byVariant[''];
|
|
112
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : null;
|
|
113
|
+
}
|
|
114
|
+
/** The lines still to ship, with their remaining units. */ export function shippingLines(order, weights = {}) {
|
|
115
|
+
var _order_lineItems;
|
|
116
|
+
const lines = (_order_lineItems = order.lineItems) != null ? _order_lineItems : [];
|
|
117
|
+
return remainingFulfillmentLines(order).map((entry)=>({
|
|
118
|
+
entry,
|
|
119
|
+
line: lines[entry.lineItemId]
|
|
120
|
+
})).filter((pair)=>Boolean(pair.line)).map(({ entry, line })=>({
|
|
121
|
+
lineItemId: entry.lineItemId,
|
|
122
|
+
line,
|
|
123
|
+
quantity: entry.quantity,
|
|
124
|
+
unitGrams: lineUnitGrams(line, weights)
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The parcel's weight in ounces: every remaining unit's recorded weight.
|
|
129
|
+
* `null` when no line records one, so a tool falls back to the default
|
|
130
|
+
* package the merchant set there rather than a weight of zero.
|
|
131
|
+
*/ export function shippingWeightOunces(lines) {
|
|
132
|
+
let grams = 0;
|
|
133
|
+
let known = false;
|
|
134
|
+
for (const entry of lines){
|
|
135
|
+
if (entry.unitGrams === null) continue;
|
|
136
|
+
known = true;
|
|
137
|
+
grams += entry.unitGrams * entry.quantity;
|
|
138
|
+
}
|
|
139
|
+
return known ? gramsToOunces(grams) : null;
|
|
140
|
+
}
|
|
141
|
+
/** A line as a packing list names it: `2 × Mug (Blue), SKU MUG-B`. */ export function describeShippingLine(entry) {
|
|
142
|
+
const { line } = entry;
|
|
143
|
+
return `${entry.quantity} × ${line.name}${line.variantLabel ? ` (${line.variantLabel})` : ''}${line.sku ? `, SKU ${line.sku}` : ''}`;
|
|
144
|
+
}
|
|
145
|
+
const text = (value)=>{
|
|
146
|
+
const trimmed = value === null || value === undefined ? '' : String(value).trim();
|
|
147
|
+
return trimmed || null;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* The shipping columns of one order, as the orders export writes them
|
|
151
|
+
* (`ORDER_SHIPPING_FIELDS`). Every value is what the order holds; nothing is
|
|
152
|
+
* invented — an order with no phone exports no phone.
|
|
153
|
+
*/ export function orderShippingRecord(docId, order, weights = {}) {
|
|
154
|
+
var _order_shippingAddress, _order_lineItems, _order_fulfillments, _text, _text1;
|
|
155
|
+
const address = (_order_shippingAddress = order.shippingAddress) != null ? _order_shippingAddress : {};
|
|
156
|
+
const lines = shippingLines({
|
|
157
|
+
lineItems: (_order_lineItems = order.lineItems) != null ? _order_lineItems : [],
|
|
158
|
+
fulfillments: (_order_fulfillments = order.fulfillments) != null ? _order_fulfillments : []
|
|
159
|
+
}, weights);
|
|
160
|
+
const ounces = shippingWeightOunces(lines);
|
|
161
|
+
return {
|
|
162
|
+
orderRef: shippingOrderNumber(order, docId),
|
|
163
|
+
shipName: (_text = text(address.name)) != null ? _text : text(order.customerName),
|
|
164
|
+
shipLine1: text(address.line1),
|
|
165
|
+
shipLine2: text(address.line2),
|
|
166
|
+
shipCity: text(address.city),
|
|
167
|
+
shipState: text(address.state),
|
|
168
|
+
shipPostalCode: text(address.postalCode),
|
|
169
|
+
shipCountry: text(address.country),
|
|
170
|
+
shipPhone: (_text1 = text(address.phone)) != null ? _text1 : text(order.customerPhone),
|
|
171
|
+
shipEmail: text(order.customerEmail),
|
|
172
|
+
itemsToShip: lines.length ? lines.map(describeShippingLine).join('; ') : null,
|
|
173
|
+
unitsToShip: lines.reduce((sum, entry)=>sum + entry.quantity, 0),
|
|
174
|
+
weightOz: ounces,
|
|
175
|
+
weightLb: ounces === null ? null : ouncesToPounds(ounces),
|
|
176
|
+
weightUnit: ounces === null ? null : 'oz'
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A tracking number as a parcel's identity: spaces and dashes dropped,
|
|
181
|
+
* upper-cased. `9400 1000 0000` and `94001000000` are one parcel.
|
|
182
|
+
*/ export function normalizeTrackingNumber(value) {
|
|
183
|
+
return String(value != null ? value : '').replace(/[\s-]+/g, '').toUpperCase();
|
|
184
|
+
}
|
|
185
|
+
/** The active fulfillment already carrying this tracking number, if any. */ export function fulfillmentWithTracking(order, trackingNumber) {
|
|
186
|
+
var _order_fulfillments;
|
|
187
|
+
const wanted = normalizeTrackingNumber(trackingNumber);
|
|
188
|
+
if (!wanted) return undefined;
|
|
189
|
+
return ((_order_fulfillments = order.fulfillments) != null ? _order_fulfillments : []).find((entry)=>fulfillmentIsActive(entry) && normalizeTrackingNumber(entry.trackingNumber) === wanted);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//# sourceMappingURL=order-shipping-export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/order-shipping-export.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 type { HostOrder, OrderAddress, OrderFulfillment, OrderLineItem } from './commerce-orders'\nimport { fulfillmentIsActive, lineRequiresShipping, remainingFulfillmentLines } from './order-fulfillment'\n\n/*\n * AN ORDER AS A SHIPPING TOOL READS IT (AGL-3613).\n *\n * ShipStation's Custom Store feed, Pirate Ship's spreadsheet upload and the\n * Shippo and EasyPost CSVs all want the same facts about an order: who it\n * goes to, what is still to be packed, and what that weighs. This module is\n * that one reading, pure, so the XML feed and the CSV export cannot disagree\n * about an order's weight or which units are still owed.\n *\n * WHAT IS STILL TO SHIP, NOT WHAT WAS BOUGHT. A partially fulfilled order\n * exports its remaining units (`remainingFulfillmentLines`), so a label tool\n * that imports it again after the first parcel left asks for the rest and\n * not the whole order a second time. Digital and service lines never ship.\n *\n * WHICH ORDERS SHIP AT ALL is stamped on the order as `requiresShipping`\n * when it is written (`withOrderListFields`), so the export and the\n * ShipStation feed ask it of their Firestore query instead of reading every\n * order and dropping the downloads afterwards.\n */\n\n/** Grams in one avoirdupois ounce. */\nexport const GRAMS_PER_OUNCE = 28.349523125\n\n/** Ounces in one pound. */\nexport const OUNCES_PER_POUND = 16\n\n/** A weight in grams as ounces, to two places. */\nexport function gramsToOunces(grams: number): number {\n return Math.round((grams / GRAMS_PER_OUNCE) * 100) / 100\n}\n\n/** A weight in ounces as pounds, to two places. */\nexport function ouncesToPounds(ounces: number): number {\n return Math.round((ounces / OUNCES_PER_POUND) * 100) / 100\n}\n\n/**\n * Whether an order has anything to put in a box.\n *\n * A line with no recorded type predates types and counts as physical, the\n * reading that never hides an order a merchant has to ship. A register sale\n * left the shop in the buyer's hands, so a POS order ships only when it was\n * given a shipping address. A legacy Commerce Starter order with no lines\n * ships when it carries an address.\n */\nexport function orderRequiresShipping(order: Partial<HostOrder>): boolean {\n const lines = Array.isArray(order.lineItems) ? order.lineItems : []\n const address = hasShippingAddress(order.shippingAddress)\n if (!lines.length) return address\n if (!lines.some((line) => line && lineRequiresShipping(line))) return false\n return order.channel === 'pos' ? address : true\n}\n\nfunction hasShippingAddress(address: OrderAddress | undefined | null): boolean {\n return Boolean(address && String(address.line1 ?? '').trim())\n}\n\n/**\n * The fields a CREATOR of an order stamps beside its list fields: whether it\n * ships, and when it last changed — its creation, for a new order. Writers\n * that change an order afterwards stamp `updatedAtMs` themselves; nothing\n * else here moves after creation, because an order's lines never do.\n */\nexport function orderSyncFields(order: object): { requiresShipping: boolean; updatedAtMs?: number } {\n const source = order as Partial<HostOrder> & { updatedAtMs?: unknown; createdAtMs?: unknown }\n const at = Number(source.updatedAtMs ?? source.createdAtMs)\n return {\n requiresShipping: orderRequiresShipping(source),\n ...(Number.isFinite(at) && at > 0 ? { updatedAtMs: at } : {}),\n }\n}\n\n/** The number a shipping tool shows and sends back: `1042`, or the document id for an unnumbered order. */\nexport function shippingOrderNumber(order: Pick<HostOrder, 'number'>, docId: string): string {\n return typeof order.number === 'number' && Number.isFinite(order.number) ? String(order.number) : docId\n}\n\n/**\n * Every spelling of an order a file or a ShipNotice may name it by: `1042`,\n * `#1042` and the document id. What `parseShippingOrderRef` reads back.\n */\nexport function shippingOrderRefs(order: Pick<HostOrder, 'number'>, docId: string): string[] {\n const refs = [docId]\n if (typeof order.number === 'number' && Number.isFinite(order.number)) {\n refs.unshift(String(order.number), `#${order.number}`)\n }\n return refs\n}\n\n/** What a reference a tool sent back names: an order number, or a document id. */\nexport function parseShippingOrderRef(value: unknown): { number?: number; id?: string } | null {\n const text = String(value ?? '').trim()\n if (!text) return null\n const numbered = /^#?\\s*(\\d{1,12})$/.exec(text)\n if (numbered) return { number: Number(numbered[1]), id: text.replace(/^#\\s*/, '') }\n // Document ids are what Firestore accepts: no slash, not reserved.\n if (/[/]/.test(text) || /^__.*__$/.test(text) || text.length > 200) return null\n return { id: text }\n}\n\n/** A product's weights, keyed by variant id (`''` for a product with no variant named). */\nexport type ProductWeights = Readonly<Record<string, Readonly<Record<string, number>>>>\n\n/** One unit of a line's weight in grams, or `null` when the product records none. */\nexport function lineUnitGrams(line: Pick<OrderLineItem, 'productId' | 'variantId'>, weights: ProductWeights): number | null {\n const byVariant = weights[line.productId]\n if (!byVariant) return null\n const grams = line.variantId ? byVariant[line.variantId] : undefined\n const value = grams ?? byVariant['']\n return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : null\n}\n\n/** One line still to ship: which line, how many units, and what one weighs. */\nexport interface ShippingLine {\n lineItemId: number\n line: OrderLineItem\n quantity: number\n unitGrams: number | null\n}\n\n/** The lines still to ship, with their remaining units. */\nexport function shippingLines(order: Pick<HostOrder, 'lineItems' | 'fulfillments'>, weights: ProductWeights = {}): ShippingLine[] {\n const lines = order.lineItems ?? []\n return remainingFulfillmentLines(order)\n .map((entry) => ({ entry, line: lines[entry.lineItemId] }))\n .filter((pair): pair is { entry: { lineItemId: number; quantity: number }; line: OrderLineItem } => Boolean(pair.line))\n .map(({ entry, line }) => ({\n lineItemId: entry.lineItemId,\n line,\n quantity: entry.quantity,\n unitGrams: lineUnitGrams(line, weights),\n }))\n}\n\n/**\n * The parcel's weight in ounces: every remaining unit's recorded weight.\n * `null` when no line records one, so a tool falls back to the default\n * package the merchant set there rather than a weight of zero.\n */\nexport function shippingWeightOunces(lines: readonly ShippingLine[]): number | null {\n let grams = 0\n let known = false\n for (const entry of lines) {\n if (entry.unitGrams === null) continue\n known = true\n grams += entry.unitGrams * entry.quantity\n }\n return known ? gramsToOunces(grams) : null\n}\n\n/** A line as a packing list names it: `2 × Mug (Blue), SKU MUG-B`. */\nexport function describeShippingLine(entry: Pick<ShippingLine, 'line' | 'quantity'>): string {\n const { line } = entry\n return `${entry.quantity} × ${line.name}${line.variantLabel ? ` (${line.variantLabel})` : ''}${line.sku ? `, SKU ${line.sku}` : ''}`\n}\n\nconst text = (value: unknown): string | null => {\n const trimmed = value === null || value === undefined ? '' : String(value).trim()\n return trimmed || null\n}\n\n/**\n * The shipping columns of one order, as the orders export writes them\n * (`ORDER_SHIPPING_FIELDS`). Every value is what the order holds; nothing is\n * invented — an order with no phone exports no phone.\n */\nexport function orderShippingRecord(\n docId: string,\n order: Partial<HostOrder>,\n weights: ProductWeights = {},\n): Record<string, unknown> {\n const address = order.shippingAddress ?? {}\n const lines = shippingLines({ lineItems: order.lineItems ?? [], fulfillments: order.fulfillments ?? [] }, weights)\n const ounces = shippingWeightOunces(lines)\n return {\n orderRef: shippingOrderNumber(order, docId),\n shipName: text(address.name) ?? text(order.customerName),\n shipLine1: text(address.line1),\n shipLine2: text(address.line2),\n shipCity: text(address.city),\n shipState: text(address.state),\n shipPostalCode: text(address.postalCode),\n shipCountry: text(address.country),\n shipPhone: text(address.phone) ?? text(order.customerPhone),\n shipEmail: text(order.customerEmail),\n itemsToShip: lines.length ? lines.map(describeShippingLine).join('; ') : null,\n unitsToShip: lines.reduce((sum, entry) => sum + entry.quantity, 0),\n weightOz: ounces,\n weightLb: ounces === null ? null : ouncesToPounds(ounces),\n weightUnit: ounces === null ? null : 'oz',\n }\n}\n\n/**\n * A tracking number as a parcel's identity: spaces and dashes dropped,\n * upper-cased. `9400 1000 0000` and `94001000000` are one parcel.\n */\nexport function normalizeTrackingNumber(value: unknown): string {\n return String(value ?? '')\n .replace(/[\\s-]+/g, '')\n .toUpperCase()\n}\n\n/** The active fulfillment already carrying this tracking number, if any. */\nexport function fulfillmentWithTracking(\n order: Pick<HostOrder, 'fulfillments'>,\n trackingNumber: unknown,\n): OrderFulfillment | undefined {\n const wanted = normalizeTrackingNumber(trackingNumber)\n if (!wanted) return undefined\n return (order.fulfillments ?? []).find(\n (entry) => fulfillmentIsActive(entry) && normalizeTrackingNumber(entry.trackingNumber) === wanted,\n )\n}\n"],"names":["fulfillmentIsActive","lineRequiresShipping","remainingFulfillmentLines","GRAMS_PER_OUNCE","OUNCES_PER_POUND","gramsToOunces","grams","Math","round","ouncesToPounds","ounces","orderRequiresShipping","order","lines","Array","isArray","lineItems","address","hasShippingAddress","shippingAddress","length","some","line","channel","Boolean","String","line1","trim","orderSyncFields","source","at","Number","updatedAtMs","createdAtMs","requiresShipping","isFinite","shippingOrderNumber","docId","number","shippingOrderRefs","refs","unshift","parseShippingOrderRef","value","text","numbered","exec","id","replace","test","lineUnitGrams","weights","byVariant","productId","variantId","undefined","shippingLines","map","entry","lineItemId","filter","pair","quantity","unitGrams","shippingWeightOunces","known","describeShippingLine","name","variantLabel","sku","trimmed","orderShippingRecord","fulfillments","orderRef","shipName","customerName","shipLine1","shipLine2","line2","shipCity","city","shipState","state","shipPostalCode","postalCode","shipCountry","country","shipPhone","phone","customerPhone","shipEmail","customerEmail","itemsToShip","join","unitsToShip","reduce","sum","weightOz","weightLb","weightUnit","normalizeTrackingNumber","toUpperCase","fulfillmentWithTracking","trackingNumber","wanted","find"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SAASA,mBAAmB,EAAEC,oBAAoB,EAAEC,yBAAyB,QAAQ,yBAAqB;AAE1G;;;;;;;;;;;;;;;;;;CAkBC,GAED,oCAAoC,GACpC,OAAO,MAAMC,kBAAkB,aAAY;AAE3C,yBAAyB,GACzB,OAAO,MAAMC,mBAAmB,GAAE;AAElC,gDAAgD,GAChD,OAAO,SAASC,cAAcC,KAAa;IACzC,OAAOC,KAAKC,KAAK,CAAC,AAACF,QAAQH,kBAAmB,OAAO;AACvD;AAEA,iDAAiD,GACjD,OAAO,SAASM,eAAeC,MAAc;IAC3C,OAAOH,KAAKC,KAAK,CAAC,AAACE,SAASN,mBAAoB,OAAO;AACzD;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASO,sBAAsBC,KAAyB;IAC7D,MAAMC,QAAQC,MAAMC,OAAO,CAACH,MAAMI,SAAS,IAAIJ,MAAMI,SAAS,GAAG,EAAE;IACnE,MAAMC,UAAUC,mBAAmBN,MAAMO,eAAe;IACxD,IAAI,CAACN,MAAMO,MAAM,EAAE,OAAOH;IAC1B,IAAI,CAACJ,MAAMQ,IAAI,CAA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