@aglyn/plugins-commerce 1.0.0-beta.285 → 1.0.0-beta.288
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/README.md +1 -1
- package/package.json +13 -13
- package/src/lib/components/cart.js +25 -12
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/commerce-console-page.js +70 -13
- package/src/lib/components/commerce-console-page.js.map +1 -1
- package/src/lib/components/console/order-detail-dialog.component.js +2 -1
- package/src/lib/components/console/order-detail-dialog.component.js.map +1 -1
- package/src/lib/components/console/order-webhooks-card.component.js +1 -1
- package/src/lib/components/console/order-webhooks-card.component.js.map +1 -1
- package/src/lib/components/console/payment-methods-card.component.js +1 -1
- package/src/lib/components/console/payment-methods-card.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-cart-panel.component.d.ts +5 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.js +18 -12
- package/src/lib/components/console/pos/pos-cart-panel.component.js.map +1 -1
- package/src/lib/components/console/pos/pos-hardware-api.d.ts +76 -5
- package/src/lib/components/console/pos/pos-hardware-api.js +53 -11
- package/src/lib/components/console/pos/pos-hardware-api.js.map +1 -1
- package/src/lib/components/console/pos/pos-hardware-buyer.component.d.ts +18 -0
- package/src/lib/components/console/pos/pos-hardware-buyer.component.js +629 -0
- package/src/lib/components/console/pos/pos-hardware-buyer.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-hardware-sale-api.d.ts +162 -0
- package/src/lib/components/console/pos/pos-hardware-sale-api.js +122 -0
- package/src/lib/components/console/pos/pos-hardware-sale-api.js.map +1 -0
- package/src/lib/components/console/pos/pos-hardware-sale-terms.component.d.ts +39 -0
- package/src/lib/components/console/pos/pos-hardware-sale-terms.component.js +251 -0
- package/src/lib/components/console/pos/pos-hardware-sale-terms.component.js.map +1 -0
- package/src/lib/components/console/pos/use-pos-display.js +50 -0
- package/src/lib/components/console/pos/use-pos-display.js.map +1 -1
- package/src/lib/components/console/pos-cellular-control.component.d.ts +41 -0
- package/src/lib/components/console/pos-cellular-control.component.js +211 -0
- package/src/lib/components/console/pos-cellular-control.component.js.map +1 -0
- package/src/lib/components/console/pos-devices-card.component.d.ts +9 -1
- package/src/lib/components/console/pos-devices-card.component.js +47 -15
- package/src/lib/components/console/pos-devices-card.component.js.map +1 -1
- package/src/lib/components/console/pos-display/pos-display-api.d.ts +6 -0
- package/src/lib/components/console/pos-display/pos-display-api.js +8 -1
- package/src/lib/components/console/pos-display/pos-display-api.js.map +1 -1
- package/src/lib/components/console/pos-display-page.component.d.ts +13 -0
- package/src/lib/components/console/pos-display-page.component.js +44 -2
- package/src/lib/components/console/pos-display-page.component.js.map +1 -1
- package/src/lib/components/console/pos-hardware-card.component.d.ts +12 -4
- package/src/lib/components/console/pos-hardware-card.component.js +157 -36
- package/src/lib/components/console/pos-hardware-card.component.js.map +1 -1
- package/src/lib/components/console/pos-hardware-orders-staff-page.component.js +360 -80
- package/src/lib/components/console/pos-hardware-orders-staff-page.component.js.map +1 -1
- package/src/lib/components/console/pos-hardware-terms-page.component.d.ts +34 -0
- package/src/lib/components/console/pos-hardware-terms-page.component.js +257 -0
- package/src/lib/components/console/pos-hardware-terms-page.component.js.map +1 -0
- package/src/lib/components/console/pos-hardware-terms-sign-page.component.d.ts +27 -0
- package/src/lib/components/console/pos-hardware-terms-sign-page.component.js +104 -0
- package/src/lib/components/console/pos-hardware-terms-sign-page.component.js.map +1 -0
- package/src/lib/components/console/pos-hardware-waiting-card.component.d.ts +24 -0
- package/src/lib/components/console/pos-hardware-waiting-card.component.js +205 -0
- package/src/lib/components/console/pos-hardware-waiting-card.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-check-in-dialog.component.js +297 -201
- package/src/lib/components/console/pos-ops/pos-check-in-dialog.component.js.map +1 -1
- package/src/lib/components/console/pos-ops/pos-check-ins-card.component.d.ts +3 -0
- package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js +260 -92
- package/src/lib/components/console/pos-ops/pos-check-ins-card.component.js.map +1 -1
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.d.ts +9 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.js +15 -6
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.js.map +1 -1
- package/src/lib/components/console/pos-ops/pos-rain-check-dialog.component.d.ts +25 -0
- package/src/lib/components/console/pos-ops/pos-rain-check-dialog.component.js +136 -0
- package/src/lib/components/console/pos-ops/pos-rain-check-dialog.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.d.ts +6 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.js +48 -31
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.js.map +1 -1
- package/src/lib/components/console/pos-page.component.d.ts +1 -1
- package/src/lib/components/console/pos-page.component.js +63 -12
- package/src/lib/components/console/pos-page.component.js.map +1 -1
- package/src/lib/components/console/pos-reader-splash-setting.component.js +1 -1
- package/src/lib/components/console/pos-reader-splash-setting.component.js.map +1 -1
- package/src/lib/components/console/product-check-in-fields.component.d.ts +4 -2
- package/src/lib/components/console/product-check-in-fields.component.js +60 -14
- package/src/lib/components/console/product-check-in-fields.component.js.map +1 -1
- package/src/lib/components/console/product-editor-dialog.component.js +44 -1
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/product-hardware-sku-field.component.d.ts +19 -0
- package/src/lib/components/console/product-hardware-sku-field.component.js +92 -0
- package/src/lib/components/console/product-hardware-sku-field.component.js.map +1 -0
- package/src/lib/components/console/product-kiosk-offer-field.component.d.ts +22 -0
- package/src/lib/components/console/product-kiosk-offer-field.component.js +94 -0
- package/src/lib/components/console/product-kiosk-offer-field.component.js.map +1 -0
- package/src/lib/components/console/product-register-fields.component.d.ts +4 -0
- package/src/lib/components/console/product-register-fields.component.js +31 -2
- package/src/lib/components/console/product-register-fields.component.js.map +1 -1
- package/src/lib/components/console/products-hub-card.component.js +11 -2
- package/src/lib/components/console/products-hub-card.component.js.map +1 -1
- package/src/lib/components/console/register-hardware-card.component.d.ts +11 -0
- package/src/lib/components/console/register-hardware-card.component.js +56 -27
- package/src/lib/components/console/register-hardware-card.component.js.map +1 -1
- package/src/lib/components/console/reservation-guests-dialog.component.d.ts +28 -0
- package/src/lib/components/console/reservation-guests-dialog.component.js +189 -0
- package/src/lib/components/console/reservation-guests-dialog.component.js.map +1 -0
- package/src/lib/components/console/reservations-card.component.d.ts +9 -0
- package/src/lib/components/console/reservations-card.component.js +158 -23
- package/src/lib/components/console/reservations-card.component.js.map +1 -1
- package/src/lib/components/console/shippingeasy-card.component.js +1 -1
- package/src/lib/components/console/shippingeasy-card.component.js.map +1 -1
- package/src/lib/components/console/shipstation-card.component.d.ts +1 -1
- package/src/lib/components/console/shipstation-card.component.js +3 -3
- package/src/lib/components/console/shipstation-card.component.js.map +1 -1
- package/src/lib/components/product-detail.d.ts +4 -0
- package/src/lib/components/product-detail.js +40 -5
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/product-reviews.js +28 -11
- package/src/lib/components/product-reviews.js.map +1 -1
- package/src/lib/components/reservation-widget.js +28 -5
- package/src/lib/components/reservation-widget.js.map +1 -1
- package/src/lib/components/use-day-picker.d.ts +25 -0
- package/src/lib/components/use-day-picker.js +57 -0
- package/src/lib/components/use-day-picker.js.map +1 -0
- package/src/lib/constants/operator-alerts.d.ts +55 -0
- package/src/lib/constants/operator-alerts.js +156 -1
- package/src/lib/constants/operator-alerts.js.map +1 -1
- package/src/lib/declarations.console-server.js +54 -1
- package/src/lib/declarations.console-server.js.map +1 -1
- package/src/lib/declarations.d.ts +4 -2
- package/src/lib/declarations.js +15 -4
- package/src/lib/declarations.js.map +1 -1
- package/src/lib/declarations.server.js +9 -0
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/model/commerce-cart.d.ts +9 -1
- package/src/lib/model/commerce-cart.js +4 -3
- package/src/lib/model/commerce-cart.js.map +1 -1
- package/src/lib/model/commerce-check-in-product.d.ts +26 -0
- package/src/lib/model/commerce-check-in-product.js +64 -2
- package/src/lib/model/commerce-check-in-product.js.map +1 -1
- package/src/lib/model/commerce-check-in-record.d.ts +127 -0
- package/src/lib/model/commerce-check-in-record.js +36 -0
- package/src/lib/model/commerce-check-in-record.js.map +1 -0
- package/src/lib/model/commerce-check-in.d.ts +91 -87
- package/src/lib/model/commerce-check-in.js +186 -62
- package/src/lib/model/commerce-check-in.js.map +1 -1
- package/src/lib/model/commerce-kiosk-offer.d.ts +31 -0
- package/src/lib/model/commerce-kiosk-offer.js +35 -0
- package/src/lib/model/commerce-kiosk-offer.js.map +1 -0
- package/src/lib/model/commerce-orders.d.ts +76 -0
- package/src/lib/model/commerce-orders.js +6 -0
- package/src/lib/model/commerce-orders.js.map +1 -1
- package/src/lib/model/commerce-pos-day-report.d.ts +54 -1
- package/src/lib/model/commerce-pos-day-report.js +39 -2
- package/src/lib/model/commerce-pos-day-report.js.map +1 -1
- package/src/lib/model/commerce-pos-offline.d.ts +1 -1
- package/src/lib/model/commerce-pos-offline.js +6 -1
- package/src/lib/model/commerce-pos-offline.js.map +1 -1
- package/src/lib/model/commerce-pos-ops.js +3 -2
- package/src/lib/model/commerce-pos-ops.js.map +1 -1
- package/src/lib/model/commerce-pos.d.ts +36 -3
- package/src/lib/model/commerce-pos.js +14 -6
- package/src/lib/model/commerce-pos.js.map +1 -1
- package/src/lib/model/commerce-receipt.js +3 -2
- package/src/lib/model/commerce-receipt.js.map +1 -1
- package/src/lib/model/commerce-reservations.d.ts +69 -4
- package/src/lib/model/commerce-reservations.js +57 -5
- package/src/lib/model/commerce-reservations.js.map +1 -1
- package/src/lib/model/commerce.d.ts +66 -0
- package/src/lib/model/commerce.js +15 -0
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/order-list-fields.d.ts +11 -0
- package/src/lib/model/order-list-fields.js +17 -1
- package/src/lib/model/order-list-fields.js.map +1 -1
- package/src/lib/model/own-store-tax-summary.d.ts +152 -0
- package/src/lib/model/own-store-tax-summary.js +288 -0
- package/src/lib/model/own-store-tax-summary.js.map +1 -0
- package/src/lib/model/plugin-permissions.d.ts +74 -0
- package/src/lib/model/plugin-permissions.js +224 -7
- package/src/lib/model/plugin-permissions.js.map +1 -1
- package/src/lib/model/pos-cellular.d.ts +223 -0
- package/src/lib/model/pos-cellular.js +293 -0
- package/src/lib/model/pos-cellular.js.map +1 -0
- package/src/lib/model/pos-hardware-in-person.d.ts +98 -0
- package/src/lib/model/pos-hardware-in-person.js +224 -0
- package/src/lib/model/pos-hardware-in-person.js.map +1 -0
- package/src/lib/model/pos-hardware-tax-summary.d.ts +166 -0
- package/src/lib/model/pos-hardware-tax-summary.js +225 -0
- package/src/lib/model/pos-hardware-tax-summary.js.map +1 -0
- package/src/lib/model/pos-hardware-terms.d.ts +74 -0
- package/src/lib/model/pos-hardware-terms.js +115 -0
- package/src/lib/model/pos-hardware-terms.js.map +1 -0
- package/src/lib/model/pos-hardware.d.ts +349 -7
- package/src/lib/model/pos-hardware.js +291 -20
- package/src/lib/model/pos-hardware.js.map +1 -1
- package/src/lib/model/product-write.d.ts +10 -0
- package/src/lib/model/product-write.js +4 -2
- package/src/lib/model/product-write.js.map +1 -1
- package/src/lib/model/workspace-site-permissions.d.ts +26 -0
- package/src/lib/model/workspace-site-permissions.js +81 -0
- package/src/lib/model/workspace-site-permissions.js.map +1 -0
- package/src/lib/plugin.js +16 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/server/billing-webhook.js +25 -1
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cancel-order.js +7 -5
- package/src/lib/server/cancel-order.js.map +1 -1
- package/src/lib/server/cart-checkout.js +20 -8
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/cart.js +29 -0
- package/src/lib/server/cart.js.map +1 -1
- package/src/lib/server/checkout.js +42 -13
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/collection-membership.d.ts +4 -0
- package/src/lib/server/collection-membership.js +5 -10
- package/src/lib/server/collection-membership.js.map +1 -1
- package/src/lib/server/commerce-site-keys.d.ts +48 -0
- package/src/lib/server/commerce-site-keys.js +61 -0
- package/src/lib/server/commerce-site-keys.js.map +1 -0
- package/src/lib/server/draft-order.js +8 -5
- package/src/lib/server/draft-order.js.map +1 -1
- package/src/lib/server/fulfill-order.js +7 -5
- package/src/lib/server/fulfill-order.js.map +1 -1
- package/src/lib/server/gift-cards.js +8 -5
- package/src/lib/server/gift-cards.js.map +1 -1
- package/src/lib/server/local-fulfillment-status.js +9 -6
- package/src/lib/server/local-fulfillment-status.js.map +1 -1
- package/src/lib/server/member-post.js +6 -5
- package/src/lib/server/member-post.js.map +1 -1
- package/src/lib/server/membership-admin-password.d.ts +4 -2
- package/src/lib/server/membership-admin-password.js +10 -8
- package/src/lib/server/membership-admin-password.js.map +1 -1
- package/src/lib/server/membership-admin-remove.d.ts +7 -5
- package/src/lib/server/membership-admin-remove.js +9 -9
- package/src/lib/server/membership-admin-remove.js.map +1 -1
- package/src/lib/server/order-notifications.js +5 -2
- package/src/lib/server/order-notifications.js.map +1 -1
- package/src/lib/server/order-print.js +7 -5
- package/src/lib/server/order-print.js.map +1 -1
- package/src/lib/server/order-receipt-send.js +8 -5
- package/src/lib/server/order-receipt-send.js.map +1 -1
- package/src/lib/server/order-webhooks.js +8 -8
- package/src/lib/server/order-webhooks.js.map +1 -1
- package/src/lib/server/orders-shipping-prepare.js +9 -6
- package/src/lib/server/orders-shipping-prepare.js.map +1 -1
- package/src/lib/server/own-store-tax-return-source.d.ts +47 -0
- package/src/lib/server/own-store-tax-return-source.js +312 -0
- package/src/lib/server/own-store-tax-return-source.js.map +1 -0
- package/src/lib/server/payment-methods.js +13 -9
- package/src/lib/server/payment-methods.js.map +1 -1
- package/src/lib/server/pos-auth.d.ts +37 -6
- package/src/lib/server/pos-auth.js +40 -15
- package/src/lib/server/pos-auth.js.map +1 -1
- package/src/lib/server/pos-cellular-billing.d.ts +81 -0
- package/src/lib/server/pos-cellular-billing.js +711 -0
- package/src/lib/server/pos-cellular-billing.js.map +1 -0
- package/src/lib/server/pos-cellular-notify.d.ts +47 -0
- package/src/lib/server/pos-cellular-notify.js +150 -0
- package/src/lib/server/pos-cellular-notify.js.map +1 -0
- package/src/lib/server/pos-cellular.d.ts +88 -0
- package/src/lib/server/pos-cellular.js +339 -0
- package/src/lib/server/pos-cellular.js.map +1 -0
- package/src/lib/server/pos-check-in.d.ts +5 -1
- package/src/lib/server/pos-check-in.js +296 -28
- package/src/lib/server/pos-check-in.js.map +1 -1
- package/src/lib/server/pos-day-report.js +29 -3
- package/src/lib/server/pos-day-report.js.map +1 -1
- package/src/lib/server/pos-display.d.ts +16 -0
- package/src/lib/server/pos-display.js +129 -2
- package/src/lib/server/pos-display.js.map +1 -1
- package/src/lib/server/pos-hardware-admin.d.ts +10 -1
- package/src/lib/server/pos-hardware-admin.js +250 -84
- package/src/lib/server/pos-hardware-admin.js.map +1 -1
- package/src/lib/server/pos-hardware-attach.d.ts +105 -0
- package/src/lib/server/pos-hardware-attach.js +443 -0
- package/src/lib/server/pos-hardware-attach.js.map +1 -0
- package/src/lib/server/pos-hardware-buyer-lookup.d.ts +58 -0
- package/src/lib/server/pos-hardware-buyer-lookup.js +180 -0
- package/src/lib/server/pos-hardware-buyer-lookup.js.map +1 -0
- package/src/lib/server/pos-hardware-buyer-record.d.ts +29 -0
- package/src/lib/server/pos-hardware-buyer-record.js +86 -0
- package/src/lib/server/pos-hardware-buyer-record.js.map +1 -0
- package/src/lib/server/pos-hardware-cancel.d.ts +58 -0
- package/src/lib/server/pos-hardware-cancel.js +147 -0
- package/src/lib/server/pos-hardware-cancel.js.map +1 -0
- package/src/lib/server/pos-hardware-closure-notices.d.ts +27 -0
- package/src/lib/server/pos-hardware-closure-notices.js +85 -0
- package/src/lib/server/pos-hardware-closure-notices.js.map +1 -0
- package/src/lib/server/pos-hardware-closure.d.ts +60 -0
- package/src/lib/server/pos-hardware-closure.js +153 -0
- package/src/lib/server/pos-hardware-closure.js.map +1 -0
- package/src/lib/server/pos-hardware-in-person.d.ts +61 -0
- package/src/lib/server/pos-hardware-in-person.js +236 -0
- package/src/lib/server/pos-hardware-in-person.js.map +1 -0
- package/src/lib/server/pos-hardware-notify.d.ts +40 -2
- package/src/lib/server/pos-hardware-notify.js +195 -14
- package/src/lib/server/pos-hardware-notify.js.map +1 -1
- package/src/lib/server/pos-hardware-readers.d.ts +115 -0
- package/src/lib/server/pos-hardware-readers.js +430 -0
- package/src/lib/server/pos-hardware-readers.js.map +1 -0
- package/src/lib/server/pos-hardware-returns.d.ts +116 -0
- package/src/lib/server/pos-hardware-returns.js +502 -0
- package/src/lib/server/pos-hardware-returns.js.map +1 -0
- package/src/lib/server/pos-hardware-sale-fields.d.ts +28 -0
- package/src/lib/server/pos-hardware-sale-fields.js +44 -0
- package/src/lib/server/pos-hardware-sale-fields.js.map +1 -0
- package/src/lib/server/pos-hardware-sale.d.ts +54 -0
- package/src/lib/server/pos-hardware-sale.js +369 -0
- package/src/lib/server/pos-hardware-sale.js.map +1 -0
- package/src/lib/server/pos-hardware-tax-return-source.d.ts +99 -0
- package/src/lib/server/pos-hardware-tax-return-source.js +462 -0
- package/src/lib/server/pos-hardware-tax-return-source.js.map +1 -0
- package/src/lib/server/pos-hardware-terms.d.ts +64 -0
- package/src/lib/server/pos-hardware-terms.js +154 -0
- package/src/lib/server/pos-hardware-terms.js.map +1 -0
- package/src/lib/server/pos-hardware-user-eraser.d.ts +3 -0
- package/src/lib/server/pos-hardware-user-eraser.js +31 -7
- package/src/lib/server/pos-hardware-user-eraser.js.map +1 -1
- package/src/lib/server/pos-hardware-webhook.d.ts +5 -0
- package/src/lib/server/pos-hardware-webhook.js +51 -6
- package/src/lib/server/pos-hardware-webhook.js.map +1 -1
- package/src/lib/server/pos-hardware.d.ts +74 -1
- package/src/lib/server/pos-hardware.js +175 -10
- package/src/lib/server/pos-hardware.js.map +1 -1
- package/src/lib/server/pos-kiosk.d.ts +2 -0
- package/src/lib/server/pos-kiosk.js +17 -12
- package/src/lib/server/pos-kiosk.js.map +1 -1
- package/src/lib/server/pos-offline-card-order.d.ts +64 -0
- package/src/lib/server/pos-offline-card-order.js +102 -0
- package/src/lib/server/pos-offline-card-order.js.map +1 -0
- package/src/lib/server/pos-offline-card-reconcile.d.ts +67 -1
- package/src/lib/server/pos-offline-card-reconcile.js +215 -18
- package/src/lib/server/pos-offline-card-reconcile.js.map +1 -1
- package/src/lib/server/pos-offline-sync.d.ts +39 -0
- package/src/lib/server/pos-offline-sync.js +190 -55
- package/src/lib/server/pos-offline-sync.js.map +1 -1
- package/src/lib/server/pos-ops-gate.d.ts +28 -9
- package/src/lib/server/pos-ops-gate.js +50 -19
- package/src/lib/server/pos-ops-gate.js.map +1 -1
- package/src/lib/server/pos-ops-routes.js +24 -0
- package/src/lib/server/pos-ops-routes.js.map +1 -1
- package/src/lib/server/pos-order-refund-ids.d.ts +28 -0
- package/src/lib/server/pos-order-refund-ids.js +31 -0
- package/src/lib/server/pos-order-refund-ids.js.map +1 -0
- package/src/lib/server/pos-order.js +52 -49
- package/src/lib/server/pos-order.js.map +1 -1
- package/src/lib/server/pos-payment.js +1 -1
- package/src/lib/server/pos-payment.js.map +1 -1
- package/src/lib/server/pos-reader-splash-admin.js +30 -32
- package/src/lib/server/pos-reader-splash-admin.js.map +1 -1
- package/src/lib/server/pos-reader-splash-images-route.d.ts +17 -0
- package/src/lib/server/pos-reader-splash-images-route.js +113 -0
- package/src/lib/server/pos-reader-splash-images-route.js.map +1 -0
- package/src/lib/server/pos-reader-splash-images.d.ts +51 -0
- package/src/lib/server/pos-reader-splash-images.js +123 -0
- package/src/lib/server/pos-reader-splash-images.js.map +1 -0
- package/src/lib/server/pos-reader-splash.d.ts +68 -1
- package/src/lib/server/pos-reader-splash.js +182 -11
- package/src/lib/server/pos-reader-splash.js.map +1 -1
- package/src/lib/server/pos-readers.d.ts +29 -0
- package/src/lib/server/pos-readers.js +134 -35
- package/src/lib/server/pos-readers.js.map +1 -1
- package/src/lib/server/pos-refund-authority.d.ts +3 -1
- package/src/lib/server/pos-refund-authority.js +3 -2
- package/src/lib/server/pos-refund-authority.js.map +1 -1
- package/src/lib/server/pos-return.d.ts +10 -0
- package/src/lib/server/pos-return.js +29 -7
- package/src/lib/server/pos-return.js.map +1 -1
- package/src/lib/server/pos-sale.js +6 -1
- package/src/lib/server/pos-sale.js.map +1 -1
- package/src/lib/server/pos-shift.js +11 -0
- package/src/lib/server/pos-shift.js.map +1 -1
- package/src/lib/server/pos-staff-pin.js +29 -24
- package/src/lib/server/pos-staff-pin.js.map +1 -1
- package/src/lib/server/pos-terminal.d.ts +14 -4
- package/src/lib/server/pos-terminal.js +34 -38
- package/src/lib/server/pos-terminal.js.map +1 -1
- package/src/lib/server/printers.d.ts +7 -3
- package/src/lib/server/printers.js +18 -12
- package/src/lib/server/printers.js.map +1 -1
- package/src/lib/server/product-drafts.d.ts +11 -1
- package/src/lib/server/product-drafts.js +12 -8
- package/src/lib/server/product-drafts.js.map +1 -1
- package/src/lib/server/product.d.ts +15 -1
- package/src/lib/server/product.js +16 -3
- package/src/lib/server/product.js.map +1 -1
- package/src/lib/server/products-write.d.ts +26 -2
- package/src/lib/server/products-write.js +19 -7
- package/src/lib/server/products-write.js.map +1 -1
- package/src/lib/server/refund.js +55 -42
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/reservation-availability-query.d.ts +8 -0
- package/src/lib/server/reservation-availability-query.js +11 -1
- package/src/lib/server/reservation-availability-query.js.map +1 -1
- package/src/lib/server/reservation-availability.d.ts +1 -1
- package/src/lib/server/reservation-availability.js +7 -2
- package/src/lib/server/reservation-availability.js.map +1 -1
- package/src/lib/server/reservation-guests.d.ts +32 -0
- package/src/lib/server/reservation-guests.js +285 -0
- package/src/lib/server/reservation-guests.js.map +1 -0
- package/src/lib/server/reservation-walk-in.d.ts +11 -1
- package/src/lib/server/reservation-walk-in.js +56 -12
- package/src/lib/server/reservation-walk-in.js.map +1 -1
- package/src/lib/server/reserve.js +18 -5
- package/src/lib/server/reserve.js.map +1 -1
- package/src/lib/server/returns.js +9 -6
- package/src/lib/server/returns.js.map +1 -1
- package/src/lib/server/reviews.d.ts +22 -2
- package/src/lib/server/reviews.js +88 -20
- package/src/lib/server/reviews.js.map +1 -1
- package/src/lib/server/shipping-connectors.js +10 -11
- package/src/lib/server/shipping-connectors.js.map +1 -1
- package/src/lib/server/site-page-resolver.js +20 -3
- package/src/lib/server/site-page-resolver.js.map +1 -1
- package/src/lib/server/store-day.d.ts +33 -0
- package/src/lib/server/store-day.js +46 -0
- package/src/lib/server/store-day.js.map +1 -0
- package/src/lib/server/store-setup-ai-writer.d.ts +2 -1
- package/src/lib/server/store-setup-ai-writer.js +5 -6
- package/src/lib/server/store-setup-ai-writer.js.map +1 -1
- package/src/lib/server/storefront-tax.d.ts +13 -0
- package/src/lib/server/storefront-tax.js +8 -1
- package/src/lib/server/storefront-tax.js.map +1 -1
- package/src/lib/server/tax-return-source.d.ts +32 -3
- package/src/lib/server/tax-return-source.js +99 -20
- package/src/lib/server/tax-return-source.js.map +1 -1
- package/src/lib/server.js +100 -2
- package/src/lib/server.js.map +1 -1
- package/src/lib/testing/fake-firestore.js +58 -16
- package/src/lib/testing/fake-firestore.js.map +1 -1
- package/src/lib/testing/pos-ops-memory-firestore.js +18 -4
- package/src/lib/testing/pos-ops-memory-firestore.js.map +1 -1
- package/src/lib/testing/site-register-permissions.d.ts +29 -0
- package/src/lib/testing/site-register-permissions.js +38 -0
- package/src/lib/testing/site-register-permissions.js.map +1 -0
- package/src/lib/transfer/tracking.server.js +8 -5
- package/src/lib/transfer/tracking.server.js.map +1 -1
- package/src/lib/utils/add-to-cart.d.ts +2 -0
- package/src/lib/utils/add-to-cart.js +6 -3
- package/src/lib/utils/add-to-cart.js.map +1 -1
|
@@ -0,0 +1,105 @@
|
|
|
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 PosHardwareAddress, type PosHardwareInPersonConfig, type PosHardwareOrder } from '../model/pos-hardware';
|
|
18
|
+
export declare class PosHardwareAttachRefusal extends Error {
|
|
19
|
+
readonly status: number;
|
|
20
|
+
constructor(message: string, status: number);
|
|
21
|
+
}
|
|
22
|
+
/** Who the register says the buyer is, before it is checked. */
|
|
23
|
+
export interface PosHardwareBuyerRequest {
|
|
24
|
+
uid?: unknown;
|
|
25
|
+
orgId?: unknown;
|
|
26
|
+
hostId?: unknown;
|
|
27
|
+
email?: unknown;
|
|
28
|
+
/** The buyer's name, typed at the sale; an account's own name wins. */
|
|
29
|
+
name?: unknown;
|
|
30
|
+
/** The buyer's business address, typed at the sale (optional). */
|
|
31
|
+
address?: unknown;
|
|
32
|
+
}
|
|
33
|
+
/** A checked buyer: who they are, where the order goes, where its emails go. */
|
|
34
|
+
export interface CheckedBuyer {
|
|
35
|
+
uid: string | null;
|
|
36
|
+
orgId: string | null;
|
|
37
|
+
hostId: string | null;
|
|
38
|
+
email: string | null;
|
|
39
|
+
/**
|
|
40
|
+
* The buyer's name and business address, for the platform's reseller
|
|
41
|
+
* records (AGL-4038): the account's name, else the one typed; the address
|
|
42
|
+
* typed at the sale, when one was.
|
|
43
|
+
*/
|
|
44
|
+
name?: string | null;
|
|
45
|
+
address?: PosHardwareAddress | null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The buyer the register named, checked. Refuses an account that does not
|
|
49
|
+
* exist or is not in the workspace, a store not in the workspace, and an
|
|
50
|
+
* address said to have no account that has one.
|
|
51
|
+
*/
|
|
52
|
+
export declare function checkHardwareBuyer(request: PosHardwareBuyerRequest): Promise<CheckedBuyer>;
|
|
53
|
+
export type PosHardwareAttachOutcome = {
|
|
54
|
+
outcome: 'waiting';
|
|
55
|
+
registerOrderId: string;
|
|
56
|
+
} | {
|
|
57
|
+
outcome: 'attached' | 'pending';
|
|
58
|
+
orderId: string;
|
|
59
|
+
orgId: string;
|
|
60
|
+
order: PosHardwareOrder;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Says whose a sale's hardware is: by the register order (the sale the
|
|
64
|
+
* register just rang, recorded or not) or by the hardware order's id (a sale
|
|
65
|
+
* on the To attach list). Invites a buyer with no account, once.
|
|
66
|
+
*/
|
|
67
|
+
export declare function attachPosHardwareSale(input: {
|
|
68
|
+
config: PosHardwareInPersonConfig;
|
|
69
|
+
buyer: CheckedBuyer;
|
|
70
|
+
attachedBy: string | null;
|
|
71
|
+
registerOrderId?: string | null;
|
|
72
|
+
orderId?: string | null;
|
|
73
|
+
now?: number;
|
|
74
|
+
}): Promise<PosHardwareAttachOutcome>;
|
|
75
|
+
/**
|
|
76
|
+
* Sends the sign-up invitation to a pending buyer with an address and no
|
|
77
|
+
* account, once per address: the stamp is claimed in a transaction before
|
|
78
|
+
* the email goes, so two callers never both send it.
|
|
79
|
+
*/
|
|
80
|
+
export declare function invitePendingBuyer(orderId: string, orgId: string, order: PosHardwareOrder): Promise<PosHardwareOrder>;
|
|
81
|
+
/**
|
|
82
|
+
* Puts an attached sale back on the To attach list: the wrong buyer was
|
|
83
|
+
* chosen. Refused once one of its readers is set up on the buyer's store.
|
|
84
|
+
*/
|
|
85
|
+
export declare function detachPosHardwareSale(input: {
|
|
86
|
+
config: PosHardwareInPersonConfig;
|
|
87
|
+
orderId: string;
|
|
88
|
+
now?: number;
|
|
89
|
+
}): Promise<{
|
|
90
|
+
order: PosHardwareOrder;
|
|
91
|
+
}>;
|
|
92
|
+
/**
|
|
93
|
+
* A workspace was just created: every pending sale naming its owner — their
|
|
94
|
+
* account, or their address once verified — moves into it. Never throws:
|
|
95
|
+
* a sale it cannot move stays on the To attach list.
|
|
96
|
+
*/
|
|
97
|
+
export declare function claimPosHardwareForNewWorkspace(input: {
|
|
98
|
+
config: PosHardwareInPersonConfig | null;
|
|
99
|
+
orgId: string;
|
|
100
|
+
ownerUid: string;
|
|
101
|
+
ownerEmail: string | null;
|
|
102
|
+
emailVerified: boolean;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
claimed: number;
|
|
105
|
+
}>;
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Aglyn LLC
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/ import { firebaseAdmin } from "@aglyn/tenant-data-admin";
|
|
18
|
+
import { findUserByEmailAcrossPools, findUserByUidAcrossPools } from "@aglyn/tenant-data-admin/server/auth-pools";
|
|
19
|
+
import { POS_HARDWARE_ORDER_ID, posHardwareBuyerAddress, posHardwareSaleRecord, posHardwareSaleSetOptions } from "../model/pos-hardware.js";
|
|
20
|
+
import { posHardwareAttachmentOf } from "../model/pos-hardware-in-person.js";
|
|
21
|
+
import { hardwareOrdersRef, posHardwareInPersonOrderId, posHardwareSaleRef } from "./pos-hardware.js";
|
|
22
|
+
import { recordInPersonPosHardwareSale } from "./pos-hardware-in-person.js";
|
|
23
|
+
import { sendPosHardwareInvite } from "./pos-hardware-notify.js";
|
|
24
|
+
/*==========================================
|
|
25
|
+
* ATTACHING AN IN-PERSON SALE TO ITS BUYER (AGL-4038).
|
|
26
|
+
*
|
|
27
|
+
* The register user who sold a card reader says whose it is: an account and
|
|
28
|
+
* the workspace (and, if they chose one, the store) it is for; an account
|
|
29
|
+
* with no workspace yet; or the address of someone with no account, who is
|
|
30
|
+
* then invited to sign up. The order moves to the buyer's workspace the
|
|
31
|
+
* moment it has one, and is pending on the selling workspace's To attach
|
|
32
|
+
* list until then.
|
|
33
|
+
*
|
|
34
|
+
* Every attachment is checked here, never trusted from the register: the
|
|
35
|
+
* account exists, it is a member of the workspace, the store is the
|
|
36
|
+
* workspace's, and an address given for "no account" really has none.
|
|
37
|
+
*
|
|
38
|
+
* A sale not recorded yet (the register attaches the buyer while the sale is
|
|
39
|
+
* still open, or the instant it is paid) carries the buyer on the register
|
|
40
|
+
* order (`hardwareBuyer`), and the recorder builds the order already
|
|
41
|
+
* attached. A sale already recorded is moved: created in the buyer's
|
|
42
|
+
* workspace and deleted from where it was, with its retained sale record and
|
|
43
|
+
* the register order, in one transaction.
|
|
44
|
+
*
|
|
45
|
+
* A NEW WORKSPACE CLAIMS ITS OWNER'S SALES. When a buyer who was invited
|
|
46
|
+
* signs up and creates a workspace, every pending sale naming their verified
|
|
47
|
+
* address (or their account) moves into it ({@link claimPosHardwareForNewWorkspace}).
|
|
48
|
+
*=========================================*/ export class PosHardwareAttachRefusal extends Error {
|
|
49
|
+
constructor(message, status){
|
|
50
|
+
super(message), this.status = status;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
54
|
+
const EMAIL = /^[^@\s]{1,64}@[^@\s]+\.[^@\s]{2,}$/;
|
|
55
|
+
const id = (value)=>typeof value === 'string' && ID.test(value.trim()) ? value.trim() : null;
|
|
56
|
+
function firestore() {
|
|
57
|
+
return firebaseAdmin.app().firestore();
|
|
58
|
+
}
|
|
59
|
+
/** The name and address the register typed, checked: an address is all of it or refused. */ function typedIdentity(request) {
|
|
60
|
+
const name = typeof request.name === 'string' && request.name.trim() ? request.name.trim().slice(0, 200) : null;
|
|
61
|
+
if (request.address === undefined || request.address === null || request.address === '') {
|
|
62
|
+
return {
|
|
63
|
+
name,
|
|
64
|
+
address: null
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const address = posHardwareBuyerAddress(request.address);
|
|
68
|
+
if (!address) {
|
|
69
|
+
throw new PosHardwareAttachRefusal('Enter the buyer’s street, city, postal code and two-letter country, or leave the address empty.', 400);
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
name,
|
|
73
|
+
address
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The buyer the register named, checked. Refuses an account that does not
|
|
78
|
+
* exist or is not in the workspace, a store not in the workspace, and an
|
|
79
|
+
* address said to have no account that has one.
|
|
80
|
+
*/ export async function checkHardwareBuyer(request) {
|
|
81
|
+
var _request_email;
|
|
82
|
+
const uid = id(request.uid);
|
|
83
|
+
const orgId = id(request.orgId);
|
|
84
|
+
const hostId = id(request.hostId);
|
|
85
|
+
const typed = typedIdentity(request);
|
|
86
|
+
if (uid) {
|
|
87
|
+
var _user_record_email, _user_record_displayName;
|
|
88
|
+
const user = await findUserByUidAcrossPools(uid);
|
|
89
|
+
if (!user) throw new PosHardwareAttachRefusal('That account no longer exists. Look the buyer up again.', 404);
|
|
90
|
+
const email = String((_user_record_email = user.record.email) != null ? _user_record_email : '').trim().toLowerCase() || null;
|
|
91
|
+
const name = String((_user_record_displayName = user.record.displayName) != null ? _user_record_displayName : '').trim().slice(0, 200) || typed.name;
|
|
92
|
+
if (!orgId) return {
|
|
93
|
+
uid,
|
|
94
|
+
orgId: null,
|
|
95
|
+
hostId: null,
|
|
96
|
+
email,
|
|
97
|
+
name,
|
|
98
|
+
address: typed.address
|
|
99
|
+
};
|
|
100
|
+
const member = await firestore().collection('orgs').doc(orgId).collection('members').doc(uid).get();
|
|
101
|
+
if (!member.exists) {
|
|
102
|
+
throw new PosHardwareAttachRefusal('That person is not on that workspace. Look the buyer up again.', 409);
|
|
103
|
+
}
|
|
104
|
+
if (hostId) {
|
|
105
|
+
const host = await firestore().collection('hosts').doc(hostId).get();
|
|
106
|
+
if (!host.exists || host.get('orgId') !== orgId) {
|
|
107
|
+
throw new PosHardwareAttachRefusal('That store is not in the buyer’s workspace.', 409);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
uid,
|
|
112
|
+
orgId,
|
|
113
|
+
hostId,
|
|
114
|
+
email,
|
|
115
|
+
name,
|
|
116
|
+
address: typed.address
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const email = String((_request_email = request.email) != null ? _request_email : '').trim().toLowerCase();
|
|
120
|
+
if (!EMAIL.test(email)) throw new PosHardwareAttachRefusal('Enter the buyer’s email address.', 400);
|
|
121
|
+
if (await findUserByEmailAcrossPools(email)) {
|
|
122
|
+
throw new PosHardwareAttachRefusal('That email already has an account. Look it up and attach the account instead.', 409);
|
|
123
|
+
}
|
|
124
|
+
return _extends({
|
|
125
|
+
uid: null,
|
|
126
|
+
orgId: null,
|
|
127
|
+
hostId: null,
|
|
128
|
+
email
|
|
129
|
+
}, typed);
|
|
130
|
+
}
|
|
131
|
+
/** The buyer as the register order keeps it. */ function orderBuyer(buyer, attachedBy, now) {
|
|
132
|
+
return _extends({
|
|
133
|
+
uid: buyer.uid,
|
|
134
|
+
orgId: buyer.orgId,
|
|
135
|
+
hostId: buyer.hostId,
|
|
136
|
+
email: buyer.email,
|
|
137
|
+
attachedBy: attachedBy != null ? attachedBy : '',
|
|
138
|
+
attachedAtMs: now
|
|
139
|
+
}, buyer.name ? {
|
|
140
|
+
name: buyer.name
|
|
141
|
+
} : {}, buyer.address ? {
|
|
142
|
+
address: buyer.address
|
|
143
|
+
} : {});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Moves (or re-stamps) a recorded order for its new buyer, in one
|
|
147
|
+
* transaction with its sale record and the register order. Returns the order
|
|
148
|
+
* as it now stands.
|
|
149
|
+
*/ async function moveRecordedOrder(input) {
|
|
150
|
+
const { orderId, buyer, attachedBy, config, now } = input;
|
|
151
|
+
const saleRef = posHardwareSaleRef(orderId);
|
|
152
|
+
return firestore().runTransaction(async (transaction)=>{
|
|
153
|
+
var _sale_get, _fresh_name, _ref, _fresh_address, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _attachment_hostId;
|
|
154
|
+
var _before_posSale, _before_attachment, _before_attachment1, _before_attachment2, _before_attachment3, _before_attachment4, _before_attachment5, _before_attachment6, _before_attachment7, _before_attachment8, _before_attachment9, _before_attachment10, _before_attachment11, _before_attachment12, _before_attachment13, _before_posSale1;
|
|
155
|
+
const sale = await transaction.get(saleRef);
|
|
156
|
+
if (!sale.exists) throw new PosHardwareAttachRefusal('No such card reader sale.', 404);
|
|
157
|
+
const fromOrgId = String((_sale_get = sale.get('orgId')) != null ? _sale_get : '');
|
|
158
|
+
const fromRef = hardwareOrdersRef(fromOrgId).doc(orderId);
|
|
159
|
+
const from = await transaction.get(fromRef);
|
|
160
|
+
if (!from.exists) throw new PosHardwareAttachRefusal('No such card reader sale.', 404);
|
|
161
|
+
const before = from.data();
|
|
162
|
+
if (before.source !== 'in_person' || ((_before_posSale = before.posSale) == null ? void 0 : _before_posSale.hostId) !== config.sellerHostId) {
|
|
163
|
+
throw new PosHardwareAttachRefusal('Only a card reader sold in person here can be attached.', 409);
|
|
164
|
+
}
|
|
165
|
+
if (before.status === 'canceled' || before.status === 'refunded') {
|
|
166
|
+
throw new PosHardwareAttachRefusal('This sale was refunded and can no longer be attached.', 409);
|
|
167
|
+
}
|
|
168
|
+
const fresh = posHardwareAttachmentOf(orderBuyer(buyer, attachedBy, now));
|
|
169
|
+
// The same person again (a claim on sign-up, a store chosen later)
|
|
170
|
+
// keeps the name and address already known of them.
|
|
171
|
+
const samePerson = Boolean(fresh.uid && ((_before_attachment = before.attachment) == null ? void 0 : _before_attachment.uid) === fresh.uid || fresh.email && ((_before_attachment1 = before.attachment) == null ? void 0 : _before_attachment1.email) === fresh.email);
|
|
172
|
+
const attachment = _extends({}, fresh, {
|
|
173
|
+
name: (_fresh_name = fresh.name) != null ? _fresh_name : samePerson ? (_ref = (_before_attachment2 = before.attachment) == null ? void 0 : _before_attachment2.name) != null ? _ref : null : null,
|
|
174
|
+
address: (_fresh_address = fresh.address) != null ? _fresh_address : samePerson ? (_ref1 = (_before_attachment3 = before.attachment) == null ? void 0 : _before_attachment3.address) != null ? _ref1 : null : null
|
|
175
|
+
});
|
|
176
|
+
const same = ((_before_attachment4 = before.attachment) == null ? void 0 : _before_attachment4.state) === attachment.state && ((_ref2 = (_before_attachment5 = before.attachment) == null ? void 0 : _before_attachment5.uid) != null ? _ref2 : null) === attachment.uid && ((_ref3 = (_before_attachment6 = before.attachment) == null ? void 0 : _before_attachment6.orgId) != null ? _ref3 : null) === attachment.orgId && ((_ref4 = (_before_attachment7 = before.attachment) == null ? void 0 : _before_attachment7.email) != null ? _ref4 : null) === attachment.email && ((_ref5 = (_before_attachment8 = before.attachment) == null ? void 0 : _before_attachment8.hostId) != null ? _ref5 : null) === attachment.hostId && ((_ref6 = (_before_attachment9 = before.attachment) == null ? void 0 : _before_attachment9.name) != null ? _ref6 : null) === attachment.name && JSON.stringify((_ref7 = (_before_attachment10 = before.attachment) == null ? void 0 : _before_attachment10.address) != null ? _ref7 : null) === JSON.stringify(attachment.address);
|
|
177
|
+
if (same) return {
|
|
178
|
+
order: before,
|
|
179
|
+
orgId: fromOrgId
|
|
180
|
+
};
|
|
181
|
+
if (input.requirePending && ((_before_attachment11 = before.attachment) == null ? void 0 : _before_attachment11.state) === 'attached') {
|
|
182
|
+
throw new PosHardwareAttachRefusal('This sale is already attached. Detach it first.', 409);
|
|
183
|
+
}
|
|
184
|
+
const toOrgId = attachment.state === 'attached' ? attachment.orgId : config.sellerOrgId;
|
|
185
|
+
const after = _extends({}, before, {
|
|
186
|
+
orgId: toOrgId,
|
|
187
|
+
hostId: attachment.state === 'attached' ? (_attachment_hostId = attachment.hostId) != null ? _attachment_hostId : '' : '',
|
|
188
|
+
createdBy: attachment.uid,
|
|
189
|
+
// The buyer's address for the order's emails; the receipt address a
|
|
190
|
+
// pending sale carried was the register's, not necessarily theirs.
|
|
191
|
+
contactEmail: attachment.email,
|
|
192
|
+
attachment: _extends({}, attachment, ((_before_attachment12 = before.attachment) == null ? void 0 : _before_attachment12.email) === attachment.email && ((_before_attachment13 = before.attachment) == null ? void 0 : _before_attachment13.invitedAtMs) ? {
|
|
193
|
+
invitedAtMs: before.attachment.invitedAtMs
|
|
194
|
+
} : {}),
|
|
195
|
+
updatedAtMs: now
|
|
196
|
+
});
|
|
197
|
+
if (toOrgId === fromOrgId) {
|
|
198
|
+
transaction.set(fromRef, after);
|
|
199
|
+
} else {
|
|
200
|
+
transaction.create(hardwareOrdersRef(toOrgId).doc(orderId), after);
|
|
201
|
+
transaction.delete(fromRef);
|
|
202
|
+
}
|
|
203
|
+
transaction.set(saleRef, posHardwareSaleRecord(orderId, after), posHardwareSaleSetOptions(after));
|
|
204
|
+
const registerOrderId = (_before_posSale1 = before.posSale) == null ? void 0 : _before_posSale1.orderId;
|
|
205
|
+
if (registerOrderId) {
|
|
206
|
+
transaction.set(firestore().collection('hosts').doc(config.sellerHostId).collection('orders').doc(registerOrderId), {
|
|
207
|
+
hardwareBuyer: orderBuyer(buyer, attachedBy, now)
|
|
208
|
+
}, {
|
|
209
|
+
merge: true
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
order: after,
|
|
214
|
+
orgId: toOrgId
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Says whose a sale's hardware is: by the register order (the sale the
|
|
220
|
+
* register just rang, recorded or not) or by the hardware order's id (a sale
|
|
221
|
+
* on the To attach list). Invites a buyer with no account, once.
|
|
222
|
+
*/ export async function attachPosHardwareSale(input) {
|
|
223
|
+
var _input_now, _input_orderId;
|
|
224
|
+
const now = (_input_now = input.now) != null ? _input_now : Date.now();
|
|
225
|
+
const registerOrderId = id(input.registerOrderId);
|
|
226
|
+
const orderId = registerOrderId ? posHardwareInPersonOrderId(input.config.sellerHostId, registerOrderId) : String((_input_orderId = input.orderId) != null ? _input_orderId : '');
|
|
227
|
+
if (!POS_HARDWARE_ORDER_ID.test(orderId)) throw new PosHardwareAttachRefusal('Name the sale to attach.', 400);
|
|
228
|
+
const recorded = (await posHardwareSaleRef(orderId).get()).exists;
|
|
229
|
+
if (!recorded) {
|
|
230
|
+
var _register_get;
|
|
231
|
+
if (!registerOrderId) throw new PosHardwareAttachRefusal('No such card reader sale.', 404);
|
|
232
|
+
const registerRef = firestore().collection('hosts').doc(input.config.sellerHostId).collection('orders').doc(registerOrderId);
|
|
233
|
+
const register = await registerRef.get();
|
|
234
|
+
if (!register.exists) throw new PosHardwareAttachRefusal('No such sale on this register.', 404);
|
|
235
|
+
const status = String((_register_get = register.get('status')) != null ? _register_get : '');
|
|
236
|
+
if (status !== 'pending' && status !== 'paid') {
|
|
237
|
+
throw new PosHardwareAttachRefusal('This sale was voided or refunded and can no longer be attached.', 409);
|
|
238
|
+
}
|
|
239
|
+
await registerRef.set({
|
|
240
|
+
hardwareBuyer: orderBuyer(input.buyer, input.attachedBy, now)
|
|
241
|
+
}, {
|
|
242
|
+
merge: true
|
|
243
|
+
});
|
|
244
|
+
if (status === 'pending') return {
|
|
245
|
+
outcome: 'waiting',
|
|
246
|
+
registerOrderId
|
|
247
|
+
};
|
|
248
|
+
// Paid and not yet recorded: record it now, already attached.
|
|
249
|
+
const outcome = await recordInPersonPosHardwareSale(input.config.sellerHostId, registerOrderId, {
|
|
250
|
+
config: input.config,
|
|
251
|
+
now
|
|
252
|
+
});
|
|
253
|
+
if (outcome.outcome !== 'recorded' && outcome.outcome !== 'already') {
|
|
254
|
+
throw new PosHardwareAttachRefusal('This sale has no card reader to attach.', 409);
|
|
255
|
+
}
|
|
256
|
+
if (outcome.outcome === 'recorded') return await settled(outcome.orderId, input.config);
|
|
257
|
+
// Recorded by the listener between the two reads: attach the recorded one.
|
|
258
|
+
}
|
|
259
|
+
const moved = await moveRecordedOrder({
|
|
260
|
+
orderId,
|
|
261
|
+
buyer: input.buyer,
|
|
262
|
+
attachedBy: input.attachedBy,
|
|
263
|
+
config: input.config,
|
|
264
|
+
now,
|
|
265
|
+
requirePending: true
|
|
266
|
+
});
|
|
267
|
+
return await settled(orderId, input.config, moved);
|
|
268
|
+
}
|
|
269
|
+
/** The order as it stands, after inviting a buyer with no account if it is owed. */ async function settled(orderId, config, known) {
|
|
270
|
+
var _order_attachment, _order_attachment1;
|
|
271
|
+
let current = known;
|
|
272
|
+
if (!current) {
|
|
273
|
+
var _sale_get;
|
|
274
|
+
const sale = await posHardwareSaleRef(orderId).get();
|
|
275
|
+
const orgId = String((_sale_get = sale.get('orgId')) != null ? _sale_get : config.sellerOrgId);
|
|
276
|
+
const doc = await hardwareOrdersRef(orgId).doc(orderId).get();
|
|
277
|
+
current = {
|
|
278
|
+
order: doc.data(),
|
|
279
|
+
orgId
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
let order = await invitePendingBuyer(orderId, current.orgId, current.order);
|
|
283
|
+
// The buyer's address for the reseller's records, from the store chosen
|
|
284
|
+
// for the readers, where the register typed none (AGL-4038).
|
|
285
|
+
if (((_order_attachment = order.attachment) == null ? void 0 : _order_attachment.state) === 'attached' && order.attachment.hostId && !order.attachment.address) {
|
|
286
|
+
const { fillPosHardwareBuyerAddress } = await import("./pos-hardware-buyer-record.js");
|
|
287
|
+
if (await fillPosHardwareBuyerAddress({
|
|
288
|
+
orgId: current.orgId,
|
|
289
|
+
orderId
|
|
290
|
+
})) {
|
|
291
|
+
var _fresh_data;
|
|
292
|
+
const fresh = await hardwareOrdersRef(current.orgId).doc(orderId).get();
|
|
293
|
+
order = (_fresh_data = fresh.data()) != null ? _fresh_data : order;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
outcome: ((_order_attachment1 = order.attachment) == null ? void 0 : _order_attachment1.state) === 'attached' ? 'attached' : 'pending',
|
|
298
|
+
orderId,
|
|
299
|
+
orgId: current.orgId,
|
|
300
|
+
order
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Sends the sign-up invitation to a pending buyer with an address and no
|
|
305
|
+
* account, once per address: the stamp is claimed in a transaction before
|
|
306
|
+
* the email goes, so two callers never both send it.
|
|
307
|
+
*/ export async function invitePendingBuyer(orderId, orgId, order) {
|
|
308
|
+
const attachment = order.attachment;
|
|
309
|
+
if (!attachment || attachment.state !== 'pending' || attachment.uid || !attachment.email || attachment.invitedAtMs) {
|
|
310
|
+
return order;
|
|
311
|
+
}
|
|
312
|
+
const ref = hardwareOrdersRef(orgId).doc(orderId);
|
|
313
|
+
const claimed = await firestore().runTransaction(async (transaction)=>{
|
|
314
|
+
const snapshot = await transaction.get(ref);
|
|
315
|
+
const now = snapshot.exists ? snapshot.data() : null;
|
|
316
|
+
if (!(now == null ? void 0 : now.attachment) || now.attachment.invitedAtMs || now.attachment.email !== attachment.email) return null;
|
|
317
|
+
const invitedAtMs = Date.now();
|
|
318
|
+
// The whole map, read in this transaction, rather than a dotted path.
|
|
319
|
+
const next = _extends({}, now.attachment, {
|
|
320
|
+
invitedAtMs
|
|
321
|
+
});
|
|
322
|
+
transaction.update(ref, {
|
|
323
|
+
attachment: next
|
|
324
|
+
});
|
|
325
|
+
return _extends({}, now, {
|
|
326
|
+
attachment: next
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
if (!claimed) return order;
|
|
330
|
+
await sendPosHardwareInvite(orderId, claimed);
|
|
331
|
+
return claimed;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Puts an attached sale back on the To attach list: the wrong buyer was
|
|
335
|
+
* chosen. Refused once one of its readers is set up on the buyer's store.
|
|
336
|
+
*/ export async function detachPosHardwareSale(input) {
|
|
337
|
+
var _input_now;
|
|
338
|
+
const { config, orderId } = input;
|
|
339
|
+
if (!POS_HARDWARE_ORDER_ID.test(orderId)) throw new PosHardwareAttachRefusal('Name the sale to detach.', 400);
|
|
340
|
+
const now = (_input_now = input.now) != null ? _input_now : Date.now();
|
|
341
|
+
const saleRef = posHardwareSaleRef(orderId);
|
|
342
|
+
return firestore().runTransaction(async (transaction)=>{
|
|
343
|
+
var _sale_get, _before_units;
|
|
344
|
+
var _before_posSale, _before_attachment, _before_posSale1;
|
|
345
|
+
const sale = await transaction.get(saleRef);
|
|
346
|
+
if (!sale.exists) throw new PosHardwareAttachRefusal('No such card reader sale.', 404);
|
|
347
|
+
const fromOrgId = String((_sale_get = sale.get('orgId')) != null ? _sale_get : '');
|
|
348
|
+
const fromRef = hardwareOrdersRef(fromOrgId).doc(orderId);
|
|
349
|
+
const from = await transaction.get(fromRef);
|
|
350
|
+
if (!from.exists) throw new PosHardwareAttachRefusal('No such card reader sale.', 404);
|
|
351
|
+
const before = from.data();
|
|
352
|
+
if (before.source !== 'in_person' || ((_before_posSale = before.posSale) == null ? void 0 : _before_posSale.hostId) !== config.sellerHostId) {
|
|
353
|
+
throw new PosHardwareAttachRefusal('Only a card reader sold in person here can be detached.', 409);
|
|
354
|
+
}
|
|
355
|
+
if (((_before_attachment = before.attachment) == null ? void 0 : _before_attachment.state) !== 'attached') return {
|
|
356
|
+
order: before
|
|
357
|
+
};
|
|
358
|
+
if (((_before_units = before.units) != null ? _before_units : []).some((unit)=>unit.readerId)) {
|
|
359
|
+
throw new PosHardwareAttachRefusal('A reader from this sale is already set up on the buyer’s store.', 409);
|
|
360
|
+
}
|
|
361
|
+
const after = _extends({}, before, {
|
|
362
|
+
orgId: config.sellerOrgId,
|
|
363
|
+
hostId: '',
|
|
364
|
+
createdBy: null,
|
|
365
|
+
contactEmail: null,
|
|
366
|
+
attachment: posHardwareAttachmentOf(null),
|
|
367
|
+
updatedAtMs: now
|
|
368
|
+
});
|
|
369
|
+
transaction.create(hardwareOrdersRef(config.sellerOrgId).doc(orderId), after);
|
|
370
|
+
transaction.delete(fromRef);
|
|
371
|
+
transaction.set(saleRef, posHardwareSaleRecord(orderId, after), posHardwareSaleSetOptions(after));
|
|
372
|
+
const registerOrderId = (_before_posSale1 = before.posSale) == null ? void 0 : _before_posSale1.orderId;
|
|
373
|
+
if (registerOrderId) {
|
|
374
|
+
transaction.set(firestore().collection('hosts').doc(config.sellerHostId).collection('orders').doc(registerOrderId), {
|
|
375
|
+
hardwareBuyer: firebaseAdmin.firestore.FieldValue.delete()
|
|
376
|
+
}, {
|
|
377
|
+
merge: true
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
order: after
|
|
382
|
+
};
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* A workspace was just created: every pending sale naming its owner — their
|
|
387
|
+
* account, or their address once verified — moves into it. Never throws:
|
|
388
|
+
* a sale it cannot move stays on the To attach list.
|
|
389
|
+
*/ export async function claimPosHardwareForNewWorkspace(input) {
|
|
390
|
+
var _input_ownerEmail, _ref;
|
|
391
|
+
const { config } = input;
|
|
392
|
+
if (!config || !id(input.orgId) || !id(input.ownerUid)) return {
|
|
393
|
+
claimed: 0
|
|
394
|
+
};
|
|
395
|
+
const pending = hardwareOrdersRef(config.sellerOrgId);
|
|
396
|
+
const email = input.emailVerified ? String((_input_ownerEmail = input.ownerEmail) != null ? _input_ownerEmail : '').trim().toLowerCase() : '';
|
|
397
|
+
const [byUid, byEmail] = await Promise.all([
|
|
398
|
+
pending.where('attachment.uid', '==', input.ownerUid).limit(20).get(),
|
|
399
|
+
email ? pending.where('attachment.email', '==', email).limit(20).get() : Promise.resolve({
|
|
400
|
+
docs: []
|
|
401
|
+
})
|
|
402
|
+
]);
|
|
403
|
+
const ids = new Set();
|
|
404
|
+
for (const doc of [
|
|
405
|
+
...byUid.docs,
|
|
406
|
+
...byEmail.docs
|
|
407
|
+
]){
|
|
408
|
+
var _doc_data_attachment;
|
|
409
|
+
if (((_doc_data_attachment = doc.data().attachment) == null ? void 0 : _doc_data_attachment.state) === 'pending') ids.add(String(doc.id));
|
|
410
|
+
}
|
|
411
|
+
let claimed = 0;
|
|
412
|
+
// Their account's name, for the reseller's records of the sale.
|
|
413
|
+
const owner = ids.size ? await findUserByUidAcrossPools(input.ownerUid).catch(()=>null) : null;
|
|
414
|
+
const name = String((_ref = owner == null ? void 0 : owner.record.displayName) != null ? _ref : '').trim().slice(0, 200) || null;
|
|
415
|
+
for (const orderId of ids){
|
|
416
|
+
try {
|
|
417
|
+
var _input_ownerEmail1;
|
|
418
|
+
await moveRecordedOrder({
|
|
419
|
+
orderId,
|
|
420
|
+
buyer: {
|
|
421
|
+
uid: input.ownerUid,
|
|
422
|
+
orgId: input.orgId,
|
|
423
|
+
hostId: null,
|
|
424
|
+
// Their account's address carries the order's emails from now on.
|
|
425
|
+
email: String((_input_ownerEmail1 = input.ownerEmail) != null ? _input_ownerEmail1 : '').trim().toLowerCase() || null,
|
|
426
|
+
name
|
|
427
|
+
},
|
|
428
|
+
attachedBy: null,
|
|
429
|
+
config,
|
|
430
|
+
now: Date.now(),
|
|
431
|
+
requirePending: true
|
|
432
|
+
});
|
|
433
|
+
claimed += 1;
|
|
434
|
+
} catch (error) {
|
|
435
|
+
console.error('[pos-hardware-attach] a pending sale was not claimed', orderId, error);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return {
|
|
439
|
+
claimed
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
//# sourceMappingURL=pos-hardware-attach.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/pos-hardware-attach.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 { firebaseAdmin } from '@aglyn/tenant-data-admin'\nimport {\n findUserByEmailAcrossPools,\n findUserByUidAcrossPools,\n} from '@aglyn/tenant-data-admin/server/auth-pools'\nimport type { OrderHardwareBuyer } from '../model/commerce-orders'\nimport {\n POS_HARDWARE_ORDER_ID,\n posHardwareBuyerAddress,\n posHardwareSaleRecord,\n posHardwareSaleSetOptions,\n type PosHardwareAddress,\n type PosHardwareInPersonConfig,\n type PosHardwareOrder,\n} from '../model/pos-hardware'\nimport { posHardwareAttachmentOf } from '../model/pos-hardware-in-person'\nimport { hardwareOrdersRef, posHardwareInPersonOrderId, posHardwareSaleRef } from './pos-hardware'\nimport { recordInPersonPosHardwareSale } from './pos-hardware-in-person'\nimport { sendPosHardwareInvite } from './pos-hardware-notify'\n\n/*==========================================\n * ATTACHING AN IN-PERSON SALE TO ITS BUYER (AGL-4038).\n *\n * The register user who sold a card reader says whose it is: an account and\n * the workspace (and, if they chose one, the store) it is for; an account\n * with no workspace yet; or the address of someone with no account, who is\n * then invited to sign up. The order moves to the buyer's workspace the\n * moment it has one, and is pending on the selling workspace's To attach\n * list until then.\n *\n * Every attachment is checked here, never trusted from the register: the\n * account exists, it is a member of the workspace, the store is the\n * workspace's, and an address given for \"no account\" really has none.\n *\n * A sale not recorded yet (the register attaches the buyer while the sale is\n * still open, or the instant it is paid) carries the buyer on the register\n * order (`hardwareBuyer`), and the recorder builds the order already\n * attached. A sale already recorded is moved: created in the buyer's\n * workspace and deleted from where it was, with its retained sale record and\n * the register order, in one transaction.\n *\n * A NEW WORKSPACE CLAIMS ITS OWNER'S SALES. When a buyer who was invited\n * signs up and creates a workspace, every pending sale naming their verified\n * address (or their account) moves into it ({@link claimPosHardwareForNewWorkspace}).\n *=========================================*/\n\nexport class PosHardwareAttachRefusal extends Error {\n constructor(\n message: string,\n readonly status: number,\n ) {\n super(message)\n }\n}\n\n/** Who the register says the buyer is, before it is checked. */\nexport interface PosHardwareBuyerRequest {\n uid?: unknown\n orgId?: unknown\n hostId?: unknown\n email?: unknown\n /** The buyer's name, typed at the sale; an account's own name wins. */\n name?: unknown\n /** The buyer's business address, typed at the sale (optional). */\n address?: unknown\n}\n\nconst ID = /^[A-Za-z0-9_-]{1,128}$/\nconst EMAIL = /^[^@\\s]{1,64}@[^@\\s]+\\.[^@\\s]{2,}$/\n\nconst id = (value: unknown): string | null => (typeof value === 'string' && ID.test(value.trim()) ? value.trim() : null)\n\nfunction firestore() {\n return firebaseAdmin.app().firestore()\n}\n\n/** A checked buyer: who they are, where the order goes, where its emails go. */\nexport interface CheckedBuyer {\n uid: string | null\n orgId: string | null\n hostId: string | null\n email: string | null\n /**\n * The buyer's name and business address, for the platform's reseller\n * records (AGL-4038): the account's name, else the one typed; the address\n * typed at the sale, when one was.\n */\n name?: string | null\n address?: PosHardwareAddress | null\n}\n\n/** The name and address the register typed, checked: an address is all of it or refused. */\nfunction typedIdentity(request: PosHardwareBuyerRequest): { name: string | null; address: PosHardwareAddress | null } {\n const name = typeof request.name === 'string' && request.name.trim() ? request.name.trim().slice(0, 200) : null\n if (request.address === undefined || request.address === null || request.address === '') {\n return { name, address: null }\n }\n const address = posHardwareBuyerAddress(request.address)\n if (!address) {\n throw new PosHardwareAttachRefusal('Enter the buyer’s street, city, postal code and two-letter country, or leave the address empty.', 400)\n }\n return { name, address }\n}\n\n/**\n * The buyer the register named, checked. Refuses an account that does not\n * exist or is not in the workspace, a store not in the workspace, and an\n * address said to have no account that has one.\n */\nexport async function checkHardwareBuyer(request: PosHardwareBuyerRequest): Promise<CheckedBuyer> {\n const uid = id(request.uid)\n const orgId = id(request.orgId)\n const hostId = id(request.hostId)\n const typed = typedIdentity(request)\n if (uid) {\n const user = await findUserByUidAcrossPools(uid)\n if (!user) throw new PosHardwareAttachRefusal('That account no longer exists. Look the buyer up again.', 404)\n const email = String(user.record.email ?? '').trim().toLowerCase() || null\n const name = String(user.record.displayName ?? '').trim().slice(0, 200) || typed.name\n if (!orgId) return { uid, orgId: null, hostId: null, email, name, address: typed.address }\n const member = await firestore().collection('orgs').doc(orgId).collection('members').doc(uid).get()\n if (!member.exists) {\n throw new PosHardwareAttachRefusal('That person is not on that workspace. Look the buyer up again.', 409)\n }\n if (hostId) {\n const host = await firestore().collection('hosts').doc(hostId).get()\n if (!host.exists || host.get('orgId') !== orgId) {\n throw new PosHardwareAttachRefusal('That store is not in the buyer’s workspace.', 409)\n }\n }\n return { uid, orgId, hostId, email, name, address: typed.address }\n }\n const email = String(request.email ?? '').trim().toLowerCase()\n if (!EMAIL.test(email)) throw new PosHardwareAttachRefusal('Enter the buyer’s email address.', 400)\n if (await findUserByEmailAcrossPools(email)) {\n throw new PosHardwareAttachRefusal(\n 'That email already has an account. Look it up and attach the account instead.',\n 409,\n )\n }\n return { uid: null, orgId: null, hostId: null, email, ...typed }\n}\n\n/** The buyer as the register order keeps it. */\nfunction orderBuyer(buyer: CheckedBuyer, attachedBy: string | null, now: number): OrderHardwareBuyer {\n return {\n uid: buyer.uid,\n orgId: buyer.orgId,\n hostId: buyer.hostId,\n email: buyer.email,\n attachedBy: attachedBy ?? '',\n attachedAtMs: now,\n ...(buyer.name ? { name: buyer.name } : {}),\n ...(buyer.address ? { address: buyer.address } : {}),\n }\n}\n\nexport type PosHardwareAttachOutcome =\n | { outcome: 'waiting'; registerOrderId: string }\n | { outcome: 'attached' | 'pending'; orderId: string; orgId: string; order: PosHardwareOrder }\n\n/**\n * Moves (or re-stamps) a recorded order for its new buyer, in one\n * transaction with its sale record and the register order. Returns the order\n * as it now stands.\n */\nasync function moveRecordedOrder(input: {\n orderId: string\n buyer: CheckedBuyer\n attachedBy: string | null\n config: PosHardwareInPersonConfig\n now: number\n /** Only a pending order moves: an attached one must be detached first. */\n requirePending: boolean\n}): Promise<{ order: PosHardwareOrder; orgId: string }> {\n const { orderId, buyer, attachedBy, config, now } = input\n const saleRef = posHardwareSaleRef(orderId)\n return firestore().runTransaction(async (transaction: any) => {\n const sale = await transaction.get(saleRef)\n if (!sale.exists) throw new PosHardwareAttachRefusal('No such card reader sale.', 404)\n const fromOrgId = String(sale.get('orgId') ?? '')\n const fromRef = hardwareOrdersRef(fromOrgId).doc(orderId)\n const from = await transaction.get(fromRef)\n if (!from.exists) throw new PosHardwareAttachRefusal('No such card reader sale.', 404)\n const before = from.data() as PosHardwareOrder\n if (before.source !== 'in_person' || before.posSale?.hostId !== config.sellerHostId) {\n throw new PosHardwareAttachRefusal('Only a card reader sold in person here can be attached.', 409)\n }\n if (before.status === 'canceled' || before.status === 'refunded') {\n throw new PosHardwareAttachRefusal('This sale was refunded and can no longer be attached.', 409)\n }\n const fresh = posHardwareAttachmentOf(orderBuyer(buyer, attachedBy, now))\n // The same person again (a claim on sign-up, a store chosen later)\n // keeps the name and address already known of them.\n const samePerson = Boolean(\n (fresh.uid && before.attachment?.uid === fresh.uid) ||\n (fresh.email && before.attachment?.email === fresh.email),\n )\n const attachment = {\n ...fresh,\n name: fresh.name ?? (samePerson ? (before.attachment?.name ?? null) : null),\n address: fresh.address ?? (samePerson ? (before.attachment?.address ?? null) : null),\n }\n const same =\n before.attachment?.state === attachment.state &&\n (before.attachment?.uid ?? null) === attachment.uid &&\n (before.attachment?.orgId ?? null) === attachment.orgId &&\n (before.attachment?.email ?? null) === attachment.email &&\n (before.attachment?.hostId ?? null) === attachment.hostId &&\n (before.attachment?.name ?? null) === attachment.name &&\n JSON.stringify(before.attachment?.address ?? null) === JSON.stringify(attachment.address)\n if (same) return { order: before, orgId: fromOrgId }\n if (input.requirePending && before.attachment?.state === 'attached') {\n throw new PosHardwareAttachRefusal('This sale is already attached. Detach it first.', 409)\n }\n const toOrgId = attachment.state === 'attached' ? (attachment.orgId as string) : config.sellerOrgId\n const after: PosHardwareOrder = {\n ...before,\n orgId: toOrgId,\n hostId: attachment.state === 'attached' ? (attachment.hostId ?? '') : '',\n createdBy: attachment.uid,\n // The buyer's address for the order's emails; the receipt address a\n // pending sale carried was the register's, not necessarily theirs.\n contactEmail: attachment.email,\n attachment: {\n ...attachment,\n // An invitation already sent stays sent for the same address.\n ...(before.attachment?.email === attachment.email && before.attachment?.invitedAtMs\n ? { invitedAtMs: before.attachment.invitedAtMs }\n : {}),\n },\n updatedAtMs: now,\n }\n if (toOrgId === fromOrgId) {\n transaction.set(fromRef, after)\n } else {\n transaction.create(hardwareOrdersRef(toOrgId).doc(orderId), after)\n transaction.delete(fromRef)\n }\n transaction.set(saleRef, posHardwareSaleRecord(orderId, after), posHardwareSaleSetOptions(after))\n const registerOrderId = before.posSale?.orderId\n if (registerOrderId) {\n transaction.set(\n firestore().collection('hosts').doc(config.sellerHostId).collection('orders').doc(registerOrderId),\n { hardwareBuyer: orderBuyer(buyer, attachedBy, now) },\n { merge: true },\n )\n }\n return { order: after, orgId: toOrgId }\n })\n}\n\n/**\n * Says whose a sale's hardware is: by the register order (the sale the\n * register just rang, recorded or not) or by the hardware order's id (a sale\n * on the To attach list). Invites a buyer with no account, once.\n */\nexport async function attachPosHardwareSale(input: {\n config: PosHardwareInPersonConfig\n buyer: CheckedBuyer\n attachedBy: string | null\n registerOrderId?: string | null\n orderId?: string | null\n now?: number\n}): Promise<PosHardwareAttachOutcome> {\n const now = input.now ?? Date.now()\n const registerOrderId = id(input.registerOrderId)\n const orderId = registerOrderId\n ? posHardwareInPersonOrderId(input.config.sellerHostId, registerOrderId)\n : String(input.orderId ?? '')\n if (!POS_HARDWARE_ORDER_ID.test(orderId)) throw new PosHardwareAttachRefusal('Name the sale to attach.', 400)\n\n const recorded = (await posHardwareSaleRef(orderId).get()).exists\n if (!recorded) {\n if (!registerOrderId) throw new PosHardwareAttachRefusal('No such card reader sale.', 404)\n const registerRef = firestore()\n .collection('hosts')\n .doc(input.config.sellerHostId)\n .collection('orders')\n .doc(registerOrderId)\n const register = await registerRef.get()\n if (!register.exists) throw new PosHardwareAttachRefusal('No such sale on this register.', 404)\n const status = String(register.get('status') ?? '')\n if (status !== 'pending' && status !== 'paid') {\n throw new PosHardwareAttachRefusal('This sale was voided or refunded and can no longer be attached.', 409)\n }\n await registerRef.set({ hardwareBuyer: orderBuyer(input.buyer, input.attachedBy, now) }, { merge: true })\n if (status === 'pending') return { outcome: 'waiting', registerOrderId }\n // Paid and not yet recorded: record it now, already attached.\n const outcome = await recordInPersonPosHardwareSale(input.config.sellerHostId, registerOrderId, {\n config: input.config,\n now,\n })\n if (outcome.outcome !== 'recorded' && outcome.outcome !== 'already') {\n throw new PosHardwareAttachRefusal('This sale has no card reader to attach.', 409)\n }\n if (outcome.outcome === 'recorded') return await settled(outcome.orderId, input.config)\n // Recorded by the listener between the two reads: attach the recorded one.\n }\n const moved = await moveRecordedOrder({\n orderId,\n buyer: input.buyer,\n attachedBy: input.attachedBy,\n config: input.config,\n now,\n requirePending: true,\n })\n return await settled(orderId, input.config, moved)\n}\n\n/** The order as it stands, after inviting a buyer with no account if it is owed. */\nasync function settled(\n orderId: string,\n config: PosHardwareInPersonConfig,\n known?: { order: PosHardwareOrder; orgId: string },\n): Promise<PosHardwareAttachOutcome> {\n let current = known\n if (!current) {\n const sale = await posHardwareSaleRef(orderId).get()\n const orgId = String(sale.get('orgId') ?? config.sellerOrgId)\n const doc = await hardwareOrdersRef(orgId).doc(orderId).get()\n current = { order: doc.data() as PosHardwareOrder, orgId }\n }\n let order = await invitePendingBuyer(orderId, current.orgId, current.order)\n // The buyer's address for the reseller's records, from the store chosen\n // for the readers, where the register typed none (AGL-4038).\n if (order.attachment?.state === 'attached' && order.attachment.hostId && !order.attachment.address) {\n const { fillPosHardwareBuyerAddress } = await import('./pos-hardware-buyer-record')\n if (await fillPosHardwareBuyerAddress({ orgId: current.orgId, orderId })) {\n const fresh = await hardwareOrdersRef(current.orgId).doc(orderId).get()\n order = (fresh.data() as PosHardwareOrder | undefined) ?? order\n }\n }\n return {\n outcome: order.attachment?.state === 'attached' ? 'attached' : 'pending',\n orderId,\n orgId: current.orgId,\n order,\n }\n}\n\n/**\n * Sends the sign-up invitation to a pending buyer with an address and no\n * account, once per address: the stamp is claimed in a transaction before\n * the email goes, so two callers never both send it.\n */\nexport async function invitePendingBuyer(\n orderId: string,\n orgId: string,\n order: PosHardwareOrder,\n): Promise<PosHardwareOrder> {\n const attachment = order.attachment\n if (!attachment || attachment.state !== 'pending' || attachment.uid || !attachment.email || attachment.invitedAtMs) {\n return order\n }\n const ref = hardwareOrdersRef(orgId).doc(orderId)\n const claimed = await firestore().runTransaction(async (transaction: any) => {\n const snapshot = await transaction.get(ref)\n const now = snapshot.exists ? (snapshot.data() as PosHardwareOrder) : null\n if (!now?.attachment || now.attachment.invitedAtMs || now.attachment.email !== attachment.email) return null\n const invitedAtMs = Date.now()\n // The whole map, read in this transaction, rather than a dotted path.\n const next = { ...now.attachment, invitedAtMs }\n transaction.update(ref, { attachment: next })\n return { ...now, attachment: next } as PosHardwareOrder\n })\n if (!claimed) return order\n await sendPosHardwareInvite(orderId, claimed)\n return claimed\n}\n\n/**\n * Puts an attached sale back on the To attach list: the wrong buyer was\n * chosen. Refused once one of its readers is set up on the buyer's store.\n */\nexport async function detachPosHardwareSale(input: {\n config: PosHardwareInPersonConfig\n orderId: string\n now?: number\n}): Promise<{ order: PosHardwareOrder }> {\n const { config, orderId } = input\n if (!POS_HARDWARE_ORDER_ID.test(orderId)) throw new PosHardwareAttachRefusal('Name the sale to detach.', 400)\n const now = input.now ?? Date.now()\n const saleRef = posHardwareSaleRef(orderId)\n return firestore().runTransaction(async (transaction: any) => {\n const sale = await transaction.get(saleRef)\n if (!sale.exists) throw new PosHardwareAttachRefusal('No such card reader sale.', 404)\n const fromOrgId = String(sale.get('orgId') ?? '')\n const fromRef = hardwareOrdersRef(fromOrgId).doc(orderId)\n const from = await transaction.get(fromRef)\n if (!from.exists) throw new PosHardwareAttachRefusal('No such card reader sale.', 404)\n const before = from.data() as PosHardwareOrder\n if (before.source !== 'in_person' || before.posSale?.hostId !== config.sellerHostId) {\n throw new PosHardwareAttachRefusal('Only a card reader sold in person here can be detached.', 409)\n }\n if (before.attachment?.state !== 'attached') return { order: before }\n if ((before.units ?? []).some((unit) => unit.readerId)) {\n throw new PosHardwareAttachRefusal('A reader from this sale is already set up on the buyer’s store.', 409)\n }\n const after: PosHardwareOrder = {\n ...before,\n orgId: config.sellerOrgId,\n hostId: '',\n createdBy: null,\n contactEmail: null,\n attachment: posHardwareAttachmentOf(null),\n updatedAtMs: now,\n }\n transaction.create(hardwareOrdersRef(config.sellerOrgId).doc(orderId), after)\n transaction.delete(fromRef)\n transaction.set(saleRef, posHardwareSaleRecord(orderId, after), posHardwareSaleSetOptions(after))\n const registerOrderId = before.posSale?.orderId\n if (registerOrderId) {\n transaction.set(\n firestore().collection('hosts').doc(config.sellerHostId).collection('orders').doc(registerOrderId),\n { hardwareBuyer: firebaseAdmin.firestore.FieldValue.delete() },\n { merge: true },\n )\n }\n return { order: after }\n })\n}\n\n/**\n * A workspace was just created: every pending sale naming its owner — their\n * account, or their address once verified — moves into it. Never throws:\n * a sale it cannot move stays on the To attach list.\n */\nexport async function claimPosHardwareForNewWorkspace(input: {\n config: PosHardwareInPersonConfig | null\n orgId: string\n ownerUid: string\n ownerEmail: string | null\n emailVerified: boolean\n}): Promise<{ claimed: number }> {\n const { config } = input\n if (!config || !id(input.orgId) || !id(input.ownerUid)) return { claimed: 0 }\n const pending = hardwareOrdersRef(config.sellerOrgId)\n const email = input.emailVerified ? String(input.ownerEmail ?? '').trim().toLowerCase() : ''\n const [byUid, byEmail] = await Promise.all([\n pending.where('attachment.uid', '==', input.ownerUid).limit(20).get(),\n email ? pending.where('attachment.email', '==', email).limit(20).get() : Promise.resolve({ docs: [] }),\n ])\n const ids = new Set<string>()\n for (const doc of [...byUid.docs, ...byEmail.docs] as Array<{ id: string; data: () => PosHardwareOrder }>) {\n if (doc.data().attachment?.state === 'pending') ids.add(String(doc.id))\n }\n let claimed = 0\n // Their account's name, for the reseller's records of the sale.\n const owner = ids.size ? await findUserByUidAcrossPools(input.ownerUid).catch(() => null) : null\n const name = String(owner?.record.displayName ?? '').trim().slice(0, 200) || null\n for (const orderId of ids) {\n try {\n await moveRecordedOrder({\n orderId,\n buyer: {\n uid: input.ownerUid,\n orgId: input.orgId,\n hostId: null,\n // Their account's address carries the order's emails from now on.\n email: String(input.ownerEmail ?? '').trim().toLowerCase() || null,\n name,\n },\n attachedBy: null,\n config,\n now: Date.now(),\n requirePending: true,\n })\n claimed += 1\n } catch (error) {\n console.error('[pos-hardware-attach] a pending sale was not claimed', orderId, error)\n }\n }\n return { claimed }\n}\n"],"names":["firebaseAdmin","findUserByEmailAcrossPools","findUserByUidAcrossPools","POS_HARDWARE_ORDER_ID","posHardwareBuyerAddress","posHardwareSaleRecord","posHardwareSaleSetOptions","posHardwareAttachmentOf","hardwareOrdersRef","posHardwareInPersonOrderId","posHardwareSaleRef","recordInPersonPosHardwareSale","sendPosHardwareInvite","PosHardwareAttachRefusal","Error","message","status","ID","EMAIL","id","value","test","trim","firestore","app","typedIdentity","request","name","slice","address","undefined","checkHardwareBuyer","uid","orgId","hostId","typed","user","email","String","record","toLowerCase","displayName","member","collection","doc","get","exists","host","orderBuyer","buyer","attachedBy","now","attachedAtMs","moveRecordedOrder","input","orderId","config","saleRef","runTransaction","transaction","sale","fresh","attachment","before","fromOrgId","fromRef","from","data","source","posSale","sellerHostId","samePerson","Boolean","same","state","JSON","stringify","order","requirePending","toOrgId","sellerOrgId","after","createdBy","contactEmail","invitedAtMs","updatedAtMs","set","create","delete","registerOrderId","hardwareBuyer","merge","attachPosHardwareSale","Date","recorded","register","registerRef","outcome","settled","moved","known","current","invitePendingBuyer","fillPosHardwareBuyerAddress","ref","claimed","snapshot","next","update","detachPosHardwareSale","units","some","unit","readerId","FieldValue","claimPosHardwareForNewWorkspace","ownerUid","pending","emailVerified","ownerEmail","byUid","byEmail","Promise","all","where","limit","resolve","docs","ids","Set","add","owner","size","catch","error","console"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,aAAa,QAAQ,2BAA0B;AACxD,SACEC,0BAA0B,EAC1BC,wBAAwB,QACnB,6CAA4C;AAEnD,SACEC,qBAAqB,EACrBC,uBAAuB,EACvBC,qBAAqB,EACrBC,yBAAyB,QAIpB,2BAAuB;AAC9B,SAASC,uBAAuB,QAAQ,qCAAiC;AACzE,SAASC,iBAAiB,EAAEC,0BAA0B,EAAEC,kBAAkB,QAAQ,oBAAgB;AAClG,SAASC,6BAA6B,QAAQ,8BAA0B;AACxE,SAASC,qBAAqB,QAAQ,2BAAuB;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;2CAwB2C,GAE3C,OAAO,MAAMC,iCAAiCC;IAC5C,YACEC,OAAe,EACf,AAASC,MAAc,CACvB;QACA,KAAK,CAACD,eAFGC,SAAAA;IAGX;AACF;AAcA,MAAMC,KAAK;AACX,MAAMC,QAAQ;AAEd,MAAMC,KAAK,CAACC,QAAmC,OAAOA,UAAU,YAAYH,GAAGI,IAAI,CAACD,MAAME,IAAI,MAAMF,MAAME,IAAI,KAAK;AAEnH,SAASC;IACP,OAAOvB,cAAcwB,GAAG,GAAGD,SAAS;AACtC;AAiBA,0FAA0F,GAC1F,SAASE,cAAcC,OAAgC;IACrD,MAAMC,OAAO,OAAOD,QAAQC,IAAI,KAAK,YAAYD,QAAQC,IAAI,CAACL,IAAI,KAAKI,QAAQC,IAAI,CAACL,IAAI,GAAGM,KAAK,CAAC,GAAG,OAAO;IAC3G,IAAIF,QAAQG,OAA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