@aglyn/plugins-commerce 1.0.0-beta.230 → 1.0.0-beta.232
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -13
- package/src/index.d.ts +0 -1
- package/src/index.js +0 -1
- package/src/index.js.map +1 -1
- package/src/lib/barcode/barcode-decode.d.ts +71 -0
- package/src/lib/barcode/barcode-decode.js +498 -0
- package/src/lib/barcode/barcode-decode.js.map +1 -0
- package/src/lib/barcode/barcode-encode.d.ts +44 -0
- package/src/lib/barcode/barcode-encode.js +138 -0
- package/src/lib/barcode/barcode-encode.js.map +1 -0
- package/src/lib/barcode/barcode-scanner.component.d.ts +23 -0
- package/src/lib/barcode/barcode-scanner.component.js +260 -0
- package/src/lib/barcode/barcode-scanner.component.js.map +1 -0
- package/src/lib/barcode/scan-button.component.d.ts +10 -0
- package/src/lib/barcode/scan-button.component.js +62 -0
- package/src/lib/barcode/scan-button.component.js.map +1 -0
- package/src/lib/barcode/scanner-wedge.d.ts +35 -0
- package/src/lib/barcode/scanner-wedge.js +108 -0
- package/src/lib/barcode/scanner-wedge.js.map +1 -0
- package/src/lib/components/account.js +10 -1
- package/src/lib/components/account.js.map +1 -1
- package/src/lib/components/cart-extras.d.ts +45 -0
- package/src/lib/components/cart-extras.js +127 -0
- package/src/lib/components/cart-extras.js.map +1 -0
- package/src/lib/components/cart.js +82 -15
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/checkout-return-notice.d.ts +26 -0
- package/src/lib/components/checkout-return-notice.js +48 -0
- package/src/lib/components/checkout-return-notice.js.map +1 -0
- package/src/lib/components/commerce-console-page.js +124 -0
- package/src/lib/components/commerce-console-page.js.map +1 -1
- package/src/lib/components/commerce-console-sections.d.ts +1 -1
- package/src/lib/components/commerce-console-sections.js +4 -0
- package/src/lib/components/commerce-console-sections.js.map +1 -1
- package/src/lib/components/console/bulk-fulfill.d.ts +44 -0
- package/src/lib/components/console/bulk-fulfill.js +84 -0
- package/src/lib/components/console/bulk-fulfill.js.map +1 -0
- package/src/lib/components/console/catalog-organization-card.component.js +1 -0
- package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
- package/src/lib/components/console/customer-notifications-card.component.d.ts +19 -0
- package/src/lib/components/console/customer-notifications-card.component.js +149 -0
- package/src/lib/components/console/customer-notifications-card.component.js.map +1 -0
- package/src/lib/components/console/host-orders-card.component.js +88 -6
- package/src/lib/components/console/host-orders-card.component.js.map +1 -1
- package/src/lib/components/console/locations-card.component.js +164 -57
- package/src/lib/components/console/locations-card.component.js.map +1 -1
- package/src/lib/components/console/order-detail-dialog.component.js +209 -61
- package/src/lib/components/console/order-detail-dialog.component.js.map +1 -1
- package/src/lib/components/console/order-fulfillment-panel.component.d.ts +48 -0
- package/src/lib/components/console/order-fulfillment-panel.component.js +542 -0
- package/src/lib/components/console/order-fulfillment-panel.component.js.map +1 -0
- package/src/lib/components/console/order-invoice.component.d.ts +33 -0
- package/src/lib/components/console/order-invoice.component.js +81 -0
- package/src/lib/components/console/order-invoice.component.js.map +1 -0
- package/src/lib/components/console/order-receipt-resend.component.d.ts +21 -0
- package/src/lib/components/console/order-receipt-resend.component.js +203 -0
- package/src/lib/components/console/order-receipt-resend.component.js.map +1 -0
- package/src/lib/components/console/order-returns.component.d.ts +36 -0
- package/src/lib/components/console/order-returns.component.js +142 -0
- package/src/lib/components/console/order-returns.component.js.map +1 -0
- package/src/lib/components/console/order-shipping-actions.component.d.ts +54 -0
- package/src/lib/components/console/order-shipping-actions.component.js +149 -0
- package/src/lib/components/console/order-shipping-actions.component.js.map +1 -0
- package/src/lib/components/console/order-webhooks-card.component.d.ts +50 -0
- package/src/lib/components/console/order-webhooks-card.component.js +623 -0
- package/src/lib/components/console/order-webhooks-card.component.js.map +1 -0
- package/src/lib/components/console/order-zones.d.ts +155 -0
- package/src/lib/components/console/order-zones.js +40 -0
- package/src/lib/components/console/order-zones.js.map +1 -0
- package/src/lib/components/console/payment-methods-card.component.d.ts +67 -0
- package/src/lib/components/console/payment-methods-card.component.js +395 -0
- package/src/lib/components/console/payment-methods-card.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-api.d.ts +124 -0
- package/src/lib/components/console/pos/pos-api.js +101 -0
- package/src/lib/components/console/pos/pos-api.js.map +1 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.d.ts +36 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.js +160 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.d.ts +39 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.js +352 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-product-grid.component.d.ts +47 -0
- package/src/lib/components/console/pos/pos-product-grid.component.js +272 -0
- package/src/lib/components/console/pos/pos-product-grid.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-receipt-panel.component.d.ts +27 -0
- package/src/lib/components/console/pos/pos-receipt-panel.component.js +282 -0
- package/src/lib/components/console/pos/pos-receipt-panel.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +53 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js +445 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-tender-panel.component.d.ts +31 -0
- package/src/lib/components/console/pos/pos-tender-panel.component.js +640 -0
- package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -0
- package/src/lib/components/console/pos/use-pos-display.d.ts +43 -0
- package/src/lib/components/console/pos/use-pos-display.js +161 -0
- package/src/lib/components/console/pos/use-pos-display.js.map +1 -0
- package/src/lib/components/console/pos-devices-card.component.d.ts +14 -0
- package/src/lib/components/console/pos-devices-card.component.js +546 -0
- package/src/lib/components/console/pos-devices-card.component.js.map +1 -0
- package/src/lib/components/console/pos-display/brand-screen.d.ts +33 -0
- package/src/lib/components/console/pos-display/brand-screen.js +85 -0
- package/src/lib/components/console/pos-display/brand-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/cart-screen.d.ts +29 -0
- package/src/lib/components/console/pos-display/cart-screen.js +166 -0
- package/src/lib/components/console/pos-display/cart-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/pairing-screen.d.ts +24 -0
- package/src/lib/components/console/pos-display/pairing-screen.js +127 -0
- package/src/lib/components/console/pos-display/pairing-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/pos-display-api.d.ts +90 -0
- package/src/lib/components/console/pos-display/pos-display-api.js +140 -0
- package/src/lib/components/console/pos-display/pos-display-api.js.map +1 -0
- package/src/lib/components/console/pos-display/receipt-screen.d.ts +35 -0
- package/src/lib/components/console/pos-display/receipt-screen.js +200 -0
- package/src/lib/components/console/pos-display/receipt-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/tip-screen.d.ts +36 -0
- package/src/lib/components/console/pos-display/tip-screen.js +211 -0
- package/src/lib/components/console/pos-display/tip-screen.js.map +1 -0
- package/src/lib/components/console/pos-display-page.component.d.ts +16 -0
- package/src/lib/components/console/pos-display-page.component.js +407 -0
- package/src/lib/components/console/pos-display-page.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-customer-lookup.component.d.ts +40 -0
- package/src/lib/components/console/pos-ops/pos-customer-lookup.component.js +289 -0
- package/src/lib/components/console/pos-ops/pos-customer-lookup.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-last-receipt.component.d.ts +34 -0
- package/src/lib/components/console/pos-ops/pos-last-receipt.component.js +61 -0
- package/src/lib/components/console/pos-ops/pos-last-receipt.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.d.ts +38 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.js +129 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-ops-api.d.ts +37 -0
- package/src/lib/components/console/pos-ops/pos-ops-api.js +60 -0
- package/src/lib/components/console/pos-ops/pos-ops-api.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-pin-pad.component.d.ts +48 -0
- package/src/lib/components/console/pos-ops/pos-pin-pad.component.js +220 -0
- package/src/lib/components/console/pos-ops/pos-pin-pad.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-receipt-actions.component.d.ts +63 -0
- package/src/lib/components/console/pos-ops/pos-receipt-actions.component.js +186 -0
- package/src/lib/components/console/pos-ops/pos-receipt-actions.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-receipt.d.ts +39 -0
- package/src/lib/components/console/pos-ops/pos-receipt.js +182 -0
- package/src/lib/components/console/pos-ops/pos-receipt.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-return-dialog.component.d.ts +40 -0
- package/src/lib/components/console/pos-ops/pos-return-dialog.component.js +465 -0
- package/src/lib/components/console/pos-ops/pos-return-dialog.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-history-card.component.d.ts +29 -0
- package/src/lib/components/console/pos-ops/pos-shift-history-card.component.js +253 -0
- package/src/lib/components/console/pos-ops/pos-shift-history-card.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.d.ts +34 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.js +494 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-report.component.d.ts +37 -0
- package/src/lib/components/console/pos-ops/pos-shift-report.component.js +102 -0
- package/src/lib/components/console/pos-ops/pos-shift-report.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.d.ts +30 -0
- package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.js +277 -0
- package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/register-ops.d.ts +28 -0
- package/src/lib/components/console/pos-ops/register-ops.js +28 -0
- package/src/lib/components/console/pos-ops/register-ops.js.map +1 -0
- package/src/lib/components/console/pos-ops/use-pos-cashier.d.ts +46 -0
- package/src/lib/components/console/pos-ops/use-pos-cashier.js +128 -0
- package/src/lib/components/console/pos-ops/use-pos-cashier.js.map +1 -0
- package/src/lib/components/console/pos-ops/use-pos-sale-receipt.d.ts +36 -0
- package/src/lib/components/console/pos-ops/use-pos-sale-receipt.js +64 -0
- package/src/lib/components/console/pos-ops/use-pos-sale-receipt.js.map +1 -0
- package/src/lib/components/console/pos-page.component.d.ts +13 -5
- package/src/lib/components/console/pos-page.component.js +756 -654
- package/src/lib/components/console/pos-page.component.js.map +1 -1
- package/src/lib/components/console/pos-zones.d.ts +23 -0
- package/src/lib/components/console/pos-zones.js +31 -0
- package/src/lib/components/console/pos-zones.js.map +1 -0
- package/src/lib/components/console/product-editor-dialog.component.js +61 -71
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/product-labels-dialog.component.d.ts +13 -0
- package/src/lib/components/console/product-labels-dialog.component.js +197 -0
- package/src/lib/components/console/product-labels-dialog.component.js.map +1 -0
- package/src/lib/components/console/product-register-fields.component.d.ts +19 -0
- package/src/lib/components/console/product-register-fields.component.js +241 -0
- package/src/lib/components/console/product-register-fields.component.js.map +1 -0
- package/src/lib/components/console/product-zones.d.ts +44 -0
- package/src/lib/components/console/product-zones.js.map +1 -1
- package/src/lib/components/console/products-hub-card.component.js +23 -20
- package/src/lib/components/console/products-hub-card.component.js.map +1 -1
- package/src/lib/components/console/register-hardware-card.component.d.ts +33 -0
- package/src/lib/components/console/register-hardware-card.component.js +826 -0
- package/src/lib/components/console/register-hardware-card.component.js.map +1 -0
- package/src/lib/components/console/registers-card.component.js +24 -5
- package/src/lib/components/console/registers-card.component.js.map +1 -1
- package/src/lib/components/console/return-actions.d.ts +38 -0
- package/src/lib/components/console/return-actions.js +76 -0
- package/src/lib/components/console/return-actions.js.map +1 -0
- package/src/lib/components/console/return-detail-dialog.component.d.ts +34 -0
- package/src/lib/components/console/return-detail-dialog.component.js +718 -0
- package/src/lib/components/console/return-detail-dialog.component.js.map +1 -0
- package/src/lib/components/console/return-settings-card.component.d.ts +34 -0
- package/src/lib/components/console/return-settings-card.component.js +195 -0
- package/src/lib/components/console/return-settings-card.component.js.map +1 -0
- package/src/lib/components/console/return-zones.d.ts +87 -0
- package/src/lib/components/console/return-zones.js +31 -0
- package/src/lib/components/console/return-zones.js.map +1 -0
- package/src/lib/components/console/returns-card.component.d.ts +45 -0
- package/src/lib/components/console/returns-card.component.js +159 -0
- package/src/lib/components/console/returns-card.component.js.map +1 -0
- package/src/lib/components/console/shipping-settings-card.component.js +161 -5
- package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
- package/src/lib/components/console/shippingeasy-card.component.d.ts +59 -0
- package/src/lib/components/console/shippingeasy-card.component.js +378 -0
- package/src/lib/components/console/shippingeasy-card.component.js.map +1 -0
- package/src/lib/components/console/shipstation-card.component.d.ts +35 -0
- package/src/lib/components/console/shipstation-card.component.js +345 -0
- package/src/lib/components/console/shipstation-card.component.js.map +1 -0
- package/src/lib/components/console/start-return-dialog.component.d.ts +40 -0
- package/src/lib/components/console/start-return-dialog.component.js +243 -0
- package/src/lib/components/console/start-return-dialog.component.js.map +1 -0
- package/src/lib/components/console/stock-movements-card.component.js +2 -1
- package/src/lib/components/console/stock-movements-card.component.js.map +1 -1
- package/src/lib/components/console/store-settings-card.component.js +2 -66
- package/src/lib/components/console/store-settings-card.component.js.map +1 -1
- package/src/lib/components/console/store-zones.d.ts +42 -0
- package/src/lib/components/console/store-zones.js +39 -0
- package/src/lib/components/console/store-zones.js.map +1 -0
- package/src/lib/components/console/storefront-tax-summary-card.component.js +1 -0
- package/src/lib/components/console/storefront-tax-summary-card.component.js.map +1 -1
- package/src/lib/components/order-status.d.ts +36 -0
- package/src/lib/components/order-status.js +502 -0
- package/src/lib/components/order-status.js.map +1 -0
- package/src/lib/components/product-detail.js +41 -2
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/return-request.d.ts +32 -0
- package/src/lib/components/return-request.js +576 -0
- package/src/lib/components/return-request.js.map +1 -0
- package/src/lib/components/storefront-payment-appearance.d.ts +32 -0
- package/src/lib/components/storefront-payment-appearance.js +114 -0
- package/src/lib/components/storefront-payment-appearance.js.map +1 -0
- package/src/lib/components/storefront-payment-element.d.ts +57 -1
- package/src/lib/components/storefront-payment-element.js +332 -33
- package/src/lib/components/storefront-payment-element.js.map +1 -1
- package/src/lib/constants/order-status.d.ts +22 -0
- package/src/lib/constants/order-status.js +22 -0
- package/src/lib/constants/order-status.js.map +1 -0
- package/src/lib/constants/return-request.d.ts +27 -0
- package/src/lib/constants/return-request.js +32 -0
- package/src/lib/constants/return-request.js.map +1 -0
- package/src/lib/constants/stock-movement-query.js +2 -1
- package/src/lib/constants/stock-movement-query.js.map +1 -1
- package/src/lib/declarations.console-server.js +9 -0
- package/src/lib/declarations.console-server.js.map +1 -1
- package/src/lib/declarations.server.d.ts +2 -1
- package/src/lib/declarations.server.js +68 -1
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/model/buyer-notifications.d.ts +59 -0
- package/src/lib/model/buyer-notifications.js +97 -0
- package/src/lib/model/buyer-notifications.js.map +1 -0
- package/src/lib/model/commerce-orders.d.ts +171 -2
- package/src/lib/model/commerce-orders.js +26 -16
- package/src/lib/model/commerce-orders.js.map +1 -1
- package/src/lib/model/commerce-payment-methods.d.ts +146 -0
- package/src/lib/model/commerce-payment-methods.js +247 -0
- package/src/lib/model/commerce-payment-methods.js.map +1 -0
- package/src/lib/model/commerce-pos-ops.d.ts +437 -0
- package/src/lib/model/commerce-pos-ops.js +721 -0
- package/src/lib/model/commerce-pos-ops.js.map +1 -0
- package/src/lib/model/commerce-pos.d.ts +263 -0
- package/src/lib/model/commerce-pos.js +375 -0
- package/src/lib/model/commerce-pos.js.map +1 -0
- package/src/lib/model/commerce-printers.d.ts +211 -0
- package/src/lib/model/commerce-printers.js +181 -0
- package/src/lib/model/commerce-printers.js.map +1 -0
- package/src/lib/model/commerce-receipt.d.ts +97 -0
- package/src/lib/model/commerce-receipt.js +180 -0
- package/src/lib/model/commerce-receipt.js.map +1 -0
- package/src/lib/model/commerce-returns.d.ts +207 -0
- package/src/lib/model/commerce-returns.js +300 -0
- package/src/lib/model/commerce-returns.js.map +1 -0
- package/src/lib/model/commerce-shipping.d.ts +44 -1
- package/src/lib/model/commerce-shipping.js +53 -9
- package/src/lib/model/commerce-shipping.js.map +1 -1
- package/src/lib/model/commerce-tax-engine.d.ts +90 -0
- package/src/lib/model/commerce-tax-engine.js +129 -0
- package/src/lib/model/commerce-tax-engine.js.map +1 -0
- package/src/lib/model/commerce.d.ts +91 -2
- package/src/lib/model/commerce.js +89 -1
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/index.d.ts +16 -0
- package/src/lib/model/index.js +16 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/order-events.d.ts +154 -0
- package/src/lib/model/order-events.js +153 -0
- package/src/lib/model/order-events.js.map +1 -0
- package/src/lib/model/order-fulfillment.d.ts +117 -0
- package/src/lib/model/order-fulfillment.js +217 -0
- package/src/lib/model/order-fulfillment.js.map +1 -0
- package/src/lib/model/order-history.d.ts +58 -0
- package/src/lib/model/order-history.js +22 -0
- package/src/lib/model/order-history.js.map +1 -0
- package/src/lib/model/order-list-fields.d.ts +9 -1
- package/src/lib/model/order-list-fields.js +7 -1
- package/src/lib/model/order-list-fields.js.map +1 -1
- package/src/lib/model/order-shipping-export.d.ts +91 -0
- package/src/lib/model/order-shipping-export.js +192 -0
- package/src/lib/model/order-shipping-export.js.map +1 -0
- package/src/lib/model/order-status-view.d.ts +103 -0
- package/src/lib/model/order-status-view.js +156 -0
- package/src/lib/model/order-status-view.js.map +1 -0
- package/src/lib/model/order-webhooks.d.ts +142 -0
- package/src/lib/model/order-webhooks.js +91 -0
- package/src/lib/model/order-webhooks.js.map +1 -0
- package/src/lib/model/product-channel.d.ts +56 -0
- package/src/lib/model/product-channel.js +86 -0
- package/src/lib/model/product-channel.js.map +1 -0
- package/src/lib/model/product-modifiers.d.ts +80 -0
- package/src/lib/model/product-modifiers.js +140 -0
- package/src/lib/model/product-modifiers.js.map +1 -0
- package/src/lib/model/product-write.d.ts +186 -0
- package/src/lib/model/product-write.js +116 -0
- package/src/lib/model/product-write.js.map +1 -0
- package/src/lib/model/shippingeasy.d.ts +94 -0
- package/src/lib/model/shippingeasy.js +267 -0
- package/src/lib/model/shippingeasy.js.map +1 -0
- package/src/lib/model/shipstation.d.ts +125 -0
- package/src/lib/model/shipstation.js +399 -0
- package/src/lib/model/shipstation.js.map +1 -0
- package/src/lib/model/smart-collection-reads.d.ts +32 -0
- package/src/lib/model/smart-collection-reads.js +63 -0
- package/src/lib/model/smart-collection-reads.js.map +1 -0
- package/src/lib/model/tracking-url.d.ts +74 -0
- package/src/lib/model/tracking-url.js +159 -0
- package/src/lib/model/tracking-url.js.map +1 -0
- package/src/lib/plugin-config.d.ts +13 -0
- package/src/lib/plugin-config.js +77 -5
- package/src/lib/plugin-config.js.map +1 -1
- package/src/lib/plugin.js +26 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/pos-ops-config.d.ts +39 -0
- package/src/lib/pos-ops-config.js +88 -0
- package/src/lib/pos-ops-config.js.map +1 -0
- package/src/lib/printing/print-document.d.ts +106 -0
- package/src/lib/printing/print-document.js +464 -0
- package/src/lib/printing/print-document.js.map +1 -0
- package/src/lib/printing/product-labels.d.ts +58 -0
- package/src/lib/printing/product-labels.js +116 -0
- package/src/lib/printing/product-labels.js.map +1 -0
- package/src/lib/printing/render-epson.d.ts +57 -0
- package/src/lib/printing/render-epson.js +135 -0
- package/src/lib/printing/render-epson.js.map +1 -0
- package/src/lib/printing/render-star.d.ts +45 -0
- package/src/lib/printing/render-star.js +100 -0
- package/src/lib/printing/render-star.js.map +1 -0
- package/src/lib/printing/render-text.d.ts +25 -0
- package/src/lib/printing/render-text.js +53 -0
- package/src/lib/printing/render-text.js.map +1 -0
- package/src/lib/server/api-v1/openapi.js +27 -4
- package/src/lib/server/api-v1/openapi.js.map +1 -1
- package/src/lib/server/api-v1/order-view.d.ts +67 -0
- package/src/lib/server/api-v1/order-view.js +120 -0
- package/src/lib/server/api-v1/order-view.js.map +1 -0
- package/src/lib/server/api-v1/orders-and-products.js +58 -65
- package/src/lib/server/api-v1/orders-and-products.js.map +1 -1
- package/src/lib/server/billing-webhook.js +135 -28
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cancel-order.js +29 -0
- package/src/lib/server/cancel-order.js.map +1 -1
- package/src/lib/server/carrier-rates-availability.d.ts +26 -0
- package/src/lib/server/carrier-rates-availability.js +76 -0
- package/src/lib/server/carrier-rates-availability.js.map +1 -0
- package/src/lib/server/carrier-shipping.d.ts +84 -0
- package/src/lib/server/carrier-shipping.js +135 -0
- package/src/lib/server/carrier-shipping.js.map +1 -0
- package/src/lib/server/cart-checkout.d.ts +2 -0
- package/src/lib/server/cart-checkout.js +226 -22
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/channel-order-updates.d.ts +50 -0
- package/src/lib/server/channel-order-updates.js +290 -0
- package/src/lib/server/channel-order-updates.js.map +1 -0
- package/src/lib/server/channel-orders.d.ts +85 -0
- package/src/lib/server/channel-orders.js +543 -0
- package/src/lib/server/channel-orders.js.map +1 -0
- package/src/lib/server/checkout-extras.d.ts +64 -0
- package/src/lib/server/checkout-extras.js +157 -0
- package/src/lib/server/checkout-extras.js.map +1 -0
- package/src/lib/server/{feed.d.ts → checkout-status.d.ts} +2 -7
- package/src/lib/server/checkout-status.js +111 -0
- package/src/lib/server/checkout-status.js.map +1 -0
- package/src/lib/server/checkout.js +86 -9
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/draft-order.js +34 -5
- package/src/lib/server/draft-order.js.map +1 -1
- package/src/lib/server/fulfill-order.d.ts +127 -10
- package/src/lib/server/fulfill-order.js +451 -49
- package/src/lib/server/fulfill-order.js.map +1 -1
- package/src/lib/server/legacy-feed.d.ts +28 -0
- package/src/lib/server/legacy-feed.js +52 -0
- package/src/lib/server/legacy-feed.js.map +1 -0
- package/src/lib/server/native-checkout.d.ts +34 -15
- package/src/lib/server/native-checkout.js +32 -17
- package/src/lib/server/native-checkout.js.map +1 -1
- package/src/lib/server/order-event-host-emit.d.ts +23 -0
- package/src/lib/server/order-event-host-emit.js +30 -0
- package/src/lib/server/order-event-host-emit.js.map +1 -0
- package/src/lib/server/order-event-triggers.d.ts +37 -0
- package/src/lib/server/order-event-triggers.js +119 -0
- package/src/lib/server/order-event-triggers.js.map +1 -0
- package/src/lib/server/order-events.d.ts +62 -0
- package/src/lib/server/order-events.js +109 -0
- package/src/lib/server/order-events.js.map +1 -0
- package/src/lib/server/order-history.d.ts +23 -0
- package/src/lib/server/order-history.js +65 -0
- package/src/lib/server/order-history.js.map +1 -0
- package/src/lib/server/order-notifications.d.ts +185 -0
- package/src/lib/server/order-notifications.js +567 -0
- package/src/lib/server/order-notifications.js.map +1 -0
- package/src/lib/server/order-receipt-send.d.ts +39 -0
- package/src/lib/server/order-receipt-send.js +151 -0
- package/src/lib/server/order-receipt-send.js.map +1 -0
- package/src/lib/server/order-status-token.d.ts +31 -0
- package/src/lib/server/order-status-token.js +75 -0
- package/src/lib/server/order-status-token.js.map +1 -0
- package/src/lib/server/order-status.d.ts +58 -0
- package/src/lib/server/order-status.js +141 -0
- package/src/lib/server/order-status.js.map +1 -0
- package/src/lib/server/order-webhooks.d.ts +108 -0
- package/src/lib/server/order-webhooks.js +622 -0
- package/src/lib/server/order-webhooks.js.map +1 -0
- package/src/lib/server/orders-shipping-prepare.d.ts +26 -0
- package/src/lib/server/orders-shipping-prepare.js +121 -0
- package/src/lib/server/orders-shipping-prepare.js.map +1 -0
- package/src/lib/server/payment-method-domains.d.ts +209 -0
- package/src/lib/server/payment-method-domains.js +444 -0
- package/src/lib/server/payment-method-domains.js.map +1 -0
- package/src/lib/server/payment-methods.d.ts +77 -0
- package/src/lib/server/payment-methods.js +284 -0
- package/src/lib/server/payment-methods.js.map +1 -0
- package/src/lib/server/pos-auth.d.ts +50 -0
- package/src/lib/server/pos-auth.js +121 -0
- package/src/lib/server/pos-auth.js.map +1 -0
- package/src/lib/server/pos-customer.d.ts +49 -0
- package/src/lib/server/pos-customer.js +257 -0
- package/src/lib/server/pos-customer.js.map +1 -0
- package/src/lib/server/pos-display.d.ts +57 -0
- package/src/lib/server/pos-display.js +419 -0
- package/src/lib/server/pos-display.js.map +1 -0
- package/src/lib/server/pos-fee-month.d.ts +34 -0
- package/src/lib/server/pos-fee-month.js +36 -0
- package/src/lib/server/pos-fee-month.js.map +1 -0
- package/src/lib/server/pos-ops-gate.d.ts +161 -0
- package/src/lib/server/pos-ops-gate.js +295 -0
- package/src/lib/server/pos-ops-gate.js.map +1 -0
- package/src/lib/server/pos-ops-routes.d.ts +22 -0
- package/src/lib/server/pos-ops-routes.js +36 -0
- package/src/lib/server/pos-ops-routes.js.map +1 -0
- package/src/lib/server/pos-order.d.ts +1 -18
- package/src/lib/server/pos-order.js +222 -42
- package/src/lib/server/pos-order.js.map +1 -1
- package/src/lib/server/pos-payment.d.ts +39 -0
- package/src/lib/server/pos-payment.js +922 -0
- package/src/lib/server/pos-payment.js.map +1 -0
- package/src/lib/server/pos-print.d.ts +82 -0
- package/src/lib/server/pos-print.js +193 -0
- package/src/lib/server/pos-print.js.map +1 -0
- package/src/lib/server/pos-readers.d.ts +27 -0
- package/src/lib/server/pos-readers.js +276 -0
- package/src/lib/server/pos-readers.js.map +1 -0
- package/src/lib/server/pos-refund-authority.d.ts +60 -0
- package/src/lib/server/pos-refund-authority.js +72 -0
- package/src/lib/server/pos-refund-authority.js.map +1 -0
- package/src/lib/server/pos-return.d.ts +58 -0
- package/src/lib/server/pos-return.js +891 -0
- package/src/lib/server/pos-return.js.map +1 -0
- package/src/lib/server/pos-sale-stamp.d.ts +66 -0
- package/src/lib/server/pos-sale-stamp.js +84 -0
- package/src/lib/server/pos-sale-stamp.js.map +1 -0
- package/src/lib/server/pos-sale.d.ts +170 -0
- package/src/lib/server/pos-sale.js +461 -0
- package/src/lib/server/pos-sale.js.map +1 -0
- package/src/lib/server/pos-shift.d.ts +45 -0
- package/src/lib/server/pos-shift.js +484 -0
- package/src/lib/server/pos-shift.js.map +1 -0
- package/src/lib/server/pos-staff-pin.d.ts +26 -0
- package/src/lib/server/pos-staff-pin.js +339 -0
- package/src/lib/server/pos-staff-pin.js.map +1 -0
- package/src/lib/server/pos-stripe.d.ts +91 -0
- package/src/lib/server/pos-stripe.js +129 -0
- package/src/lib/server/pos-stripe.js.map +1 -0
- package/src/lib/server/pos-terminal-connection-token.d.ts +48 -0
- package/src/lib/server/pos-terminal-connection-token.js +166 -0
- package/src/lib/server/pos-terminal-connection-token.js.map +1 -0
- package/src/lib/server/pos-terminal.d.ts +218 -0
- package/src/lib/server/pos-terminal.js +1014 -0
- package/src/lib/server/pos-terminal.js.map +1 -0
- package/src/lib/server/print-queue.d.ts +124 -0
- package/src/lib/server/print-queue.js +301 -0
- package/src/lib/server/print-queue.js.map +1 -0
- package/src/lib/server/printer-poll.d.ts +75 -0
- package/src/lib/server/printer-poll.js +325 -0
- package/src/lib/server/printer-poll.js.map +1 -0
- package/src/lib/server/printer-secret.d.ts +39 -0
- package/src/lib/server/printer-secret.js +56 -0
- package/src/lib/server/printer-secret.js.map +1 -0
- package/src/lib/server/printers.d.ts +114 -0
- package/src/lib/server/printers.js +546 -0
- package/src/lib/server/printers.js.map +1 -0
- package/src/lib/server/product-catalog.d.ts +42 -0
- package/src/lib/server/product-catalog.js +309 -0
- package/src/lib/server/product-catalog.js.map +1 -0
- package/src/lib/server/product-drafts.d.ts +5 -1
- package/src/lib/server/product-drafts.js +3 -3
- package/src/lib/server/product-drafts.js.map +1 -1
- package/src/lib/server/product-writer.d.ts +19 -0
- package/src/lib/server/product-writer.js +261 -0
- package/src/lib/server/product-writer.js.map +1 -0
- package/src/lib/server/products-write.d.ts +61 -0
- package/src/lib/server/products-write.js +375 -0
- package/src/lib/server/products-write.js.map +1 -0
- package/src/lib/server/refund.js +110 -45
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/reserve.js +2 -0
- package/src/lib/server/reserve.js.map +1 -1
- package/src/lib/server/return-status-action.d.ts +37 -0
- package/src/lib/server/return-status-action.js +57 -0
- package/src/lib/server/return-status-action.js.map +1 -0
- package/src/lib/server/returns.d.ts +119 -0
- package/src/lib/server/returns.js +938 -0
- package/src/lib/server/returns.js.map +1 -0
- package/src/lib/server/shipment-records.d.ts +36 -0
- package/src/lib/server/shipment-records.js +289 -0
- package/src/lib/server/shipment-records.js.map +1 -0
- package/src/lib/server/shipping-connector-gates.d.ts +40 -0
- package/src/lib/server/shipping-connector-gates.js +97 -0
- package/src/lib/server/shipping-connector-gates.js.map +1 -0
- package/src/lib/server/shipping-connectors.d.ts +29 -0
- package/src/lib/server/shipping-connectors.js +236 -0
- package/src/lib/server/shipping-connectors.js.map +1 -0
- package/src/lib/server/shippingeasy.d.ts +238 -0
- package/src/lib/server/shippingeasy.js +787 -0
- package/src/lib/server/shippingeasy.js.map +1 -0
- package/src/lib/server/shipstation.d.ts +129 -0
- package/src/lib/server/shipstation.js +483 -0
- package/src/lib/server/shipstation.js.map +1 -0
- package/src/lib/server/site-page-resolver.d.ts +5 -0
- package/src/lib/server/site-page-resolver.js +156 -1
- package/src/lib/server/site-page-resolver.js.map +1 -1
- package/src/lib/server/stock-levels.d.ts +21 -0
- package/src/lib/server/stock-levels.js +263 -0
- package/src/lib/server/stock-levels.js.map +1 -0
- package/src/lib/server/stripe-refund.d.ts +47 -0
- package/src/lib/server/stripe-refund.js +87 -0
- package/src/lib/server/stripe-refund.js.map +1 -0
- package/src/lib/server/supplier-update.js +46 -5
- package/src/lib/server/supplier-update.js.map +1 -1
- package/src/lib/server/tax-engine-quote.d.ts +47 -0
- package/src/lib/server/tax-engine-quote.js +105 -0
- package/src/lib/server/tax-engine-quote.js.map +1 -0
- package/src/lib/server.js +143 -2
- package/src/lib/server.js.map +1 -1
- package/src/lib/site.js +12 -0
- package/src/lib/site.js.map +1 -1
- package/src/lib/subprocessors.d.ts +26 -0
- package/src/lib/subprocessors.js +50 -0
- package/src/lib/subprocessors.js.map +1 -0
- package/src/lib/tenant-emails.js +461 -3
- package/src/lib/tenant-emails.js.map +1 -1
- package/src/lib/testing/fake-firestore.d.ts +45 -0
- package/src/lib/testing/fake-firestore.js +189 -0
- package/src/lib/testing/fake-firestore.js.map +1 -0
- package/src/lib/testing/memory-firestore.d.ts +136 -0
- package/src/lib/testing/memory-firestore.js +282 -0
- package/src/lib/testing/memory-firestore.js.map +1 -0
- package/src/lib/testing/pos-ops-harness.d.ts +50 -0
- package/src/lib/testing/pos-ops-harness.js +184 -0
- package/src/lib/testing/pos-ops-harness.js.map +1 -0
- package/src/lib/testing/pos-ops-memory-firestore.d.ts +55 -0
- package/src/lib/testing/pos-ops-memory-firestore.js +376 -0
- package/src/lib/testing/pos-ops-memory-firestore.js.map +1 -0
- package/src/lib/transfer/products.server.d.ts +5 -0
- package/src/lib/transfer/products.server.js +2 -2
- package/src/lib/transfer/products.server.js.map +1 -1
- package/src/lib/transfer/records-transfer.d.ts +11 -1
- package/src/lib/transfer/records-transfer.js +127 -5
- package/src/lib/transfer/records-transfer.js.map +1 -1
- package/src/lib/transfer/records.server.d.ts +9 -2
- package/src/lib/transfer/records.server.js +58 -7
- package/src/lib/transfer/records.server.js.map +1 -1
- package/src/lib/transfer/register-transfer-resources.js +40 -1
- package/src/lib/transfer/register-transfer-resources.js.map +1 -1
- package/src/lib/transfer/register-transfer-ui.js +4 -1
- package/src/lib/transfer/register-transfer-ui.js.map +1 -1
- package/src/lib/transfer/shipping-presets.d.ts +23 -0
- package/src/lib/transfer/shipping-presets.js +156 -0
- package/src/lib/transfer/shipping-presets.js.map +1 -0
- package/src/lib/transfer/tracking-transfer.d.ts +101 -0
- package/src/lib/transfer/tracking-transfer.js +546 -0
- package/src/lib/transfer/tracking-transfer.js.map +1 -0
- package/src/lib/transfer/tracking.server.d.ts +37 -0
- package/src/lib/transfer/tracking.server.js +393 -0
- package/src/lib/transfer/tracking.server.js.map +1 -0
- package/src/lib/transfer/transfer-keys.d.ts +2 -1
- package/src/lib/transfer/transfer-keys.js +6 -2
- package/src/lib/transfer/transfer-keys.js.map +1 -1
- package/src/lib/utils/code128.d.ts +37 -0
- package/src/lib/utils/code128.js +199 -0
- package/src/lib/utils/code128.js.map +1 -0
- package/src/lib/utils/order-invoice.d.ts +55 -0
- package/src/lib/utils/order-invoice.js +127 -0
- package/src/lib/utils/order-invoice.js.map +1 -0
- package/src/lib/utils/use-checkout-return-notice.d.ts +34 -0
- package/src/lib/utils/use-checkout-return-notice.js +78 -0
- package/src/lib/utils/use-checkout-return-notice.js.map +1 -0
- package/src/lib/server/feed.js +0 -69
- package/src/lib/server/feed.js.map +0 -1
|
@@ -0,0 +1,444 @@
|
|
|
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 { siteOwnHosts } from "@aglyn/aglyn/app-utils/site-return-url";
|
|
18
|
+
import { TENANT_APEX } from "@aglyn/aglyn/app-utils/tenant-apex";
|
|
19
|
+
import { firebaseAdmin } from "@aglyn/tenant-data-admin";
|
|
20
|
+
/**
|
|
21
|
+
* Stripe payment method domains for storefronts (AGL-3629).
|
|
22
|
+
*
|
|
23
|
+
* The in-page checkout mounts Stripe's Payment Element on the merchant's own
|
|
24
|
+
* domain, and Stripe shows Apple Pay there only on a REGISTERED domain (Google
|
|
25
|
+
* Pay, Link, Amazon Pay and Klarna's express button use the same registration).
|
|
26
|
+
* Nothing registered one, so a shopper on `shop.example.com` with a card in
|
|
27
|
+
* Apple Wallet never saw the button.
|
|
28
|
+
*
|
|
29
|
+
* ## Which account the domain is registered on
|
|
30
|
+
*
|
|
31
|
+
* Stripe's rule: "The domain where the charge is being run needs to be
|
|
32
|
+
* registered for the user running the charge." Storefront charges are
|
|
33
|
+
* DESTINATION charges created by the platform with no `Stripe-Account` header
|
|
34
|
+
* and no `on_behalf_of`, so the platform runs them and the platform's key
|
|
35
|
+
* registers the domain, with no `Stripe-Account` header. A direct-charge flow
|
|
36
|
+
* would register on the connected account instead; there is none today, and
|
|
37
|
+
* `registerOnPlatform` is named for that reason.
|
|
38
|
+
*
|
|
39
|
+
* ## When
|
|
40
|
+
*
|
|
41
|
+
* - On connect: core raises `host.domain.attached`, and commerce registers
|
|
42
|
+
* the custom domain and its `www.` twin.
|
|
43
|
+
* - On first checkout: the session handlers call `ensureCheckoutDomain` for
|
|
44
|
+
* the page the shopper is on, which covers every `{site}.aglyn.app`
|
|
45
|
+
* subdomain without registering thousands of sites that never sell.
|
|
46
|
+
* - Daily: `reconcileCustomDomains` registers any connected custom domain the
|
|
47
|
+
* first two missed (domains connected before AGL-3629 included) — the
|
|
48
|
+
* backfill is a job rather than a one-off script, so it also repairs a
|
|
49
|
+
* missed event later.
|
|
50
|
+
* - On release: `host.domain.released` DISABLES the domain. Stripe has no
|
|
51
|
+
* delete; a disabled domain stops showing the methods and can be enabled
|
|
52
|
+
* again if the name comes back.
|
|
53
|
+
*
|
|
54
|
+
* ## The cache
|
|
55
|
+
*
|
|
56
|
+
* `paymentMethodDomains/{mode}~{domain}` records what Stripe last said, so a
|
|
57
|
+
* checkout costs one document read rather than a Stripe round trip. The mode is
|
|
58
|
+
* in the id because a test key and a live key register in different worlds and
|
|
59
|
+
* a domain registered in one is not registered in the other. Server-only: the
|
|
60
|
+
* rules deny every client.
|
|
61
|
+
*/ export const PAYMENT_METHOD_DOMAINS_COLLECTION = 'paymentMethodDomains';
|
|
62
|
+
/** How long a recorded registration is trusted before Stripe is asked again. */ export const PAYMENT_METHOD_DOMAIN_RECHECK_MS = 7 * 24 * 60 * 60 * 1000;
|
|
63
|
+
/** The most a checkout waits on Stripe before selling without the domain. */ export const CHECKOUT_DOMAIN_BUDGET_MS = 2500;
|
|
64
|
+
/** Which Stripe world the platform key is in, from its prefix. */ export function stripeModeOfKey(key) {
|
|
65
|
+
const value = String(key != null ? key : '');
|
|
66
|
+
if (/^(sk|rk)_live_/.test(value)) return 'live';
|
|
67
|
+
if (/^(sk|rk)_test_/.test(value)) return 'test';
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A hostname Stripe can register: lowercased, no trailing dot, at least two
|
|
72
|
+
* labels, and never a local or IP host — a checkout opened on `localhost`
|
|
73
|
+
* must not try to register it.
|
|
74
|
+
*/ export function registrableDomain(input) {
|
|
75
|
+
const value = String(input != null ? input : '').trim().toLowerCase().replace(/\.+$/, '');
|
|
76
|
+
if (!value || value.length > 253) return null;
|
|
77
|
+
if (value === 'localhost' || value.endsWith('.localhost')) return null;
|
|
78
|
+
if (/^[0-9.]+$/.test(value) || value.includes(':')) return null;
|
|
79
|
+
if (!/^[a-z0-9-]+(\.[a-z0-9-]+)+$/.test(value)) return null;
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
/** The cache document id for a domain in a mode. */ export function paymentMethodDomainDocId(mode, domain) {
|
|
83
|
+
return `${mode}~${domain}`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The domains a site's custom domain needs: the domain and its `www.` twin,
|
|
87
|
+
* since the platform answers on both (`siteOwnHosts`).
|
|
88
|
+
*/ export function customDomainNames(cname) {
|
|
89
|
+
const domain = registrableDomain(cname);
|
|
90
|
+
if (!domain) return [];
|
|
91
|
+
const twin = domain.startsWith('www.') ? domain.slice(4) : `www.${domain}`;
|
|
92
|
+
return [
|
|
93
|
+
domain,
|
|
94
|
+
...registrableDomain(twin) ? [
|
|
95
|
+
twin
|
|
96
|
+
] : []
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
function statusOf(object) {
|
|
100
|
+
var _ref, _ref1, _ref2, _ref3, _ref4;
|
|
101
|
+
var _object_apple_pay, _object_google_pay, _object_link, _object_amazon_pay, _object_klarna;
|
|
102
|
+
return {
|
|
103
|
+
applePay: (_ref = (_object_apple_pay = object.apple_pay) == null ? void 0 : _object_apple_pay.status) != null ? _ref : null,
|
|
104
|
+
googlePay: (_ref1 = (_object_google_pay = object.google_pay) == null ? void 0 : _object_google_pay.status) != null ? _ref1 : null,
|
|
105
|
+
link: (_ref2 = (_object_link = object.link) == null ? void 0 : _object_link.status) != null ? _ref2 : null,
|
|
106
|
+
amazonPay: (_ref3 = (_object_amazon_pay = object.amazon_pay) == null ? void 0 : _object_amazon_pay.status) != null ? _ref3 : null,
|
|
107
|
+
klarna: (_ref4 = (_object_klarna = object.klarna) == null ? void 0 : _object_klarna.status) != null ? _ref4 : null
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
async function stripeRequest(method, path, params, options = {}) {
|
|
111
|
+
const query = method === 'GET' && params ? `?${new URLSearchParams(params)}` : '';
|
|
112
|
+
const response = await fetch(`https://api.stripe.com/v1/${path}${query}`, _extends({
|
|
113
|
+
method,
|
|
114
|
+
headers: _extends({
|
|
115
|
+
Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`
|
|
116
|
+
}, method === 'POST' && {
|
|
117
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
118
|
+
}, options.idempotencyKey && {
|
|
119
|
+
'Idempotency-Key': options.idempotencyKey
|
|
120
|
+
})
|
|
121
|
+
}, method === 'POST' && params && {
|
|
122
|
+
body: new URLSearchParams(params).toString()
|
|
123
|
+
}, options.signal && {
|
|
124
|
+
signal: options.signal
|
|
125
|
+
}));
|
|
126
|
+
const payload = await response.json().catch(()=>({}));
|
|
127
|
+
if (!response.ok) {
|
|
128
|
+
var _ref;
|
|
129
|
+
var _payload_error;
|
|
130
|
+
throw new Error((_ref = payload == null ? void 0 : (_payload_error = payload.error) == null ? void 0 : _payload_error.message) != null ? _ref : `Stripe ${path} failed (${response.status})`);
|
|
131
|
+
}
|
|
132
|
+
return payload;
|
|
133
|
+
}
|
|
134
|
+
async function findOnStripe(domain, signal) {
|
|
135
|
+
var _ref;
|
|
136
|
+
var _list_data;
|
|
137
|
+
const list = await stripeRequest('GET', 'payment_method_domains', {
|
|
138
|
+
domain_name: domain,
|
|
139
|
+
limit: '1'
|
|
140
|
+
}, {
|
|
141
|
+
signal
|
|
142
|
+
});
|
|
143
|
+
return (_ref = (_list_data = list.data) == null ? void 0 : _list_data.find((entry)=>entry.domain_name === domain)) != null ? _ref : null;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Register (or re-enable) one domain on the platform account. Idempotent end
|
|
147
|
+
* to end: an existing registration is found first and reused, a disabled one
|
|
148
|
+
* is enabled rather than duplicated, and the create carries an idempotency key
|
|
149
|
+
* so two checkouts racing on a fresh subdomain open one registration.
|
|
150
|
+
*/ export async function registerOnPlatform(domain, signal) {
|
|
151
|
+
const existing = await findOnStripe(domain, signal);
|
|
152
|
+
if (existing) {
|
|
153
|
+
if (existing.enabled) return existing;
|
|
154
|
+
return stripeRequest('POST', `payment_method_domains/${encodeURIComponent(existing.id)}`, {
|
|
155
|
+
enabled: 'true'
|
|
156
|
+
}, {
|
|
157
|
+
signal
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
return await stripeRequest('POST', 'payment_method_domains', {
|
|
162
|
+
domain_name: domain,
|
|
163
|
+
enabled: 'true'
|
|
164
|
+
}, {
|
|
165
|
+
idempotencyKey: `aglyn-pmd-register:${domain}`,
|
|
166
|
+
signal
|
|
167
|
+
});
|
|
168
|
+
} catch (error) {
|
|
169
|
+
// Lost a race to a create that landed between the lookup and this call:
|
|
170
|
+
// the registration exists, which is what was wanted.
|
|
171
|
+
const raced = await findOnStripe(domain, signal).catch(()=>null);
|
|
172
|
+
if (raced) return raced;
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function docRef(mode, domain) {
|
|
177
|
+
return firebaseAdmin.app().firestore().collection(PAYMENT_METHOD_DOMAINS_COLLECTION).doc(paymentMethodDomainDocId(mode, domain));
|
|
178
|
+
}
|
|
179
|
+
async function record(mode, domain, patch) {
|
|
180
|
+
await docRef(mode, domain).set(_extends({
|
|
181
|
+
domain,
|
|
182
|
+
mode,
|
|
183
|
+
checkedAtMs: Date.now()
|
|
184
|
+
}, patch), {
|
|
185
|
+
merge: true
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Make sure one domain is registered and enabled, reading the cache first.
|
|
190
|
+
*
|
|
191
|
+
* Never throws: every caller is on its way to something more important (a
|
|
192
|
+
* sale, a domain connect), and a domain Stripe would not take today is
|
|
193
|
+
* recorded with its error and retried by the daily reconcile.
|
|
194
|
+
*/ export async function ensurePaymentMethodDomain(rawDomain, options = {}) {
|
|
195
|
+
const domain = registrableDomain(rawDomain);
|
|
196
|
+
const mode = stripeModeOfKey(process.env.STRIPE_SECRET_KEY);
|
|
197
|
+
if (!domain || !mode) {
|
|
198
|
+
return {
|
|
199
|
+
domain: String(rawDomain != null ? rawDomain : ''),
|
|
200
|
+
outcome: 'skipped'
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
var _options_hostId;
|
|
205
|
+
if (!options.force) {
|
|
206
|
+
var _data_checkedAtMs;
|
|
207
|
+
const cached = await docRef(mode, domain).get();
|
|
208
|
+
const data = cached.data == null ? void 0 : cached.data.call(cached);
|
|
209
|
+
if (cached.exists && (data == null ? void 0 : data.enabled) === true && data.stripeId && Date.now() - Number((_data_checkedAtMs = data.checkedAtMs) != null ? _data_checkedAtMs : 0) < PAYMENT_METHOD_DOMAIN_RECHECK_MS) {
|
|
210
|
+
return {
|
|
211
|
+
domain,
|
|
212
|
+
outcome: 'cached',
|
|
213
|
+
record: data
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const object = await registerOnPlatform(domain, options.signal);
|
|
218
|
+
const next = {
|
|
219
|
+
domain,
|
|
220
|
+
mode,
|
|
221
|
+
stripeId: object.id,
|
|
222
|
+
enabled: object.enabled !== false,
|
|
223
|
+
status: statusOf(object),
|
|
224
|
+
hostId: (_options_hostId = options.hostId) != null ? _options_hostId : null,
|
|
225
|
+
checkedAtMs: Date.now(),
|
|
226
|
+
lastError: null
|
|
227
|
+
};
|
|
228
|
+
await record(mode, domain, next);
|
|
229
|
+
return {
|
|
230
|
+
domain,
|
|
231
|
+
outcome: 'registered',
|
|
232
|
+
record: next
|
|
233
|
+
};
|
|
234
|
+
} catch (error) {
|
|
235
|
+
var _options_hostId1;
|
|
236
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
237
|
+
await record(mode, domain, {
|
|
238
|
+
enabled: false,
|
|
239
|
+
hostId: (_options_hostId1 = options.hostId) != null ? _options_hostId1 : null,
|
|
240
|
+
lastError: message.slice(0, 500)
|
|
241
|
+
}).catch(()=>undefined);
|
|
242
|
+
return {
|
|
243
|
+
domain,
|
|
244
|
+
outcome: 'failed',
|
|
245
|
+
error: message
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Disable a domain the platform no longer serves for a site. Stripe has no
|
|
251
|
+
* delete for a payment method domain; disabling stops every method on it, and
|
|
252
|
+
* `ensurePaymentMethodDomain` re-enables the same registration if the name is
|
|
253
|
+
* connected again.
|
|
254
|
+
*/ export async function disablePaymentMethodDomain(rawDomain) {
|
|
255
|
+
const domain = registrableDomain(rawDomain);
|
|
256
|
+
const mode = stripeModeOfKey(process.env.STRIPE_SECRET_KEY);
|
|
257
|
+
if (!domain || !mode) return {
|
|
258
|
+
domain: String(rawDomain != null ? rawDomain : ''),
|
|
259
|
+
outcome: 'skipped'
|
|
260
|
+
};
|
|
261
|
+
try {
|
|
262
|
+
const existing = await findOnStripe(domain);
|
|
263
|
+
if (!existing) {
|
|
264
|
+
await record(mode, domain, {
|
|
265
|
+
enabled: false,
|
|
266
|
+
stripeId: null,
|
|
267
|
+
lastError: null
|
|
268
|
+
});
|
|
269
|
+
return {
|
|
270
|
+
domain,
|
|
271
|
+
outcome: 'absent'
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
const object = existing.enabled ? await stripeRequest('POST', `payment_method_domains/${encodeURIComponent(existing.id)}`, {
|
|
275
|
+
enabled: 'false'
|
|
276
|
+
}) : existing;
|
|
277
|
+
await record(mode, domain, {
|
|
278
|
+
stripeId: object.id,
|
|
279
|
+
enabled: false,
|
|
280
|
+
status: statusOf(object),
|
|
281
|
+
lastError: null
|
|
282
|
+
});
|
|
283
|
+
return {
|
|
284
|
+
domain,
|
|
285
|
+
outcome: 'disabled'
|
|
286
|
+
};
|
|
287
|
+
} catch (error) {
|
|
288
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
289
|
+
return {
|
|
290
|
+
domain,
|
|
291
|
+
outcome: 'failed',
|
|
292
|
+
error: message
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Is a name still served for some OTHER site? A custom domain's `www.` twin
|
|
298
|
+
* can be another site's own `cname`, and an aglyn subdomain released by a
|
|
299
|
+
* deleted site can already belong to a new one. Disabling either would take
|
|
300
|
+
* Apple Pay away from a store that did nothing.
|
|
301
|
+
*/ export async function domainStillClaimed(domain, exceptHostId) {
|
|
302
|
+
const firestore = firebaseAdmin.app().firestore();
|
|
303
|
+
const hosts = firestore.collection('hosts');
|
|
304
|
+
const names = customDomainNames(domain);
|
|
305
|
+
const byCname = await hosts.where('cname', 'in', names.length ? names : [
|
|
306
|
+
domain
|
|
307
|
+
]).limit(3).get();
|
|
308
|
+
if (byCname.docs.some((doc)=>doc.id !== exceptHostId)) return true;
|
|
309
|
+
const suffix = `.${TENANT_APEX}`;
|
|
310
|
+
if (domain.endsWith(suffix)) {
|
|
311
|
+
const subdomain = domain.slice(0, -suffix.length);
|
|
312
|
+
const bySubdomain = await hosts.where('subdomain', '==', subdomain).limit(3).get();
|
|
313
|
+
if (bySubdomain.docs.some((doc)=>doc.id !== exceptHostId)) return true;
|
|
314
|
+
}
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* The checkout's hook: register the domain the shopper is paying on, within a
|
|
319
|
+
* budget, before the client secret goes back to the browser. Only a name the
|
|
320
|
+
* SITE answers on is ever registered — the return URL has already been judged
|
|
321
|
+
* against `siteOwnHosts` by `siteReturnUrl`, and it is judged again here so a
|
|
322
|
+
* forged `Host` can never make the platform register a stranger's domain.
|
|
323
|
+
*/ export async function ensureCheckoutDomain(input) {
|
|
324
|
+
var _input_budgetMs;
|
|
325
|
+
let hostname;
|
|
326
|
+
try {
|
|
327
|
+
hostname = new URL(input.pageUrl).hostname.toLowerCase();
|
|
328
|
+
} catch (unused) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
if (!siteOwnHosts(input.site).includes(hostname)) return null;
|
|
332
|
+
if (!registrableDomain(hostname)) return null;
|
|
333
|
+
const controller = new AbortController();
|
|
334
|
+
const budget = (_input_budgetMs = input.budgetMs) != null ? _input_budgetMs : CHECKOUT_DOMAIN_BUDGET_MS;
|
|
335
|
+
const timer = setTimeout(()=>controller.abort(), budget);
|
|
336
|
+
try {
|
|
337
|
+
return await ensurePaymentMethodDomain(hostname, {
|
|
338
|
+
hostId: input.hostId,
|
|
339
|
+
signal: controller.signal
|
|
340
|
+
});
|
|
341
|
+
} finally{
|
|
342
|
+
clearTimeout(timer);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/** One page of the daily reconcile. */ export const RECONCILE_PAGE_SIZE = 200;
|
|
346
|
+
/**
|
|
347
|
+
* The backfill and the safety net in one pass: every site with a connected
|
|
348
|
+
* custom domain gets its domain and `www.` twin registered. A cached, enabled
|
|
349
|
+
* registration costs one read and no Stripe call, so the steady state is cheap;
|
|
350
|
+
* a domain connected before AGL-3629, or whose connect event was lost, is
|
|
351
|
+
* registered on the first pass after it.
|
|
352
|
+
*
|
|
353
|
+
* Paged by `cname` with a cursor so it reads every site once and stops; the
|
|
354
|
+
* `cname > ''` range uses Firestore's automatic single-field index.
|
|
355
|
+
*/ export async function reconcileCustomDomains(gate, options = {}) {
|
|
356
|
+
var _options_maxPages;
|
|
357
|
+
const result = {
|
|
358
|
+
hosts: 0,
|
|
359
|
+
registered: 0,
|
|
360
|
+
failed: 0,
|
|
361
|
+
skippedLocked: 0
|
|
362
|
+
};
|
|
363
|
+
if (!stripeModeOfKey(process.env.STRIPE_SECRET_KEY)) return result;
|
|
364
|
+
const firestore = firebaseAdmin.app().firestore();
|
|
365
|
+
let cursor = null;
|
|
366
|
+
const maxPages = (_options_maxPages = options.maxPages) != null ? _options_maxPages : 50;
|
|
367
|
+
for(let page = 0; page < maxPages; page += 1){
|
|
368
|
+
var _ref;
|
|
369
|
+
var _snapshot_docs_;
|
|
370
|
+
let query = firestore.collection('hosts').where('cname', '>', '').orderBy('cname').limit(RECONCILE_PAGE_SIZE);
|
|
371
|
+
if (cursor) query = query.startAfter(cursor);
|
|
372
|
+
const snapshot = await query.get();
|
|
373
|
+
if (snapshot.empty) break;
|
|
374
|
+
for (const hostDoc of snapshot.docs){
|
|
375
|
+
result.hosts += 1;
|
|
376
|
+
// Skipped, not dropped: a locked site is left as it is and picked up on
|
|
377
|
+
// the first pass after the lift.
|
|
378
|
+
if (await gate.isLocked(hostDoc.id)) {
|
|
379
|
+
result.skippedLocked += 1;
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
for (const domain of customDomainNames(hostDoc.get('cname'))){
|
|
383
|
+
const outcome = await ensurePaymentMethodDomain(domain, {
|
|
384
|
+
hostId: hostDoc.id
|
|
385
|
+
});
|
|
386
|
+
if (outcome.outcome === 'registered') result.registered += 1;
|
|
387
|
+
if (outcome.outcome === 'failed') result.failed += 1;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
cursor = String((_ref = (_snapshot_docs_ = snapshot.docs[snapshot.docs.length - 1]) == null ? void 0 : _snapshot_docs_.get('cname')) != null ? _ref : '');
|
|
391
|
+
if (snapshot.size < RECONCILE_PAGE_SIZE || !cursor) break;
|
|
392
|
+
}
|
|
393
|
+
return result;
|
|
394
|
+
}
|
|
395
|
+
/** Core's `host.domain.attached`: register the custom domain and its twin. */ export async function onHostDomainAttached(payload) {
|
|
396
|
+
for (const domain of customDomainNames(payload.domain)){
|
|
397
|
+
const outcome = await ensurePaymentMethodDomain(domain, {
|
|
398
|
+
hostId: payload.hostId,
|
|
399
|
+
force: true
|
|
400
|
+
});
|
|
401
|
+
if (outcome.outcome === 'failed') {
|
|
402
|
+
console.warn(`[commerce] payment method domain ${domain} not registered: ${outcome.error}`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
/** Core's `host.domain.released`: disable what no other site still serves. */ export async function onHostDomainReleased(payload) {
|
|
407
|
+
const names = payload.domain.endsWith(`.${TENANT_APEX}`) ? [
|
|
408
|
+
registrableDomain(payload.domain)
|
|
409
|
+
].filter((name)=>Boolean(name)) : customDomainNames(payload.domain);
|
|
410
|
+
for (const domain of names){
|
|
411
|
+
if (await domainStillClaimed(domain, payload.hostId)) continue;
|
|
412
|
+
const outcome = await disablePaymentMethodDomain(domain);
|
|
413
|
+
if (outcome.outcome === 'failed') {
|
|
414
|
+
console.warn(`[commerce] payment method domain ${domain} not disabled: ${outcome.error}`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
/** The registrations a settings card shows for one site. */ export async function readSiteDomainRecords(site) {
|
|
419
|
+
const mode = stripeModeOfKey(process.env.STRIPE_SECRET_KEY);
|
|
420
|
+
if (!mode) return [];
|
|
421
|
+
const names = siteOwnHosts(site).filter((name)=>registrableDomain(name));
|
|
422
|
+
const snapshots = await Promise.all(names.map((name)=>docRef(mode, name).get()));
|
|
423
|
+
return snapshots.map((snapshot, index)=>{
|
|
424
|
+
const data = snapshot.exists ? snapshot.data == null ? void 0 : snapshot.data.call(snapshot) : null;
|
|
425
|
+
return data != null ? data : {
|
|
426
|
+
domain: names[index],
|
|
427
|
+
mode,
|
|
428
|
+
stripeId: null,
|
|
429
|
+
enabled: false,
|
|
430
|
+
status: {
|
|
431
|
+
applePay: null,
|
|
432
|
+
googlePay: null,
|
|
433
|
+
link: null,
|
|
434
|
+
amazonPay: null,
|
|
435
|
+
klarna: null
|
|
436
|
+
},
|
|
437
|
+
hostId: null,
|
|
438
|
+
checkedAtMs: 0,
|
|
439
|
+
lastError: null
|
|
440
|
+
};
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
//# sourceMappingURL=payment-method-domains.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/payment-method-domains.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 SiteReturnHost, siteOwnHosts } from '@aglyn/aglyn/app-utils/site-return-url'\nimport { TENANT_APEX } from '@aglyn/aglyn/app-utils/tenant-apex'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin'\n\n/**\n * Stripe payment method domains for storefronts (AGL-3629).\n *\n * The in-page checkout mounts Stripe's Payment Element on the merchant's own\n * domain, and Stripe shows Apple Pay there only on a REGISTERED domain (Google\n * Pay, Link, Amazon Pay and Klarna's express button use the same registration).\n * Nothing registered one, so a shopper on `shop.example.com` with a card in\n * Apple Wallet never saw the button.\n *\n * ## Which account the domain is registered on\n *\n * Stripe's rule: \"The domain where the charge is being run needs to be\n * registered for the user running the charge.\" Storefront charges are\n * DESTINATION charges created by the platform with no `Stripe-Account` header\n * and no `on_behalf_of`, so the platform runs them and the platform's key\n * registers the domain, with no `Stripe-Account` header. A direct-charge flow\n * would register on the connected account instead; there is none today, and\n * `registerOnPlatform` is named for that reason.\n *\n * ## When\n *\n * - On connect: core raises `host.domain.attached`, and commerce registers\n * the custom domain and its `www.` twin.\n * - On first checkout: the session handlers call `ensureCheckoutDomain` for\n * the page the shopper is on, which covers every `{site}.aglyn.app`\n * subdomain without registering thousands of sites that never sell.\n * - Daily: `reconcileCustomDomains` registers any connected custom domain the\n * first two missed (domains connected before AGL-3629 included) — the\n * backfill is a job rather than a one-off script, so it also repairs a\n * missed event later.\n * - On release: `host.domain.released` DISABLES the domain. Stripe has no\n * delete; a disabled domain stops showing the methods and can be enabled\n * again if the name comes back.\n *\n * ## The cache\n *\n * `paymentMethodDomains/{mode}~{domain}` records what Stripe last said, so a\n * checkout costs one document read rather than a Stripe round trip. The mode is\n * in the id because a test key and a live key register in different worlds and\n * a domain registered in one is not registered in the other. Server-only: the\n * rules deny every client.\n */\n\nexport const PAYMENT_METHOD_DOMAINS_COLLECTION = 'paymentMethodDomains'\n\n/** How long a recorded registration is trusted before Stripe is asked again. */\nexport const PAYMENT_METHOD_DOMAIN_RECHECK_MS = 7 * 24 * 60 * 60 * 1000\n\n/** The most a checkout waits on Stripe before selling without the domain. */\nexport const CHECKOUT_DOMAIN_BUDGET_MS = 2500\n\nexport type StripeMode = 'live' | 'test'\n\n/** Stripe's per-method verdict on a domain. */\nexport interface PaymentMethodDomainStatus {\n applePay: string | null\n googlePay: string | null\n link: string | null\n amazonPay: string | null\n klarna: string | null\n}\n\nexport interface PaymentMethodDomainRecord {\n domain: string\n mode: StripeMode\n stripeId: string | null\n enabled: boolean\n status: PaymentMethodDomainStatus\n hostId: string | null\n checkedAtMs: number\n lastError: string | null\n}\n\ninterface StripeDomainObject {\n id: string\n domain_name: string\n enabled: boolean\n apple_pay?: { status?: string }\n google_pay?: { status?: string }\n link?: { status?: string }\n amazon_pay?: { status?: string }\n klarna?: { status?: string }\n}\n\n/** Which Stripe world the platform key is in, from its prefix. */\nexport function stripeModeOfKey(key: string | undefined): StripeMode | null {\n const value = String(key ?? '')\n if (/^(sk|rk)_live_/.test(value)) return 'live'\n if (/^(sk|rk)_test_/.test(value)) return 'test'\n return null\n}\n\n/**\n * A hostname Stripe can register: lowercased, no trailing dot, at least two\n * labels, and never a local or IP host — a checkout opened on `localhost`\n * must not try to register it.\n */\nexport function registrableDomain(input: unknown): string | null {\n const value = String(input ?? '')\n .trim()\n .toLowerCase()\n .replace(/\\.+$/, '')\n if (!value || value.length > 253) return null\n if (value === 'localhost' || value.endsWith('.localhost')) return null\n if (/^[0-9.]+$/.test(value) || value.includes(':')) return null\n if (!/^[a-z0-9-]+(\\.[a-z0-9-]+)+$/.test(value)) return null\n return value\n}\n\n/** The cache document id for a domain in a mode. */\nexport function paymentMethodDomainDocId(mode: StripeMode, domain: string): string {\n return `${mode}~${domain}`\n}\n\n/**\n * The domains a site's custom domain needs: the domain and its `www.` twin,\n * since the platform answers on both (`siteOwnHosts`).\n */\nexport function customDomainNames(cname: unknown): string[] {\n const domain = registrableDomain(cname)\n if (!domain) return []\n const twin = domain.startsWith('www.') ? domain.slice(4) : `www.${domain}`\n return [domain, ...(registrableDomain(twin) ? [twin] : [])]\n}\n\nfunction statusOf(object: StripeDomainObject): PaymentMethodDomainStatus {\n return {\n applePay: object.apple_pay?.status ?? null,\n googlePay: object.google_pay?.status ?? null,\n link: object.link?.status ?? null,\n amazonPay: object.amazon_pay?.status ?? null,\n klarna: object.klarna?.status ?? null,\n }\n}\n\nasync function stripeRequest<T>(\n method: 'GET' | 'POST',\n path: string,\n params?: Record<string, string>,\n options: { idempotencyKey?: string; signal?: AbortSignal } = {},\n): Promise<T> {\n const query = method === 'GET' && params ? `?${new URLSearchParams(params)}` : ''\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 ...(method === 'POST' && {\n 'Content-Type': 'application/x-www-form-urlencoded',\n }),\n // The platform's own key and NO `Stripe-Account`: destination charges\n // are run by the platform, so the platform holds the registration.\n ...(options.idempotencyKey && { 'Idempotency-Key': options.idempotencyKey }),\n },\n ...(method === 'POST' && params && { body: new URLSearchParams(params).toString() }),\n ...(options.signal && { signal: options.signal }),\n })\n const payload = (await response.json().catch(() => ({}))) as T & {\n error?: { message?: string }\n }\n if (!response.ok) {\n throw new Error(payload?.error?.message ?? `Stripe ${path} failed (${response.status})`)\n }\n return payload\n}\n\nasync function findOnStripe(\n domain: string,\n signal?: AbortSignal,\n): Promise<StripeDomainObject | null> {\n const list = await stripeRequest<{ data?: StripeDomainObject[] }>(\n 'GET',\n 'payment_method_domains',\n { domain_name: domain, limit: '1' },\n { signal },\n )\n return list.data?.find((entry) => entry.domain_name === domain) ?? null\n}\n\n/**\n * Register (or re-enable) one domain on the platform account. Idempotent end\n * to end: an existing registration is found first and reused, a disabled one\n * is enabled rather than duplicated, and the create carries an idempotency key\n * so two checkouts racing on a fresh subdomain open one registration.\n */\nexport async function registerOnPlatform(\n domain: string,\n signal?: AbortSignal,\n): Promise<StripeDomainObject> {\n const existing = await findOnStripe(domain, signal)\n if (existing) {\n if (existing.enabled) return existing\n return stripeRequest<StripeDomainObject>(\n 'POST',\n `payment_method_domains/${encodeURIComponent(existing.id)}`,\n { enabled: 'true' },\n { signal },\n )\n }\n try {\n return await stripeRequest<StripeDomainObject>(\n 'POST',\n 'payment_method_domains',\n { domain_name: domain, enabled: 'true' },\n { idempotencyKey: `aglyn-pmd-register:${domain}`, signal },\n )\n } catch (error) {\n // Lost a race to a create that landed between the lookup and this call:\n // the registration exists, which is what was wanted.\n const raced = await findOnStripe(domain, signal).catch(() => null)\n if (raced) return raced\n throw error\n }\n}\n\nfunction docRef(mode: StripeMode, domain: string) {\n return firebaseAdmin\n .app()\n .firestore()\n .collection(PAYMENT_METHOD_DOMAINS_COLLECTION)\n .doc(paymentMethodDomainDocId(mode, domain))\n}\n\nasync function record(\n mode: StripeMode,\n domain: string,\n patch: Partial<PaymentMethodDomainRecord>,\n): Promise<void> {\n await docRef(mode, domain).set(\n { domain, mode, checkedAtMs: Date.now(), ...patch },\n { merge: true },\n )\n}\n\nexport interface EnsureDomainResult {\n domain: string\n outcome: 'registered' | 'cached' | 'skipped' | 'failed'\n record?: PaymentMethodDomainRecord\n error?: string\n}\n\n/**\n * Make sure one domain is registered and enabled, reading the cache first.\n *\n * Never throws: every caller is on its way to something more important (a\n * sale, a domain connect), and a domain Stripe would not take today is\n * recorded with its error and retried by the daily reconcile.\n */\nexport async function ensurePaymentMethodDomain(\n rawDomain: string,\n options: { hostId?: string | null; signal?: AbortSignal; force?: boolean } = {},\n): Promise<EnsureDomainResult> {\n const domain = registrableDomain(rawDomain)\n const mode = stripeModeOfKey(process.env.STRIPE_SECRET_KEY)\n if (!domain || !mode) {\n return { domain: String(rawDomain ?? ''), outcome: 'skipped' }\n }\n try {\n if (!options.force) {\n const cached = await docRef(mode, domain).get()\n const data = cached.data?.() as PaymentMethodDomainRecord | undefined\n if (\n cached.exists &&\n data?.enabled === true &&\n data.stripeId &&\n Date.now() - Number(data.checkedAtMs ?? 0) < PAYMENT_METHOD_DOMAIN_RECHECK_MS\n ) {\n return { domain, outcome: 'cached', record: data }\n }\n }\n const object = await registerOnPlatform(domain, options.signal)\n const next: PaymentMethodDomainRecord = {\n domain,\n mode,\n stripeId: object.id,\n enabled: object.enabled !== false,\n status: statusOf(object),\n hostId: options.hostId ?? null,\n checkedAtMs: Date.now(),\n lastError: null,\n }\n await record(mode, domain, next)\n return { domain, outcome: 'registered', record: next }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n await record(mode, domain, {\n enabled: false,\n hostId: options.hostId ?? null,\n lastError: message.slice(0, 500),\n }).catch(() => undefined)\n return { domain, outcome: 'failed', error: message }\n }\n}\n\n/**\n * Disable a domain the platform no longer serves for a site. Stripe has no\n * delete for a payment method domain; disabling stops every method on it, and\n * `ensurePaymentMethodDomain` re-enables the same registration if the name is\n * connected again.\n */\nexport async function disablePaymentMethodDomain(\n rawDomain: string,\n): Promise<{ domain: string; outcome: 'disabled' | 'absent' | 'skipped' | 'failed'; error?: string }> {\n const domain = registrableDomain(rawDomain)\n const mode = stripeModeOfKey(process.env.STRIPE_SECRET_KEY)\n if (!domain || !mode) return { domain: String(rawDomain ?? ''), outcome: 'skipped' }\n try {\n const existing = await findOnStripe(domain)\n if (!existing) {\n await record(mode, domain, { enabled: false, stripeId: null, lastError: null })\n return { domain, outcome: 'absent' }\n }\n const object = existing.enabled\n ? await stripeRequest<StripeDomainObject>(\n 'POST',\n `payment_method_domains/${encodeURIComponent(existing.id)}`,\n { enabled: 'false' },\n )\n : existing\n await record(mode, domain, {\n stripeId: object.id,\n enabled: false,\n status: statusOf(object),\n lastError: null,\n })\n return { domain, outcome: 'disabled' }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n return { domain, outcome: 'failed', error: message }\n }\n}\n\n/**\n * Is a name still served for some OTHER site? A custom domain's `www.` twin\n * can be another site's own `cname`, and an aglyn subdomain released by a\n * deleted site can already belong to a new one. Disabling either would take\n * Apple Pay away from a store that did nothing.\n */\nexport async function domainStillClaimed(domain: string, exceptHostId: string): Promise<boolean> {\n const firestore = firebaseAdmin.app().firestore()\n const hosts = firestore.collection('hosts')\n const names = customDomainNames(domain)\n const byCname = await hosts\n .where('cname', 'in', names.length ? names : [domain])\n .limit(3)\n .get()\n if (byCname.docs.some((doc) => doc.id !== exceptHostId)) return true\n const suffix = `.${TENANT_APEX}`\n if (domain.endsWith(suffix)) {\n const subdomain = domain.slice(0, -suffix.length)\n const bySubdomain = await hosts.where('subdomain', '==', subdomain).limit(3).get()\n if (bySubdomain.docs.some((doc) => doc.id !== exceptHostId)) return true\n }\n return false\n}\n\n/**\n * The checkout's hook: register the domain the shopper is paying on, within a\n * budget, before the client secret goes back to the browser. Only a name the\n * SITE answers on is ever registered — the return URL has already been judged\n * against `siteOwnHosts` by `siteReturnUrl`, and it is judged again here so a\n * forged `Host` can never make the platform register a stranger's domain.\n */\nexport async function ensureCheckoutDomain(input: {\n pageUrl: string\n site: SiteReturnHost | null | undefined\n hostId: string\n budgetMs?: number\n}): Promise<EnsureDomainResult | null> {\n let hostname: string\n try {\n hostname = new URL(input.pageUrl).hostname.toLowerCase()\n } catch {\n return null\n }\n if (!siteOwnHosts(input.site).includes(hostname)) return null\n if (!registrableDomain(hostname)) return null\n const controller = new AbortController()\n const budget = input.budgetMs ?? CHECKOUT_DOMAIN_BUDGET_MS\n const timer = setTimeout(() => controller.abort(), budget)\n try {\n return await ensurePaymentMethodDomain(hostname, {\n hostId: input.hostId,\n signal: controller.signal,\n })\n } finally {\n clearTimeout(timer)\n }\n}\n\n/** One page of the daily reconcile. */\nexport const RECONCILE_PAGE_SIZE = 200\n\n/**\n * The backfill and the safety net in one pass: every site with a connected\n * custom domain gets its domain and `www.` twin registered. A cached, enabled\n * registration costs one read and no Stripe call, so the steady state is cheap;\n * a domain connected before AGL-3629, or whose connect event was lost, is\n * registered on the first pass after it.\n *\n * Paged by `cname` with a cursor so it reads every site once and stops; the\n * `cname > ''` range uses Firestore's automatic single-field index.\n */\nexport async function reconcileCustomDomains(\n gate: { isLocked(hostId: string): Promise<boolean> },\n options: { maxPages?: number } = {},\n): Promise<{ hosts: number; registered: number; failed: number; skippedLocked: number }> {\n const result = { hosts: 0, registered: 0, failed: 0, skippedLocked: 0 }\n if (!stripeModeOfKey(process.env.STRIPE_SECRET_KEY)) return result\n const firestore = firebaseAdmin.app().firestore()\n let cursor: string | null = null\n const maxPages = options.maxPages ?? 50\n for (let page = 0; page < maxPages; page += 1) {\n let query = firestore\n .collection('hosts')\n .where('cname', '>', '')\n .orderBy('cname')\n .limit(RECONCILE_PAGE_SIZE)\n if (cursor) query = query.startAfter(cursor)\n const snapshot = await query.get()\n if (snapshot.empty) break\n for (const hostDoc of snapshot.docs) {\n result.hosts += 1\n // Skipped, not dropped: a locked site is left as it is and picked up on\n // the first pass after the lift.\n if (await gate.isLocked(hostDoc.id)) {\n result.skippedLocked += 1\n continue\n }\n for (const domain of customDomainNames(hostDoc.get('cname'))) {\n const outcome = await ensurePaymentMethodDomain(domain, { hostId: hostDoc.id })\n if (outcome.outcome === 'registered') result.registered += 1\n if (outcome.outcome === 'failed') result.failed += 1\n }\n }\n cursor = String(snapshot.docs[snapshot.docs.length - 1]?.get('cname') ?? '')\n if (snapshot.size < RECONCILE_PAGE_SIZE || !cursor) break\n }\n return result\n}\n\n/** Core's `host.domain.attached`: register the custom domain and its twin. */\nexport async function onHostDomainAttached(payload: {\n hostId: string\n domain: string\n}): Promise<void> {\n for (const domain of customDomainNames(payload.domain)) {\n const outcome = await ensurePaymentMethodDomain(domain, {\n hostId: payload.hostId,\n force: true,\n })\n if (outcome.outcome === 'failed') {\n console.warn(`[commerce] payment method domain ${domain} not registered: ${outcome.error}`)\n }\n }\n}\n\n/** Core's `host.domain.released`: disable what no other site still serves. */\nexport async function onHostDomainReleased(payload: {\n hostId: string\n domain: string\n}): Promise<void> {\n const names = payload.domain.endsWith(`.${TENANT_APEX}`)\n ? [registrableDomain(payload.domain)].filter((name): name is string => Boolean(name))\n : customDomainNames(payload.domain)\n for (const domain of names) {\n if (await domainStillClaimed(domain, payload.hostId)) continue\n const outcome = await disablePaymentMethodDomain(domain)\n if (outcome.outcome === 'failed') {\n console.warn(`[commerce] payment method domain ${domain} not disabled: ${outcome.error}`)\n }\n }\n}\n\n/** The registrations a settings card shows for one site. */\nexport async function readSiteDomainRecords(\n site: SiteReturnHost | null | undefined,\n): Promise<PaymentMethodDomainRecord[]> {\n const mode = stripeModeOfKey(process.env.STRIPE_SECRET_KEY)\n if (!mode) return []\n const names = siteOwnHosts(site).filter((name) => registrableDomain(name))\n const snapshots = await Promise.all(names.map((name) => docRef(mode, name).get()))\n return snapshots.map((snapshot, index) => {\n const data = (snapshot.exists ? snapshot.data?.() : null) as PaymentMethodDomainRecord | null\n return (\n data ?? {\n domain: names[index],\n mode,\n stripeId: null,\n enabled: false,\n status: { applePay: null, googlePay: null, link: null, amazonPay: null, klarna: null },\n hostId: null,\n checkedAtMs: 0,\n lastError: null,\n }\n )\n })\n}\n"],"names":["siteOwnHosts","TENANT_APEX","firebaseAdmin","PAYMENT_METHOD_DOMAINS_COLLECTION","PAYMENT_METHOD_DOMAIN_RECHECK_MS","CHECKOUT_DOMAIN_BUDGET_MS","stripeModeOfKey","key","value","String","test","registrableDomain","input","trim","toLowerCase","replace","length","endsWith","includes","paymentMethodDomainDocId","mode","domain","customDomainNames","cname","twin","startsWith","slice","statusOf","object","applePay","apple_pay","status","googlePay","google_pay","link","amazonPay","amazon_pay","klarna","stripeRequest","method","path","params","options","query","URLSearchParams","response","fetch","headers","Authorization","process","env","STRIPE_SECRET_KEY","idempotencyKey","body","toString","signal","payload","json","catch","ok","Error","error","message","findOnStripe","list","domain_name","limit","data","find","entry","registerOnPlatform","existing","enabled","encodeURIComponent","id","raced","docRef","app","firestore","collection","doc","record","patch","set","checkedAtMs","Date","now","merge","ensurePaymentMethodDomain","rawDomain","outcome","force","cached","get","exists","stripeId","Number","next","hostId","lastError","undefined","disablePaymentMethodDomain","domainStillClaimed","exceptHostId","hosts","names","byCname","where","docs","some","suffix","subdomain","bySubdomain","ensureCheckoutDomain","hostname","URL","pageUrl","site","controller","AbortController","budget","budgetMs","timer","setTimeout","abort","clearTimeout","RECONCILE_PAGE_SIZE","reconcileCustomDomains","gate","result","registered","failed","skippedLocked","cursor","maxPages","page","snapshot","orderBy","startAfter","empty","hostDoc","isLocked","size","onHostDomainAttached","console","warn","onHostDomainReleased","filter","name","Boolean","readSiteDomainRecords","snapshots","Promise","all","map","index"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAA8BA,YAAY,QAAQ,yCAAwC;AAC1F,SAASC,WAAW,QAAQ,qCAAoC;AAChE,SAASC,aAAa,QAAQ,2BAA0B;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyCC,GAED,OAAO,MAAMC,oCAAoC,uBAAsB;AAEvE,8EAA8E,GAC9E,OAAO,MAAMC,mCAAmC,IAAI,KAAK,KAAK,KAAK,KAAI;AAEvE,2EAA2E,GAC3E,OAAO,MAAMC,4BAA4B,KAAI;AAmC7C,gEAAgE,GAChE,OAAO,SAASC,gBAAgBC,GAAuB;IACrD,MAAMC,QAAQC,OAAOF,cAAAA,MAAO;IAC5B,IAAI,iBAAiBG,IAAI,CAACF,QAAQ,OAAO;IACzC,IAAI,iBAAiBE,IAAI,CAACF,QAAQ,OAAO;IACzC,OAAO;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASG,kBAAkBC,KAAc;IAC9C,MAAMJ,QAAQC,OAAOG,gBAAAA,QAAS,IAC3BC,IAAI,GACJC,WAAW,GACXC,OAAO,CAAC,QAAQ;IACnB,IAAI,CAACP,SAASA,MAAMQ,MAAM,GAAG,KAAK,OAAO;IACzC,IAAIR,UAAU,eAAeA,MAAMS,QAAQ,CAAC,eAAe,OAAO;IAClE,IAAI,YAAYP,IAAI,CAACF,UAAUA,MAAMU,QAAQ,CAAC,MAAM,OAAO;IAC3D,IAAI,CAAC,8BAA8BR,IAAI,CAACF,QAAQ,OAAO;IACvD,OAAOA;AACT;AAEA,kDAAkD,GAClD,OAAO,SAASW,yBAAyBC,IAAgB,EAAEC,MAAc;IACvE,OAAO,GAAG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
/**
|
|
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 StorefrontPaymentMethodId, type StorefrontPaymentMethodSettings } from '../model/commerce-payment-methods';
|
|
18
|
+
import { type PaymentMethodDomainRecord } from './payment-method-domains';
|
|
19
|
+
/**
|
|
20
|
+
* The merchant's payment methods card (AGL-3629):
|
|
21
|
+
* `GET|POST /api/commerce/payment-methods?hostId=…`, served by the console.
|
|
22
|
+
*
|
|
23
|
+
* GET answers, per method, three facts the card needs and no client can read:
|
|
24
|
+
*
|
|
25
|
+
* - whether the PLATFORM offers it (its default payment method configuration
|
|
26
|
+
* — storefront charges are destination charges with the platform as
|
|
27
|
+
* merchant of record, so that configuration is the ceiling). A method the
|
|
28
|
+
* platform has not turned on, or that Stripe has not made available to it,
|
|
29
|
+
* is reported `unavailable` and the card does not show it at all;
|
|
30
|
+
* - the connected account's capability for it, which Stripe asks platforms to
|
|
31
|
+
* request before an account accepts BNPL, Cash App, Amazon Pay or crypto;
|
|
32
|
+
* - the site's domain registrations, which Apple Pay depends on.
|
|
33
|
+
*
|
|
34
|
+
* POST saves the toggles to `hosts/{hostId}/settings/store.paymentMethods` and
|
|
35
|
+
* requests the capability of each method turned on, in one account update with
|
|
36
|
+
* an idempotency key. Server-side, because the toggle and the capability are
|
|
37
|
+
* one decision: a toggle saved by the browser with no capability behind it
|
|
38
|
+
* would read as on and never appear.
|
|
39
|
+
*/
|
|
40
|
+
export type PlatformAvailability = 'on' | 'unavailable' | null;
|
|
41
|
+
export type CapabilityStatus = 'active' | 'pending' | 'inactive' | 'unrequested' | null;
|
|
42
|
+
export interface PaymentMethodRow {
|
|
43
|
+
id: StorefrontPaymentMethodId;
|
|
44
|
+
on: boolean;
|
|
45
|
+
platform: PlatformAvailability;
|
|
46
|
+
capability: CapabilityStatus;
|
|
47
|
+
}
|
|
48
|
+
export interface PaymentMethodsAnswer {
|
|
49
|
+
methods: PaymentMethodRow[];
|
|
50
|
+
domains: PaymentMethodDomainRecord[];
|
|
51
|
+
accountConnected: boolean;
|
|
52
|
+
/** The caller may save toggles: a site admin. */
|
|
53
|
+
canEdit: boolean;
|
|
54
|
+
/** The caller may open Stripe to finish a method: the organization owner. */
|
|
55
|
+
canFinish: boolean;
|
|
56
|
+
warnings: string[];
|
|
57
|
+
}
|
|
58
|
+
/** Test seam: forget the cached platform configuration. */
|
|
59
|
+
export declare function resetPlatformPaymentMethodCacheForTests(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Which methods the platform's own default configuration offers. The list
|
|
62
|
+
* also returns configurations OTHER Connect applications made for this
|
|
63
|
+
* account (`application` set); those do not govern our sessions and are
|
|
64
|
+
* skipped. `null` per method when Stripe could not be asked — the card then
|
|
65
|
+
* shows the toggle without a verdict rather than hiding a method that may work.
|
|
66
|
+
*/
|
|
67
|
+
export declare function platformPaymentMethodAvailability(): Promise<Record<string, PlatformAvailability>>;
|
|
68
|
+
/** The capabilities a save asks Stripe for: on, offered, not yet requested. */
|
|
69
|
+
export declare function capabilitiesToRequest(settings: StorefrontPaymentMethodSettings, platform: Record<string, PlatformAvailability>, capabilities: Record<string, string> | undefined): string[];
|
|
70
|
+
export declare function buildPaymentMethodRows(settings: StorefrontPaymentMethodSettings, platform: Record<string, PlatformAvailability>, capabilities: Record<string, string> | undefined): PaymentMethodRow[];
|
|
71
|
+
/**
|
|
72
|
+
* Where Stripe sends the owner back: the console page they pressed the button
|
|
73
|
+
* on, judged against the request's own origin so a forged `Referer` cannot
|
|
74
|
+
* turn the link into a redirect to somewhere else.
|
|
75
|
+
*/
|
|
76
|
+
export declare function consoleReturnUrl(headers: Partial<Record<string, string>>): string;
|
|
77
|
+
export declare function paymentMethodsHandler(request: Request): Promise<Response>;
|