@aglyn/plugins-commerce 1.0.0-beta.230 → 1.0.0-beta.232
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -13
- package/src/index.d.ts +0 -1
- package/src/index.js +0 -1
- package/src/index.js.map +1 -1
- package/src/lib/barcode/barcode-decode.d.ts +71 -0
- package/src/lib/barcode/barcode-decode.js +498 -0
- package/src/lib/barcode/barcode-decode.js.map +1 -0
- package/src/lib/barcode/barcode-encode.d.ts +44 -0
- package/src/lib/barcode/barcode-encode.js +138 -0
- package/src/lib/barcode/barcode-encode.js.map +1 -0
- package/src/lib/barcode/barcode-scanner.component.d.ts +23 -0
- package/src/lib/barcode/barcode-scanner.component.js +260 -0
- package/src/lib/barcode/barcode-scanner.component.js.map +1 -0
- package/src/lib/barcode/scan-button.component.d.ts +10 -0
- package/src/lib/barcode/scan-button.component.js +62 -0
- package/src/lib/barcode/scan-button.component.js.map +1 -0
- package/src/lib/barcode/scanner-wedge.d.ts +35 -0
- package/src/lib/barcode/scanner-wedge.js +108 -0
- package/src/lib/barcode/scanner-wedge.js.map +1 -0
- package/src/lib/components/account.js +10 -1
- package/src/lib/components/account.js.map +1 -1
- package/src/lib/components/cart-extras.d.ts +45 -0
- package/src/lib/components/cart-extras.js +127 -0
- package/src/lib/components/cart-extras.js.map +1 -0
- package/src/lib/components/cart.js +82 -15
- package/src/lib/components/cart.js.map +1 -1
- package/src/lib/components/checkout-return-notice.d.ts +26 -0
- package/src/lib/components/checkout-return-notice.js +48 -0
- package/src/lib/components/checkout-return-notice.js.map +1 -0
- package/src/lib/components/commerce-console-page.js +124 -0
- package/src/lib/components/commerce-console-page.js.map +1 -1
- package/src/lib/components/commerce-console-sections.d.ts +1 -1
- package/src/lib/components/commerce-console-sections.js +4 -0
- package/src/lib/components/commerce-console-sections.js.map +1 -1
- package/src/lib/components/console/bulk-fulfill.d.ts +44 -0
- package/src/lib/components/console/bulk-fulfill.js +84 -0
- package/src/lib/components/console/bulk-fulfill.js.map +1 -0
- package/src/lib/components/console/catalog-organization-card.component.js +1 -0
- package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
- package/src/lib/components/console/customer-notifications-card.component.d.ts +19 -0
- package/src/lib/components/console/customer-notifications-card.component.js +149 -0
- package/src/lib/components/console/customer-notifications-card.component.js.map +1 -0
- package/src/lib/components/console/host-orders-card.component.js +88 -6
- package/src/lib/components/console/host-orders-card.component.js.map +1 -1
- package/src/lib/components/console/locations-card.component.js +164 -57
- package/src/lib/components/console/locations-card.component.js.map +1 -1
- package/src/lib/components/console/order-detail-dialog.component.js +209 -61
- package/src/lib/components/console/order-detail-dialog.component.js.map +1 -1
- package/src/lib/components/console/order-fulfillment-panel.component.d.ts +48 -0
- package/src/lib/components/console/order-fulfillment-panel.component.js +542 -0
- package/src/lib/components/console/order-fulfillment-panel.component.js.map +1 -0
- package/src/lib/components/console/order-invoice.component.d.ts +33 -0
- package/src/lib/components/console/order-invoice.component.js +81 -0
- package/src/lib/components/console/order-invoice.component.js.map +1 -0
- package/src/lib/components/console/order-receipt-resend.component.d.ts +21 -0
- package/src/lib/components/console/order-receipt-resend.component.js +203 -0
- package/src/lib/components/console/order-receipt-resend.component.js.map +1 -0
- package/src/lib/components/console/order-returns.component.d.ts +36 -0
- package/src/lib/components/console/order-returns.component.js +142 -0
- package/src/lib/components/console/order-returns.component.js.map +1 -0
- package/src/lib/components/console/order-shipping-actions.component.d.ts +54 -0
- package/src/lib/components/console/order-shipping-actions.component.js +149 -0
- package/src/lib/components/console/order-shipping-actions.component.js.map +1 -0
- package/src/lib/components/console/order-webhooks-card.component.d.ts +50 -0
- package/src/lib/components/console/order-webhooks-card.component.js +623 -0
- package/src/lib/components/console/order-webhooks-card.component.js.map +1 -0
- package/src/lib/components/console/order-zones.d.ts +155 -0
- package/src/lib/components/console/order-zones.js +40 -0
- package/src/lib/components/console/order-zones.js.map +1 -0
- package/src/lib/components/console/payment-methods-card.component.d.ts +67 -0
- package/src/lib/components/console/payment-methods-card.component.js +395 -0
- package/src/lib/components/console/payment-methods-card.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-api.d.ts +124 -0
- package/src/lib/components/console/pos/pos-api.js +101 -0
- package/src/lib/components/console/pos/pos-api.js.map +1 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.d.ts +36 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.js +160 -0
- package/src/lib/components/console/pos/pos-cart-panel.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.d.ts +39 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.js +352 -0
- package/src/lib/components/console/pos/pos-item-dialog.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-product-grid.component.d.ts +47 -0
- package/src/lib/components/console/pos/pos-product-grid.component.js +272 -0
- package/src/lib/components/console/pos/pos-product-grid.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-receipt-panel.component.d.ts +27 -0
- package/src/lib/components/console/pos/pos-receipt-panel.component.js +282 -0
- package/src/lib/components/console/pos/pos-receipt-panel.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +53 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js +445 -0
- package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -0
- package/src/lib/components/console/pos/pos-tender-panel.component.d.ts +31 -0
- package/src/lib/components/console/pos/pos-tender-panel.component.js +640 -0
- package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -0
- package/src/lib/components/console/pos/use-pos-display.d.ts +43 -0
- package/src/lib/components/console/pos/use-pos-display.js +161 -0
- package/src/lib/components/console/pos/use-pos-display.js.map +1 -0
- package/src/lib/components/console/pos-devices-card.component.d.ts +14 -0
- package/src/lib/components/console/pos-devices-card.component.js +546 -0
- package/src/lib/components/console/pos-devices-card.component.js.map +1 -0
- package/src/lib/components/console/pos-display/brand-screen.d.ts +33 -0
- package/src/lib/components/console/pos-display/brand-screen.js +85 -0
- package/src/lib/components/console/pos-display/brand-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/cart-screen.d.ts +29 -0
- package/src/lib/components/console/pos-display/cart-screen.js +166 -0
- package/src/lib/components/console/pos-display/cart-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/pairing-screen.d.ts +24 -0
- package/src/lib/components/console/pos-display/pairing-screen.js +127 -0
- package/src/lib/components/console/pos-display/pairing-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/pos-display-api.d.ts +90 -0
- package/src/lib/components/console/pos-display/pos-display-api.js +140 -0
- package/src/lib/components/console/pos-display/pos-display-api.js.map +1 -0
- package/src/lib/components/console/pos-display/receipt-screen.d.ts +35 -0
- package/src/lib/components/console/pos-display/receipt-screen.js +200 -0
- package/src/lib/components/console/pos-display/receipt-screen.js.map +1 -0
- package/src/lib/components/console/pos-display/tip-screen.d.ts +36 -0
- package/src/lib/components/console/pos-display/tip-screen.js +211 -0
- package/src/lib/components/console/pos-display/tip-screen.js.map +1 -0
- package/src/lib/components/console/pos-display-page.component.d.ts +16 -0
- package/src/lib/components/console/pos-display-page.component.js +407 -0
- package/src/lib/components/console/pos-display-page.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-customer-lookup.component.d.ts +40 -0
- package/src/lib/components/console/pos-ops/pos-customer-lookup.component.js +289 -0
- package/src/lib/components/console/pos-ops/pos-customer-lookup.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-last-receipt.component.d.ts +34 -0
- package/src/lib/components/console/pos-ops/pos-last-receipt.component.js +61 -0
- package/src/lib/components/console/pos-ops/pos-last-receipt.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.d.ts +38 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.js +129 -0
- package/src/lib/components/console/pos-ops/pos-operations-bar.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-ops-api.d.ts +37 -0
- package/src/lib/components/console/pos-ops/pos-ops-api.js +60 -0
- package/src/lib/components/console/pos-ops/pos-ops-api.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-pin-pad.component.d.ts +48 -0
- package/src/lib/components/console/pos-ops/pos-pin-pad.component.js +220 -0
- package/src/lib/components/console/pos-ops/pos-pin-pad.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-receipt-actions.component.d.ts +63 -0
- package/src/lib/components/console/pos-ops/pos-receipt-actions.component.js +186 -0
- package/src/lib/components/console/pos-ops/pos-receipt-actions.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-receipt.d.ts +39 -0
- package/src/lib/components/console/pos-ops/pos-receipt.js +182 -0
- package/src/lib/components/console/pos-ops/pos-receipt.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-return-dialog.component.d.ts +40 -0
- package/src/lib/components/console/pos-ops/pos-return-dialog.component.js +465 -0
- package/src/lib/components/console/pos-ops/pos-return-dialog.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-history-card.component.d.ts +29 -0
- package/src/lib/components/console/pos-ops/pos-shift-history-card.component.js +253 -0
- package/src/lib/components/console/pos-ops/pos-shift-history-card.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.d.ts +34 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.js +494 -0
- package/src/lib/components/console/pos-ops/pos-shift-panel.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-shift-report.component.d.ts +37 -0
- package/src/lib/components/console/pos-ops/pos-shift-report.component.js +102 -0
- package/src/lib/components/console/pos-ops/pos-shift-report.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.d.ts +30 -0
- package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.js +277 -0
- package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.js.map +1 -0
- package/src/lib/components/console/pos-ops/register-ops.d.ts +28 -0
- package/src/lib/components/console/pos-ops/register-ops.js +28 -0
- package/src/lib/components/console/pos-ops/register-ops.js.map +1 -0
- package/src/lib/components/console/pos-ops/use-pos-cashier.d.ts +46 -0
- package/src/lib/components/console/pos-ops/use-pos-cashier.js +128 -0
- package/src/lib/components/console/pos-ops/use-pos-cashier.js.map +1 -0
- package/src/lib/components/console/pos-ops/use-pos-sale-receipt.d.ts +36 -0
- package/src/lib/components/console/pos-ops/use-pos-sale-receipt.js +64 -0
- package/src/lib/components/console/pos-ops/use-pos-sale-receipt.js.map +1 -0
- package/src/lib/components/console/pos-page.component.d.ts +13 -5
- package/src/lib/components/console/pos-page.component.js +756 -654
- package/src/lib/components/console/pos-page.component.js.map +1 -1
- package/src/lib/components/console/pos-zones.d.ts +23 -0
- package/src/lib/components/console/pos-zones.js +31 -0
- package/src/lib/components/console/pos-zones.js.map +1 -0
- package/src/lib/components/console/product-editor-dialog.component.js +61 -71
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/components/console/product-labels-dialog.component.d.ts +13 -0
- package/src/lib/components/console/product-labels-dialog.component.js +197 -0
- package/src/lib/components/console/product-labels-dialog.component.js.map +1 -0
- package/src/lib/components/console/product-register-fields.component.d.ts +19 -0
- package/src/lib/components/console/product-register-fields.component.js +241 -0
- package/src/lib/components/console/product-register-fields.component.js.map +1 -0
- package/src/lib/components/console/product-zones.d.ts +44 -0
- package/src/lib/components/console/product-zones.js.map +1 -1
- package/src/lib/components/console/products-hub-card.component.js +23 -20
- package/src/lib/components/console/products-hub-card.component.js.map +1 -1
- package/src/lib/components/console/register-hardware-card.component.d.ts +33 -0
- package/src/lib/components/console/register-hardware-card.component.js +826 -0
- package/src/lib/components/console/register-hardware-card.component.js.map +1 -0
- package/src/lib/components/console/registers-card.component.js +24 -5
- package/src/lib/components/console/registers-card.component.js.map +1 -1
- package/src/lib/components/console/return-actions.d.ts +38 -0
- package/src/lib/components/console/return-actions.js +76 -0
- package/src/lib/components/console/return-actions.js.map +1 -0
- package/src/lib/components/console/return-detail-dialog.component.d.ts +34 -0
- package/src/lib/components/console/return-detail-dialog.component.js +718 -0
- package/src/lib/components/console/return-detail-dialog.component.js.map +1 -0
- package/src/lib/components/console/return-settings-card.component.d.ts +34 -0
- package/src/lib/components/console/return-settings-card.component.js +195 -0
- package/src/lib/components/console/return-settings-card.component.js.map +1 -0
- package/src/lib/components/console/return-zones.d.ts +87 -0
- package/src/lib/components/console/return-zones.js +31 -0
- package/src/lib/components/console/return-zones.js.map +1 -0
- package/src/lib/components/console/returns-card.component.d.ts +45 -0
- package/src/lib/components/console/returns-card.component.js +159 -0
- package/src/lib/components/console/returns-card.component.js.map +1 -0
- package/src/lib/components/console/shipping-settings-card.component.js +161 -5
- package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
- package/src/lib/components/console/shippingeasy-card.component.d.ts +59 -0
- package/src/lib/components/console/shippingeasy-card.component.js +378 -0
- package/src/lib/components/console/shippingeasy-card.component.js.map +1 -0
- package/src/lib/components/console/shipstation-card.component.d.ts +35 -0
- package/src/lib/components/console/shipstation-card.component.js +345 -0
- package/src/lib/components/console/shipstation-card.component.js.map +1 -0
- package/src/lib/components/console/start-return-dialog.component.d.ts +40 -0
- package/src/lib/components/console/start-return-dialog.component.js +243 -0
- package/src/lib/components/console/start-return-dialog.component.js.map +1 -0
- package/src/lib/components/console/stock-movements-card.component.js +2 -1
- package/src/lib/components/console/stock-movements-card.component.js.map +1 -1
- package/src/lib/components/console/store-settings-card.component.js +2 -66
- package/src/lib/components/console/store-settings-card.component.js.map +1 -1
- package/src/lib/components/console/store-zones.d.ts +42 -0
- package/src/lib/components/console/store-zones.js +39 -0
- package/src/lib/components/console/store-zones.js.map +1 -0
- package/src/lib/components/console/storefront-tax-summary-card.component.js +1 -0
- package/src/lib/components/console/storefront-tax-summary-card.component.js.map +1 -1
- package/src/lib/components/order-status.d.ts +36 -0
- package/src/lib/components/order-status.js +502 -0
- package/src/lib/components/order-status.js.map +1 -0
- package/src/lib/components/product-detail.js +41 -2
- package/src/lib/components/product-detail.js.map +1 -1
- package/src/lib/components/return-request.d.ts +32 -0
- package/src/lib/components/return-request.js +576 -0
- package/src/lib/components/return-request.js.map +1 -0
- package/src/lib/components/storefront-payment-appearance.d.ts +32 -0
- package/src/lib/components/storefront-payment-appearance.js +114 -0
- package/src/lib/components/storefront-payment-appearance.js.map +1 -0
- package/src/lib/components/storefront-payment-element.d.ts +57 -1
- package/src/lib/components/storefront-payment-element.js +332 -33
- package/src/lib/components/storefront-payment-element.js.map +1 -1
- package/src/lib/constants/order-status.d.ts +22 -0
- package/src/lib/constants/order-status.js +22 -0
- package/src/lib/constants/order-status.js.map +1 -0
- package/src/lib/constants/return-request.d.ts +27 -0
- package/src/lib/constants/return-request.js +32 -0
- package/src/lib/constants/return-request.js.map +1 -0
- package/src/lib/constants/stock-movement-query.js +2 -1
- package/src/lib/constants/stock-movement-query.js.map +1 -1
- package/src/lib/declarations.console-server.js +9 -0
- package/src/lib/declarations.console-server.js.map +1 -1
- package/src/lib/declarations.server.d.ts +2 -1
- package/src/lib/declarations.server.js +68 -1
- package/src/lib/declarations.server.js.map +1 -1
- package/src/lib/model/buyer-notifications.d.ts +59 -0
- package/src/lib/model/buyer-notifications.js +97 -0
- package/src/lib/model/buyer-notifications.js.map +1 -0
- package/src/lib/model/commerce-orders.d.ts +171 -2
- package/src/lib/model/commerce-orders.js +26 -16
- package/src/lib/model/commerce-orders.js.map +1 -1
- package/src/lib/model/commerce-payment-methods.d.ts +146 -0
- package/src/lib/model/commerce-payment-methods.js +247 -0
- package/src/lib/model/commerce-payment-methods.js.map +1 -0
- package/src/lib/model/commerce-pos-ops.d.ts +437 -0
- package/src/lib/model/commerce-pos-ops.js +721 -0
- package/src/lib/model/commerce-pos-ops.js.map +1 -0
- package/src/lib/model/commerce-pos.d.ts +263 -0
- package/src/lib/model/commerce-pos.js +375 -0
- package/src/lib/model/commerce-pos.js.map +1 -0
- package/src/lib/model/commerce-printers.d.ts +211 -0
- package/src/lib/model/commerce-printers.js +181 -0
- package/src/lib/model/commerce-printers.js.map +1 -0
- package/src/lib/model/commerce-receipt.d.ts +97 -0
- package/src/lib/model/commerce-receipt.js +180 -0
- package/src/lib/model/commerce-receipt.js.map +1 -0
- package/src/lib/model/commerce-returns.d.ts +207 -0
- package/src/lib/model/commerce-returns.js +300 -0
- package/src/lib/model/commerce-returns.js.map +1 -0
- package/src/lib/model/commerce-shipping.d.ts +44 -1
- package/src/lib/model/commerce-shipping.js +53 -9
- package/src/lib/model/commerce-shipping.js.map +1 -1
- package/src/lib/model/commerce-tax-engine.d.ts +90 -0
- package/src/lib/model/commerce-tax-engine.js +129 -0
- package/src/lib/model/commerce-tax-engine.js.map +1 -0
- package/src/lib/model/commerce.d.ts +91 -2
- package/src/lib/model/commerce.js +89 -1
- package/src/lib/model/commerce.js.map +1 -1
- package/src/lib/model/index.d.ts +16 -0
- package/src/lib/model/index.js +16 -0
- package/src/lib/model/index.js.map +1 -1
- package/src/lib/model/order-events.d.ts +154 -0
- package/src/lib/model/order-events.js +153 -0
- package/src/lib/model/order-events.js.map +1 -0
- package/src/lib/model/order-fulfillment.d.ts +117 -0
- package/src/lib/model/order-fulfillment.js +217 -0
- package/src/lib/model/order-fulfillment.js.map +1 -0
- package/src/lib/model/order-history.d.ts +58 -0
- package/src/lib/model/order-history.js +22 -0
- package/src/lib/model/order-history.js.map +1 -0
- package/src/lib/model/order-list-fields.d.ts +9 -1
- package/src/lib/model/order-list-fields.js +7 -1
- package/src/lib/model/order-list-fields.js.map +1 -1
- package/src/lib/model/order-shipping-export.d.ts +91 -0
- package/src/lib/model/order-shipping-export.js +192 -0
- package/src/lib/model/order-shipping-export.js.map +1 -0
- package/src/lib/model/order-status-view.d.ts +103 -0
- package/src/lib/model/order-status-view.js +156 -0
- package/src/lib/model/order-status-view.js.map +1 -0
- package/src/lib/model/order-webhooks.d.ts +142 -0
- package/src/lib/model/order-webhooks.js +91 -0
- package/src/lib/model/order-webhooks.js.map +1 -0
- package/src/lib/model/product-channel.d.ts +56 -0
- package/src/lib/model/product-channel.js +86 -0
- package/src/lib/model/product-channel.js.map +1 -0
- package/src/lib/model/product-modifiers.d.ts +80 -0
- package/src/lib/model/product-modifiers.js +140 -0
- package/src/lib/model/product-modifiers.js.map +1 -0
- package/src/lib/model/product-write.d.ts +186 -0
- package/src/lib/model/product-write.js +116 -0
- package/src/lib/model/product-write.js.map +1 -0
- package/src/lib/model/shippingeasy.d.ts +94 -0
- package/src/lib/model/shippingeasy.js +267 -0
- package/src/lib/model/shippingeasy.js.map +1 -0
- package/src/lib/model/shipstation.d.ts +125 -0
- package/src/lib/model/shipstation.js +399 -0
- package/src/lib/model/shipstation.js.map +1 -0
- package/src/lib/model/smart-collection-reads.d.ts +32 -0
- package/src/lib/model/smart-collection-reads.js +63 -0
- package/src/lib/model/smart-collection-reads.js.map +1 -0
- package/src/lib/model/tracking-url.d.ts +74 -0
- package/src/lib/model/tracking-url.js +159 -0
- package/src/lib/model/tracking-url.js.map +1 -0
- package/src/lib/plugin-config.d.ts +13 -0
- package/src/lib/plugin-config.js +77 -5
- package/src/lib/plugin-config.js.map +1 -1
- package/src/lib/plugin.js +26 -0
- package/src/lib/plugin.js.map +1 -1
- package/src/lib/pos-ops-config.d.ts +39 -0
- package/src/lib/pos-ops-config.js +88 -0
- package/src/lib/pos-ops-config.js.map +1 -0
- package/src/lib/printing/print-document.d.ts +106 -0
- package/src/lib/printing/print-document.js +464 -0
- package/src/lib/printing/print-document.js.map +1 -0
- package/src/lib/printing/product-labels.d.ts +58 -0
- package/src/lib/printing/product-labels.js +116 -0
- package/src/lib/printing/product-labels.js.map +1 -0
- package/src/lib/printing/render-epson.d.ts +57 -0
- package/src/lib/printing/render-epson.js +135 -0
- package/src/lib/printing/render-epson.js.map +1 -0
- package/src/lib/printing/render-star.d.ts +45 -0
- package/src/lib/printing/render-star.js +100 -0
- package/src/lib/printing/render-star.js.map +1 -0
- package/src/lib/printing/render-text.d.ts +25 -0
- package/src/lib/printing/render-text.js +53 -0
- package/src/lib/printing/render-text.js.map +1 -0
- package/src/lib/server/api-v1/openapi.js +27 -4
- package/src/lib/server/api-v1/openapi.js.map +1 -1
- package/src/lib/server/api-v1/order-view.d.ts +67 -0
- package/src/lib/server/api-v1/order-view.js +120 -0
- package/src/lib/server/api-v1/order-view.js.map +1 -0
- package/src/lib/server/api-v1/orders-and-products.js +58 -65
- package/src/lib/server/api-v1/orders-and-products.js.map +1 -1
- package/src/lib/server/billing-webhook.js +135 -28
- package/src/lib/server/billing-webhook.js.map +1 -1
- package/src/lib/server/cancel-order.js +29 -0
- package/src/lib/server/cancel-order.js.map +1 -1
- package/src/lib/server/carrier-rates-availability.d.ts +26 -0
- package/src/lib/server/carrier-rates-availability.js +76 -0
- package/src/lib/server/carrier-rates-availability.js.map +1 -0
- package/src/lib/server/carrier-shipping.d.ts +84 -0
- package/src/lib/server/carrier-shipping.js +135 -0
- package/src/lib/server/carrier-shipping.js.map +1 -0
- package/src/lib/server/cart-checkout.d.ts +2 -0
- package/src/lib/server/cart-checkout.js +226 -22
- package/src/lib/server/cart-checkout.js.map +1 -1
- package/src/lib/server/channel-order-updates.d.ts +50 -0
- package/src/lib/server/channel-order-updates.js +290 -0
- package/src/lib/server/channel-order-updates.js.map +1 -0
- package/src/lib/server/channel-orders.d.ts +85 -0
- package/src/lib/server/channel-orders.js +543 -0
- package/src/lib/server/channel-orders.js.map +1 -0
- package/src/lib/server/checkout-extras.d.ts +64 -0
- package/src/lib/server/checkout-extras.js +157 -0
- package/src/lib/server/checkout-extras.js.map +1 -0
- package/src/lib/server/{feed.d.ts → checkout-status.d.ts} +2 -7
- package/src/lib/server/checkout-status.js +111 -0
- package/src/lib/server/checkout-status.js.map +1 -0
- package/src/lib/server/checkout.js +86 -9
- package/src/lib/server/checkout.js.map +1 -1
- package/src/lib/server/draft-order.js +34 -5
- package/src/lib/server/draft-order.js.map +1 -1
- package/src/lib/server/fulfill-order.d.ts +127 -10
- package/src/lib/server/fulfill-order.js +451 -49
- package/src/lib/server/fulfill-order.js.map +1 -1
- package/src/lib/server/legacy-feed.d.ts +28 -0
- package/src/lib/server/legacy-feed.js +52 -0
- package/src/lib/server/legacy-feed.js.map +1 -0
- package/src/lib/server/native-checkout.d.ts +34 -15
- package/src/lib/server/native-checkout.js +32 -17
- package/src/lib/server/native-checkout.js.map +1 -1
- package/src/lib/server/order-event-host-emit.d.ts +23 -0
- package/src/lib/server/order-event-host-emit.js +30 -0
- package/src/lib/server/order-event-host-emit.js.map +1 -0
- package/src/lib/server/order-event-triggers.d.ts +37 -0
- package/src/lib/server/order-event-triggers.js +119 -0
- package/src/lib/server/order-event-triggers.js.map +1 -0
- package/src/lib/server/order-events.d.ts +62 -0
- package/src/lib/server/order-events.js +109 -0
- package/src/lib/server/order-events.js.map +1 -0
- package/src/lib/server/order-history.d.ts +23 -0
- package/src/lib/server/order-history.js +65 -0
- package/src/lib/server/order-history.js.map +1 -0
- package/src/lib/server/order-notifications.d.ts +185 -0
- package/src/lib/server/order-notifications.js +567 -0
- package/src/lib/server/order-notifications.js.map +1 -0
- package/src/lib/server/order-receipt-send.d.ts +39 -0
- package/src/lib/server/order-receipt-send.js +151 -0
- package/src/lib/server/order-receipt-send.js.map +1 -0
- package/src/lib/server/order-status-token.d.ts +31 -0
- package/src/lib/server/order-status-token.js +75 -0
- package/src/lib/server/order-status-token.js.map +1 -0
- package/src/lib/server/order-status.d.ts +58 -0
- package/src/lib/server/order-status.js +141 -0
- package/src/lib/server/order-status.js.map +1 -0
- package/src/lib/server/order-webhooks.d.ts +108 -0
- package/src/lib/server/order-webhooks.js +622 -0
- package/src/lib/server/order-webhooks.js.map +1 -0
- package/src/lib/server/orders-shipping-prepare.d.ts +26 -0
- package/src/lib/server/orders-shipping-prepare.js +121 -0
- package/src/lib/server/orders-shipping-prepare.js.map +1 -0
- package/src/lib/server/payment-method-domains.d.ts +209 -0
- package/src/lib/server/payment-method-domains.js +444 -0
- package/src/lib/server/payment-method-domains.js.map +1 -0
- package/src/lib/server/payment-methods.d.ts +77 -0
- package/src/lib/server/payment-methods.js +284 -0
- package/src/lib/server/payment-methods.js.map +1 -0
- package/src/lib/server/pos-auth.d.ts +50 -0
- package/src/lib/server/pos-auth.js +121 -0
- package/src/lib/server/pos-auth.js.map +1 -0
- package/src/lib/server/pos-customer.d.ts +49 -0
- package/src/lib/server/pos-customer.js +257 -0
- package/src/lib/server/pos-customer.js.map +1 -0
- package/src/lib/server/pos-display.d.ts +57 -0
- package/src/lib/server/pos-display.js +419 -0
- package/src/lib/server/pos-display.js.map +1 -0
- package/src/lib/server/pos-fee-month.d.ts +34 -0
- package/src/lib/server/pos-fee-month.js +36 -0
- package/src/lib/server/pos-fee-month.js.map +1 -0
- package/src/lib/server/pos-ops-gate.d.ts +161 -0
- package/src/lib/server/pos-ops-gate.js +295 -0
- package/src/lib/server/pos-ops-gate.js.map +1 -0
- package/src/lib/server/pos-ops-routes.d.ts +22 -0
- package/src/lib/server/pos-ops-routes.js +36 -0
- package/src/lib/server/pos-ops-routes.js.map +1 -0
- package/src/lib/server/pos-order.d.ts +1 -18
- package/src/lib/server/pos-order.js +222 -42
- package/src/lib/server/pos-order.js.map +1 -1
- package/src/lib/server/pos-payment.d.ts +39 -0
- package/src/lib/server/pos-payment.js +922 -0
- package/src/lib/server/pos-payment.js.map +1 -0
- package/src/lib/server/pos-print.d.ts +82 -0
- package/src/lib/server/pos-print.js +193 -0
- package/src/lib/server/pos-print.js.map +1 -0
- package/src/lib/server/pos-readers.d.ts +27 -0
- package/src/lib/server/pos-readers.js +276 -0
- package/src/lib/server/pos-readers.js.map +1 -0
- package/src/lib/server/pos-refund-authority.d.ts +60 -0
- package/src/lib/server/pos-refund-authority.js +72 -0
- package/src/lib/server/pos-refund-authority.js.map +1 -0
- package/src/lib/server/pos-return.d.ts +58 -0
- package/src/lib/server/pos-return.js +891 -0
- package/src/lib/server/pos-return.js.map +1 -0
- package/src/lib/server/pos-sale-stamp.d.ts +66 -0
- package/src/lib/server/pos-sale-stamp.js +84 -0
- package/src/lib/server/pos-sale-stamp.js.map +1 -0
- package/src/lib/server/pos-sale.d.ts +170 -0
- package/src/lib/server/pos-sale.js +461 -0
- package/src/lib/server/pos-sale.js.map +1 -0
- package/src/lib/server/pos-shift.d.ts +45 -0
- package/src/lib/server/pos-shift.js +484 -0
- package/src/lib/server/pos-shift.js.map +1 -0
- package/src/lib/server/pos-staff-pin.d.ts +26 -0
- package/src/lib/server/pos-staff-pin.js +339 -0
- package/src/lib/server/pos-staff-pin.js.map +1 -0
- package/src/lib/server/pos-stripe.d.ts +91 -0
- package/src/lib/server/pos-stripe.js +129 -0
- package/src/lib/server/pos-stripe.js.map +1 -0
- package/src/lib/server/pos-terminal-connection-token.d.ts +48 -0
- package/src/lib/server/pos-terminal-connection-token.js +166 -0
- package/src/lib/server/pos-terminal-connection-token.js.map +1 -0
- package/src/lib/server/pos-terminal.d.ts +218 -0
- package/src/lib/server/pos-terminal.js +1014 -0
- package/src/lib/server/pos-terminal.js.map +1 -0
- package/src/lib/server/print-queue.d.ts +124 -0
- package/src/lib/server/print-queue.js +301 -0
- package/src/lib/server/print-queue.js.map +1 -0
- package/src/lib/server/printer-poll.d.ts +75 -0
- package/src/lib/server/printer-poll.js +325 -0
- package/src/lib/server/printer-poll.js.map +1 -0
- package/src/lib/server/printer-secret.d.ts +39 -0
- package/src/lib/server/printer-secret.js +56 -0
- package/src/lib/server/printer-secret.js.map +1 -0
- package/src/lib/server/printers.d.ts +114 -0
- package/src/lib/server/printers.js +546 -0
- package/src/lib/server/printers.js.map +1 -0
- package/src/lib/server/product-catalog.d.ts +42 -0
- package/src/lib/server/product-catalog.js +309 -0
- package/src/lib/server/product-catalog.js.map +1 -0
- package/src/lib/server/product-drafts.d.ts +5 -1
- package/src/lib/server/product-drafts.js +3 -3
- package/src/lib/server/product-drafts.js.map +1 -1
- package/src/lib/server/product-writer.d.ts +19 -0
- package/src/lib/server/product-writer.js +261 -0
- package/src/lib/server/product-writer.js.map +1 -0
- package/src/lib/server/products-write.d.ts +61 -0
- package/src/lib/server/products-write.js +375 -0
- package/src/lib/server/products-write.js.map +1 -0
- package/src/lib/server/refund.js +110 -45
- package/src/lib/server/refund.js.map +1 -1
- package/src/lib/server/reserve.js +2 -0
- package/src/lib/server/reserve.js.map +1 -1
- package/src/lib/server/return-status-action.d.ts +37 -0
- package/src/lib/server/return-status-action.js +57 -0
- package/src/lib/server/return-status-action.js.map +1 -0
- package/src/lib/server/returns.d.ts +119 -0
- package/src/lib/server/returns.js +938 -0
- package/src/lib/server/returns.js.map +1 -0
- package/src/lib/server/shipment-records.d.ts +36 -0
- package/src/lib/server/shipment-records.js +289 -0
- package/src/lib/server/shipment-records.js.map +1 -0
- package/src/lib/server/shipping-connector-gates.d.ts +40 -0
- package/src/lib/server/shipping-connector-gates.js +97 -0
- package/src/lib/server/shipping-connector-gates.js.map +1 -0
- package/src/lib/server/shipping-connectors.d.ts +29 -0
- package/src/lib/server/shipping-connectors.js +236 -0
- package/src/lib/server/shipping-connectors.js.map +1 -0
- package/src/lib/server/shippingeasy.d.ts +238 -0
- package/src/lib/server/shippingeasy.js +787 -0
- package/src/lib/server/shippingeasy.js.map +1 -0
- package/src/lib/server/shipstation.d.ts +129 -0
- package/src/lib/server/shipstation.js +483 -0
- package/src/lib/server/shipstation.js.map +1 -0
- package/src/lib/server/site-page-resolver.d.ts +5 -0
- package/src/lib/server/site-page-resolver.js +156 -1
- package/src/lib/server/site-page-resolver.js.map +1 -1
- package/src/lib/server/stock-levels.d.ts +21 -0
- package/src/lib/server/stock-levels.js +263 -0
- package/src/lib/server/stock-levels.js.map +1 -0
- package/src/lib/server/stripe-refund.d.ts +47 -0
- package/src/lib/server/stripe-refund.js +87 -0
- package/src/lib/server/stripe-refund.js.map +1 -0
- package/src/lib/server/supplier-update.js +46 -5
- package/src/lib/server/supplier-update.js.map +1 -1
- package/src/lib/server/tax-engine-quote.d.ts +47 -0
- package/src/lib/server/tax-engine-quote.js +105 -0
- package/src/lib/server/tax-engine-quote.js.map +1 -0
- package/src/lib/server.js +143 -2
- package/src/lib/server.js.map +1 -1
- package/src/lib/site.js +12 -0
- package/src/lib/site.js.map +1 -1
- package/src/lib/subprocessors.d.ts +26 -0
- package/src/lib/subprocessors.js +50 -0
- package/src/lib/subprocessors.js.map +1 -0
- package/src/lib/tenant-emails.js +461 -3
- package/src/lib/tenant-emails.js.map +1 -1
- package/src/lib/testing/fake-firestore.d.ts +45 -0
- package/src/lib/testing/fake-firestore.js +189 -0
- package/src/lib/testing/fake-firestore.js.map +1 -0
- package/src/lib/testing/memory-firestore.d.ts +136 -0
- package/src/lib/testing/memory-firestore.js +282 -0
- package/src/lib/testing/memory-firestore.js.map +1 -0
- package/src/lib/testing/pos-ops-harness.d.ts +50 -0
- package/src/lib/testing/pos-ops-harness.js +184 -0
- package/src/lib/testing/pos-ops-harness.js.map +1 -0
- package/src/lib/testing/pos-ops-memory-firestore.d.ts +55 -0
- package/src/lib/testing/pos-ops-memory-firestore.js +376 -0
- package/src/lib/testing/pos-ops-memory-firestore.js.map +1 -0
- package/src/lib/transfer/products.server.d.ts +5 -0
- package/src/lib/transfer/products.server.js +2 -2
- package/src/lib/transfer/products.server.js.map +1 -1
- package/src/lib/transfer/records-transfer.d.ts +11 -1
- package/src/lib/transfer/records-transfer.js +127 -5
- package/src/lib/transfer/records-transfer.js.map +1 -1
- package/src/lib/transfer/records.server.d.ts +9 -2
- package/src/lib/transfer/records.server.js +58 -7
- package/src/lib/transfer/records.server.js.map +1 -1
- package/src/lib/transfer/register-transfer-resources.js +40 -1
- package/src/lib/transfer/register-transfer-resources.js.map +1 -1
- package/src/lib/transfer/register-transfer-ui.js +4 -1
- package/src/lib/transfer/register-transfer-ui.js.map +1 -1
- package/src/lib/transfer/shipping-presets.d.ts +23 -0
- package/src/lib/transfer/shipping-presets.js +156 -0
- package/src/lib/transfer/shipping-presets.js.map +1 -0
- package/src/lib/transfer/tracking-transfer.d.ts +101 -0
- package/src/lib/transfer/tracking-transfer.js +546 -0
- package/src/lib/transfer/tracking-transfer.js.map +1 -0
- package/src/lib/transfer/tracking.server.d.ts +37 -0
- package/src/lib/transfer/tracking.server.js +393 -0
- package/src/lib/transfer/tracking.server.js.map +1 -0
- package/src/lib/transfer/transfer-keys.d.ts +2 -1
- package/src/lib/transfer/transfer-keys.js +6 -2
- package/src/lib/transfer/transfer-keys.js.map +1 -1
- package/src/lib/utils/code128.d.ts +37 -0
- package/src/lib/utils/code128.js +199 -0
- package/src/lib/utils/code128.js.map +1 -0
- package/src/lib/utils/order-invoice.d.ts +55 -0
- package/src/lib/utils/order-invoice.js +127 -0
- package/src/lib/utils/order-invoice.js.map +1 -0
- package/src/lib/utils/use-checkout-return-notice.d.ts +34 -0
- package/src/lib/utils/use-checkout-return-notice.js +78 -0
- package/src/lib/utils/use-checkout-return-notice.js.map +1 -0
- package/src/lib/server/feed.js +0 -69
- package/src/lib/server/feed.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/order-webhooks.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createResourceUid } from '@aglyn/aglyn/app-utils/create-resource-uid'\nimport { PLATFORM_BRAND_NAME } from '@aglyn/aglyn/app-utils/platform-brand'\nimport type { PluginApiHandler } from '@aglyn/aglyn/server'\nimport type { PluginDomainEventEnvelope } from '@aglyn/aglyn/plugin-manager/plugin-domain-events'\nimport {\n describeConfiguredUrlRefusal,\n configuredUrlRefusal,\n fetchConfiguredPublicUrl,\n firebaseAdmin,\n notifyHostManagers,\n} from '@aglyn/tenant-data-admin'\nimport { PLUGIN_EVENT_MAX_ATTEMPTS } from '@aglyn/tenant-data-admin/server/plugin-event-outbox'\nimport { resolveOrgPermissions } from '@aglyn/tenant-runtime/org-permissions'\nimport {\n createSecretBoxKey,\n openSecret,\n parseSecretBoxKeyring,\n sealSecret,\n SECRET_BOX_KEY_BYTES,\n type SecretBoxKey,\n type SecretBoxKeyring,\n} from '@aglyn/shared-util-tools/secret-box'\nimport { createHmac, hkdfSync, randomBytes } from 'node:crypto'\nimport { COMMERCE_EVENT_DECLARATIONS } from '../model/order-events'\nimport * as Webhooks from '../model/order-webhooks'\n\n/**\n * Merchant order webhooks (AGL-3611): the console's door and the delivery\n * behind it. The model (`model/order-webhooks.ts`) says what is stored where.\n *\n * DELIVERY RIDES THE PLUGIN EVENT OUTBOX. Commerce subscribes to its own\n * order and return events under the name `webhooks`; the subscriber posts the\n * event to every endpoint that takes it and records each attempt in the\n * delivery log. An endpoint that already took an event is not posted it\n * again, so when one of three endpoints fails, the subscriber throws, the\n * outbox retries it with its backoff (30s, 2m, 10m, 30m, 1h, 6h, 12h), and\n * only the failing endpoint is called again. On the last attempt the delivery\n * is marked failed and the site's managers are told.\n *\n * EVERY CALL GOES THROUGH `fetchConfiguredPublicUrl`: https on the default\n * port, a public address pinned at connect time, no redirect followed. A\n * merchant's endpoint is a stranger's server to us.\n *\n * THE SECRET IS SEALED with the shared secret box, under the keyring\n * `readCommerceSecretKeyring` answers, bound to its endpoint by the seal's\n * context. The plaintext leaves the server once, in the answer to the request\n * that made or rolled it.\n */\n\nexport const COMMERCE_SECRET_KEY_ENV = 'COMMERCE_SECRET_KEY'\n\nconst SECRETS = 'orderWebhookSecrets'\n\n/** Delivery rows live this long, then Firestore's TTL removes them. */\nexport const ORDER_WEBHOOK_LOG_RETENTION_MS = 30 * 86_400_000\n\ntype Firestore = FirebaseFirestore.Firestore\n\n/** The id of the key derived from `TOKEN_SIGNING_SECRET`. */\nexport const DERIVED_COMMERCE_KEY_ID = 'tss1'\n\n/**\n * A secret-box key derived from `TOKEN_SIGNING_SECRET` with HKDF, under its\n * own label, so the commerce tokens and the sealed secrets never share key\n * material. `null` when that secret is unset.\n */\nfunction derivedCommerceKey(): SecretBoxKey | null {\n const base = String(process.env['TOKEN_SIGNING_SECRET'] ?? '')\n if (!base) return null\n const material = new Uint8Array(hkdfSync('sha256', base, 'aglyn-commerce', 'secret-box:v1', SECRET_BOX_KEY_BYTES))\n return createSecretBoxKey(material, DERIVED_COMMERCE_KEY_ID)\n}\n\n/**\n * The keyring commerce seals its stored secrets with. `COMMERCE_SECRET_KEY`\n * (a secret-box keyring) when it is set, its first key sealing; otherwise the\n * key derived from `TOKEN_SIGNING_SECRET`, which every deployment that sells\n * already has. The derived key stays in the ring after a dedicated key is\n * configured, so what it sealed still opens. `null` when neither is usable.\n * Never throws.\n */\nexport function readCommerceSecretKeyring(): SecretBoxKeyring | null {\n let derived: SecretBoxKey | null = null\n try {\n derived = derivedCommerceKey()\n } catch {\n derived = null\n }\n const raw = String(process.env[COMMERCE_SECRET_KEY_ENV] ?? '').trim()\n if (raw) {\n try {\n const ring = parseSecretBoxKeyring(raw)\n const keys = derived && !ring.keys.some((key) => key.id === derived!.id) ? [...ring.keys, derived] : ring.keys\n return { current: ring.current, keys }\n } catch {\n // An unusable dedicated key falls back to the derived one rather than\n // sealing nothing.\n }\n }\n return derived ? { current: derived, keys: [derived] } : null\n}\n\n/** Whether this deployment can sign webhooks at all. */\nexport function orderWebhooksConfigured(): boolean {\n return readCommerceSecretKeyring() !== null\n}\n\nconst sealContext = (hostId: string, endpointId: string) => `hosts/${hostId}/${SECRETS}/${endpointId}#secret`\n\n/** A fresh signing secret: `whsec_` and 32 random bytes. */\nexport function mintOrderWebhookSecret(): string {\n return `whsec_${randomBytes(32).toString('base64url')}`\n}\n\n/** The HMAC-SHA256 of `{t}.{body}` under the secret, as hex. */\nexport function signOrderWebhook(secret: string, timestampSeconds: number, body: string): string {\n return createHmac('sha256', secret).update(Webhooks.orderWebhookSignedPayload(timestampSeconds, body)).digest('hex')\n}\n\nconst hostRefFor = (firestore: Firestore, hostId: string) => firestore.collection('hosts').doc(hostId)\n\nasync function readSecret(\n firestore: Firestore,\n hostId: string,\n endpointId: string,\n keyring: SecretBoxKeyring,\n): Promise<string> {\n const hostRef = hostRefFor(firestore, hostId)\n const snapshot = await hostRef.collection('orderWebhookSecrets').doc(endpointId).get()\n const sealed = String(snapshot.get('sealedSecret') ?? '')\n if (!sealed) throw new Error('This endpoint has no signing secret')\n return openSecret(sealed, keyring, { context: sealContext(hostId, endpointId) }).plaintext\n}\n\nfunction sealedSecretRecord(\n hostId: string,\n endpointId: string,\n secret: string,\n keyring: SecretBoxKeyring,\n now: number,\n): Webhooks.OrderWebhookSecretRecord {\n return {\n sealedSecret: sealSecret(secret, keyring.current, { context: sealContext(hostId, endpointId) }),\n secretKeyId: keyring.current.id,\n updatedAtMs: now,\n }\n}\n\n/** What one POST came to. */\nexport interface OrderWebhookPostResult {\n attempt: Webhooks.OrderWebhookAttempt\n delivered: boolean\n}\n\n/**\n * Posts one body to one endpoint, signed. Never throws: a refusal, a timeout\n * or a reset is an attempt that failed, with the reason in words.\n */\nexport async function postOrderWebhook(input: {\n url: string\n secret: string\n event: string\n eventId: string\n body: string\n now?: () => number\n fetchImpl?: typeof fetchConfiguredPublicUrl\n}): Promise<OrderWebhookPostResult> {\n const clock = input.now ?? Date.now\n const startedAt = clock()\n const timestamp = Math.floor(startedAt / 1000)\n const signature = Webhooks.formatOrderWebhookSignature(timestamp, signOrderWebhook(input.secret, timestamp, input.body))\n let httpStatus: number | null = null\n let error: string | undefined\n try {\n const result = await (input.fetchImpl ?? fetchConfiguredPublicUrl)(input.url, {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n 'user-agent': 'Aglyn-Webhooks/1.0',\n [Webhooks.ORDER_WEBHOOK_SIGNATURE_HEADER]: signature,\n [Webhooks.ORDER_WEBHOOK_EVENT_HEADER]: input.event,\n [Webhooks.ORDER_WEBHOOK_EVENT_ID_HEADER]: input.eventId,\n },\n body: input.body,\n signal: AbortSignal.timeout(Webhooks.ORDER_WEBHOOK_TIMEOUT_MS),\n })\n if ('refusal' in result) {\n error = `Not sent: ${describeConfiguredUrlRefusal(result.refusal)}`\n } else {\n httpStatus = result.status\n if (!Webhooks.orderWebhookAccepted(httpStatus)) {\n error =\n httpStatus >= 300 && httpStatus < 400\n ? `The endpoint answered ${httpStatus}, a redirect; redirects are not followed`\n : `The endpoint answered ${httpStatus}`\n }\n }\n } catch (caught) {\n const name = (caught as Error)?.name\n error =\n name === 'TimeoutError' || name === 'AbortError'\n ? `No answer within ${Webhooks.ORDER_WEBHOOK_TIMEOUT_MS / 1000} seconds`\n : `The connection failed: ${String((caught as Error)?.message ?? caught).slice(0, 200)}`\n }\n const attempt: Webhooks.OrderWebhookAttempt = {\n atMs: startedAt,\n httpStatus,\n ...(error ? { error } : {}),\n durationMs: Math.max(0, clock() - startedAt),\n }\n return { attempt, delivered: !error }\n}\n\nfunction expiresAt(now: number) {\n return firebaseAdmin.firestore.Timestamp.fromMillis(now + ORDER_WEBHOOK_LOG_RETENTION_MS)\n}\n\n/** Records an attempt on the delivery row and on the endpoint's summary. */\nasync function recordAttempt(\n firestore: Firestore,\n hostId: string,\n endpointId: string,\n delivery: {\n id: string\n eventId: string\n event: string\n orderId: string | null\n body: string\n test?: boolean\n prior: Webhooks.OrderWebhookDelivery | null\n },\n result: OrderWebhookPostResult,\n status: Webhooks.OrderWebhookDeliveryStatus,\n now: number,\n): Promise<void> {\n const hostRef = hostRefFor(firestore, hostId)\n const row: Webhooks.OrderWebhookDelivery & { expiresAt: unknown } = {\n endpointId,\n eventId: delivery.eventId,\n event: delivery.event,\n orderId: delivery.orderId,\n status,\n attempts: Webhooks.appendOrderWebhookAttempt(delivery.prior?.attempts, result.attempt),\n body: delivery.body.slice(0, Webhooks.ORDER_WEBHOOK_BODY_MAX),\n ...(delivery.test ? { test: true } : {}),\n createdAtMs: delivery.prior?.createdAtMs ?? now,\n updatedAtMs: now,\n expiresAt: expiresAt(now),\n }\n await hostRef.collection('orderWebhookDeliveries').doc(delivery.id).set(row)\n await hostRef\n .collection('orderWebhooks')\n .doc(endpointId)\n .update({\n lastDeliveryAtMs: now,\n lastDeliveryStatus: status,\n consecutiveFailures: result.delivered ? 0 : firebaseAdmin.firestore.FieldValue.increment(1),\n })\n .catch(() => undefined)\n}\n\n/**\n * The subscriber: posts one event to every endpoint of the site that takes\n * it and has not taken it already. Throws when any endpoint still owes it, so\n * the outbox retries; on the outbox's last attempt it records the failure and\n * tells the site's managers instead.\n */\nexport async function deliverOrderEventToWebhooks(\n envelope: PluginDomainEventEnvelope,\n deps: { fetchImpl?: typeof fetchConfiguredPublicUrl; now?: () => number } = {},\n): Promise<{ delivered: number; failed: number }> {\n const firestore = firebaseAdmin.app().firestore()\n const hostRef = hostRefFor(firestore, envelope.hostId)\n const endpoints = await hostRef.collection('orderWebhooks').where('enabled', '==', true).get()\n const taking = endpoints.docs.filter((doc) =>\n Webhooks.orderWebhookTakes(doc.data() as Webhooks.OrderWebhookEndpoint, envelope.event, envelope.occurredAtMs),\n )\n if (taking.length === 0) return { delivered: 0, failed: 0 }\n const keyring = readCommerceSecretKeyring()\n const clock = deps.now ?? Date.now\n const final = envelope.attempt >= PLUGIN_EVENT_MAX_ATTEMPTS\n const body = Webhooks.orderWebhookBody({\n eventId: envelope.id,\n event: envelope.event,\n occurredAtMs: envelope.occurredAtMs,\n hostId: envelope.hostId,\n payload: envelope.payload,\n })\n const orderId = String(((envelope.payload ?? {}) as { order?: { id?: unknown } }).order?.id ?? '') || null\n const outcomes = await Promise.all(\n taking.map(async (doc) => {\n const endpoint = doc.data() as Webhooks.OrderWebhookEndpoint\n const deliveryId = Webhooks.orderWebhookDeliveryId(envelope.id, doc.id)\n const priorSnapshot = await hostRef.collection('orderWebhookDeliveries').doc(deliveryId).get()\n const prior = priorSnapshot.exists ? (priorSnapshot.data() as Webhooks.OrderWebhookDelivery) : null\n // Taken already, on an earlier pass or by a resend from the console.\n if (prior?.status === 'delivered') return 'delivered' as const\n const settled = await attemptEndpoint({\n firestore,\n hostId: envelope.hostId,\n endpointId: doc.id,\n url: endpoint.url,\n keyring,\n event: envelope.event,\n eventId: envelope.id,\n body,\n clock,\n fetchImpl: deps.fetchImpl,\n })\n const status: Webhooks.OrderWebhookDeliveryStatus = settled.delivered ? 'delivered' : final ? 'failed' : 'retrying'\n await recordAttempt(\n firestore,\n envelope.hostId,\n doc.id,\n { id: deliveryId, eventId: envelope.id, event: envelope.event, orderId, body, prior },\n settled,\n status,\n clock(),\n )\n if (status === 'failed') {\n await notifyHostManagers(envelope.hostId, {\n type: 'content.order',\n title: 'An order webhook could not be delivered',\n body:\n `${envelope.event} never reached ${safeHost(endpoint.url)} on {site} after ` +\n `${envelope.attempt} attempts (${settled.attempt.error ?? 'no answer'}). ` +\n 'Resend it from the delivery log once the endpoint is fixed.',\n link: `/${envelope.hostId}/products/settings`,\n }).catch(() => undefined)\n }\n return status\n }),\n )\n const delivered = outcomes.filter((status) => status === 'delivered').length\n const failed = outcomes.length - delivered\n if (failed > 0 && !final) {\n throw new Error(`${failed} of ${outcomes.length} order webhook endpoints did not take ${envelope.event}`)\n }\n return { delivered, failed }\n}\n\n/** One signed attempt at one endpoint; a missing key or secret is a failed attempt. */\nasync function attemptEndpoint(input: {\n firestore: Firestore\n hostId: string\n endpointId: string\n url: string\n keyring: SecretBoxKeyring | null\n event: string\n eventId: string\n body: string\n clock: () => number\n fetchImpl?: typeof fetchConfiguredPublicUrl\n}): Promise<OrderWebhookPostResult> {\n const failed = (error: string): OrderWebhookPostResult => ({\n delivered: false,\n attempt: { atMs: input.clock(), httpStatus: null, error, durationMs: 0 },\n })\n if (!input.keyring) return failed('Webhook signing is not configured')\n let secret: string\n try {\n secret = await readSecret(input.firestore, input.hostId, input.endpointId, input.keyring)\n } catch (error) {\n return failed(`The signing secret could not be read: ${String((error as Error)?.message ?? error).slice(0, 120)}`)\n }\n return postOrderWebhook({\n url: input.url,\n secret,\n event: input.event,\n eventId: input.eventId,\n body: input.body,\n fetchImpl: input.fetchImpl,\n now: input.clock,\n })\n}\n\nfunction safeHost(url: string): string {\n try {\n return new URL(url).hostname\n } catch {\n return 'the endpoint'\n }\n}\n\n// ---------------------------------------------------------------------------\n// The console's door\n// ---------------------------------------------------------------------------\n\nconst ACTIONS = ['status', 'create', 'update', 'roll-secret', 'delete', 'test', 'resend'] as const\ntype Action = (typeof ACTIONS)[number]\n\nconst isId = (value: string) => Boolean(value) && value.length <= 1500 && !/^__.*__$/.test(value) && !value.includes('/')\n\nfunction cleanUrl(raw: unknown): { url: string } | { error: string } {\n const url = String(raw ?? '').trim()\n if (!url) return { error: 'Enter the endpoint’s address' }\n if (url.length > 2048) return { error: 'That address is too long' }\n const refusal = configuredUrlRefusal(url)\n if (refusal) return { error: `This endpoint cannot be used: ${describeConfiguredUrlRefusal(refusal)}` }\n return { url }\n}\n\nconst cleanDescription = (raw: unknown) => String(raw ?? '').trim().slice(0, 120)\n\n/**\n * `POST /api/commerce/order-webhooks` with `{ hostId, action, … }`. Endpoints\n * post the order book to an outside server, so only an admin of the whole\n * workspace manages them — the bar a refund sets.\n *\n * - `status` → `{ configured, events: [{ event, label, description }] }`\n * - `create` `{ url, events, description? }` → `{ id, secret }` (shown once)\n * - `update` `{ endpointId, url?, events?, enabled?, description? }`\n * - `roll-secret` `{ endpointId }` → `{ secret }`\n * - `delete` `{ endpointId }`; the delivery log stays until it expires\n * - `test` `{ endpointId }` → posts a `webhook.test` event now\n * - `resend` `{ deliveryId }` → posts a logged delivery again now\n */\nexport const orderWebhooksHandler: PluginApiHandler = async (req, res) => {\n if (req.method !== 'POST') return res.status(405).json({ error: 'Method not allowed' })\n const authorization = String(req.headers.authorization ?? '')\n const idToken = authorization.startsWith('Bearer ') ? authorization.slice('Bearer '.length) : undefined\n if (!idToken) return res.status(401).json({ error: 'Unauthenticated' })\n let body: Record<string, any>\n try {\n body = (typeof req.body === 'string' ? JSON.parse(req.body) : req.body) ?? {}\n } catch {\n return res.status(400).json({ error: 'Invalid JSON' })\n }\n const hostId = String(body.hostId ?? '')\n const action = String(body.action ?? '') as Action\n if (!isId(hostId)) return res.status(400).json({ error: 'Missing hostId' })\n if (!ACTIONS.includes(action)) return res.status(400).json({ error: 'Unknown action' })\n try {\n const decoded = await firebaseAdmin.app().auth().verifyIdToken(idToken)\n const firestore = firebaseAdmin.app().firestore()\n const hostRef = hostRefFor(firestore, hostId)\n const hostSnapshot = await hostRef.get()\n if (!hostSnapshot.exists) return res.status(404).json({ error: 'Unknown site' })\n if ((hostSnapshot.get('memberRoles') ?? {})[decoded.uid] !== 'admin') {\n return res.status(403).json({ error: 'Webhooks are managed by a site admin' })\n }\n const membership = await resolveOrgPermissions(decoded.uid, { hostId })\n if (!membership.orgWide || membership.hostRole !== 'admin') {\n return res.status(403).json({ error: 'Webhooks are managed by an admin of the whole workspace' })\n }\n const keyring = readCommerceSecretKeyring()\n if (action === 'status') {\n return res.status(200).json({\n configured: Boolean(keyring),\n maxEndpoints: Webhooks.ORDER_WEBHOOK_MAX_ENDPOINTS,\n events: COMMERCE_EVENT_DECLARATIONS.map((entry) => ({\n event: entry.event.id,\n label: entry.label,\n description: entry.description,\n })),\n })\n }\n if (!keyring) {\n return res.status(503).json({ error: 'Order webhooks are not configured on this deployment' })\n }\n const now = Date.now()\n const endpoints = hostRef.collection('orderWebhooks')\n\n if (action === 'create') {\n const url = cleanUrl(body.url)\n if ('error' in url) return res.status(400).json({ error: url.error })\n const events = Webhooks.normalizeOrderWebhookEvents(body.events)\n if (events.length === 0) return res.status(400).json({ error: 'Choose at least one event' })\n const secret = mintOrderWebhookSecret()\n const ref = endpoints.doc(createResourceUid())\n const created = await firestore.runTransaction(async (transaction) => {\n const existing = await transaction.get(endpoints.limit(Webhooks.ORDER_WEBHOOK_MAX_ENDPOINTS))\n if (existing.size >= Webhooks.ORDER_WEBHOOK_MAX_ENDPOINTS) return false\n const endpoint: Webhooks.OrderWebhookEndpoint = {\n url: url.url,\n events,\n enabled: true,\n ...(cleanDescription(body.description) ? { description: cleanDescription(body.description) } : {}),\n secretHint: secret.slice(-4),\n consecutiveFailures: 0,\n createdAtMs: now,\n updatedAtMs: now,\n createdBy: decoded.uid,\n }\n transaction.create(ref, endpoint)\n transaction.create(hostRef.collection('orderWebhookSecrets').doc(ref.id), sealedSecretRecord(hostId, ref.id, secret, keyring, now))\n return true\n })\n if (!created) {\n return res.status(409).json({ error: `A store can keep ${Webhooks.ORDER_WEBHOOK_MAX_ENDPOINTS} webhook endpoints` })\n }\n return res.status(200).json({ ok: true, id: ref.id, secret })\n }\n\n if (action === 'resend') {\n const deliveryId = String(body.deliveryId ?? '')\n if (!isId(deliveryId)) return res.status(400).json({ error: 'Missing deliveryId' })\n const deliveryRef = hostRef.collection('orderWebhookDeliveries').doc(deliveryId)\n const deliverySnapshot = await deliveryRef.get()\n if (!deliverySnapshot.exists) return res.status(404).json({ error: 'Unknown delivery' })\n const delivery = deliverySnapshot.data() as Webhooks.OrderWebhookDelivery\n const endpointSnapshot = await endpoints.doc(delivery.endpointId).get()\n if (!endpointSnapshot.exists) return res.status(404).json({ error: 'That endpoint was deleted' })\n if (delivery.body.length >= Webhooks.ORDER_WEBHOOK_BODY_MAX) {\n return res.status(409).json({ error: 'This delivery was too large to keep, so it cannot be resent' })\n }\n const endpoint = endpointSnapshot.data() as Webhooks.OrderWebhookEndpoint\n const secret = await readSecret(firestore, hostId, delivery.endpointId, keyring)\n const result = await postOrderWebhook({ url: endpoint.url, secret, event: delivery.event, eventId: delivery.eventId, body: delivery.body })\n const status: Webhooks.OrderWebhookDeliveryStatus = result.delivered\n ? 'delivered'\n : delivery.status === 'delivered'\n ? 'delivered'\n : delivery.status\n await recordAttempt(\n firestore,\n hostId,\n delivery.endpointId,\n { id: deliveryId, eventId: delivery.eventId, event: delivery.event, orderId: delivery.orderId, body: delivery.body, test: delivery.test, prior: delivery },\n result,\n status,\n Date.now(),\n )\n return res.status(200).json({ ok: true, delivered: result.delivered, attempt: result.attempt })\n }\n\n const endpointId = String(body.endpointId ?? '')\n if (!isId(endpointId)) return res.status(400).json({ error: 'Missing endpointId' })\n const endpointRef = endpoints.doc(endpointId)\n const endpointSnapshot = await endpointRef.get()\n if (!endpointSnapshot.exists) return res.status(404).json({ error: 'Unknown endpoint' })\n const endpoint = endpointSnapshot.data() as Webhooks.OrderWebhookEndpoint\n\n if (action === 'update') {\n const patch: Partial<Webhooks.OrderWebhookEndpoint> = { updatedAtMs: now }\n if (body.url !== undefined) {\n const url = cleanUrl(body.url)\n if ('error' in url) return res.status(400).json({ error: url.error })\n patch.url = url.url\n }\n if (body.events !== undefined) {\n const events = Webhooks.normalizeOrderWebhookEvents(body.events)\n if (events.length === 0) return res.status(400).json({ error: 'Choose at least one event' })\n patch.events = events\n }\n if (body.enabled !== undefined) {\n patch.enabled = Boolean(body.enabled)\n if (patch.enabled) patch.consecutiveFailures = 0\n }\n if (body.description !== undefined) patch.description = cleanDescription(body.description)\n await endpointRef.update(patch)\n return res.status(200).json({ ok: true })\n }\n\n if (action === 'roll-secret') {\n const secret = mintOrderWebhookSecret()\n const batch = firestore.batch()\n batch.set(hostRef.collection('orderWebhookSecrets').doc(endpointId), sealedSecretRecord(hostId, endpointId, secret, keyring, now))\n batch.update(endpointRef, { secretHint: secret.slice(-4), updatedAtMs: now })\n await batch.commit()\n return res.status(200).json({ ok: true, secret })\n }\n\n if (action === 'delete') {\n const batch = firestore.batch()\n batch.delete(endpointRef)\n batch.delete(hostRef.collection('orderWebhookSecrets').doc(endpointId))\n await batch.commit()\n return res.status(200).json({ ok: true })\n }\n\n // test\n const eventId = `test_${randomBytes(9).toString('base64url')}`\n const testBody = Webhooks.orderWebhookBody({\n eventId,\n event: Webhooks.ORDER_WEBHOOK_TEST_EVENT,\n occurredAtMs: now,\n hostId,\n payload: { message: `A test event from ${PLATFORM_BRAND_NAME}. Answer with any 2xx status.` },\n })\n const secret = await readSecret(firestore, hostId, endpointId, keyring)\n const result = await postOrderWebhook({ url: endpoint.url, secret, event: Webhooks.ORDER_WEBHOOK_TEST_EVENT, eventId, body: testBody })\n await recordAttempt(\n firestore,\n hostId,\n endpointId,\n { id: Webhooks.orderWebhookDeliveryId(eventId, endpointId), eventId, event: Webhooks.ORDER_WEBHOOK_TEST_EVENT, orderId: null, body: testBody, test: true, prior: null },\n result,\n result.delivered ? 'delivered' : 'failed',\n Date.now(),\n )\n return res.status(200).json({ ok: true, delivered: result.delivered, attempt: result.attempt })\n } catch (error) {\n console.error('order webhooks action failed', action, error)\n return res.status(500).json({ error: 'The webhook could not be updated. Please try again.' })\n }\n}\n"],"names":["createResourceUid","PLATFORM_BRAND_NAME","describeConfiguredUrlRefusal","configuredUrlRefusal","fetchConfiguredPublicUrl","firebaseAdmin","notifyHostManagers","PLUGIN_EVENT_MAX_ATTEMPTS","resolveOrgPermissions","createSecretBoxKey","openSecret","parseSecretBoxKeyring","sealSecret","SECRET_BOX_KEY_BYTES","createHmac","hkdfSync","randomBytes","COMMERCE_EVENT_DECLARATIONS","Webhooks","COMMERCE_SECRET_KEY_ENV","SECRETS","ORDER_WEBHOOK_LOG_RETENTION_MS","DERIVED_COMMERCE_KEY_ID","derivedCommerceKey","process","base","String","env","material","Uint8Array","readCommerceSecretKeyring","derived","raw","trim","ring","keys","some","key","id","current","orderWebhooksConfigured","sealContext","hostId","endpointId","mintOrderWebhookSecret","toString","signOrderWebhook","secret","timestampSeconds","body","update","orderWebhookSignedPayload","digest","hostRefFor","firestore","collection","doc","readSecret","keyring","snapshot","hostRef","get","sealed","Error","context","plaintext","sealedSecretRecord","now","sealedSecret","secretKeyId","updatedAtMs","postOrderWebhook","input","clock","Date","startedAt","timestamp","Math","floor","signature","formatOrderWebhookSignature","httpStatus","error","result","fetchImpl","url","method","headers","ORDER_WEBHOOK_SIGNATURE_HEADER","ORDER_WEBHOOK_EVENT_HEADER","event","ORDER_WEBHOOK_EVENT_ID_HEADER","eventId","signal","AbortSignal","timeout","ORDER_WEBHOOK_TIMEOUT_MS","refusal","status","orderWebhookAccepted","caught","name","message","slice","attempt","atMs","durationMs","max","delivered","expiresAt","Timestamp","fromMillis","recordAttempt","delivery","row","orderId","attempts","appendOrderWebhookAttempt","prior","ORDER_WEBHOOK_BODY_MAX","test","createdAtMs","set","lastDeliveryAtMs","lastDeliveryStatus","consecutiveFailures","FieldValue","increment","catch","undefined","deliverOrderEventToWebhooks","envelope","deps","app","endpoints","where","taking","docs","filter","orderWebhookTakes","data","occurredAtMs","length","failed","final","orderWebhookBody","payload","order","outcomes","Promise","all","map","endpoint","deliveryId","orderWebhookDeliveryId","priorSnapshot","exists","settled","attemptEndpoint","type","title","safeHost","link","URL","hostname","ACTIONS","isId","value","Boolean","includes","cleanUrl","cleanDescription","orderWebhooksHandler","req","res","json","authorization","idToken","startsWith","JSON","parse","action","hostSnapshot","decoded","auth","verifyIdToken","uid","membership","orgWide","hostRole","configured","maxEndpoints","ORDER_WEBHOOK_MAX_ENDPOINTS","events","entry","label","description","normalizeOrderWebhookEvents","ref","created","runTransaction","transaction","existing","limit","size","enabled","secretHint","createdBy","create","ok","deliveryRef","deliverySnapshot","endpointSnapshot","endpointRef","patch","batch","commit","delete","testBody","ORDER_WEBHOOK_TEST_EVENT","console"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,iBAAiB,QAAQ,6CAA4C;AAC9E,SAASC,mBAAmB,QAAQ,wCAAuC;AAG3E,SACEC,4BAA4B,EAC5BC,oBAAoB,EACpBC,wBAAwB,EACxBC,aAAa,EACbC,kBAAkB,QACb,2BAA0B;AACjC,SAASC,yBAAyB,QAAQ,sDAAqD;AAC/F,SAASC,qBAAqB,QAAQ,wCAAuC;AAC7E,SACEC,kBAAkB,EAClBC,UAAU,EACVC,qBAAqB,EACrBC,UAAU,EACVC,oBAAoB,QAGf,sCAAqC;AAC5C,SAASC,UAAU,EAAEC,QAAQ,EAAEC,WAAW,QAAQ,cAAa;AAC/D,SAASC,2BAA2B,QAAQ,2BAAuB;A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KAAKmE,SAASnE,GAAG;YAAEtC;YAAQ2C,OAAOxE,SAASyM,wBAAwB;YAAE/H;YAAS3C,MAAMyK;QAAS;QACrI,MAAM1G,cACJ1D,WACAZ,QACAC,YACA;YAAEL,IAAIpB,SAASwI,sBAAsB,CAAC9D,SAASjD;YAAaiD;YAASF,OAAOxE,SAASyM,wBAAwB;YAAExG,SAAS;YAAMlE,MAAMyK;YAAUlG,MAAM;YAAMF,OAAO;QAAK,GACtKnC,QACAA,OAAOyB,SAAS,GAAG,cAAc,UACjClC,KAAKP,GAAG;QAEV,OAAO2G,IAAI5E,MAAM,CAAC,KAAK6E,IAAI,CAAC;YAAEkC,IAAI;YAAMrG,WAAWzB,OAAOyB,SAAS;YAAEJ,SAASrB,OAAOqB,OAAO;QAAC;IAC/F,EAAE,OAAOtB,OAAO;QACd0I,QAAQ1I,KAAK,CAAC,gCAAgCmG,QAAQnG;QACtD,OAAO4F,IAAI5E,MAAM,CAAC,KAAK6E,IAAI,CAAC;YAAE7F,OAAO;QAAsD;IAC7F;AACF,EAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import * as Aglyn from '@aglyn/aglyn/server';
|
|
18
|
+
/** The most open orders one `prepare` stamps; a store with more is stamped over several calls. */
|
|
19
|
+
export declare const PREPARE_MAX_ORDERS = 2000;
|
|
20
|
+
/**
|
|
21
|
+
* Stamps the site's open orders that predate the stamp. Answers how many it
|
|
22
|
+
* stamped. `updatedAtMs` is the order's creation, not now: stamping is not
|
|
23
|
+
* a change ShipStation needs to hear about.
|
|
24
|
+
*/
|
|
25
|
+
export declare function prepareOpenOrders(hostId: string): Promise<number>;
|
|
26
|
+
export declare const ordersShippingPrepareHandler: Aglyn.PluginApiHandler;
|
|
@@ -0,0 +1,121 @@
|
|
|
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 * as Aglyn from "@aglyn/aglyn/server";
|
|
18
|
+
import { firebaseAdmin, getOrgForHost } from "@aglyn/tenant-data-admin";
|
|
19
|
+
import * as CommerceModel from "../model/index.js";
|
|
20
|
+
/*
|
|
21
|
+
* `commerce/orders-shipping-prepare` (AGL-3613): POST `{ hostId }` stamps the
|
|
22
|
+
* site's open orders written before AGL-3613 with what the shipping export
|
|
23
|
+
* and a shipping tool's feed ask (`requiresShipping`, `updatedAtMs`), so the
|
|
24
|
+
* indexed query finds them. The console calls it before an export for
|
|
25
|
+
* shipping. Bounded to OPEN orders — the ones a shipping tool still has to
|
|
26
|
+
* see — and a no-op for an order already stamped. The site's admins and
|
|
27
|
+
* editors, the order book's roles.
|
|
28
|
+
*/ /** Statuses a shipping tool still has to see an order in. */ const OPEN_STATUSES = [
|
|
29
|
+
'pending',
|
|
30
|
+
'paid',
|
|
31
|
+
'partially_fulfilled'
|
|
32
|
+
];
|
|
33
|
+
/** The most open orders one `prepare` stamps; a store with more is stamped over several calls. */ export const PREPARE_MAX_ORDERS = 2000;
|
|
34
|
+
/**
|
|
35
|
+
* Stamps the site's open orders that predate the stamp. Answers how many it
|
|
36
|
+
* stamped. `updatedAtMs` is the order's creation, not now: stamping is not
|
|
37
|
+
* a change ShipStation needs to hear about.
|
|
38
|
+
*/ export async function prepareOpenOrders(hostId) {
|
|
39
|
+
const firestore = firebaseAdmin.app().firestore();
|
|
40
|
+
const orders = firestore.collection('hosts').doc(hostId).collection('orders');
|
|
41
|
+
const snapshot = await orders.where('status', 'in', [
|
|
42
|
+
...OPEN_STATUSES
|
|
43
|
+
]).limit(PREPARE_MAX_ORDERS).get();
|
|
44
|
+
let stamped = 0;
|
|
45
|
+
let batch = firestore.batch();
|
|
46
|
+
let inBatch = 0;
|
|
47
|
+
for (const doc of snapshot.docs){
|
|
48
|
+
var _doc_data;
|
|
49
|
+
const data = (_doc_data = doc.data()) != null ? _doc_data : {};
|
|
50
|
+
if (typeof data.requiresShipping === 'boolean' && typeof data.updatedAtMs === 'number') continue;
|
|
51
|
+
const createdAtMs = Number(data.createdAtMs);
|
|
52
|
+
batch.update(doc.ref, _extends({}, typeof data.requiresShipping === 'boolean' ? {} : {
|
|
53
|
+
requiresShipping: CommerceModel.orderRequiresShipping(data)
|
|
54
|
+
}, typeof data.updatedAtMs === 'number' ? {} : {
|
|
55
|
+
updatedAtMs: Number.isFinite(createdAtMs) && createdAtMs > 0 ? createdAtMs : Date.now()
|
|
56
|
+
}));
|
|
57
|
+
stamped += 1;
|
|
58
|
+
inBatch += 1;
|
|
59
|
+
if (inBatch === 400) {
|
|
60
|
+
await batch.commit();
|
|
61
|
+
batch = firestore.batch();
|
|
62
|
+
inBatch = 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (inBatch) await batch.commit();
|
|
66
|
+
return stamped;
|
|
67
|
+
}
|
|
68
|
+
export const ordersShippingPrepareHandler = async (req, res)=>{
|
|
69
|
+
var _req_headers_authorization, _body_hostId;
|
|
70
|
+
if (req.method !== 'POST') return res.status(405).json({
|
|
71
|
+
error: 'Method not allowed'
|
|
72
|
+
});
|
|
73
|
+
const authorization = String((_req_headers_authorization = req.headers.authorization) != null ? _req_headers_authorization : '');
|
|
74
|
+
const idToken = authorization.startsWith('Bearer ') ? authorization.slice('Bearer '.length) : undefined;
|
|
75
|
+
if (!idToken) return res.status(401).json({
|
|
76
|
+
error: 'Unauthenticated'
|
|
77
|
+
});
|
|
78
|
+
let body;
|
|
79
|
+
try {
|
|
80
|
+
var _req_body;
|
|
81
|
+
body = typeof req.body === 'string' ? JSON.parse(req.body) : (_req_body = req.body) != null ? _req_body : {};
|
|
82
|
+
} catch (unused) {
|
|
83
|
+
return res.status(400).json({
|
|
84
|
+
error: 'The request could not be read'
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const hostId = String((_body_hostId = body['hostId']) != null ? _body_hostId : '');
|
|
88
|
+
if (!/^[A-Za-z0-9_-]{1,128}$/.test(hostId)) return res.status(400).json({
|
|
89
|
+
error: 'Missing hostId'
|
|
90
|
+
});
|
|
91
|
+
try {
|
|
92
|
+
var _hostSnapshot_get;
|
|
93
|
+
const decoded = await firebaseAdmin.app().auth().verifyIdToken(idToken);
|
|
94
|
+
const hostSnapshot = await firebaseAdmin.app().firestore().collection('hosts').doc(hostId).get();
|
|
95
|
+
if (!hostSnapshot.exists) return res.status(404).json({
|
|
96
|
+
error: 'Unknown site'
|
|
97
|
+
});
|
|
98
|
+
const role = ((_hostSnapshot_get = hostSnapshot.get('memberRoles')) != null ? _hostSnapshot_get : {})[decoded.uid];
|
|
99
|
+
if (role !== 'admin' && role !== 'editor') return res.status(403).json({
|
|
100
|
+
error: 'Not permitted'
|
|
101
|
+
});
|
|
102
|
+
const owner = await getOrgForHost(hostId);
|
|
103
|
+
if (!Aglyn.checkEntitlement(owner == null ? void 0 : owner.org, 'commerce')) {
|
|
104
|
+
return res.status(403).json({
|
|
105
|
+
error: 'Selling is not enabled'
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
const stamped = await prepareOpenOrders(hostId);
|
|
109
|
+
return res.status(200).json({
|
|
110
|
+
ok: true,
|
|
111
|
+
stamped
|
|
112
|
+
});
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.error('orders-shipping-prepare failed', hostId, error);
|
|
115
|
+
return res.status(500).json({
|
|
116
|
+
error: 'That did not work. Try again.'
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=orders-shipping-prepare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/orders-shipping-prepare.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 * as Aglyn from '@aglyn/aglyn/server'\nimport { firebaseAdmin, getOrgForHost } from '@aglyn/tenant-data-admin'\nimport * as CommerceModel from '../model'\n\n/*\n * `commerce/orders-shipping-prepare` (AGL-3613): POST `{ hostId }` stamps the\n * site's open orders written before AGL-3613 with what the shipping export\n * and a shipping tool's feed ask (`requiresShipping`, `updatedAtMs`), so the\n * indexed query finds them. The console calls it before an export for\n * shipping. Bounded to OPEN orders — the ones a shipping tool still has to\n * see — and a no-op for an order already stamped. The site's admins and\n * editors, the order book's roles.\n */\n\n/** Statuses a shipping tool still has to see an order in. */\nconst OPEN_STATUSES: readonly CommerceModel.OrderStatus[] = ['pending', 'paid', 'partially_fulfilled']\n\n/** The most open orders one `prepare` stamps; a store with more is stamped over several calls. */\nexport const PREPARE_MAX_ORDERS = 2000\n\n/**\n * Stamps the site's open orders that predate the stamp. Answers how many it\n * stamped. `updatedAtMs` is the order's creation, not now: stamping is not\n * a change ShipStation needs to hear about.\n */\nexport async function prepareOpenOrders(hostId: string): Promise<number> {\n const firestore = firebaseAdmin.app().firestore()\n const orders = firestore.collection('hosts').doc(hostId).collection('orders')\n const snapshot = await orders.where('status', 'in', [...OPEN_STATUSES]).limit(PREPARE_MAX_ORDERS).get()\n let stamped = 0\n let batch = firestore.batch()\n let inBatch = 0\n for (const doc of snapshot.docs) {\n const data = (doc.data() ?? {}) as Partial<CommerceModel.HostOrder> & { requiresShipping?: unknown; updatedAtMs?: unknown; createdAtMs?: unknown }\n if (typeof data.requiresShipping === 'boolean' && typeof data.updatedAtMs === 'number') continue\n const createdAtMs = Number(data.createdAtMs)\n batch.update(doc.ref, {\n ...(typeof data.requiresShipping === 'boolean' ? {} : { requiresShipping: CommerceModel.orderRequiresShipping(data) }),\n ...(typeof data.updatedAtMs === 'number'\n ? {}\n : { updatedAtMs: Number.isFinite(createdAtMs) && createdAtMs > 0 ? createdAtMs : Date.now() }),\n })\n stamped += 1\n inBatch += 1\n if (inBatch === 400) {\n await batch.commit()\n batch = firestore.batch()\n inBatch = 0\n }\n }\n if (inBatch) await batch.commit()\n return stamped\n}\n\nexport const ordersShippingPrepareHandler: Aglyn.PluginApiHandler = async (req, res) => {\n if (req.method !== 'POST') return res.status(405).json({ error: 'Method not allowed' })\n const authorization = String(req.headers.authorization ?? '')\n const idToken = authorization.startsWith('Bearer ') ? authorization.slice('Bearer '.length) : undefined\n if (!idToken) return res.status(401).json({ error: 'Unauthenticated' })\n let body: Record<string, unknown>\n try {\n body = typeof req.body === 'string' ? JSON.parse(req.body) : (req.body ?? {})\n } catch {\n return res.status(400).json({ error: 'The request could not be read' })\n }\n const hostId = String(body['hostId'] ?? '')\n if (!/^[A-Za-z0-9_-]{1,128}$/.test(hostId)) return res.status(400).json({ error: 'Missing hostId' })\n try {\n const decoded = await firebaseAdmin.app().auth().verifyIdToken(idToken)\n const hostSnapshot = await firebaseAdmin.app().firestore().collection('hosts').doc(hostId).get()\n if (!hostSnapshot.exists) return res.status(404).json({ error: 'Unknown site' })\n const role = (hostSnapshot.get('memberRoles') ?? {})[decoded.uid]\n if (role !== 'admin' && role !== 'editor') return res.status(403).json({ error: 'Not permitted' })\n const owner = await getOrgForHost(hostId)\n if (!Aglyn.checkEntitlement(owner?.org as never, 'commerce')) {\n return res.status(403).json({ error: 'Selling is not enabled' })\n }\n const stamped = await prepareOpenOrders(hostId)\n return res.status(200).json({ ok: true, stamped })\n } catch (error) {\n console.error('orders-shipping-prepare failed', hostId, error)\n return res.status(500).json({ error: 'That did not work. Try again.' })\n }\n}\n"],"names":["Aglyn","firebaseAdmin","getOrgForHost","CommerceModel","OPEN_STATUSES","PREPARE_MAX_ORDERS","prepareOpenOrders","hostId","firestore","app","orders","collection","doc","snapshot","where","limit","get","stamped","batch","inBatch","docs","data","requiresShipping","updatedAtMs","createdAtMs","Number","update","ref","orderRequiresShipping","isFinite","Date","now","commit","ordersShippingPrepareHandler","req","res","body","method","status","json","error","authorization","String","headers","idToken","startsWith","slice","length","undefined","JSON","parse","test","hostSnapshot","decoded","auth","verifyIdToken","exists","role","uid","owner","checkEntitlement","org","ok","console"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,sBAAqB;AAC5C,SAASC,aAAa,EAAEC,aAAa,QAAQ,2BAA0B;AACvE,YAAYC,mBAAmB,oBAAU;AAEzC;;;;;;;;CAQC,GAED,2DAA2D,GAC3D,MAAMC,gBAAsD;IAAC;IAAW;IAAQ;CAA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,IAAI,CAAC;YAAEC,OAAO;QAAgB;QAChG,MAAMmB,QAAQ,MAAMzD,cAAcK;QAClC,IAAI,CAACP,MAAM4D,gBAAgB,CAACD,yBAAAA,MAAOE,GAAG,EAAW,aAAa;YAC5D,OAAO1B,IAAIG,MAAM,CAAC,KAAKC,IAAI,CAAC;gBAAEC,OAAO;YAAyB;QAChE;QACA,MAAMvB,UAAU,MAAMX,kBAAkBC;QACxC,OAAO4B,IAAIG,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEuB,IAAI;YAAM7C;QAAQ;IAClD,EAAE,OAAOuB,OAAO;QACduB,QAAQvB,KAAK,CAAC,kCAAkCjC,QAAQiC;QACxD,OAAOL,IAAIG,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAAgC;IACvE;AACF,EAAC"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { type SiteReturnHost } from '@aglyn/aglyn/app-utils/site-return-url';
|
|
18
|
+
/**
|
|
19
|
+
* Stripe payment method domains for storefronts (AGL-3629).
|
|
20
|
+
*
|
|
21
|
+
* The in-page checkout mounts Stripe's Payment Element on the merchant's own
|
|
22
|
+
* domain, and Stripe shows Apple Pay there only on a REGISTERED domain (Google
|
|
23
|
+
* Pay, Link, Amazon Pay and Klarna's express button use the same registration).
|
|
24
|
+
* Nothing registered one, so a shopper on `shop.example.com` with a card in
|
|
25
|
+
* Apple Wallet never saw the button.
|
|
26
|
+
*
|
|
27
|
+
* ## Which account the domain is registered on
|
|
28
|
+
*
|
|
29
|
+
* Stripe's rule: "The domain where the charge is being run needs to be
|
|
30
|
+
* registered for the user running the charge." Storefront charges are
|
|
31
|
+
* DESTINATION charges created by the platform with no `Stripe-Account` header
|
|
32
|
+
* and no `on_behalf_of`, so the platform runs them and the platform's key
|
|
33
|
+
* registers the domain, with no `Stripe-Account` header. A direct-charge flow
|
|
34
|
+
* would register on the connected account instead; there is none today, and
|
|
35
|
+
* `registerOnPlatform` is named for that reason.
|
|
36
|
+
*
|
|
37
|
+
* ## When
|
|
38
|
+
*
|
|
39
|
+
* - On connect: core raises `host.domain.attached`, and commerce registers
|
|
40
|
+
* the custom domain and its `www.` twin.
|
|
41
|
+
* - On first checkout: the session handlers call `ensureCheckoutDomain` for
|
|
42
|
+
* the page the shopper is on, which covers every `{site}.aglyn.app`
|
|
43
|
+
* subdomain without registering thousands of sites that never sell.
|
|
44
|
+
* - Daily: `reconcileCustomDomains` registers any connected custom domain the
|
|
45
|
+
* first two missed (domains connected before AGL-3629 included) — the
|
|
46
|
+
* backfill is a job rather than a one-off script, so it also repairs a
|
|
47
|
+
* missed event later.
|
|
48
|
+
* - On release: `host.domain.released` DISABLES the domain. Stripe has no
|
|
49
|
+
* delete; a disabled domain stops showing the methods and can be enabled
|
|
50
|
+
* again if the name comes back.
|
|
51
|
+
*
|
|
52
|
+
* ## The cache
|
|
53
|
+
*
|
|
54
|
+
* `paymentMethodDomains/{mode}~{domain}` records what Stripe last said, so a
|
|
55
|
+
* checkout costs one document read rather than a Stripe round trip. The mode is
|
|
56
|
+
* in the id because a test key and a live key register in different worlds and
|
|
57
|
+
* a domain registered in one is not registered in the other. Server-only: the
|
|
58
|
+
* rules deny every client.
|
|
59
|
+
*/
|
|
60
|
+
export declare const PAYMENT_METHOD_DOMAINS_COLLECTION = "paymentMethodDomains";
|
|
61
|
+
/** How long a recorded registration is trusted before Stripe is asked again. */
|
|
62
|
+
export declare const PAYMENT_METHOD_DOMAIN_RECHECK_MS: number;
|
|
63
|
+
/** The most a checkout waits on Stripe before selling without the domain. */
|
|
64
|
+
export declare const CHECKOUT_DOMAIN_BUDGET_MS = 2500;
|
|
65
|
+
export type StripeMode = 'live' | 'test';
|
|
66
|
+
/** Stripe's per-method verdict on a domain. */
|
|
67
|
+
export interface PaymentMethodDomainStatus {
|
|
68
|
+
applePay: string | null;
|
|
69
|
+
googlePay: string | null;
|
|
70
|
+
link: string | null;
|
|
71
|
+
amazonPay: string | null;
|
|
72
|
+
klarna: string | null;
|
|
73
|
+
}
|
|
74
|
+
export interface PaymentMethodDomainRecord {
|
|
75
|
+
domain: string;
|
|
76
|
+
mode: StripeMode;
|
|
77
|
+
stripeId: string | null;
|
|
78
|
+
enabled: boolean;
|
|
79
|
+
status: PaymentMethodDomainStatus;
|
|
80
|
+
hostId: string | null;
|
|
81
|
+
checkedAtMs: number;
|
|
82
|
+
lastError: string | null;
|
|
83
|
+
}
|
|
84
|
+
interface StripeDomainObject {
|
|
85
|
+
id: string;
|
|
86
|
+
domain_name: string;
|
|
87
|
+
enabled: boolean;
|
|
88
|
+
apple_pay?: {
|
|
89
|
+
status?: string;
|
|
90
|
+
};
|
|
91
|
+
google_pay?: {
|
|
92
|
+
status?: string;
|
|
93
|
+
};
|
|
94
|
+
link?: {
|
|
95
|
+
status?: string;
|
|
96
|
+
};
|
|
97
|
+
amazon_pay?: {
|
|
98
|
+
status?: string;
|
|
99
|
+
};
|
|
100
|
+
klarna?: {
|
|
101
|
+
status?: string;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Which Stripe world the platform key is in, from its prefix. */
|
|
105
|
+
export declare function stripeModeOfKey(key: string | undefined): StripeMode | null;
|
|
106
|
+
/**
|
|
107
|
+
* A hostname Stripe can register: lowercased, no trailing dot, at least two
|
|
108
|
+
* labels, and never a local or IP host — a checkout opened on `localhost`
|
|
109
|
+
* must not try to register it.
|
|
110
|
+
*/
|
|
111
|
+
export declare function registrableDomain(input: unknown): string | null;
|
|
112
|
+
/** The cache document id for a domain in a mode. */
|
|
113
|
+
export declare function paymentMethodDomainDocId(mode: StripeMode, domain: string): string;
|
|
114
|
+
/**
|
|
115
|
+
* The domains a site's custom domain needs: the domain and its `www.` twin,
|
|
116
|
+
* since the platform answers on both (`siteOwnHosts`).
|
|
117
|
+
*/
|
|
118
|
+
export declare function customDomainNames(cname: unknown): string[];
|
|
119
|
+
/**
|
|
120
|
+
* Register (or re-enable) one domain on the platform account. Idempotent end
|
|
121
|
+
* to end: an existing registration is found first and reused, a disabled one
|
|
122
|
+
* is enabled rather than duplicated, and the create carries an idempotency key
|
|
123
|
+
* so two checkouts racing on a fresh subdomain open one registration.
|
|
124
|
+
*/
|
|
125
|
+
export declare function registerOnPlatform(domain: string, signal?: AbortSignal): Promise<StripeDomainObject>;
|
|
126
|
+
export interface EnsureDomainResult {
|
|
127
|
+
domain: string;
|
|
128
|
+
outcome: 'registered' | 'cached' | 'skipped' | 'failed';
|
|
129
|
+
record?: PaymentMethodDomainRecord;
|
|
130
|
+
error?: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Make sure one domain is registered and enabled, reading the cache first.
|
|
134
|
+
*
|
|
135
|
+
* Never throws: every caller is on its way to something more important (a
|
|
136
|
+
* sale, a domain connect), and a domain Stripe would not take today is
|
|
137
|
+
* recorded with its error and retried by the daily reconcile.
|
|
138
|
+
*/
|
|
139
|
+
export declare function ensurePaymentMethodDomain(rawDomain: string, options?: {
|
|
140
|
+
hostId?: string | null;
|
|
141
|
+
signal?: AbortSignal;
|
|
142
|
+
force?: boolean;
|
|
143
|
+
}): Promise<EnsureDomainResult>;
|
|
144
|
+
/**
|
|
145
|
+
* Disable a domain the platform no longer serves for a site. Stripe has no
|
|
146
|
+
* delete for a payment method domain; disabling stops every method on it, and
|
|
147
|
+
* `ensurePaymentMethodDomain` re-enables the same registration if the name is
|
|
148
|
+
* connected again.
|
|
149
|
+
*/
|
|
150
|
+
export declare function disablePaymentMethodDomain(rawDomain: string): Promise<{
|
|
151
|
+
domain: string;
|
|
152
|
+
outcome: 'disabled' | 'absent' | 'skipped' | 'failed';
|
|
153
|
+
error?: string;
|
|
154
|
+
}>;
|
|
155
|
+
/**
|
|
156
|
+
* Is a name still served for some OTHER site? A custom domain's `www.` twin
|
|
157
|
+
* can be another site's own `cname`, and an aglyn subdomain released by a
|
|
158
|
+
* deleted site can already belong to a new one. Disabling either would take
|
|
159
|
+
* Apple Pay away from a store that did nothing.
|
|
160
|
+
*/
|
|
161
|
+
export declare function domainStillClaimed(domain: string, exceptHostId: string): Promise<boolean>;
|
|
162
|
+
/**
|
|
163
|
+
* The checkout's hook: register the domain the shopper is paying on, within a
|
|
164
|
+
* budget, before the client secret goes back to the browser. Only a name the
|
|
165
|
+
* SITE answers on is ever registered — the return URL has already been judged
|
|
166
|
+
* against `siteOwnHosts` by `siteReturnUrl`, and it is judged again here so a
|
|
167
|
+
* forged `Host` can never make the platform register a stranger's domain.
|
|
168
|
+
*/
|
|
169
|
+
export declare function ensureCheckoutDomain(input: {
|
|
170
|
+
pageUrl: string;
|
|
171
|
+
site: SiteReturnHost | null | undefined;
|
|
172
|
+
hostId: string;
|
|
173
|
+
budgetMs?: number;
|
|
174
|
+
}): Promise<EnsureDomainResult | null>;
|
|
175
|
+
/** One page of the daily reconcile. */
|
|
176
|
+
export declare const RECONCILE_PAGE_SIZE = 200;
|
|
177
|
+
/**
|
|
178
|
+
* The backfill and the safety net in one pass: every site with a connected
|
|
179
|
+
* custom domain gets its domain and `www.` twin registered. A cached, enabled
|
|
180
|
+
* registration costs one read and no Stripe call, so the steady state is cheap;
|
|
181
|
+
* a domain connected before AGL-3629, or whose connect event was lost, is
|
|
182
|
+
* registered on the first pass after it.
|
|
183
|
+
*
|
|
184
|
+
* Paged by `cname` with a cursor so it reads every site once and stops; the
|
|
185
|
+
* `cname > ''` range uses Firestore's automatic single-field index.
|
|
186
|
+
*/
|
|
187
|
+
export declare function reconcileCustomDomains(gate: {
|
|
188
|
+
isLocked(hostId: string): Promise<boolean>;
|
|
189
|
+
}, options?: {
|
|
190
|
+
maxPages?: number;
|
|
191
|
+
}): Promise<{
|
|
192
|
+
hosts: number;
|
|
193
|
+
registered: number;
|
|
194
|
+
failed: number;
|
|
195
|
+
skippedLocked: number;
|
|
196
|
+
}>;
|
|
197
|
+
/** Core's `host.domain.attached`: register the custom domain and its twin. */
|
|
198
|
+
export declare function onHostDomainAttached(payload: {
|
|
199
|
+
hostId: string;
|
|
200
|
+
domain: string;
|
|
201
|
+
}): Promise<void>;
|
|
202
|
+
/** Core's `host.domain.released`: disable what no other site still serves. */
|
|
203
|
+
export declare function onHostDomainReleased(payload: {
|
|
204
|
+
hostId: string;
|
|
205
|
+
domain: string;
|
|
206
|
+
}): Promise<void>;
|
|
207
|
+
/** The registrations a settings card shows for one site. */
|
|
208
|
+
export declare function readSiteDomainRecords(site: SiteReturnHost | null | undefined): Promise<PaymentMethodDomainRecord[]>;
|
|
209
|
+
export {};
|