@aglyn/plugins-commerce 1.0.0-beta.229 → 1.0.0-beta.231
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/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 +84 -5
- 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 +729 -657
- package/src/lib/components/console/pos-page.component.js.map +1 -1
- package/src/lib/components/console/product-editor-dialog.component.js +51 -7
- 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 +58 -2
- package/src/lib/components/console/product-zones.js +10 -2
- package/src/lib/components/console/product-zones.js.map +1 -1
- package/src/lib/components/console/products-hub-card.component.js +51 -11
- 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/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 +44 -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 +47 -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 +127 -1
- package/src/lib/model/commerce-orders.js +24 -15
- 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 +88 -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 +15 -0
- package/src/lib/model/index.js +15 -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/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 +23 -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/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-ai-capability.d.ts +42 -0
- package/src/lib/server/product-ai-capability.js +159 -0
- package/src/lib/server/product-ai-capability.js.map +1 -0
- package/src/lib/server/product-catalog.d.ts +42 -0
- package/src/lib/server/product-catalog.js +305 -0
- package/src/lib/server/product-catalog.js.map +1 -0
- package/src/lib/server/product-drafts.d.ts +119 -0
- package/src/lib/server/product-drafts.js +384 -0
- package/src/lib/server/product-drafts.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 +146 -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 +123 -0
- package/src/lib/testing/memory-firestore.js +274 -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/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/utils/use-storefront-purchase-event.js +4 -0
- package/src/lib/utils/use-storefront-purchase-event.js.map +1 -1
- package/src/lib/server/feed.js +0 -69
- package/src/lib/server/feed.js.map +0 -1
|
@@ -0,0 +1,339 @@
|
|
|
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 { POS_PIN_LOCKOUT_MS, POS_PIN_MAX_ATTEMPTS, posPinProblem } from "../model/commerce-pos-ops.js";
|
|
18
|
+
import { hashMemberPassword, verifyMemberPassword } from "./membership.js";
|
|
19
|
+
import { authorizePosOps, defaultPosOpsDeps, isPosManager, mayWorkRegister, mintPosAssertion, posOpsBody, posOpsCleanId, readPosAssertion, readPosRegister, resolvePosStaffAssertion } from "./pos-ops-gate.js";
|
|
20
|
+
function pinRef(hostRef, uid) {
|
|
21
|
+
return hostRef.collection('posStaffPins').doc(uid);
|
|
22
|
+
}
|
|
23
|
+
export async function handlePosStaffPin(deps, req) {
|
|
24
|
+
var _body_action;
|
|
25
|
+
if (req.method !== 'POST') return {
|
|
26
|
+
status: 405,
|
|
27
|
+
body: {
|
|
28
|
+
error: 'Method not allowed'
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const body = posOpsBody(req);
|
|
32
|
+
const gate = await authorizePosOps(deps, req, body['hostId']);
|
|
33
|
+
if ('error' in gate) return {
|
|
34
|
+
status: gate.status,
|
|
35
|
+
body: {
|
|
36
|
+
error: gate.error
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const staff = gate.staff;
|
|
40
|
+
const action = String((_body_action = body['action']) != null ? _body_action : '');
|
|
41
|
+
const firestore = deps.firestore();
|
|
42
|
+
switch(action){
|
|
43
|
+
case 'status':
|
|
44
|
+
{
|
|
45
|
+
const snapshot = await pinRef(staff.hostRef, staff.uid).get();
|
|
46
|
+
return {
|
|
47
|
+
status: 200,
|
|
48
|
+
body: {
|
|
49
|
+
hasPin: snapshot.exists && Boolean(snapshot.get('pinScrypt')),
|
|
50
|
+
isManager: staff.isManager
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
case 'set':
|
|
55
|
+
case 'clear':
|
|
56
|
+
{
|
|
57
|
+
var _body_pin;
|
|
58
|
+
const target = posOpsCleanId(body['memberUid']) || staff.uid;
|
|
59
|
+
if (target !== staff.uid && !staff.isManager) {
|
|
60
|
+
return {
|
|
61
|
+
status: 403,
|
|
62
|
+
body: {
|
|
63
|
+
error: "Only a workspace admin can set another member's PIN."
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (target !== staff.uid) {
|
|
68
|
+
var _host_get;
|
|
69
|
+
const host = await staff.hostRef.get();
|
|
70
|
+
const role = ((_host_get = host.get('memberRoles')) != null ? _host_get : {})[target];
|
|
71
|
+
if (role !== 'admin' && role !== 'editor') {
|
|
72
|
+
return {
|
|
73
|
+
status: 404,
|
|
74
|
+
body: {
|
|
75
|
+
error: 'That member does not work on this site.'
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (action === 'clear') {
|
|
81
|
+
await pinRef(staff.hostRef, target).delete();
|
|
82
|
+
return {
|
|
83
|
+
status: 200,
|
|
84
|
+
body: {
|
|
85
|
+
ok: true,
|
|
86
|
+
hasPin: false
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const pin = String((_body_pin = body['pin']) != null ? _body_pin : '');
|
|
91
|
+
const problem = posPinProblem(pin);
|
|
92
|
+
if (problem) return {
|
|
93
|
+
status: 400,
|
|
94
|
+
body: {
|
|
95
|
+
error: problem
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
await pinRef(staff.hostRef, target).set({
|
|
99
|
+
pinScrypt: hashMemberPassword(pin),
|
|
100
|
+
setAtMs: deps.now(),
|
|
101
|
+
setBy: staff.uid,
|
|
102
|
+
failedAttempts: 0,
|
|
103
|
+
lockedUntilMs: null
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
status: 200,
|
|
107
|
+
body: {
|
|
108
|
+
ok: true,
|
|
109
|
+
hasPin: true
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
case 'roster':
|
|
114
|
+
{
|
|
115
|
+
var _host_get1;
|
|
116
|
+
const host = await staff.hostRef.get();
|
|
117
|
+
const roles = (_host_get1 = host.get('memberRoles')) != null ? _host_get1 : {};
|
|
118
|
+
const pins = await staff.hostRef.collection('posStaffPins').limit(200).get();
|
|
119
|
+
const staffWithPins = pins.docs.map((doc)=>doc.id).filter((uid)=>roles[uid] === 'admin' || roles[uid] === 'editor');
|
|
120
|
+
const members = await Promise.all(staffWithPins.map(async (uid)=>({
|
|
121
|
+
uid,
|
|
122
|
+
name: await deps.memberName(uid)
|
|
123
|
+
})));
|
|
124
|
+
members.sort((a, b)=>a.name.localeCompare(b.name));
|
|
125
|
+
return {
|
|
126
|
+
status: 200,
|
|
127
|
+
body: {
|
|
128
|
+
members
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
case 'verify':
|
|
133
|
+
{
|
|
134
|
+
var _body_pin1, _host_get2;
|
|
135
|
+
const register = await readPosRegister(staff, body['registerId']);
|
|
136
|
+
if ('error' in register) return {
|
|
137
|
+
status: register.status,
|
|
138
|
+
body: {
|
|
139
|
+
error: register.error
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const purpose = body['purpose'] === 'manager' ? 'manager' : 'cashier';
|
|
143
|
+
const memberUid = posOpsCleanId(body['memberUid']);
|
|
144
|
+
const pin = String((_body_pin1 = body['pin']) != null ? _body_pin1 : '');
|
|
145
|
+
if (!memberUid || !/^\d{4,6}$/.test(pin)) {
|
|
146
|
+
return {
|
|
147
|
+
status: 400,
|
|
148
|
+
body: {
|
|
149
|
+
error: 'Choose your name and enter your PIN.'
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const ref = pinRef(staff.hostRef, memberUid);
|
|
154
|
+
const now = deps.now();
|
|
155
|
+
// Claim the attempt first; the PIN is checked only inside the budget.
|
|
156
|
+
const claim = await firestore.runTransaction(async (transaction)=>{
|
|
157
|
+
var _snapshot_get, _snapshot_get1;
|
|
158
|
+
const snapshot = await transaction.get(ref);
|
|
159
|
+
if (!snapshot.exists || !snapshot.get('pinScrypt')) return {
|
|
160
|
+
kind: 'none'
|
|
161
|
+
};
|
|
162
|
+
const lockedUntilMs = Number((_snapshot_get = snapshot.get('lockedUntilMs')) != null ? _snapshot_get : 0);
|
|
163
|
+
if (lockedUntilMs > now) return {
|
|
164
|
+
kind: 'locked',
|
|
165
|
+
lockedUntilMs
|
|
166
|
+
};
|
|
167
|
+
const failed = lockedUntilMs ? 0 : Number((_snapshot_get1 = snapshot.get('failedAttempts')) != null ? _snapshot_get1 : 0);
|
|
168
|
+
if (failed >= POS_PIN_MAX_ATTEMPTS) {
|
|
169
|
+
const until = now + POS_PIN_LOCKOUT_MS;
|
|
170
|
+
transaction.update(ref, {
|
|
171
|
+
lockedUntilMs: until,
|
|
172
|
+
failedAttempts: 0
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
kind: 'locked',
|
|
176
|
+
lockedUntilMs: until
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
transaction.update(ref, {
|
|
180
|
+
failedAttempts: failed + 1,
|
|
181
|
+
lockedUntilMs: null
|
|
182
|
+
});
|
|
183
|
+
return {
|
|
184
|
+
kind: 'claimed',
|
|
185
|
+
hash: String(snapshot.get('pinScrypt')),
|
|
186
|
+
attempt: failed + 1
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
if (claim.kind === 'none') {
|
|
190
|
+
return {
|
|
191
|
+
status: 404,
|
|
192
|
+
body: {
|
|
193
|
+
error: 'That member has not set a PIN on this site.'
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
if (claim.kind === 'locked') {
|
|
198
|
+
return {
|
|
199
|
+
status: 423,
|
|
200
|
+
body: {
|
|
201
|
+
error: 'Too many wrong PINs. Try again later, or ask a workspace admin to reset it.',
|
|
202
|
+
lockedUntilMs: claim.lockedUntilMs
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
if (!verifyMemberPassword(pin, claim.hash)) {
|
|
207
|
+
const left = POS_PIN_MAX_ATTEMPTS - claim.attempt;
|
|
208
|
+
if (left <= 0) {
|
|
209
|
+
await ref.update({
|
|
210
|
+
lockedUntilMs: now + POS_PIN_LOCKOUT_MS,
|
|
211
|
+
failedAttempts: 0
|
|
212
|
+
});
|
|
213
|
+
return {
|
|
214
|
+
status: 423,
|
|
215
|
+
body: {
|
|
216
|
+
error: 'Too many wrong PINs. Try again later, or ask a workspace admin to reset it.',
|
|
217
|
+
lockedUntilMs: now + POS_PIN_LOCKOUT_MS
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
status: 401,
|
|
223
|
+
body: {
|
|
224
|
+
error: `That PIN is not right. ${left} ${left === 1 ? 'try' : 'tries'} left.`,
|
|
225
|
+
attemptsLeft: left
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
await ref.update({
|
|
230
|
+
failedAttempts: 0,
|
|
231
|
+
lockedUntilMs: null,
|
|
232
|
+
lastUsedAtMs: now
|
|
233
|
+
});
|
|
234
|
+
// The PIN is right; whether it still buys anything is today's role.
|
|
235
|
+
const host = await staff.hostRef.get();
|
|
236
|
+
const role = ((_host_get2 = host.get('memberRoles')) != null ? _host_get2 : {})[memberUid];
|
|
237
|
+
const membership = await deps.membership(memberUid, staff.hostId);
|
|
238
|
+
const allowed = purpose === 'manager' ? isPosManager(role, membership) : mayWorkRegister(role, membership);
|
|
239
|
+
if (!allowed) {
|
|
240
|
+
return {
|
|
241
|
+
status: 403,
|
|
242
|
+
body: {
|
|
243
|
+
error: purpose === 'manager' ? 'Only a workspace admin can approve this.' : 'That member cannot use the register.'
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
let minted;
|
|
248
|
+
try {
|
|
249
|
+
minted = mintPosAssertion(deps, {
|
|
250
|
+
hostId: staff.hostId,
|
|
251
|
+
registerId: register.ref.id,
|
|
252
|
+
memberUid,
|
|
253
|
+
purpose
|
|
254
|
+
});
|
|
255
|
+
} catch (unused) {
|
|
256
|
+
return {
|
|
257
|
+
status: 501,
|
|
258
|
+
body: {
|
|
259
|
+
error: 'Staff PINs are not configured on this server.'
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
status: 200,
|
|
265
|
+
body: {
|
|
266
|
+
assertion: minted.token,
|
|
267
|
+
expiresAtMs: minted.expiresAtMs,
|
|
268
|
+
memberUid,
|
|
269
|
+
name: await deps.memberName(memberUid),
|
|
270
|
+
purpose
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
case 'refresh':
|
|
275
|
+
{
|
|
276
|
+
const register = await readPosRegister(staff, body['registerId']);
|
|
277
|
+
if ('error' in register) return {
|
|
278
|
+
status: register.status,
|
|
279
|
+
body: {
|
|
280
|
+
error: register.error
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
const expected = {
|
|
284
|
+
hostId: staff.hostId,
|
|
285
|
+
registerId: register.ref.id,
|
|
286
|
+
purpose: 'cashier'
|
|
287
|
+
};
|
|
288
|
+
if (!readPosAssertion(deps, body['assertion'], expected)) {
|
|
289
|
+
return {
|
|
290
|
+
status: 401,
|
|
291
|
+
body: {
|
|
292
|
+
error: 'Enter your PIN again.'
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
const memberUid = await resolvePosStaffAssertion(deps, staff.hostRef, body['assertion'], expected);
|
|
297
|
+
if (!memberUid) return {
|
|
298
|
+
status: 403,
|
|
299
|
+
body: {
|
|
300
|
+
error: 'That member cannot use the register.'
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const minted = mintPosAssertion(deps, _extends({}, expected, {
|
|
304
|
+
memberUid
|
|
305
|
+
}));
|
|
306
|
+
return {
|
|
307
|
+
status: 200,
|
|
308
|
+
body: {
|
|
309
|
+
assertion: minted.token,
|
|
310
|
+
expiresAtMs: minted.expiresAtMs,
|
|
311
|
+
memberUid
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
default:
|
|
316
|
+
return {
|
|
317
|
+
status: 400,
|
|
318
|
+
body: {
|
|
319
|
+
error: 'Unknown action'
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
export function createPosStaffPinHandler(deps = defaultPosOpsDeps) {
|
|
325
|
+
return async (req, res)=>{
|
|
326
|
+
try {
|
|
327
|
+
const outcome = await handlePosStaffPin(deps(), req);
|
|
328
|
+
return res.status(outcome.status).json(outcome.body);
|
|
329
|
+
} catch (error) {
|
|
330
|
+
console.error('[pos-staff-pin] failed', error);
|
|
331
|
+
return res.status(500).json({
|
|
332
|
+
error: 'The PIN could not be checked'
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
export const posStaffPinHandler = createPosStaffPinHandler();
|
|
338
|
+
|
|
339
|
+
//# sourceMappingURL=pos-staff-pin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/pos-staff-pin.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 { PluginApiHandler, PluginApiRequest } from '@aglyn/aglyn/server'\nimport {\n POS_PIN_LOCKOUT_MS,\n POS_PIN_MAX_ATTEMPTS,\n posPinProblem,\n} from '../model/commerce-pos-ops'\nimport { hashMemberPassword, verifyMemberPassword } from './membership'\nimport {\n authorizePosOps,\n defaultPosOpsDeps,\n isPosManager,\n mayWorkRegister,\n mintPosAssertion,\n posOpsBody,\n posOpsCleanId,\n readPosAssertion,\n readPosRegister,\n resolvePosStaffAssertion,\n type PosAssertionPurpose,\n type PosOpsDeps,\n} from './pos-ops-gate'\n\n/*==========================================\n * STAFF PINS (AGL-3609): `POST /api/commerce/pos-staff-pin`.\n *\n * status whether the signed-in member has a PIN on this site\n * set a member sets their own PIN; a workspace admin may set or\n * reset anyone's, which also lifts a lockout\n * clear the same, removing it\n * roster who can switch in at this register: members with a PIN\n * verify a member's PIN at a register → a signed, short-lived\n * assertion that they are at it (`cashier`), or that a manager\n * approved one action (`manager`)\n * refresh a still-valid cashier assertion → a fresh one, re-checked\n *\n * The hash is scrypt with a per-PIN salt — the membership password helper —\n * at `hosts/{hostId}/posStaffPins/{uid}`, a collection no client may read or\n * write (the rules deny it outright, staff included).\n *\n * LOCKOUT is counted BEFORE the PIN is checked: each attempt is claimed in a\n * transaction that refuses once {@link POS_PIN_MAX_ATTEMPTS} have failed, so\n * a burst of parallel guesses gets five tries in the lockout window, not five\n * each. A right PIN clears the count.\n *=========================================*/\n\ntype Outcome = { status: number; body: Record<string, unknown> }\n\nfunction pinRef(hostRef: FirebaseFirestore.DocumentReference, uid: string) {\n return hostRef.collection('posStaffPins').doc(uid)\n}\n\nexport async function handlePosStaffPin(deps: PosOpsDeps, req: PluginApiRequest): Promise<Outcome> {\n if (req.method !== 'POST') return { status: 405, body: { error: 'Method not allowed' } }\n const body = posOpsBody(req)\n const gate = await authorizePosOps(deps, req, body['hostId'])\n if ('error' in gate) return { status: gate.status, body: { error: gate.error } }\n const staff = gate.staff\n const action = String(body['action'] ?? '')\n const firestore = deps.firestore()\n\n switch (action) {\n case 'status': {\n const snapshot = await pinRef(staff.hostRef, staff.uid).get()\n return {\n status: 200,\n body: {\n hasPin: snapshot.exists && Boolean(snapshot.get('pinScrypt')),\n isManager: staff.isManager,\n },\n }\n }\n\n case 'set':\n case 'clear': {\n const target = posOpsCleanId(body['memberUid']) || staff.uid\n if (target !== staff.uid && !staff.isManager) {\n return {\n status: 403,\n body: { error: \"Only a workspace admin can set another member's PIN.\" },\n }\n }\n if (target !== staff.uid) {\n const host = await staff.hostRef.get()\n const role = (host.get('memberRoles') ?? {})[target]\n if (role !== 'admin' && role !== 'editor') {\n return { status: 404, body: { error: 'That member does not work on this site.' } }\n }\n }\n if (action === 'clear') {\n await pinRef(staff.hostRef, target).delete()\n return { status: 200, body: { ok: true, hasPin: false } }\n }\n const pin = String(body['pin'] ?? '')\n const problem = posPinProblem(pin)\n if (problem) return { status: 400, body: { error: problem } }\n await pinRef(staff.hostRef, target).set({\n pinScrypt: hashMemberPassword(pin),\n setAtMs: deps.now(),\n setBy: staff.uid,\n failedAttempts: 0,\n lockedUntilMs: null,\n })\n return { status: 200, body: { ok: true, hasPin: true } }\n }\n\n case 'roster': {\n const host = await staff.hostRef.get()\n const roles = (host.get('memberRoles') ?? {}) as Record<string, string>\n const pins = await staff.hostRef.collection('posStaffPins').limit(200).get()\n const staffWithPins = pins.docs\n .map((doc) => doc.id)\n .filter((uid) => roles[uid] === 'admin' || roles[uid] === 'editor')\n const members = await Promise.all(\n staffWithPins.map(async (uid) => ({ uid, name: await deps.memberName(uid) })),\n )\n members.sort((a, b) => a.name.localeCompare(b.name))\n return { status: 200, body: { members } }\n }\n\n case 'verify': {\n const register = await readPosRegister(staff, body['registerId'])\n if ('error' in register) return { status: register.status, body: { error: register.error } }\n const purpose: PosAssertionPurpose = body['purpose'] === 'manager' ? 'manager' : 'cashier'\n const memberUid = posOpsCleanId(body['memberUid'])\n const pin = String(body['pin'] ?? '')\n if (!memberUid || !/^\\d{4,6}$/.test(pin)) {\n return { status: 400, body: { error: 'Choose your name and enter your PIN.' } }\n }\n const ref = pinRef(staff.hostRef, memberUid)\n const now = deps.now()\n // Claim the attempt first; the PIN is checked only inside the budget.\n const claim = await firestore.runTransaction(async (transaction) => {\n const snapshot = await transaction.get(ref)\n if (!snapshot.exists || !snapshot.get('pinScrypt')) return { kind: 'none' as const }\n const lockedUntilMs = Number(snapshot.get('lockedUntilMs') ?? 0)\n if (lockedUntilMs > now) return { kind: 'locked' as const, lockedUntilMs }\n const failed = lockedUntilMs ? 0 : Number(snapshot.get('failedAttempts') ?? 0)\n if (failed >= POS_PIN_MAX_ATTEMPTS) {\n const until = now + POS_PIN_LOCKOUT_MS\n transaction.update(ref, { lockedUntilMs: until, failedAttempts: 0 })\n return { kind: 'locked' as const, lockedUntilMs: until }\n }\n transaction.update(ref, { failedAttempts: failed + 1, lockedUntilMs: null })\n return { kind: 'claimed' as const, hash: String(snapshot.get('pinScrypt')), attempt: failed + 1 }\n })\n if (claim.kind === 'none') {\n return { status: 404, body: { error: 'That member has not set a PIN on this site.' } }\n }\n if (claim.kind === 'locked') {\n return {\n status: 423,\n body: {\n error: 'Too many wrong PINs. Try again later, or ask a workspace admin to reset it.',\n lockedUntilMs: claim.lockedUntilMs,\n },\n }\n }\n if (!verifyMemberPassword(pin, claim.hash)) {\n const left = POS_PIN_MAX_ATTEMPTS - claim.attempt\n if (left <= 0) {\n await ref.update({ lockedUntilMs: now + POS_PIN_LOCKOUT_MS, failedAttempts: 0 })\n return {\n status: 423,\n body: {\n error: 'Too many wrong PINs. Try again later, or ask a workspace admin to reset it.',\n lockedUntilMs: now + POS_PIN_LOCKOUT_MS,\n },\n }\n }\n return {\n status: 401,\n body: { error: `That PIN is not right. ${left} ${left === 1 ? 'try' : 'tries'} left.`, attemptsLeft: left },\n }\n }\n await ref.update({ failedAttempts: 0, lockedUntilMs: null, lastUsedAtMs: now })\n // The PIN is right; whether it still buys anything is today's role.\n const host = await staff.hostRef.get()\n const role = (host.get('memberRoles') ?? {})[memberUid]\n const membership = await deps.membership(memberUid, staff.hostId)\n const allowed =\n purpose === 'manager' ? isPosManager(role, membership) : mayWorkRegister(role, membership)\n if (!allowed) {\n return {\n status: 403,\n body: {\n error:\n purpose === 'manager'\n ? 'Only a workspace admin can approve this.'\n : 'That member cannot use the register.',\n },\n }\n }\n let minted: { token: string; expiresAtMs: number }\n try {\n minted = mintPosAssertion(deps, {\n hostId: staff.hostId,\n registerId: register.ref.id,\n memberUid,\n purpose,\n })\n } catch {\n return { status: 501, body: { error: 'Staff PINs are not configured on this server.' } }\n }\n return {\n status: 200,\n body: {\n assertion: minted.token,\n expiresAtMs: minted.expiresAtMs,\n memberUid,\n name: await deps.memberName(memberUid),\n purpose,\n },\n }\n }\n\n case 'refresh': {\n const register = await readPosRegister(staff, body['registerId'])\n if ('error' in register) return { status: register.status, body: { error: register.error } }\n const expected = { hostId: staff.hostId, registerId: register.ref.id, purpose: 'cashier' as const }\n if (!readPosAssertion(deps, body['assertion'], expected)) {\n return { status: 401, body: { error: 'Enter your PIN again.' } }\n }\n const memberUid = await resolvePosStaffAssertion(deps, staff.hostRef, body['assertion'], expected)\n if (!memberUid) return { status: 403, body: { error: 'That member cannot use the register.' } }\n const minted = mintPosAssertion(deps, { ...expected, memberUid })\n return { status: 200, body: { assertion: minted.token, expiresAtMs: minted.expiresAtMs, memberUid } }\n }\n\n default:\n return { status: 400, body: { error: 'Unknown action' } }\n }\n}\n\nexport function createPosStaffPinHandler(deps: () => PosOpsDeps = defaultPosOpsDeps): PluginApiHandler {\n return async (req, res) => {\n try {\n const outcome = await handlePosStaffPin(deps(), req)\n return res.status(outcome.status).json(outcome.body)\n } catch (error) {\n console.error('[pos-staff-pin] failed', error)\n return res.status(500).json({ error: 'The PIN could not be checked' })\n }\n }\n}\n\nexport const posStaffPinHandler = createPosStaffPinHandler()\n"],"names":["POS_PIN_LOCKOUT_MS","POS_PIN_MAX_ATTEMPTS","posPinProblem","hashMemberPassword","verifyMemberPassword","authorizePosOps","defaultPosOpsDeps","isPosManager","mayWorkRegister","mintPosAssertion","posOpsBody","posOpsCleanId","readPosAssertion","readPosRegister","resolvePosStaffAssertion","pinRef","hostRef","uid","collection","doc","handlePosStaffPin","deps","req","body","method","status","error","gate","staff","action","String","firestore","snapshot","get","hasPin","exists","Boolean","isManager","target","host","role","delete","ok","pin","problem","set","pinScrypt","setAtMs","now","setBy","failedAttempts","lockedUntilMs","roles","pins","limit","staffWithPins","docs","map","id","filter","members","Promise","all","name","memberName","sort","a","b","localeCompare","register","purpose","memberUid","test","ref","claim","runTransaction","transaction","kind","Number","failed","until","update","hash","attempt","left","attemptsLeft","lastUsedAtMs","membership","hostId","allowed","minted","registerId","assertion","token","expiresAtMs","expected","createPosStaffPinHandler","res","outcome","json","console","posStaffPinHandler"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SACEA,kBAAkB,EAClBC,oBAAoB,EACpBC,aAAa,QACR,+BAA2B;AAClC,SAASC,kBAAkB,EAAEC,oBAAoB,QAAQ,kBAAc;AACvE,SACEC,eAAe,EACfC,iBAAiB,EACjBC,YAAY,EACZC,eAAe,EACfC,gBAAgB,EAChBC,UAAU,EACVC,aAAa,EACbC,gBAAgB,EAChBC,eAAe,EACfC,wBAAwB,QAGnB,oBAAgB;AA2BvB,SAASC,OAAOC,OAA4C,EAAEC,GAAW;IACvE,OAAOD,QAAQE,UAAU,CAAC,gBAAgBC,GAAG,CAACF;AAChD;AAEA,OAAO,eAAeG,kBAAkBC,IAAg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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
|
+
/**
|
|
18
|
+
* The register's Stripe calls (AGL-3607), over raw `fetch` like every other
|
|
19
|
+
* money route in this plugin.
|
|
20
|
+
*
|
|
21
|
+
* ## Pinned to one API version
|
|
22
|
+
*
|
|
23
|
+
* The platform account's default version predates the fields this flow reads
|
|
24
|
+
* — `amount_details.tip` on a PaymentIntent, a reader's `action` — so every
|
|
25
|
+
* request here carries the same `Stripe-Version` the storefront Payment
|
|
26
|
+
* Element pins. Webhook deliveries keep the endpoint's version, which is why
|
|
27
|
+
* the webhook branch never trusts the event's object and re-reads the
|
|
28
|
+
* PaymentIntent through {@link posStripe} instead.
|
|
29
|
+
*
|
|
30
|
+
* ## Every create is keyed
|
|
31
|
+
*
|
|
32
|
+
* A caller passes the idempotency key; Stripe replays the first answer for a
|
|
33
|
+
* repeated key, so a lost response cannot become a second charge.
|
|
34
|
+
*/
|
|
35
|
+
export declare const POS_STRIPE_VERSION = "2026-03-25.dahlia";
|
|
36
|
+
/** The currency every register sale is in: the store charges in US dollars. */
|
|
37
|
+
export declare const POS_CURRENCY = "usd";
|
|
38
|
+
export interface PosStripeResult<T = any> {
|
|
39
|
+
ok: boolean;
|
|
40
|
+
status: number;
|
|
41
|
+
body: T & {
|
|
42
|
+
error?: {
|
|
43
|
+
message?: string;
|
|
44
|
+
code?: string;
|
|
45
|
+
type?: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Form-encodes nested params the way Stripe reads them. */
|
|
50
|
+
export declare function posStripeForm(params: Record<string, string | number | boolean | undefined | null | readonly string[]>): URLSearchParams;
|
|
51
|
+
/** One Stripe API request from the register's server routes. */
|
|
52
|
+
export declare function posStripe<T = any>(method: 'GET' | 'POST' | 'DELETE', path: string, options?: {
|
|
53
|
+
params?: Record<string, string | number | boolean | undefined | null | readonly string[]>;
|
|
54
|
+
idempotencyKey?: string;
|
|
55
|
+
}): Promise<PosStripeResult<T>>;
|
|
56
|
+
/** Whether the platform key is a test key: simulated readers only work there. */
|
|
57
|
+
export declare function posStripeTestMode(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Whether Stripe Terminal card readers are offered at all.
|
|
60
|
+
*
|
|
61
|
+
* Always in test mode, where Stripe's simulated reader needs nothing turned
|
|
62
|
+
* on. In live mode only once `STRIPE_TERMINAL_LIVE_ENABLED` is `true`, which
|
|
63
|
+
* is set after Terminal is activated for live payments on the platform's
|
|
64
|
+
* Stripe account. Until then the register and the settings hide every reader
|
|
65
|
+
* control rather than offering hardware that would be refused.
|
|
66
|
+
*/
|
|
67
|
+
export declare function posTerminalAvailable(): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Stripe's processing cost on a register CARD payment, passed through at cost
|
|
70
|
+
* beside the platform's take (the AGL-2152 rule, on the register's tenders).
|
|
71
|
+
*
|
|
72
|
+
* At the CARD rate, not `saleProcessingCostCents`'s dearest-method rate: every
|
|
73
|
+
* register card payment pins its payment method types to `card` or
|
|
74
|
+
* `card_present`, so no buy-now-pay-later method can be chosen and 2.9% + 30¢
|
|
75
|
+
* is at least what Stripe debits (an in-person tap costs less). The base is
|
|
76
|
+
* the whole CHARGE, tip included, because Stripe's own fee is on the whole
|
|
77
|
+
* charge; the platform's take is not.
|
|
78
|
+
*/
|
|
79
|
+
export declare function posCardProcessingCostCents(chargeCents: number): number;
|
|
80
|
+
/** The `application_fee_amount` for a register card payment. */
|
|
81
|
+
export declare function posCardApplicationFeeCents(input: {
|
|
82
|
+
takeShareCents: number;
|
|
83
|
+
chargeCents: number;
|
|
84
|
+
}): number;
|
|
85
|
+
/** A refusal Stripe sent, in words a cashier can read out. */
|
|
86
|
+
export declare function posStripeErrorMessage(body: {
|
|
87
|
+
error?: {
|
|
88
|
+
message?: string;
|
|
89
|
+
code?: string;
|
|
90
|
+
};
|
|
91
|
+
} | undefined, fallback: string): string;
|
|
@@ -0,0 +1,129 @@
|
|
|
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 { CARD_PROCESSING_PERCENT, PROCESSING_FIXED_CENTS } from "@aglyn/aglyn/app-utils/plan-entitlements";
|
|
18
|
+
import { NATIVE_CHECKOUT_STRIPE_VERSION } from "./native-checkout.js";
|
|
19
|
+
/**
|
|
20
|
+
* The register's Stripe calls (AGL-3607), over raw `fetch` like every other
|
|
21
|
+
* money route in this plugin.
|
|
22
|
+
*
|
|
23
|
+
* ## Pinned to one API version
|
|
24
|
+
*
|
|
25
|
+
* The platform account's default version predates the fields this flow reads
|
|
26
|
+
* — `amount_details.tip` on a PaymentIntent, a reader's `action` — so every
|
|
27
|
+
* request here carries the same `Stripe-Version` the storefront Payment
|
|
28
|
+
* Element pins. Webhook deliveries keep the endpoint's version, which is why
|
|
29
|
+
* the webhook branch never trusts the event's object and re-reads the
|
|
30
|
+
* PaymentIntent through {@link posStripe} instead.
|
|
31
|
+
*
|
|
32
|
+
* ## Every create is keyed
|
|
33
|
+
*
|
|
34
|
+
* A caller passes the idempotency key; Stripe replays the first answer for a
|
|
35
|
+
* repeated key, so a lost response cannot become a second charge.
|
|
36
|
+
*/ export const POS_STRIPE_VERSION = NATIVE_CHECKOUT_STRIPE_VERSION;
|
|
37
|
+
/** The currency every register sale is in: the store charges in US dollars. */ export const POS_CURRENCY = 'usd';
|
|
38
|
+
/** Form-encodes nested params the way Stripe reads them. */ export function posStripeForm(params) {
|
|
39
|
+
const form = new URLSearchParams();
|
|
40
|
+
for (const [key, value] of Object.entries(params)){
|
|
41
|
+
if (value === undefined || value === null) continue;
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
for (const item of value)form.append(`${key}[]`, String(item));
|
|
44
|
+
} else {
|
|
45
|
+
form.set(key, String(value));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return form;
|
|
49
|
+
}
|
|
50
|
+
/** One Stripe API request from the register's server routes. */ export async function posStripe(method, path, options = {}) {
|
|
51
|
+
var _options_params;
|
|
52
|
+
const form = posStripeForm((_options_params = options.params) != null ? _options_params : {});
|
|
53
|
+
const query = method === 'GET' && [
|
|
54
|
+
...form.keys()
|
|
55
|
+
].length ? `?${form.toString()}` : '';
|
|
56
|
+
const response = await fetch(`https://api.stripe.com/v1/${path}${query}`, _extends({
|
|
57
|
+
method,
|
|
58
|
+
headers: _extends({
|
|
59
|
+
Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`,
|
|
60
|
+
'Stripe-Version': POS_STRIPE_VERSION
|
|
61
|
+
}, method === 'POST' ? {
|
|
62
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
63
|
+
} : {}, options.idempotencyKey && method === 'POST' ? {
|
|
64
|
+
'Idempotency-Key': options.idempotencyKey.slice(0, 255)
|
|
65
|
+
} : {})
|
|
66
|
+
}, method === 'POST' ? {
|
|
67
|
+
body: form.toString()
|
|
68
|
+
} : {}));
|
|
69
|
+
const body = await response.json().catch(()=>({}));
|
|
70
|
+
return {
|
|
71
|
+
ok: response.ok,
|
|
72
|
+
status: response.status,
|
|
73
|
+
body
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Whether the platform key is a test key: simulated readers only work there. */ export function posStripeTestMode() {
|
|
77
|
+
var _process_env_STRIPE_SECRET_KEY;
|
|
78
|
+
return String((_process_env_STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY) != null ? _process_env_STRIPE_SECRET_KEY : '').startsWith('sk_test_');
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Whether Stripe Terminal card readers are offered at all.
|
|
82
|
+
*
|
|
83
|
+
* Always in test mode, where Stripe's simulated reader needs nothing turned
|
|
84
|
+
* on. In live mode only once `STRIPE_TERMINAL_LIVE_ENABLED` is `true`, which
|
|
85
|
+
* is set after Terminal is activated for live payments on the platform's
|
|
86
|
+
* Stripe account. Until then the register and the settings hide every reader
|
|
87
|
+
* control rather than offering hardware that would be refused.
|
|
88
|
+
*/ export function posTerminalAvailable() {
|
|
89
|
+
var _process_env_STRIPE_TERMINAL_LIVE_ENABLED;
|
|
90
|
+
if (!process.env.STRIPE_SECRET_KEY) return false;
|
|
91
|
+
return posStripeTestMode() || String((_process_env_STRIPE_TERMINAL_LIVE_ENABLED = process.env.STRIPE_TERMINAL_LIVE_ENABLED) != null ? _process_env_STRIPE_TERMINAL_LIVE_ENABLED : '').toLowerCase() === 'true';
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Stripe's processing cost on a register CARD payment, passed through at cost
|
|
95
|
+
* beside the platform's take (the AGL-2152 rule, on the register's tenders).
|
|
96
|
+
*
|
|
97
|
+
* At the CARD rate, not `saleProcessingCostCents`'s dearest-method rate: every
|
|
98
|
+
* register card payment pins its payment method types to `card` or
|
|
99
|
+
* `card_present`, so no buy-now-pay-later method can be chosen and 2.9% + 30¢
|
|
100
|
+
* is at least what Stripe debits (an in-person tap costs less). The base is
|
|
101
|
+
* the whole CHARGE, tip included, because Stripe's own fee is on the whole
|
|
102
|
+
* charge; the platform's take is not.
|
|
103
|
+
*/ export function posCardProcessingCostCents(chargeCents) {
|
|
104
|
+
if (!Number.isFinite(chargeCents) || chargeCents <= 0) return 0;
|
|
105
|
+
return Math.ceil(chargeCents * CARD_PROCESSING_PERCENT / 100) + PROCESSING_FIXED_CENTS;
|
|
106
|
+
}
|
|
107
|
+
/** The `application_fee_amount` for a register card payment. */ export function posCardApplicationFeeCents(input) {
|
|
108
|
+
// The processing half is owed even on a plan whose take is 0%: Stripe debits
|
|
109
|
+
// it from the platform on every destination charge (AGL-2071).
|
|
110
|
+
const take = Math.max(0, Math.round(input.takeShareCents));
|
|
111
|
+
return take + posCardProcessingCostCents(input.chargeCents);
|
|
112
|
+
}
|
|
113
|
+
/** A refusal Stripe sent, in words a cashier can read out. */ export function posStripeErrorMessage(body, fallback) {
|
|
114
|
+
var _ref, _ref1;
|
|
115
|
+
var _body_error, _body_error1;
|
|
116
|
+
const code = String((_ref = body == null ? void 0 : (_body_error = body.error) == null ? void 0 : _body_error.code) != null ? _ref : '');
|
|
117
|
+
if (code === 'terminal_reader_offline') {
|
|
118
|
+
return 'The card reader is offline. Check it is on and connected to the internet.';
|
|
119
|
+
}
|
|
120
|
+
if (code === 'terminal_reader_busy') {
|
|
121
|
+
return 'The card reader is busy with another payment. Cancel it on the reader or wait a moment.';
|
|
122
|
+
}
|
|
123
|
+
if (code === 'terminal_reader_timeout') {
|
|
124
|
+
return 'The card reader did not answer in time. Try again.';
|
|
125
|
+
}
|
|
126
|
+
return String((_ref1 = body == null ? void 0 : (_body_error1 = body.error) == null ? void 0 : _body_error1.message) != null ? _ref1 : '') || fallback;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//# sourceMappingURL=pos-stripe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/pos-stripe.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 {\n CARD_PROCESSING_PERCENT,\n PROCESSING_FIXED_CENTS,\n} from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport { NATIVE_CHECKOUT_STRIPE_VERSION } from './native-checkout'\n\n/**\n * The register's Stripe calls (AGL-3607), over raw `fetch` like every other\n * money route in this plugin.\n *\n * ## Pinned to one API version\n *\n * The platform account's default version predates the fields this flow reads\n * — `amount_details.tip` on a PaymentIntent, a reader's `action` — so every\n * request here carries the same `Stripe-Version` the storefront Payment\n * Element pins. Webhook deliveries keep the endpoint's version, which is why\n * the webhook branch never trusts the event's object and re-reads the\n * PaymentIntent through {@link posStripe} instead.\n *\n * ## Every create is keyed\n *\n * A caller passes the idempotency key; Stripe replays the first answer for a\n * repeated key, so a lost response cannot become a second charge.\n */\nexport const POS_STRIPE_VERSION = NATIVE_CHECKOUT_STRIPE_VERSION\n\n/** The currency every register sale is in: the store charges in US dollars. */\nexport const POS_CURRENCY = 'usd'\n\nexport interface PosStripeResult<T = any> {\n ok: boolean\n status: number\n body: T & { error?: { message?: string; code?: string; type?: string } }\n}\n\n/** Form-encodes nested params the way Stripe reads them. */\nexport function posStripeForm(\n params: Record<string, string | number | boolean | undefined | null | readonly string[]>,\n): URLSearchParams {\n const form = new URLSearchParams()\n for (const [key, value] of Object.entries(params)) {\n if (value === undefined || value === null) continue\n if (Array.isArray(value)) {\n for (const item of value) form.append(`${key}[]`, String(item))\n } else {\n form.set(key, String(value))\n }\n }\n return form\n}\n\n/** One Stripe API request from the register's server routes. */\nexport async function posStripe<T = any>(\n method: 'GET' | 'POST' | 'DELETE',\n path: string,\n options: {\n params?: Record<string, string | number | boolean | undefined | null | readonly string[]>\n idempotencyKey?: string\n } = {},\n): Promise<PosStripeResult<T>> {\n const form = posStripeForm(options.params ?? {})\n const query = method === 'GET' && [...form.keys()].length ? `?${form.toString()}` : ''\n const response = await fetch(`https://api.stripe.com/v1/${path}${query}`, {\n method,\n headers: {\n Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`,\n 'Stripe-Version': POS_STRIPE_VERSION,\n ...(method === 'POST'\n ? { 'Content-Type': 'application/x-www-form-urlencoded' }\n : {}),\n ...(options.idempotencyKey && method === 'POST'\n ? { 'Idempotency-Key': options.idempotencyKey.slice(0, 255) }\n : {}),\n },\n ...(method === 'POST' ? { body: form.toString() } : {}),\n })\n const body = (await response.json().catch(() => ({}))) as PosStripeResult<T>['body']\n return { ok: response.ok, status: response.status, body }\n}\n\n/** Whether the platform key is a test key: simulated readers only work there. */\nexport function posStripeTestMode(): boolean {\n return String(process.env.STRIPE_SECRET_KEY ?? '').startsWith('sk_test_')\n}\n\n/**\n * Whether Stripe Terminal card readers are offered at all.\n *\n * Always in test mode, where Stripe's simulated reader needs nothing turned\n * on. In live mode only once `STRIPE_TERMINAL_LIVE_ENABLED` is `true`, which\n * is set after Terminal is activated for live payments on the platform's\n * Stripe account. Until then the register and the settings hide every reader\n * control rather than offering hardware that would be refused.\n */\nexport function posTerminalAvailable(): boolean {\n if (!process.env.STRIPE_SECRET_KEY) return false\n return (\n posStripeTestMode() ||\n String(process.env.STRIPE_TERMINAL_LIVE_ENABLED ?? '').toLowerCase() === 'true'\n )\n}\n\n/**\n * Stripe's processing cost on a register CARD payment, passed through at cost\n * beside the platform's take (the AGL-2152 rule, on the register's tenders).\n *\n * At the CARD rate, not `saleProcessingCostCents`'s dearest-method rate: every\n * register card payment pins its payment method types to `card` or\n * `card_present`, so no buy-now-pay-later method can be chosen and 2.9% + 30¢\n * is at least what Stripe debits (an in-person tap costs less). The base is\n * the whole CHARGE, tip included, because Stripe's own fee is on the whole\n * charge; the platform's take is not.\n */\nexport function posCardProcessingCostCents(chargeCents: number): number {\n if (!Number.isFinite(chargeCents) || chargeCents <= 0) return 0\n return (\n Math.ceil((chargeCents * CARD_PROCESSING_PERCENT) / 100) + PROCESSING_FIXED_CENTS\n )\n}\n\n/** The `application_fee_amount` for a register card payment. */\nexport function posCardApplicationFeeCents(input: {\n takeShareCents: number\n chargeCents: number\n}): number {\n // The processing half is owed even on a plan whose take is 0%: Stripe debits\n // it from the platform on every destination charge (AGL-2071).\n const take = Math.max(0, Math.round(input.takeShareCents))\n return take + posCardProcessingCostCents(input.chargeCents)\n}\n\n/** A refusal Stripe sent, in words a cashier can read out. */\nexport function posStripeErrorMessage(\n body: { error?: { message?: string; code?: string } } | undefined,\n fallback: string,\n): string {\n const code = String(body?.error?.code ?? '')\n if (code === 'terminal_reader_offline') {\n return 'The card reader is offline. Check it is on and connected to the internet.'\n }\n if (code === 'terminal_reader_busy') {\n return 'The card reader is busy with another payment. Cancel it on the reader or wait a moment.'\n }\n if (code === 'terminal_reader_timeout') {\n return 'The card reader did not answer in time. Try again.'\n }\n return String(body?.error?.message ?? '') || fallback\n}\n"],"names":["CARD_PROCESSING_PERCENT","PROCESSING_FIXED_CENTS","NATIVE_CHECKOUT_STRIPE_VERSION","POS_STRIPE_VERSION","POS_CURRENCY","posStripeForm","params","form","URLSearchParams","key","value","Object","entries","undefined","Array","isArray","item","append","String","set","posStripe","method","path","options","query","keys","length","toString","response","fetch","headers","Authorization","process","env","STRIPE_SECRET_KEY","idempotencyKey","slice","body","json","catch","ok","status","posStripeTestMode","startsWith","posTerminalAvailable","STRIPE_TERMINAL_LIVE_ENABLED","toLowerCase","posCardProcessingCostCents","chargeCents","Number","isFinite","Math","ceil","posCardApplicationFeeCents","input","take","max","round","takeShareCents","posStripeErrorMessage","fallback","code","error","message"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,uBAAuB,EACvBC,sBAAsB,QACjB,2CAA0C;AACjD,SAASC,8BAA8B,QAAQ,uBAAmB;AAElE;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,MAAMC,qBAAqBD,+BAA8B;AAEhE,6EAA6E,GAC7E,OAAO,MAAME,eAAe,MAAK;AAQjC,0DAA0D,GAC1D,OAAO,SAASC,cACdC,MAAwF;IAExF,MAAMC,OAAO,IAAIC;IACjB,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIC,OAAOC,OAAO,CAACN,QAAS;QACjD,IAAII,UAAUG,aAAaH,UAAU,MAAM;QAC3C,IAAII,MAAMC,OAAO,CAACL,QAAQ;YACxB,KAAK,MAAMM,QAAQN,MAAOH,KAAKU,MAAM,CAAC,GAAGR,IAAI,EAAE,CAAC,EAAES,OAAOF;QAC3D,OAAO;YACLT,KAAKY,GAAG,CAACV,KAAKS,OAAOR;QACvB;IACF;IACA,OAAOH;AACT;AAEA,8DAA8D,GAC9D,OAAO,eAAea,UACpBC,MAAiC,EACjCC,IAAY,EACZC,UAGI,CAAC,CAAC;QAEqBA;IAA3B,MAAMhB,OAAOF,eAAckB,kBAAAA,QAAQjB,MAAM,YAAdiB,kBAAkB,CAAC;IAC9C,MAAMC,QAAQH,WAAW,SAAS;WAAId,KAAKkB,IAAI;KAAG,CAACC,MAAM,GAAG,CAAC,CAAC,EAAEnB,KAAKoB,QAAQ,IAAI,GAAG;IACpF,MAAMC,WAAW,MAAMC,MAAM,CAAC,0BAA0B,EAAEP,OAAOE,OAAO,EAAE;QACxEH;QACAS,SAAS;YACPC,eAAe,CAAC,OAAO,EAAEC,QAAQC,GAAG,CAACC,iBAAiB,EAAE;YACxD,kB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