@aglyn/plugins-commerce 1.0.0-beta.143
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/LICENSE +201 -0
- package/README.md +10 -0
- package/package.json +57 -0
- package/src/index.d.ts +38 -0
- package/src/index.js +38 -0
- package/src/index.js.map +1 -0
- package/src/lib/components/account.d.ts +31 -0
- package/src/lib/components/account.js +645 -0
- package/src/lib/components/account.js.map +1 -0
- package/src/lib/components/cart.d.ts +38 -0
- package/src/lib/components/cart.js +851 -0
- package/src/lib/components/cart.js.map +1 -0
- package/src/lib/components/commerce-console-page.d.ts +32 -0
- package/src/lib/components/commerce-console-page.js +296 -0
- package/src/lib/components/commerce-console-page.js.map +1 -0
- package/src/lib/components/commerce-console-sections.d.ts +34 -0
- package/src/lib/components/commerce-console-sections.js +62 -0
- package/src/lib/components/commerce-console-sections.js.map +1 -0
- package/src/lib/components/console/catalog-organization-card.component.d.ts +14 -0
- package/src/lib/components/console/catalog-organization-card.component.js +1087 -0
- package/src/lib/components/console/catalog-organization-card.component.js.map +1 -0
- package/src/lib/components/console/commerce-analytics-card.component.d.ts +27 -0
- package/src/lib/components/console/commerce-analytics-card.component.js +310 -0
- package/src/lib/components/console/commerce-analytics-card.component.js.map +1 -0
- package/src/lib/components/console/commerce-glance-card.component.d.ts +20 -0
- package/src/lib/components/console/commerce-glance-card.component.js +340 -0
- package/src/lib/components/console/commerce-glance-card.component.js.map +1 -0
- package/src/lib/components/console/commerce-stat-tile.component.d.ts +37 -0
- package/src/lib/components/console/commerce-stat-tile.component.js +72 -0
- package/src/lib/components/console/commerce-stat-tile.component.js.map +1 -0
- package/src/lib/components/console/discounts-card.component.d.ts +14 -0
- package/src/lib/components/console/discounts-card.component.js +443 -0
- package/src/lib/components/console/discounts-card.component.js.map +1 -0
- package/src/lib/components/console/entitlement-gate.component.d.ts +76 -0
- package/src/lib/components/console/entitlement-gate.component.js +115 -0
- package/src/lib/components/console/entitlement-gate.component.js.map +1 -0
- package/src/lib/components/console/gift-cards-card.component.d.ts +29 -0
- package/src/lib/components/console/gift-cards-card.component.js +379 -0
- package/src/lib/components/console/gift-cards-card.component.js.map +1 -0
- package/src/lib/components/console/host-coupons-card.component.d.ts +14 -0
- package/src/lib/components/console/host-coupons-card.component.js +252 -0
- package/src/lib/components/console/host-coupons-card.component.js.map +1 -0
- package/src/lib/components/console/host-orders-card.component.d.ts +13 -0
- package/src/lib/components/console/host-orders-card.component.js +861 -0
- package/src/lib/components/console/host-orders-card.component.js.map +1 -0
- package/src/lib/components/console/locations-card.component.d.ts +14 -0
- package/src/lib/components/console/locations-card.component.js +256 -0
- package/src/lib/components/console/locations-card.component.js.map +1 -0
- package/src/lib/components/console/member-posts-card.component.d.ts +8 -0
- package/src/lib/components/console/member-posts-card.component.js +283 -0
- package/src/lib/components/console/member-posts-card.component.js.map +1 -0
- package/src/lib/components/console/newest-site-users-card.component.d.ts +36 -0
- package/src/lib/components/console/newest-site-users-card.component.js +126 -0
- package/src/lib/components/console/newest-site-users-card.component.js.map +1 -0
- package/src/lib/components/console/order-detail-dialog.component.d.ts +28 -0
- package/src/lib/components/console/order-detail-dialog.component.js +976 -0
- package/src/lib/components/console/order-detail-dialog.component.js.map +1 -0
- package/src/lib/components/console/paid-media.d.ts +127 -0
- package/src/lib/components/console/paid-media.js +397 -0
- package/src/lib/components/console/paid-media.js.map +1 -0
- package/src/lib/components/console/payments-settings-card.component.d.ts +13 -0
- package/src/lib/components/console/payments-settings-card.component.js +295 -0
- package/src/lib/components/console/payments-settings-card.component.js.map +1 -0
- package/src/lib/components/console/pos-page.component.d.ts +13 -0
- package/src/lib/components/console/pos-page.component.js +916 -0
- package/src/lib/components/console/pos-page.component.js.map +1 -0
- package/src/lib/components/console/product-editor-dialog.component.d.ts +32 -0
- package/src/lib/components/console/product-editor-dialog.component.js +1374 -0
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -0
- package/src/lib/components/console/products-hub-card.component.d.ts +16 -0
- package/src/lib/components/console/products-hub-card.component.js +1280 -0
- package/src/lib/components/console/products-hub-card.component.js.map +1 -0
- package/src/lib/components/console/products-hub-zone.component.d.ts +50 -0
- package/src/lib/components/console/products-hub-zone.component.js +200 -0
- package/src/lib/components/console/products-hub-zone.component.js.map +1 -0
- package/src/lib/components/console/recovery-queue-card.component.d.ts +39 -0
- package/src/lib/components/console/recovery-queue-card.component.js +262 -0
- package/src/lib/components/console/recovery-queue-card.component.js.map +1 -0
- package/src/lib/components/console/registers-card.component.d.ts +21 -0
- package/src/lib/components/console/registers-card.component.js +296 -0
- package/src/lib/components/console/registers-card.component.js.map +1 -0
- package/src/lib/components/console/reservations-card.component.d.ts +14 -0
- package/src/lib/components/console/reservations-card.component.js +650 -0
- package/src/lib/components/console/reservations-card.component.js.map +1 -0
- package/src/lib/components/console/reviews-moderation-card.component.d.ts +8 -0
- package/src/lib/components/console/reviews-moderation-card.component.js +235 -0
- package/src/lib/components/console/reviews-moderation-card.component.js.map +1 -0
- package/src/lib/components/console/shipping-settings-card.component.d.ts +38 -0
- package/src/lib/components/console/shipping-settings-card.component.js +560 -0
- package/src/lib/components/console/shipping-settings-card.component.js.map +1 -0
- package/src/lib/components/console/stock-movements-card.component.d.ts +31 -0
- package/src/lib/components/console/stock-movements-card.component.js +333 -0
- package/src/lib/components/console/stock-movements-card.component.js.map +1 -0
- package/src/lib/components/console/store-settings-card.component.d.ts +14 -0
- package/src/lib/components/console/store-settings-card.component.js +300 -0
- package/src/lib/components/console/store-settings-card.component.js.map +1 -0
- package/src/lib/components/console/storefront-tax-summary-card.component.d.ts +73 -0
- package/src/lib/components/console/storefront-tax-summary-card.component.js +408 -0
- package/src/lib/components/console/storefront-tax-summary-card.component.js.map +1 -0
- package/src/lib/components/console/suppliers-card.component.d.ts +8 -0
- package/src/lib/components/console/suppliers-card.component.js +328 -0
- package/src/lib/components/console/suppliers-card.component.js.map +1 -0
- package/src/lib/components/console/tax-settings-card.component.d.ts +14 -0
- package/src/lib/components/console/tax-settings-card.component.js +473 -0
- package/src/lib/components/console/tax-settings-card.component.js.map +1 -0
- package/src/lib/components/gate.d.ts +39 -0
- package/src/lib/components/gate.js +202 -0
- package/src/lib/components/gate.js.map +1 -0
- package/src/lib/components/gated-video.d.ts +40 -0
- package/src/lib/components/gated-video.js +366 -0
- package/src/lib/components/gated-video.js.map +1 -0
- package/src/lib/components/member-feed.d.ts +32 -0
- package/src/lib/components/member-feed.js +198 -0
- package/src/lib/components/member-feed.js.map +1 -0
- package/src/lib/components/member-recovery.d.ts +35 -0
- package/src/lib/components/member-recovery.js +313 -0
- package/src/lib/components/member-recovery.js.map +1 -0
- package/src/lib/components/member-signin.d.ts +35 -0
- package/src/lib/components/member-signin.js +257 -0
- package/src/lib/components/member-signin.js.map +1 -0
- package/src/lib/components/member-signup.d.ts +34 -0
- package/src/lib/components/member-signup.js +287 -0
- package/src/lib/components/member-signup.js.map +1 -0
- package/src/lib/components/newsletter-signup.d.ts +39 -0
- package/src/lib/components/newsletter-signup.js +229 -0
- package/src/lib/components/newsletter-signup.js.map +1 -0
- package/src/lib/components/product-detail.d.ts +38 -0
- package/src/lib/components/product-detail.js +1022 -0
- package/src/lib/components/product-detail.js.map +1 -0
- package/src/lib/components/product-grid.d.ts +67 -0
- package/src/lib/components/product-grid.js +909 -0
- package/src/lib/components/product-grid.js.map +1 -0
- package/src/lib/components/product-reviews.d.ts +32 -0
- package/src/lib/components/product-reviews.js +349 -0
- package/src/lib/components/product-reviews.js.map +1 -0
- package/src/lib/components/related-products.d.ts +33 -0
- package/src/lib/components/related-products.js +232 -0
- package/src/lib/components/related-products.js.map +1 -0
- package/src/lib/components/reservation-widget.d.ts +33 -0
- package/src/lib/components/reservation-widget.js +418 -0
- package/src/lib/components/reservation-widget.js.map +1 -0
- package/src/lib/components/storefront-payment-element-fallback.d.ts +18 -0
- package/src/lib/components/storefront-payment-element-fallback.js +51 -0
- package/src/lib/components/storefront-payment-element-fallback.js.map +1 -0
- package/src/lib/components/storefront-payment-element.d.ts +78 -0
- package/src/lib/components/storefront-payment-element.js +156 -0
- package/src/lib/components/storefront-payment-element.js.map +1 -0
- package/src/lib/components/wishlist.d.ts +46 -0
- package/src/lib/components/wishlist.js +304 -0
- package/src/lib/components/wishlist.js.map +1 -0
- package/src/lib/constants/bundle-common.d.ts +18 -0
- package/src/lib/constants/bundle-common.js +18 -0
- package/src/lib/constants/bundle-common.js.map +1 -0
- package/src/lib/constants/product-filters.d.ts +35 -0
- package/src/lib/constants/product-filters.js +109 -0
- package/src/lib/constants/product-filters.js.map +1 -0
- package/src/lib/model/commerce-cart.d.ts +52 -0
- package/src/lib/model/commerce-cart.js +102 -0
- package/src/lib/model/commerce-cart.js.map +1 -0
- package/src/lib/model/commerce-connect-transfer.d.ts +243 -0
- package/src/lib/model/commerce-connect-transfer.js +231 -0
- package/src/lib/model/commerce-connect-transfer.js.map +1 -0
- package/src/lib/model/commerce-discounts.d.ts +164 -0
- package/src/lib/model/commerce-discounts.js +231 -0
- package/src/lib/model/commerce-discounts.js.map +1 -0
- package/src/lib/model/commerce-dispute.d.ts +124 -0
- package/src/lib/model/commerce-dispute.js +225 -0
- package/src/lib/model/commerce-dispute.js.map +1 -0
- package/src/lib/model/commerce-gift-cards.d.ts +107 -0
- package/src/lib/model/commerce-gift-cards.js +121 -0
- package/src/lib/model/commerce-gift-cards.js.map +1 -0
- package/src/lib/model/commerce-io.d.ts +36 -0
- package/src/lib/model/commerce-io.js +245 -0
- package/src/lib/model/commerce-io.js.map +1 -0
- package/src/lib/model/commerce-orders.d.ts +1040 -0
- package/src/lib/model/commerce-orders.js +1022 -0
- package/src/lib/model/commerce-orders.js.map +1 -0
- package/src/lib/model/commerce-promotions.d.ts +188 -0
- package/src/lib/model/commerce-promotions.js +199 -0
- package/src/lib/model/commerce-promotions.js.map +1 -0
- package/src/lib/model/commerce-reservations.d.ts +175 -0
- package/src/lib/model/commerce-reservations.js +157 -0
- package/src/lib/model/commerce-reservations.js.map +1 -0
- package/src/lib/model/commerce-shipping.d.ts +316 -0
- package/src/lib/model/commerce-shipping.js +484 -0
- package/src/lib/model/commerce-shipping.js.map +1 -0
- package/src/lib/model/commerce-stock-holds.d.ts +199 -0
- package/src/lib/model/commerce-stock-holds.js +190 -0
- package/src/lib/model/commerce-stock-holds.js.map +1 -0
- package/src/lib/model/commerce-subscription-status.d.ts +67 -0
- package/src/lib/model/commerce-subscription-status.js +76 -0
- package/src/lib/model/commerce-subscription-status.js.map +1 -0
- package/src/lib/model/commerce-tax-decision.d.ts +222 -0
- package/src/lib/model/commerce-tax-decision.js +165 -0
- package/src/lib/model/commerce-tax-decision.js.map +1 -0
- package/src/lib/model/commerce-tax.d.ts +176 -0
- package/src/lib/model/commerce-tax.js +92 -0
- package/src/lib/model/commerce-tax.js.map +1 -0
- package/src/lib/model/commerce.d.ts +551 -0
- package/src/lib/model/commerce.js +739 -0
- package/src/lib/model/commerce.js.map +1 -0
- package/src/lib/model/index.d.ts +40 -0
- package/src/lib/model/index.js +40 -0
- package/src/lib/model/index.js.map +1 -0
- package/src/lib/model/order-figures.d.ts +48 -0
- package/src/lib/model/order-figures.js +74 -0
- package/src/lib/model/order-figures.js.map +1 -0
- package/src/lib/model/plugin-permissions.d.ts +23 -0
- package/src/lib/model/plugin-permissions.js +34 -0
- package/src/lib/model/plugin-permissions.js.map +1 -0
- package/src/lib/model/purchase-analytics.d.ts +186 -0
- package/src/lib/model/purchase-analytics.js +216 -0
- package/src/lib/model/purchase-analytics.js.map +1 -0
- package/src/lib/plugin-config.d.ts +62 -0
- package/src/lib/plugin-config.js +78 -0
- package/src/lib/plugin-config.js.map +1 -0
- package/src/lib/plugin.d.ts +28 -0
- package/src/lib/plugin.js +147 -0
- package/src/lib/plugin.js.map +1 -0
- package/src/lib/server/billing-webhook.d.ts +26 -0
- package/src/lib/server/billing-webhook.js +4011 -0
- package/src/lib/server/billing-webhook.js.map +1 -0
- package/src/lib/server/cancel-order.d.ts +87 -0
- package/src/lib/server/cancel-order.js +368 -0
- package/src/lib/server/cancel-order.js.map +1 -0
- package/src/lib/server/cart-checkout.d.ts +25 -0
- package/src/lib/server/cart-checkout.js +976 -0
- package/src/lib/server/cart-checkout.js.map +1 -0
- package/src/lib/server/cart-cookie.d.ts +32 -0
- package/src/lib/server/cart-cookie.js +77 -0
- package/src/lib/server/cart-cookie.js.map +1 -0
- package/src/lib/server/cart.d.ts +34 -0
- package/src/lib/server/cart.js +181 -0
- package/src/lib/server/cart.js.map +1 -0
- package/src/lib/server/catalog.d.ts +127 -0
- package/src/lib/server/catalog.js +277 -0
- package/src/lib/server/catalog.js.map +1 -0
- package/src/lib/server/checkout.d.ts +36 -0
- package/src/lib/server/checkout.js +915 -0
- package/src/lib/server/checkout.js.map +1 -0
- package/src/lib/server/connect.d.ts +26 -0
- package/src/lib/server/connect.js +238 -0
- package/src/lib/server/connect.js.map +1 -0
- package/src/lib/server/contact-refund.d.ts +117 -0
- package/src/lib/server/contact-refund.js +196 -0
- package/src/lib/server/contact-refund.js.map +1 -0
- package/src/lib/server/download.d.ts +39 -0
- package/src/lib/server/download.js +206 -0
- package/src/lib/server/download.js.map +1 -0
- package/src/lib/server/draft-order.d.ts +26 -0
- package/src/lib/server/draft-order.js +706 -0
- package/src/lib/server/draft-order.js.map +1 -0
- package/src/lib/server/feed.d.ts +24 -0
- package/src/lib/server/feed.js +59 -0
- package/src/lib/server/feed.js.map +1 -0
- package/src/lib/server/fulfill-order.d.ts +97 -0
- package/src/lib/server/fulfill-order.js +235 -0
- package/src/lib/server/fulfill-order.js.map +1 -0
- package/src/lib/server/gate.d.ts +36 -0
- package/src/lib/server/gate.js +112 -0
- package/src/lib/server/gate.js.map +1 -0
- package/src/lib/server/gift-cards.d.ts +42 -0
- package/src/lib/server/gift-cards.js +219 -0
- package/src/lib/server/gift-cards.js.map +1 -0
- package/src/lib/server/low-stock.d.ts +49 -0
- package/src/lib/server/low-stock.js +60 -0
- package/src/lib/server/low-stock.js.map +1 -0
- package/src/lib/server/manual-tax-rate.d.ts +82 -0
- package/src/lib/server/manual-tax-rate.js +113 -0
- package/src/lib/server/manual-tax-rate.js.map +1 -0
- package/src/lib/server/member-feed.d.ts +24 -0
- package/src/lib/server/member-feed.js +72 -0
- package/src/lib/server/member-feed.js.map +1 -0
- package/src/lib/server/member-name-search.d.ts +37 -0
- package/src/lib/server/member-name-search.js +42 -0
- package/src/lib/server/member-name-search.js.map +1 -0
- package/src/lib/server/member-post.d.ts +23 -0
- package/src/lib/server/member-post.js +166 -0
- package/src/lib/server/member-post.js.map +1 -0
- package/src/lib/server/membership-account.d.ts +37 -0
- package/src/lib/server/membership-account.js +148 -0
- package/src/lib/server/membership-account.js.map +1 -0
- package/src/lib/server/membership-admin-password.d.ts +33 -0
- package/src/lib/server/membership-admin-password.js +202 -0
- package/src/lib/server/membership-admin-password.js.map +1 -0
- package/src/lib/server/membership-content.d.ts +23 -0
- package/src/lib/server/membership-content.js +105 -0
- package/src/lib/server/membership-content.js.map +1 -0
- package/src/lib/server/membership-login.d.ts +19 -0
- package/src/lib/server/membership-login.js +137 -0
- package/src/lib/server/membership-login.js.map +1 -0
- package/src/lib/server/membership-logout.d.ts +19 -0
- package/src/lib/server/membership-logout.js +35 -0
- package/src/lib/server/membership-logout.js.map +1 -0
- package/src/lib/server/membership-recover.d.ts +60 -0
- package/src/lib/server/membership-recover.js +244 -0
- package/src/lib/server/membership-recover.js.map +1 -0
- package/src/lib/server/membership-register.d.ts +22 -0
- package/src/lib/server/membership-register.js +241 -0
- package/src/lib/server/membership-register.js.map +1 -0
- package/src/lib/server/membership-reset.d.ts +26 -0
- package/src/lib/server/membership-reset.js +88 -0
- package/src/lib/server/membership-reset.js.map +1 -0
- package/src/lib/server/membership-wishlist.d.ts +23 -0
- package/src/lib/server/membership-wishlist.js +89 -0
- package/src/lib/server/membership-wishlist.js.map +1 -0
- package/src/lib/server/membership.d.ts +96 -0
- package/src/lib/server/membership.js +222 -0
- package/src/lib/server/membership.js.map +1 -0
- package/src/lib/server/native-checkout.d.ts +170 -0
- package/src/lib/server/native-checkout.js +193 -0
- package/src/lib/server/native-checkout.js.map +1 -0
- package/src/lib/server/newsletter.d.ts +23 -0
- package/src/lib/server/newsletter.js +323 -0
- package/src/lib/server/newsletter.js.map +1 -0
- package/src/lib/server/notify-restock.d.ts +22 -0
- package/src/lib/server/notify-restock.js +84 -0
- package/src/lib/server/notify-restock.js.map +1 -0
- package/src/lib/server/order-analytics.d.ts +134 -0
- package/src/lib/server/order-analytics.js +263 -0
- package/src/lib/server/order-analytics.js.map +1 -0
- package/src/lib/server/order-figures.d.ts +33 -0
- package/src/lib/server/order-figures.js +220 -0
- package/src/lib/server/order-figures.js.map +1 -0
- package/src/lib/server/paid-media-delivery.d.ts +173 -0
- package/src/lib/server/paid-media-delivery.js +212 -0
- package/src/lib/server/paid-media-delivery.js.map +1 -0
- package/src/lib/server/pos-order.d.ts +54 -0
- package/src/lib/server/pos-order.js +1137 -0
- package/src/lib/server/pos-order.js.map +1 -0
- package/src/lib/server/process-abandoned.d.ts +54 -0
- package/src/lib/server/process-abandoned.js +222 -0
- package/src/lib/server/process-abandoned.js.map +1 -0
- package/src/lib/server/process-restock.d.ts +42 -0
- package/src/lib/server/process-restock.js +219 -0
- package/src/lib/server/process-restock.js.map +1 -0
- package/src/lib/server/product-card.d.ts +29 -0
- package/src/lib/server/product-card.js +54 -0
- package/src/lib/server/product-card.js.map +1 -0
- package/src/lib/server/product.d.ts +70 -0
- package/src/lib/server/product.js +105 -0
- package/src/lib/server/product.js.map +1 -0
- package/src/lib/server/promotion-hold.d.ts +144 -0
- package/src/lib/server/promotion-hold.js +174 -0
- package/src/lib/server/promotion-hold.js.map +1 -0
- package/src/lib/server/reconcile-stock.d.ts +106 -0
- package/src/lib/server/reconcile-stock.js +349 -0
- package/src/lib/server/reconcile-stock.js.map +1 -0
- package/src/lib/server/refund.d.ts +45 -0
- package/src/lib/server/refund.js +607 -0
- package/src/lib/server/refund.js.map +1 -0
- package/src/lib/server/related.d.ts +24 -0
- package/src/lib/server/related.js +104 -0
- package/src/lib/server/related.js.map +1 -0
- package/src/lib/server/reservation-availability.d.ts +23 -0
- package/src/lib/server/reservation-availability.js +111 -0
- package/src/lib/server/reservation-availability.js.map +1 -0
- package/src/lib/server/reserve-stock.d.ts +156 -0
- package/src/lib/server/reserve-stock.js +146 -0
- package/src/lib/server/reserve-stock.js.map +1 -0
- package/src/lib/server/reserve.d.ts +25 -0
- package/src/lib/server/reserve.js +426 -0
- package/src/lib/server/reserve.js.map +1 -0
- package/src/lib/server/restock-flag.d.ts +202 -0
- package/src/lib/server/restock-flag.js +449 -0
- package/src/lib/server/restock-flag.js.map +1 -0
- package/src/lib/server/reviews.d.ts +51 -0
- package/src/lib/server/reviews.js +132 -0
- package/src/lib/server/reviews.js.map +1 -0
- package/src/lib/server/site-page-enricher.d.ts +42 -0
- package/src/lib/server/site-page-enricher.js +149 -0
- package/src/lib/server/site-page-enricher.js.map +1 -0
- package/src/lib/server/site-page-resolver.d.ts +26 -0
- package/src/lib/server/site-page-resolver.js +223 -0
- package/src/lib/server/site-page-resolver.js.map +1 -0
- package/src/lib/server/stock-hold.d.ts +127 -0
- package/src/lib/server/stock-hold.js +258 -0
- package/src/lib/server/stock-hold.js.map +1 -0
- package/src/lib/server/storefront-tax-record.d.ts +22 -0
- package/src/lib/server/storefront-tax-record.js +218 -0
- package/src/lib/server/storefront-tax-record.js.map +1 -0
- package/src/lib/server/storefront-tax.d.ts +197 -0
- package/src/lib/server/storefront-tax.js +245 -0
- package/src/lib/server/storefront-tax.js.map +1 -0
- package/src/lib/server/stream.d.ts +25 -0
- package/src/lib/server/stream.js +191 -0
- package/src/lib/server/stream.js.map +1 -0
- package/src/lib/server/subscription-portal.d.ts +24 -0
- package/src/lib/server/subscription-portal.js +91 -0
- package/src/lib/server/subscription-portal.js.map +1 -0
- package/src/lib/server/supplier-outbox.d.ts +190 -0
- package/src/lib/server/supplier-outbox.js +342 -0
- package/src/lib/server/supplier-outbox.js.map +1 -0
- package/src/lib/server/supplier-update.d.ts +23 -0
- package/src/lib/server/supplier-update.js +289 -0
- package/src/lib/server/supplier-update.js.map +1 -0
- package/src/lib/server/tax-profile.d.ts +29 -0
- package/src/lib/server/tax-profile.js +40 -0
- package/src/lib/server/tax-profile.js.map +1 -0
- package/src/lib/server.d.ts +32 -0
- package/src/lib/server.js +311 -0
- package/src/lib/server.js.map +1 -0
- package/src/lib/site.d.ts +27 -0
- package/src/lib/site.js +134 -0
- package/src/lib/site.js.map +1 -0
- package/src/lib/utils/escape-html.d.ts +41 -0
- package/src/lib/utils/escape-html.js +41 -0
- package/src/lib/utils/escape-html.js.map +1 -0
- package/src/lib/utils/generate-preset-id.d.ts +19 -0
- package/src/lib/utils/generate-preset-id.js +25 -0
- package/src/lib/utils/generate-preset-id.js.map +1 -0
- package/src/lib/utils/member-continue.d.ts +45 -0
- package/src/lib/utils/member-continue.js +49 -0
- package/src/lib/utils/member-continue.js.map +1 -0
- package/src/lib/utils/use-storefront-purchase-event.d.ts +60 -0
- package/src/lib/utils/use-storefront-purchase-event.js +142 -0
- package/src/lib/utils/use-storefront-purchase-event.js.map +1 -0
|
@@ -0,0 +1,1040 @@
|
|
|
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 { ProductType } from './commerce';
|
|
18
|
+
import type { StorefrontTaxMode } from './commerce-tax-decision';
|
|
19
|
+
export type OrderStatus = 'pending' | 'paid' | 'partially_fulfilled' | 'fulfilled' | 'delivered' | 'cancelled' | 'refunded';
|
|
20
|
+
/**
|
|
21
|
+
* Where the sale came through. `subscription` is a recurring cycle of a
|
|
22
|
+
* PHYSICAL subscription product (AGL-1750): each paid invoice mints one order
|
|
23
|
+
* so fulfilment has something to pick, pack and label against, and so
|
|
24
|
+
* recurring revenue reaches the surfaces that read `orders`. Digital and
|
|
25
|
+
* service subscriptions still record on the subscription document alone —
|
|
26
|
+
* there is nothing to ship, and AGL-1732's "a subscription is not an order"
|
|
27
|
+
* stands for them.
|
|
28
|
+
*/
|
|
29
|
+
export type OrderChannel = 'online' | 'pos' | 'draft' | 'subscription';
|
|
30
|
+
/** Snapshot of what was bought — self-contained for history. */
|
|
31
|
+
export interface OrderLineItem {
|
|
32
|
+
productId: string;
|
|
33
|
+
variantId?: string;
|
|
34
|
+
/** Display snapshot at purchase time. */
|
|
35
|
+
name: string;
|
|
36
|
+
variantLabel?: string;
|
|
37
|
+
sku?: string;
|
|
38
|
+
productType?: ProductType;
|
|
39
|
+
quantity: number;
|
|
40
|
+
/** Per-unit price in cents at purchase time. */
|
|
41
|
+
unitAmountCents: number;
|
|
42
|
+
/** Supplier at purchase time (dropship routing, AGL-289). */
|
|
43
|
+
supplierId?: string;
|
|
44
|
+
/** Fulfillment id once this line ships (AGL-288). */
|
|
45
|
+
fulfillmentId?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface OrderTotals {
|
|
48
|
+
itemsCents: number;
|
|
49
|
+
shippingCents: number;
|
|
50
|
+
taxCents: number;
|
|
51
|
+
/** Positive number subtracted from the total. */
|
|
52
|
+
discountCents: number;
|
|
53
|
+
totalCents: number;
|
|
54
|
+
/** Aglyn platform fee (Connect application fee, AGL-278/307). */
|
|
55
|
+
feeCents: number;
|
|
56
|
+
}
|
|
57
|
+
export interface OrderAddress {
|
|
58
|
+
name?: string;
|
|
59
|
+
line1?: string;
|
|
60
|
+
line2?: string;
|
|
61
|
+
city?: string;
|
|
62
|
+
state?: string;
|
|
63
|
+
postalCode?: string;
|
|
64
|
+
country?: string;
|
|
65
|
+
phone?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface OrderTimelineEvent {
|
|
68
|
+
atMs: number;
|
|
69
|
+
/** Machine event key, e.g. 'paid', 'fulfilled', 'refund', 'note'. */
|
|
70
|
+
event: string;
|
|
71
|
+
/** Human-readable detail shown in the console timeline. */
|
|
72
|
+
detail?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface OrderFulfillment {
|
|
75
|
+
id: string;
|
|
76
|
+
lineItemIds: number[];
|
|
77
|
+
carrier?: string;
|
|
78
|
+
trackingNumber?: string;
|
|
79
|
+
trackingUrl?: string;
|
|
80
|
+
atMs: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A card dispute against this order's charge (AGL-1787).
|
|
84
|
+
*
|
|
85
|
+
* The DISTINCTION a chargeback carries, kept off `status` on purpose. A lost
|
|
86
|
+
* dispute leaves the order `refunded` — that is what every reader of the status
|
|
87
|
+
* already means by it, and five entitlement gates (`gate.ts`, `download.ts`,
|
|
88
|
+
* `reviews.ts`, `membership-account.ts` and the glance card) match on the
|
|
89
|
+
* literal `'refunded'`, so a new terminal status would have left the shopper
|
|
90
|
+
* their digital downloads and their verified-purchase review. That is AGL-1546
|
|
91
|
+
* reproduced on the tenant side, and the reason this record sits BESIDE the
|
|
92
|
+
* status rather than replacing it: the money question is answered by `status`
|
|
93
|
+
* and `refundedCents`, the "by what door" question by this.
|
|
94
|
+
*
|
|
95
|
+
* Written whole rather than merged into, so a second dispute on the same charge
|
|
96
|
+
* cannot inherit the previous one's `outcome` — see the handler.
|
|
97
|
+
*/
|
|
98
|
+
export interface OrderDispute {
|
|
99
|
+
/** Stripe dispute id (`dp_…`). */
|
|
100
|
+
id: string;
|
|
101
|
+
/** Stripe's dispute status verbatim, e.g. `needs_response`, `lost`. */
|
|
102
|
+
status: string;
|
|
103
|
+
/** Stripe's reason code, e.g. `fraudulent`, `product_not_received`. */
|
|
104
|
+
reason?: string;
|
|
105
|
+
/** Disputed cents — a partial dispute is less than the order total. */
|
|
106
|
+
amountCents: number;
|
|
107
|
+
openedAtMs: number;
|
|
108
|
+
/** Evidence deadline, when Stripe supplied one. */
|
|
109
|
+
evidenceDueByMs?: number;
|
|
110
|
+
closedAtMs?: number;
|
|
111
|
+
/** `won` | `lost` | `warning_closed`, set once the dispute closes. */
|
|
112
|
+
outcome?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Cents this dispute actually reversed on the order — a LOST dispute only,
|
|
115
|
+
* and capped against what was left, so it is not always `amountCents`.
|
|
116
|
+
*/
|
|
117
|
+
reversedCents?: number;
|
|
118
|
+
/**
|
|
119
|
+
* Stripe transfer-reversal id (`trr_…`) that pulled the seller's share back
|
|
120
|
+
* from the connected account (AGL-1794) — set only when a reversal was
|
|
121
|
+
* actually created or found already sitting on the transfer.
|
|
122
|
+
*/
|
|
123
|
+
transferReversalId?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Cents pulled back from the CONNECTED account for this lost dispute
|
|
126
|
+
* (AGL-1794). Its presence — 0 included — is the settle marker for the
|
|
127
|
+
* reversal step: 0 means the step ran and found nothing to reverse (no
|
|
128
|
+
* transfer on the charge, or a transfer with nothing left), recorded so a
|
|
129
|
+
* redelivery does not retry a failure no redelivery can fix.
|
|
130
|
+
*/
|
|
131
|
+
reversedTransferCents?: number;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* One line whose stock a reversal MAY need to put back (AGL-1797).
|
|
135
|
+
*
|
|
136
|
+
* Only lines the sale actually DECREMENTED appear here — an untracked variant
|
|
137
|
+
* (`inventory == null`) had nothing taken off it, so it has nothing to return,
|
|
138
|
+
* and a digital line is untracked for that same reason rather than by a
|
|
139
|
+
* type test of its own. A merchant who tracks license stock on a digital
|
|
140
|
+
* product does get it back.
|
|
141
|
+
*/
|
|
142
|
+
export interface OrderRestockLine {
|
|
143
|
+
productId: string;
|
|
144
|
+
variantId: string;
|
|
145
|
+
/**
|
|
146
|
+
* Units this line sold. It is the MOST that can come back, never a claim
|
|
147
|
+
* that they did: on a partial reversal the merchant reversed some of the
|
|
148
|
+
* money and only they know which goods returned.
|
|
149
|
+
*/
|
|
150
|
+
quantity: number;
|
|
151
|
+
/** Purchase-time snapshots, so a reader renders the prompt with no product read. */
|
|
152
|
+
name?: string;
|
|
153
|
+
variantLabel?: string;
|
|
154
|
+
/**
|
|
155
|
+
* Which `lineItems` entry this came from, matching `refundedLineItemIds`
|
|
156
|
+
* (AGL-2325).
|
|
157
|
+
*
|
|
158
|
+
* The index rather than the product, because a cart can hold one product on
|
|
159
|
+
* two lines and a line-scoped refund may name only one of them. It is what
|
|
160
|
+
* lets a SECOND partial refund be told apart from a repeat of the first: a
|
|
161
|
+
* reversal naming a line the open question already covers adds nothing, and
|
|
162
|
+
* one naming a line it misses is a new question rather than noise.
|
|
163
|
+
*
|
|
164
|
+
* Absent on a check written before this shipped, and that absence is read as
|
|
165
|
+
* "covers the whole order" — the assumption those checks were written under.
|
|
166
|
+
*/
|
|
167
|
+
lineIndex?: number;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Stock left off the shelf by a reversed order, FLAGGED rather than released
|
|
171
|
+
* (AGL-1797).
|
|
172
|
+
*
|
|
173
|
+
* The checkout webhook decrements variant inventory on a sale and nothing put
|
|
174
|
+
* it back, so a fully reversed order read one unit light forever and the error
|
|
175
|
+
* compounded with every return. The fix is not the obvious increment, because
|
|
176
|
+
* an increment is wrong more often than it is right:
|
|
177
|
+
*
|
|
178
|
+
* - a **returned** item genuinely comes back, and stock should rise — but only
|
|
179
|
+
* once it is RECEIVED, and there is no fulfilment event that records receipt
|
|
180
|
+
* (`OrderFulfillment` has no returned state);
|
|
181
|
+
* - a **refund with no return** — goodwill, damaged, lost in post — leaves the
|
|
182
|
+
* goods gone, so incrementing invents stock the merchant does not have and
|
|
183
|
+
* sells something that is not on the shelf. That is worse than the bug it
|
|
184
|
+
* replaces: under-counting refuses a sale, over-counting takes one it cannot
|
|
185
|
+
* fill;
|
|
186
|
+
* - a **chargeback** is the clearest do-not-restock case of all, since the
|
|
187
|
+
* shopper kept the item and took the money back.
|
|
188
|
+
*
|
|
189
|
+
* And the quantities are not always knowable on a partial reversal: a refund
|
|
190
|
+
* requested as an AMOUNT names no line at all, so "$17 of a $62 order" selects
|
|
191
|
+
* nothing. `quantity` is an upper bound there and `fullyReversed` says whether
|
|
192
|
+
* it is a tight one.
|
|
193
|
+
*
|
|
194
|
+
* A refund that DID name its lines is scoped to them (AGL-2325). `refund.ts`
|
|
195
|
+
* records `refundedLineItemIds` with the money (AGL-2454), so the flag asks
|
|
196
|
+
* about the lines that reversal withdrew rather than about the whole order —
|
|
197
|
+
* and `lineIndex` on each line is what lets a second partial withdrawing a
|
|
198
|
+
* DIFFERENT line re-ask, instead of being swallowed by the still-open question
|
|
199
|
+
* about the first.
|
|
200
|
+
*
|
|
201
|
+
* So this records the question instead of guessing the answer, and the merchant
|
|
202
|
+
* answers it from the stock adjustment they already have. The release action is
|
|
203
|
+
* NOT rebuilt here: the products hub's "Adjust stock" already writes the
|
|
204
|
+
* variant counts and an `InventoryAdjustment` row with a reason.
|
|
205
|
+
*/
|
|
206
|
+
export interface OrderRestockCheck {
|
|
207
|
+
/** Which door the money left by; the two deserve different default wording. */
|
|
208
|
+
kind: 'refund' | 'chargeback';
|
|
209
|
+
/** Inventory-tracked lines only — exactly what the sale decremented. */
|
|
210
|
+
lines: OrderRestockLine[];
|
|
211
|
+
/** Sum of `lines[].quantity`, denormalized so a badge needs no arithmetic. */
|
|
212
|
+
units: number;
|
|
213
|
+
/**
|
|
214
|
+
* False when only part of the money came back, which is what makes
|
|
215
|
+
* `quantity` an upper bound rather than a proposal.
|
|
216
|
+
*/
|
|
217
|
+
fullyReversed: boolean;
|
|
218
|
+
flaggedAtMs: number;
|
|
219
|
+
/**
|
|
220
|
+
* Set once a merchant answers. Absent means the question is still open, and
|
|
221
|
+
* it is the only state a fresh reversal will overwrite.
|
|
222
|
+
*/
|
|
223
|
+
resolution?: 'restocked' | 'dismissed';
|
|
224
|
+
resolvedAtMs?: number;
|
|
225
|
+
/** Console uid that answered. */
|
|
226
|
+
resolvedBy?: string;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* A cart line a paid order could not record (AGL-2149). All that survives a
|
|
230
|
+
* deleted product is what the shopper's cart asked for.
|
|
231
|
+
*/
|
|
232
|
+
export interface OrderUnresolvedLine {
|
|
233
|
+
productId: string;
|
|
234
|
+
variantId?: string;
|
|
235
|
+
quantity: number;
|
|
236
|
+
}
|
|
237
|
+
/** `hosts/{hostId}/orders/{id}` doc. */
|
|
238
|
+
export interface HostOrder {
|
|
239
|
+
/** Human order number, sequential per host (e.g. #1042). */
|
|
240
|
+
number?: number;
|
|
241
|
+
status: OrderStatus;
|
|
242
|
+
channel?: OrderChannel;
|
|
243
|
+
/**
|
|
244
|
+
* Which location's stock this sale came off, for the multi-location counts
|
|
245
|
+
* of AGL-286. Written by the POS register, the only sale path that decrements
|
|
246
|
+
* a location bucket rather than the flat count — and read back when the order
|
|
247
|
+
* is cancelled (AGL-1808), because putting the units on the flat total when
|
|
248
|
+
* the sale took them out of a bucket leaves the two disagreeing, and the next
|
|
249
|
+
* location-aware write recomputes the total from the buckets and silently
|
|
250
|
+
* erases the restock.
|
|
251
|
+
*/
|
|
252
|
+
locationId?: string;
|
|
253
|
+
/**
|
|
254
|
+
* The register discount that was applied, and the member who applied it
|
|
255
|
+
* (AGL-2161). Present only on a POS order that carries a discount.
|
|
256
|
+
*
|
|
257
|
+
* `totals.discountCents` records that money came off; these record who
|
|
258
|
+
* decided it should. Without them a full comp read exactly like a
|
|
259
|
+
* correctly-priced sale after the fact, on the one channel where a person is
|
|
260
|
+
* standing in front of the goods and can ring whatever they like. The
|
|
261
|
+
* ceiling that bounds `discountPct` is the org's `posMaxDiscountPct` plugin
|
|
262
|
+
* setting, enforced server-side in `pos-order.ts`.
|
|
263
|
+
*/
|
|
264
|
+
discountPct?: number;
|
|
265
|
+
discountBy?: string;
|
|
266
|
+
lineItems?: OrderLineItem[];
|
|
267
|
+
totals?: OrderTotals;
|
|
268
|
+
/**
|
|
269
|
+
* WHICH TAX REGIME this order carried (AGL-2451), resolved at the moment the
|
|
270
|
+
* sale decided it and stamped here rather than re-derived later.
|
|
271
|
+
*
|
|
272
|
+
* `totals.taxCents` says how much tax was charged and nothing about who
|
|
273
|
+
* computed it. Those are different facts about whose registration the money
|
|
274
|
+
* is held under: a `stripe-automatic` storefront sale's tax is computed
|
|
275
|
+
* against AGLYN's registrations and settles into Aglyn's balance (MEASURED —
|
|
276
|
+
* see `server/storefront-tax.ts`), while a `manual` one is the merchant's own
|
|
277
|
+
* rate on their own origin. An order that cannot say which one it carried
|
|
278
|
+
* cannot be reconciled against the return, or corrected afterwards.
|
|
279
|
+
*
|
|
280
|
+
* AGL-2440's merchant report reads the authoritative
|
|
281
|
+
* `storefrontTaxCollected` record; this is the same fact on the single order,
|
|
282
|
+
* and both come from `storefrontTaxMode` so the two cannot drift.
|
|
283
|
+
*
|
|
284
|
+
* ## ABSENT MEANS "NOT RECORDED" — AND NOTHING MAY DEFAULT IT
|
|
285
|
+
*
|
|
286
|
+
* Every order written before AGL-2451 shipped genuinely has no stamp, and
|
|
287
|
+
* that is the honest reading. `liftLegacyOrder` deliberately does NOT
|
|
288
|
+
* synthesise one the way it synthesises `totals.taxCents: 0`: it runs on the
|
|
289
|
+
* READ path, its result is spread into merge writes, and a defaulted `none`
|
|
290
|
+
* would overwrite a real `stripe-automatic` — the converter-on-partial-writes
|
|
291
|
+
* hazard, in a place where the destroyed value is a tax fact. The console
|
|
292
|
+
* renders an absent mode as unknown, never as `none`
|
|
293
|
+
* (`describeOrderTaxMode`).
|
|
294
|
+
*/
|
|
295
|
+
taxMode?: StorefrontTaxMode;
|
|
296
|
+
customerEmail?: string | null;
|
|
297
|
+
customerName?: string | null;
|
|
298
|
+
/** Storefront customer id once accounts exist (AGL-294). */
|
|
299
|
+
customerId?: string;
|
|
300
|
+
shippingAddress?: OrderAddress;
|
|
301
|
+
billingAddress?: OrderAddress;
|
|
302
|
+
timeline?: OrderTimelineEvent[];
|
|
303
|
+
fulfillments?: OrderFulfillment[];
|
|
304
|
+
note?: string;
|
|
305
|
+
couponCode?: string;
|
|
306
|
+
/** Stripe references for refunds. */
|
|
307
|
+
paymentIntentId?: string;
|
|
308
|
+
checkoutSessionId?: string;
|
|
309
|
+
/**
|
|
310
|
+
* The recurring cycle this order fulfils (channel `subscription`,
|
|
311
|
+
* AGL-1750). The order's own doc id is the invoice id — that identity is
|
|
312
|
+
* the redelivery key — and these carry the join back to
|
|
313
|
+
* `subscriptions/{subscriptionId}/invoices/{invoiceId}`.
|
|
314
|
+
*/
|
|
315
|
+
subscriptionId?: string;
|
|
316
|
+
invoiceId?: string;
|
|
317
|
+
/** Draft orders (AGL-287): the link sent to the buyer. */
|
|
318
|
+
paymentLinkUrl?: string;
|
|
319
|
+
refundedCents?: number;
|
|
320
|
+
/**
|
|
321
|
+
* Line indexes an admin refunded BY NAME (AGL-2454), and therefore the lines
|
|
322
|
+
* whose digital entitlements are withdrawn.
|
|
323
|
+
*
|
|
324
|
+
* A refund carries an AMOUNT, not lines — `refund.ts` takes `amountCents`
|
|
325
|
+
* and Stripe knows nothing about what was in the basket — so a partial refund
|
|
326
|
+
* cannot in general be attributed to anything. That is why five entitlement
|
|
327
|
+
* gates matched the literal `'refunded'` on `status` and a 99%-refunded order
|
|
328
|
+
* kept every download, licence key, gated page and verified review.
|
|
329
|
+
*
|
|
330
|
+
* This is the case where attribution IS possible: the console refund dialog
|
|
331
|
+
* lets an admin pick the lines they are refunding, and when it does the
|
|
332
|
+
* amount is computed FROM those lines rather than typed beside them. An
|
|
333
|
+
* amount-only refund still revokes nothing per-line — deciding for the
|
|
334
|
+
* merchant which lines a bare figure covers would be a guess about their
|
|
335
|
+
* goods — but it is no longer silent: `orderRefundState` reports it, the
|
|
336
|
+
* console shows it, and the order timeline records it.
|
|
337
|
+
*
|
|
338
|
+
* Indexes rather than product ids, because a cart can hold two lines of the
|
|
339
|
+
* same product (different variants) and only one may be coming back.
|
|
340
|
+
*/
|
|
341
|
+
refundedLineItemIds?: number[];
|
|
342
|
+
/** The card dispute against this charge, open or settled (AGL-1787). */
|
|
343
|
+
dispute?: OrderDispute;
|
|
344
|
+
/** Stock a reversal left off the shelf, awaiting the merchant (AGL-1797). */
|
|
345
|
+
restockCheck?: OrderRestockCheck;
|
|
346
|
+
/**
|
|
347
|
+
* Cart lines the webhook could not price because the product was deleted
|
|
348
|
+
* between session creation and payment (AGL-2149). Present ONLY on an order
|
|
349
|
+
* that is short of what the shopper was charged: `totals.itemsCents` is
|
|
350
|
+
* missing these lines while `amountCents` still holds the full
|
|
351
|
+
* `amount_total`, and this is the record of which lines the difference is.
|
|
352
|
+
*
|
|
353
|
+
* Deliberately NOT an `OrderLineItem[]`: the product doc is gone, so there is
|
|
354
|
+
* no name, no price and no type to record — only what the cart asked for.
|
|
355
|
+
*/
|
|
356
|
+
unresolvedLines?: OrderUnresolvedLine[];
|
|
357
|
+
createdAtMs?: number;
|
|
358
|
+
productId?: string;
|
|
359
|
+
amountCents?: number;
|
|
360
|
+
feeCents?: number;
|
|
361
|
+
}
|
|
362
|
+
export declare function canTransitionOrder(from: OrderStatus, to: OrderStatus): boolean;
|
|
363
|
+
/**
|
|
364
|
+
* Split `totalCents` across `weights` so the parts sum to it EXACTLY.
|
|
365
|
+
*
|
|
366
|
+
* Largest-remainder (Hamilton) apportionment. Each weight takes its exact
|
|
367
|
+
* share, the shares are floored, and the cents left over by flooring are handed
|
|
368
|
+
* one each to the largest fractional parts, ties going to the lower index so
|
|
369
|
+
* the answer is deterministic for a given input.
|
|
370
|
+
*
|
|
371
|
+
* The exactness is the whole point and it is a money property, not a
|
|
372
|
+
* neatness one: `Math.round` per line loses or invents cents against the total
|
|
373
|
+
* — three lines splitting a 10¢ discount round to 3+3+3=9 and the missing cent
|
|
374
|
+
* has to come from somewhere. A refund built on a split that does not close is
|
|
375
|
+
* a reconciliation defect that surfaces months later against Stripe's numbers.
|
|
376
|
+
*
|
|
377
|
+
* Pure and total. A non-positive total, an empty weight list, or weights that
|
|
378
|
+
* sum to nothing all answer zeros — never a division by zero, never a NaN
|
|
379
|
+
* propagated into an amount someone is charged.
|
|
380
|
+
*/
|
|
381
|
+
export declare function apportionCents(weights: readonly number[], totalCents: number): number[];
|
|
382
|
+
/**
|
|
383
|
+
* What refunding the named lines is actually worth.
|
|
384
|
+
*
|
|
385
|
+
* A line's LIST value is `unitAmountCents x quantity`, and that is what the
|
|
386
|
+
* refund route used to hand back. It is the wrong number on any order that
|
|
387
|
+
* carried an order-level discount, because the buyer never paid it: a $10
|
|
388
|
+
* coupon on two $50 lines means each line cost $45, and refunding one at $50
|
|
389
|
+
* pays back $5 the buyer never spent. The order then has less left than its
|
|
390
|
+
* remaining line is worth, so the SECOND line refund is refused outright and
|
|
391
|
+
* the merchant cannot finish the job they started.
|
|
392
|
+
*
|
|
393
|
+
* So each line carries its share of the discount, apportioned by list value
|
|
394
|
+
* through {@link apportionCents} — which guarantees the shares sum to the whole
|
|
395
|
+
* discount, so refunding every line returns exactly `itemsCents - discountCents`
|
|
396
|
+
* and no cent is stranded or invented.
|
|
397
|
+
*
|
|
398
|
+
* SHIPPING AND TAX ARE DELIBERATELY NOT IN THIS FIGURE. Refunding a line
|
|
399
|
+
* returns what the goods cost. Shipping is charged for the consignment rather
|
|
400
|
+
* than the line, so no split of it is defensible without knowing whether the
|
|
401
|
+
* parcel still ships; tax follows the goods but is Stripe's to recompute, and
|
|
402
|
+
* an order whose tax was collected under Aglyn's own registration
|
|
403
|
+
* (`taxMode: 'stripe-automatic'`) is not one this function may quietly decide
|
|
404
|
+
* to hand back. Both remain whole-order concerns, refundable by amount.
|
|
405
|
+
*
|
|
406
|
+
* Pure: unknown indexes contribute nothing rather than throwing.
|
|
407
|
+
*/
|
|
408
|
+
export declare function orderLineRefundCents(order: Pick<Partial<HostOrder>, 'lineItems' | 'totals'>, lineIndexes: readonly number[]): number;
|
|
409
|
+
/**
|
|
410
|
+
* A REHEARSAL IS NOT REVENUE.
|
|
411
|
+
*
|
|
412
|
+
* A smoke-test checkout writes a real order document. Stripe never moved money
|
|
413
|
+
* for it — the session id is `cs_test_…` — but every surface that sums paid
|
|
414
|
+
* orders counted it, so a storefront with one test order and no sales reported
|
|
415
|
+
* revenue it had never earned. Found in production: a single $18.00 order from
|
|
416
|
+
* an end-to-end run, standing as the whole platform's storefront revenue.
|
|
417
|
+
*
|
|
418
|
+
* ## Two signals, in order of trust
|
|
419
|
+
*
|
|
420
|
+
* `livemode` is a RECORDED FACT and wins whenever it is present: the webhook
|
|
421
|
+
* knows which Stripe environment an event came from and now writes it onto the
|
|
422
|
+
* order. Only a literal boolean counts, the same three-valued reading every
|
|
423
|
+
* other money gate in this codebase uses.
|
|
424
|
+
*
|
|
425
|
+
* The session id prefix is the FALLBACK, for the orders written before
|
|
426
|
+
* anything recorded the fact. It is Stripe's convention rather than our data,
|
|
427
|
+
* so it lives behind `stripeIdIsTestMode` and is not spelled out here.
|
|
428
|
+
*
|
|
429
|
+
* ## An unknowable order is LIVE
|
|
430
|
+
*
|
|
431
|
+
* An order with no `livemode` and no Stripe session id — a POS cash sale, a
|
|
432
|
+
* folio charge, a draft order paid offline — is real money and is counted.
|
|
433
|
+
* Answering "test" for anything we cannot identify would zero genuine sales,
|
|
434
|
+
* which is the one direction this must never fail in: a merchant under-reporting
|
|
435
|
+
* their own revenue has no way to tell it is happening.
|
|
436
|
+
*/
|
|
437
|
+
export declare function orderIsTestMode(order: Pick<Partial<HostOrder>, 'checkoutSessionId'> & {
|
|
438
|
+
livemode?: unknown;
|
|
439
|
+
/** The Firestore doc id, which for a storefront order IS the session id. */
|
|
440
|
+
$id?: unknown;
|
|
441
|
+
}): boolean;
|
|
442
|
+
/** Sums line items and folds in shipping/tax/discount/fee, all cents. */
|
|
443
|
+
export declare function computeOrderTotals(lineItems: OrderLineItem[], parts?: Partial<Pick<OrderTotals, 'shippingCents' | 'taxCents' | 'discountCents' | 'feeCents'>>): OrderTotals;
|
|
444
|
+
/**
|
|
445
|
+
* The completed Checkout Session fields an online order's totals are built
|
|
446
|
+
* from. Typed structurally rather than against Stripe's SDK: the plugin talks
|
|
447
|
+
* to Stripe over raw `fetch` and never installs the package.
|
|
448
|
+
*/
|
|
449
|
+
export interface CheckoutSessionTotalsSource {
|
|
450
|
+
amount_total?: unknown;
|
|
451
|
+
total_details?: {
|
|
452
|
+
amount_tax?: unknown;
|
|
453
|
+
amount_shipping?: unknown;
|
|
454
|
+
amount_discount?: unknown;
|
|
455
|
+
} | null;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Stored `OrderTotals` for an `online` order, from the completed session.
|
|
459
|
+
*
|
|
460
|
+
* AGL-1698: the webhook used to read `amount_tax` and `amount_discount` and
|
|
461
|
+
* silently skip their third sibling, so `computeOrderTotals` defaulted
|
|
462
|
+
* `shippingCents` to 0 on every online order while the shipping the shopper
|
|
463
|
+
* paid sat inside `amount_total`. The stored parts then did not sum to the
|
|
464
|
+
* stored total, and every merchant reconciling their own books against these
|
|
465
|
+
* records understated shipping by exactly the amount charged. `amount_shipping`
|
|
466
|
+
* is the figure to read — `shipping_cost.amount_total` carries the same number
|
|
467
|
+
* but is null unless a rate was chosen, whereas `total_details.amount_shipping`
|
|
468
|
+
* is always present and sits beside the two fields already read.
|
|
469
|
+
*
|
|
470
|
+
* `totalCents` still comes from Stripe's `amount_total` verbatim rather than
|
|
471
|
+
* from our arithmetic: `itemsCents` is priced from the host's product docs, so
|
|
472
|
+
* a price edit between session creation and webhook delivery would otherwise
|
|
473
|
+
* make our sum, not Stripe's charge, the stored truth. With shipping passed the
|
|
474
|
+
* two agree by construction — which is now an invariant a fixture can pin
|
|
475
|
+
* rather than a discrepancy that papers over a missing part.
|
|
476
|
+
*
|
|
477
|
+
* Note this also unclamps the discount correctly: `computeOrderTotals` caps
|
|
478
|
+
* `discountCents` at `itemsCents + shippingCents`, so a discount that reached
|
|
479
|
+
* into shipping was previously clamped down as well.
|
|
480
|
+
*/
|
|
481
|
+
export interface CheckoutSessionTotalsParts {
|
|
482
|
+
/** Aglyn's cut, from the session metadata rather than from Stripe. */
|
|
483
|
+
feeCents?: number;
|
|
484
|
+
/**
|
|
485
|
+
* Tax we charged as an ordinary Stripe line item (AGL-1711). It is inside
|
|
486
|
+
* `amount_total` but Stripe was never told it was tax, so it is absent from
|
|
487
|
+
* `total_details.amount_tax` and has to be supplied by the caller that built
|
|
488
|
+
* the session. Added to Stripe's figure, not substituted for it: the two are
|
|
489
|
+
* mutually exclusive by construction — `checkout.ts` adds the manual line
|
|
490
|
+
* only in `manual` tax mode and sets `automatic_tax` only in `stripe` mode —
|
|
491
|
+
* so summing is right in every reachable case and correct in principle if
|
|
492
|
+
* both were ever charged at once.
|
|
493
|
+
*
|
|
494
|
+
* A manual-tax SUBSCRIPTION session is the third construction (AGL-1751):
|
|
495
|
+
* there the tax is a real Stripe Tax Rate (a one-time line would bill on
|
|
496
|
+
* the first invoice only), `amount_tax` carries it, and `checkout.ts`
|
|
497
|
+
* writes `metadata[taxCents]` as 0 — the exclusivity this sum rests on,
|
|
498
|
+
* kept from the other side.
|
|
499
|
+
*/
|
|
500
|
+
lineItemTaxCents?: number;
|
|
501
|
+
/**
|
|
502
|
+
* A discount applied by lowering the unit price we sent to Stripe rather
|
|
503
|
+
* than as a Stripe discount (AGL-1711). Same shape as `lineItemTaxCents`:
|
|
504
|
+
* invisible to `total_details.amount_discount`, so it is added to it.
|
|
505
|
+
*/
|
|
506
|
+
pricedInDiscountCents?: number;
|
|
507
|
+
}
|
|
508
|
+
export declare function computeCheckoutSessionTotals(lineItems: OrderLineItem[], session: CheckoutSessionTotalsSource | null | undefined, parts?: CheckoutSessionTotalsParts): OrderTotals;
|
|
509
|
+
/** The buy-now Checkout Session as the webhook sees it — metadata included. */
|
|
510
|
+
export interface BuyNowSessionSource extends CheckoutSessionTotalsSource {
|
|
511
|
+
metadata?: Record<string, unknown> | null;
|
|
512
|
+
}
|
|
513
|
+
/** What the host's product doc contributes to the line-item snapshot. */
|
|
514
|
+
export interface BuyNowProductSnapshot {
|
|
515
|
+
/** Product name at purchase time. */
|
|
516
|
+
name: string;
|
|
517
|
+
/** Joined variant options, e.g. `Large / Blue`. */
|
|
518
|
+
variantLabel?: string;
|
|
519
|
+
sku?: string;
|
|
520
|
+
productType?: ProductType;
|
|
521
|
+
supplierId?: string;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* The stored line items and totals for a `commerce-order` (buy-now) session
|
|
525
|
+
* (AGL-1711).
|
|
526
|
+
*
|
|
527
|
+
* ## What was wrong
|
|
528
|
+
*
|
|
529
|
+
* The webhook built the whole order from one number — it read
|
|
530
|
+
* `object.amount_total` into `amountCents`, wrote a single line item with
|
|
531
|
+
* `quantity` literal 1 and `unitAmountCents` set to that `amountCents`, and
|
|
532
|
+
* passed `computeOrderTotals` nothing but `feeCents`.
|
|
533
|
+
*
|
|
534
|
+
* `amount_total` is the ENTIRE charge, so the merchant's record said the
|
|
535
|
+
* product's unit price was the whole session total, that one unit was sold, and
|
|
536
|
+
* that tax and discount were zero. A 3 × $100 purchase recorded as 1 × $300.
|
|
537
|
+
*
|
|
538
|
+
* The dangerous property, and why this outlived AGL-1698: it is not internally
|
|
539
|
+
* inconsistent. `itemsCents` equalled `totalCents`, so the parts summed and any
|
|
540
|
+
* arithmetic check passed while every individual component was wrong. The
|
|
541
|
+
* useful test is not "do the parts sum" but "does each part match what Stripe
|
|
542
|
+
* actually charged", which is what the fixtures assert component by component.
|
|
543
|
+
*
|
|
544
|
+
* ## Why metadata, when AGL-1698's lesson was to read Stripe's own fields
|
|
545
|
+
*
|
|
546
|
+
* Two of the four parts are genuinely absent from Stripe's decomposition, and
|
|
547
|
+
* `checkout.ts` is what hid them:
|
|
548
|
+
*
|
|
549
|
+
* - **Tax.** In `manual` mode the tax is appended as `line_items[1]`, a normal
|
|
550
|
+
* product line labelled e.g. "Tax (8.25%)". Stripe does not know it is tax,
|
|
551
|
+
* so `total_details.amount_tax` is 0 while the money sits in `amount_total`.
|
|
552
|
+
* (In `stripe` mode `automatic_tax` makes `amount_tax` real — and it was not
|
|
553
|
+
* read either, so that tax was lost as well.)
|
|
554
|
+
* - **Discount.** A host coupon is applied by lowering the unit price we send,
|
|
555
|
+
* not as a Stripe discount, so `total_details.amount_discount` is 0.
|
|
556
|
+
*
|
|
557
|
+
* So `checkout.ts` now records both figures, plus the list unit price, in the
|
|
558
|
+
* session metadata as it computes them. This is NOT the reconstruction AGL-1698
|
|
559
|
+
* warned against: the guard there is against pricing from the host's product
|
|
560
|
+
* docs at webhook time, where an edit between session creation and delivery
|
|
561
|
+
* makes our sum disagree with the actual charge. Metadata is a snapshot of the
|
|
562
|
+
* numbers we handed Stripe, frozen at session creation, so it cannot drift.
|
|
563
|
+
* Everything Stripe does know — `amount_total`, `amount_tax`, `amount_shipping`,
|
|
564
|
+
* `amount_discount` — still comes from Stripe, via the shared
|
|
565
|
+
* `computeCheckoutSessionTotals` rather than a parallel decomposition.
|
|
566
|
+
*
|
|
567
|
+
* Shipping is read even though `checkout.ts` declares no `shipping_options`
|
|
568
|
+
* today (AGL-1720): the read is not conditioned on that, so the figure lands on
|
|
569
|
+
* its own the moment buy-now starts charging shipping.
|
|
570
|
+
*
|
|
571
|
+
* ## Sessions created before this change
|
|
572
|
+
*
|
|
573
|
+
* They carry `quantity` (always sent) but none of the three new keys, so the
|
|
574
|
+
* unit price falls back to what Stripe charged per unit, derived from
|
|
575
|
+
* `amount_total` with tax, shipping and discount taken back out. Those orders
|
|
576
|
+
* still reconcile against `amount_total` and their quantity is now right; what
|
|
577
|
+
* cannot be recovered is a priced-in coupon, which stays folded into the unit
|
|
578
|
+
* price exactly as it is today. Deriving from the product doc instead would
|
|
579
|
+
* make `itemsCents` gross with no matching `discountCents`, breaking the sum.
|
|
580
|
+
*
|
|
581
|
+
* ## Worked example — the spec fixture
|
|
582
|
+
*
|
|
583
|
+
* Three $100 units, a 10% host coupon, manual destination tax at 8.25%:
|
|
584
|
+
*
|
|
585
|
+
* listUnit 10000 metadata `unitAmountCents`
|
|
586
|
+
* × quantity 3 metadata `quantity`
|
|
587
|
+
* = itemsCents 30000
|
|
588
|
+
* - discountCents 3000 metadata `discountCents` (priced into the
|
|
589
|
+
* 9000 unit price sent to Stripe)
|
|
590
|
+
* + taxCents 2228 metadata `taxCents` (Stripe `line_items[1]`;
|
|
591
|
+
* `total_details.amount_tax` is 0)
|
|
592
|
+
* + shippingCents 0 Stripe `total_details.amount_shipping`
|
|
593
|
+
* = totalCents 29228 Stripe `amount_total`, verbatim
|
|
594
|
+
*
|
|
595
|
+
* The pre-fix record for the same purchase: `1 × 29228`, tax 0, discount 0 —
|
|
596
|
+
* which also sums to 29228.
|
|
597
|
+
*
|
|
598
|
+
* ## Also the subscription sale record (AGL-1732)
|
|
599
|
+
*
|
|
600
|
+
* `checkout.ts` builds a subscription session with the same function and the
|
|
601
|
+
* same metadata snapshot — only `mode` differs — so the initial charge of a
|
|
602
|
+
* storefront subscription decomposes identically. The webhook's
|
|
603
|
+
* `commerce-subscription` branch stores the result on the subscription
|
|
604
|
+
* document rather than as an order; the arithmetic is the same either way,
|
|
605
|
+
* which is why it lives here and is not duplicated there.
|
|
606
|
+
*/
|
|
607
|
+
export declare function computeBuyNowOrder(session: BuyNowSessionSource | null | undefined, snapshot: BuyNowProductSnapshot): {
|
|
608
|
+
lineItems: OrderLineItem[];
|
|
609
|
+
totals: OrderTotals;
|
|
610
|
+
};
|
|
611
|
+
/** One line on a Stripe invoice, structurally typed like the session above. */
|
|
612
|
+
export interface SubscriptionInvoiceLine {
|
|
613
|
+
/** The line total in cents, after any line-level discount, excluding tax. */
|
|
614
|
+
amount?: unknown;
|
|
615
|
+
quantity?: unknown;
|
|
616
|
+
description?: unknown;
|
|
617
|
+
/** True on the credit/charge pair a mid-cycle plan switch generates. */
|
|
618
|
+
proration?: unknown;
|
|
619
|
+
price?: {
|
|
620
|
+
unit_amount?: unknown;
|
|
621
|
+
recurring?: {
|
|
622
|
+
interval?: unknown;
|
|
623
|
+
} | null;
|
|
624
|
+
} | null;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* The paid-invoice fields a renewal's totals are built from (AGL-1743).
|
|
628
|
+
*
|
|
629
|
+
* ## An invoice is not a Checkout Session
|
|
630
|
+
*
|
|
631
|
+
* This was checked field by field rather than assumed, and the two objects
|
|
632
|
+
* agree on almost nothing:
|
|
633
|
+
*
|
|
634
|
+
* - **There is no `total_details` on an invoice at all.** That object is a
|
|
635
|
+
* Checkout Session field. `computeCheckoutSessionTotals` cannot be handed an
|
|
636
|
+
* invoice — every part would read 0 and the whole renewal would decompose to
|
|
637
|
+
* `amount_total` with nothing in it, which is exactly the AGL-1711 failure
|
|
638
|
+
* shape (internally consistent, individually wrong).
|
|
639
|
+
* - **Tax** is `tax` (a scalar) on the API versions this repo pins, and
|
|
640
|
+
* `total_taxes[]` on newer ones, where the scalar was removed. Both are read,
|
|
641
|
+
* the scalar preferred, because a webhook endpoint's version is dashboard
|
|
642
|
+
* configuration this repo cannot see.
|
|
643
|
+
* - **Discount** is `total_discount_amounts[]`, an array of per-discount
|
|
644
|
+
* amounts, not a single `amount_discount`.
|
|
645
|
+
* - **Shipping** is `shipping_cost.amount_total` — note AGL-1698 preferred
|
|
646
|
+
* `total_details.amount_shipping` over exactly this field ON A SESSION,
|
|
647
|
+
* because there it is null unless a rate was chosen. On an invoice it is the
|
|
648
|
+
* only form there is.
|
|
649
|
+
* - **The fee** is a real field here: a subscription carries
|
|
650
|
+
* `application_fee_percent`, so every invoice reports the resulting
|
|
651
|
+
* `application_fee_amount`. The session path has to read it out of metadata.
|
|
652
|
+
* - **What was bought** is `lines.data[]` rather than the session's metadata
|
|
653
|
+
* snapshot — `checkout.ts` puts only `type`, `hostId` and `productId` on
|
|
654
|
+
* `subscription_data[metadata]`, so the quantity and unit price of a renewal
|
|
655
|
+
* have to come from the invoice itself.
|
|
656
|
+
*
|
|
657
|
+
* The arithmetic is still the shared one: the fields above are mapped onto the
|
|
658
|
+
* session shape and handed to `computeCheckoutSessionTotals`, so a renewal and
|
|
659
|
+
* a sale clamp, sum and reconcile identically.
|
|
660
|
+
*/
|
|
661
|
+
export interface SubscriptionInvoiceSource {
|
|
662
|
+
/** What actually arrived — the figure this records as collected. */
|
|
663
|
+
amount_paid?: unknown;
|
|
664
|
+
total?: unknown;
|
|
665
|
+
subtotal?: unknown;
|
|
666
|
+
/** Total tax; removed in favor of `total_taxes` on newer API versions. */
|
|
667
|
+
tax?: unknown;
|
|
668
|
+
total_taxes?: readonly {
|
|
669
|
+
amount?: unknown;
|
|
670
|
+
}[] | null;
|
|
671
|
+
total_tax_amounts?: readonly {
|
|
672
|
+
amount?: unknown;
|
|
673
|
+
}[] | null;
|
|
674
|
+
total_discount_amounts?: readonly {
|
|
675
|
+
amount?: unknown;
|
|
676
|
+
}[] | null;
|
|
677
|
+
shipping_cost?: {
|
|
678
|
+
amount_total?: unknown;
|
|
679
|
+
} | null;
|
|
680
|
+
application_fee_amount?: unknown;
|
|
681
|
+
/** Why Stripe raised it: `subscription_cycle`, `subscription_update`, … */
|
|
682
|
+
billing_reason?: unknown;
|
|
683
|
+
lines?: {
|
|
684
|
+
data?: readonly SubscriptionInvoiceLine[] | null;
|
|
685
|
+
} | null;
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* The base a subscription invoice's platform fee SHOULD be taken on
|
|
689
|
+
* (AGL-2317): post-discount items, with tax and shipping removed.
|
|
690
|
+
*
|
|
691
|
+
* Every one-time door — `checkout.ts`, `cart-checkout.ts`, `draft-order.ts`,
|
|
692
|
+
* `pos-order.ts` and (since AGL-2315) bookings — sends a cents amount computed
|
|
693
|
+
* on items alone. The recurring door sent `application_fee_percent`, which
|
|
694
|
+
* Stripe applies to the WHOLE invoice, so Aglyn took a cut of sales tax — money
|
|
695
|
+
* that is the state's — and of shipping. On the issue's worked example ($30/mo
|
|
696
|
+
* digital, Business 2%, an 8.25% TX rate) the one-time base is $30.00 → 60¢ and
|
|
697
|
+
* the invoice total is $32.48 → 65¢.
|
|
698
|
+
*
|
|
699
|
+
* `total` and not a re-summed `lines.data[]`, deliberately. Stripe's own total
|
|
700
|
+
* is already net of every invoice-level discount and of any proration CREDIT,
|
|
701
|
+
* both of which `computeSubscriptionInvoiceOrder` drops (it floors a line at 0,
|
|
702
|
+
* which is right for a stored line item and wrong for a fee base — a mid-cycle
|
|
703
|
+
* downgrade credit reduces what the merchant is actually paid). Subtracting the
|
|
704
|
+
* two parts Stripe reports separately leaves exactly what was charged for goods.
|
|
705
|
+
*
|
|
706
|
+
* Tax is read on both spellings for the reason stated on `SubscriptionInvoiceSource`
|
|
707
|
+
* — the scalar was removed on newer API versions and the endpoint's version is
|
|
708
|
+
* dashboard configuration this repo cannot see. Reading only one of them would
|
|
709
|
+
* silently value tax at 0 and hand back the whole invoice total as the base,
|
|
710
|
+
* which is the very bug this closes.
|
|
711
|
+
*/
|
|
712
|
+
export declare function subscriptionInvoiceFeeBasisCents(invoice: SubscriptionInvoiceSource | null | undefined): number;
|
|
713
|
+
/**
|
|
714
|
+
* What the platform fee on a paid subscription invoice WOULD have been on the
|
|
715
|
+
* items-only base, at the rate Stripe actually applied (AGL-2317).
|
|
716
|
+
*
|
|
717
|
+
* ## The rate is never named here, on purpose
|
|
718
|
+
*
|
|
719
|
+
* Pricing is locked for Sept 1, so this is a BASE correction and must not be
|
|
720
|
+
* able to become a rate change. It therefore takes no plan, no entitlement and
|
|
721
|
+
* no `resolveTransactionFeePct` call: it scales the fee Stripe already charged
|
|
722
|
+
* by `base / total`. Whatever rate produced `application_fee_amount` — the
|
|
723
|
+
* sale-time one, a rate AGL-2289 has since re-priced, or a staff override —
|
|
724
|
+
* comes through untouched, and the only thing removed is the portion that was
|
|
725
|
+
* taken on tax and shipping. A test that changed a rate could not make this
|
|
726
|
+
* function agree with it.
|
|
727
|
+
*
|
|
728
|
+
* `Math.max(1, …)` matches `checkout.ts`: where a rate applies at all, the
|
|
729
|
+
* floor is a cent, never zero. An invoice with no fee, no total, or nothing but
|
|
730
|
+
* tax answers 0 and asks for no correction it cannot justify.
|
|
731
|
+
*/
|
|
732
|
+
export declare function subscriptionInvoiceItemsOnlyFeeCents(invoice: SubscriptionInvoiceSource | null | undefined): number;
|
|
733
|
+
/**
|
|
734
|
+
* The recurring goods a storefront subscription's `application_fee_percent`
|
|
735
|
+
* is sized against when a paid invoice re-prices it (AGL-2655).
|
|
736
|
+
*
|
|
737
|
+
* The percent carries Stripe's fixed 30¢ folded into a rate, so it depends
|
|
738
|
+
* on the amount it will be applied to — and the amount that matters is the
|
|
739
|
+
* NEXT cycle's, which nobody has yet. The best predictor is this cycle's
|
|
740
|
+
* items-only basis, for a cycle that bills the full recurring price:
|
|
741
|
+
* `subscription_cycle`, and `subscription_create` for the opening charge.
|
|
742
|
+
* Any other reason — a `subscription_update` proration, a threshold
|
|
743
|
+
* invoice — bills a fraction, and a percent sized on a fraction would be
|
|
744
|
+
* applied to the following full cycle and over-recover on it. Those, and a
|
|
745
|
+
* $0 opening invoice (a trial converts later), fall back to what the sale
|
|
746
|
+
* recorded: the sold lines' price × quantity, the stable figure the
|
|
747
|
+
* subscription bills every cycle it is not being adjusted.
|
|
748
|
+
*
|
|
749
|
+
* Zero when neither source knows — and the caller then leaves the rate as it
|
|
750
|
+
* stands rather than sizing a percent on nothing.
|
|
751
|
+
*/
|
|
752
|
+
export declare function subscriptionRecurringBasisCents(invoice: SubscriptionInvoiceSource | null | undefined, soldLineItems: readonly Pick<OrderLineItem, 'quantity' | 'unitAmountCents'>[] | null | undefined): number;
|
|
753
|
+
/**
|
|
754
|
+
* The line that describes the SUBSCRIPTION being billed.
|
|
755
|
+
*
|
|
756
|
+
* `lines.data[0]` is not it, for the AGL-1640 reason: a mid-cycle plan switch
|
|
757
|
+
* invoices the proration against the OLD price ahead of the new plan, and an
|
|
758
|
+
* invoice also carries one-off items and credits, any of which can sort first.
|
|
759
|
+
* Prefer a non-proration line stating a cadence; fall back to a proration one,
|
|
760
|
+
* since Stripe requires every recurring item on one subscription to share a
|
|
761
|
+
* cadence; fall back to the first line so a renewal still records a name.
|
|
762
|
+
*/
|
|
763
|
+
export declare function selectSubscriptionInvoiceLine(invoice: SubscriptionInvoiceSource | null | undefined): SubscriptionInvoiceLine | undefined;
|
|
764
|
+
/**
|
|
765
|
+
* The cadence a paid invoice was billed on, or undefined when it does not say.
|
|
766
|
+
*
|
|
767
|
+
* Never guessed — the same three-state discipline as `billingIntervalFromInvoice`
|
|
768
|
+
* (AGL-1640). Storing `month` for an invoice that did not state one would make
|
|
769
|
+
* the merchant's own record of what a subscriber pays wrong in the one way that
|
|
770
|
+
* cannot be spotted by looking at it.
|
|
771
|
+
*/
|
|
772
|
+
export declare function subscriptionInvoiceInterval(invoice: SubscriptionInvoiceSource | null | undefined): 'month' | 'year' | undefined;
|
|
773
|
+
/**
|
|
774
|
+
* The stored line items and totals for one paid subscription invoice
|
|
775
|
+
* (AGL-1743) — a renewal, or the opening cycle.
|
|
776
|
+
*
|
|
777
|
+
* `snapshot` supplies the product identity, taken from what the sale already
|
|
778
|
+
* recorded rather than re-derived: an invoice line knows a description and a
|
|
779
|
+
* price, not a productId, a variant or a SKU. It is applied to the
|
|
780
|
+
* subscription's own line only; a proration or one-off line on the same invoice
|
|
781
|
+
* keeps Stripe's description and carries no product identity, because it is not
|
|
782
|
+
* a sale of that product.
|
|
783
|
+
*
|
|
784
|
+
* `totalCents` is Stripe's `amount_paid` verbatim, for the AGL-1698 reason —
|
|
785
|
+
* our sum is priced from lines we did not authorize and must never become the
|
|
786
|
+
* stored truth. Where a customer credit balance covers part of an invoice the
|
|
787
|
+
* parts will therefore exceed the collected total; the collected figure is the
|
|
788
|
+
* one that matters and the invoice's own `total` is stored beside it.
|
|
789
|
+
*/
|
|
790
|
+
export declare function computeSubscriptionInvoiceOrder(invoice: SubscriptionInvoiceSource | null | undefined, snapshot: BuyNowProductSnapshot & {
|
|
791
|
+
productId: string;
|
|
792
|
+
variantId?: string;
|
|
793
|
+
}): {
|
|
794
|
+
lineItems: OrderLineItem[];
|
|
795
|
+
totals: OrderTotals;
|
|
796
|
+
};
|
|
797
|
+
/** Display form: `#1042`; falls back to a doc-id stub for legacy rows. */
|
|
798
|
+
export declare function formatOrderNumber(order: Pick<HostOrder, 'number'>, docId?: string): string;
|
|
799
|
+
/**
|
|
800
|
+
* Lifts a legacy Commerce Starter order row (flat productId/amountCents)
|
|
801
|
+
* into the v1 shape for display; already-shaped orders pass through.
|
|
802
|
+
*/
|
|
803
|
+
export declare function liftLegacyOrder(raw: Partial<HostOrder>): HostOrder;
|
|
804
|
+
/**
|
|
805
|
+
* An orders-console row: the stored doc plus the Firestore id the collection
|
|
806
|
+
* hook attaches. `createdAt` is typed structurally rather than against the
|
|
807
|
+
* Firestore SDK — this module is pure and installs no client.
|
|
808
|
+
*/
|
|
809
|
+
export interface OrderExportRow extends Partial<HostOrder> {
|
|
810
|
+
$id?: string;
|
|
811
|
+
createdAt?: {
|
|
812
|
+
toDate?: () => Date;
|
|
813
|
+
} | null;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Does this order contain `productId`?
|
|
817
|
+
*
|
|
818
|
+
* Line items first, legacy flat `productId` as the fallback — the same test
|
|
819
|
+
* `gate.ts`, `download.ts` and `reviews.ts` already apply. Only the two
|
|
820
|
+
* buy-now-shaped Stripe paths ever write the flat field, so a legacy-only
|
|
821
|
+
* check silently excludes every cart, POS and draft order.
|
|
822
|
+
*/
|
|
823
|
+
export declare function orderContainsProduct(order: Partial<HostOrder>, productId: string): boolean;
|
|
824
|
+
/**
|
|
825
|
+
* Line indexes already covered by a recorded fulfillment (AGL-2455).
|
|
826
|
+
*
|
|
827
|
+
* The set the supplier callback and the console's own fulfil both have to
|
|
828
|
+
* reason about, and the reason `status` alone could not: `supplier-update.ts`
|
|
829
|
+
* wrote `status: 'fulfilled'` as a LITERAL, so the first supplier to post
|
|
830
|
+
* tracking on a two-supplier order marked every line shipped — including lines
|
|
831
|
+
* they have never seen — and the second supplier's POST met a 409 because
|
|
832
|
+
* `fulfilled` cannot transition to `fulfilled`. The buyer was told their whole
|
|
833
|
+
* order shipped with one carrier and one tracking number.
|
|
834
|
+
*/
|
|
835
|
+
export declare function coveredLineItemIds(order: Partial<HostOrder>): Set<number>;
|
|
836
|
+
/** Distinct suppliers with at least one line on this order (AGL-2455). */
|
|
837
|
+
export declare function orderSupplierIds(order: Partial<HostOrder>): string[];
|
|
838
|
+
/** Line indexes belonging to one supplier (AGL-2455). */
|
|
839
|
+
export declare function supplierLineItemIds(order: Partial<HostOrder>, supplierId: string): number[];
|
|
840
|
+
/**
|
|
841
|
+
* The status an order reaches once `covered` lines are shipped (AGL-2455).
|
|
842
|
+
*
|
|
843
|
+
* COMPUTED from the fulfillment set rather than written as a literal, which is
|
|
844
|
+
* the whole of this issue's third requirement. `partially_fulfilled` has existed
|
|
845
|
+
* in `ORDER_TRANSITIONS` since orders shipped and nothing ever wrote it.
|
|
846
|
+
*
|
|
847
|
+
* An order with no lines at all reads as fulfilled — there is nothing left to
|
|
848
|
+
* ship, and answering `partially_fulfilled` would strand it forever.
|
|
849
|
+
*/
|
|
850
|
+
export declare function statusAfterFulfilling(order: Partial<HostOrder>, covered: Set<number>): OrderStatus;
|
|
851
|
+
/**
|
|
852
|
+
* How much of this order has been given back (AGL-2454).
|
|
853
|
+
*
|
|
854
|
+
* `full` follows `status` OR the money, because the two can legitimately
|
|
855
|
+
* disagree for a moment: `refund.ts` reserves `refundedCents` before it calls
|
|
856
|
+
* Stripe and flips `status` after, and a lost dispute reverses money on an
|
|
857
|
+
* order whose status is still `paid` until it closes. Reading only the status
|
|
858
|
+
* would treat that window as "nothing refunded".
|
|
859
|
+
*/
|
|
860
|
+
export declare function orderRefundState(order: Partial<HostOrder>): 'none' | 'partial' | 'full';
|
|
861
|
+
/**
|
|
862
|
+
* Is this line's entitlement withdrawn?
|
|
863
|
+
*
|
|
864
|
+
* By INDEX, matching `refundedLineItemIds`. A cart can hold the same product on
|
|
865
|
+
* two lines and only one may be coming back, so a product-keyed test would
|
|
866
|
+
* revoke goods the buyer still owns.
|
|
867
|
+
*/
|
|
868
|
+
export declare function orderLineRefunded(order: Partial<HostOrder>, lineIndex: number): boolean;
|
|
869
|
+
/**
|
|
870
|
+
* THE ONE ENTITLEMENT TEST (AGL-2454). Does this order still entitle the buyer
|
|
871
|
+
* to `productId`?
|
|
872
|
+
*
|
|
873
|
+
* Five gates asked this question and all five asked it as
|
|
874
|
+
* `!['pending','cancelled','refunded'].includes(status) && orderContainsProduct(…)`.
|
|
875
|
+
* That reading is why a partial refund revoked NOTHING: `refund.ts` writes
|
|
876
|
+
* `status: 'refunded'` only when the order is FULLY refunded, so a 99%-refunded
|
|
877
|
+
* order stayed `paid` and every gate said yes — downloads, licence keys, gated
|
|
878
|
+
* content and the right to post a verified review, all still live.
|
|
879
|
+
*
|
|
880
|
+
* Withdrawn now means either of two things, and both had to be expressible in
|
|
881
|
+
* one place or the five gates would drift again:
|
|
882
|
+
*
|
|
883
|
+
* - the whole order is withdrawn by `status`, as before; or
|
|
884
|
+
* - every line carrying this product was refunded BY NAME, which is the case a
|
|
885
|
+
* line-scoped refund creates and the only case where an amount can honestly
|
|
886
|
+
* be attributed to goods.
|
|
887
|
+
*
|
|
888
|
+
* `'any'` asks whether the order still entitles ANYTHING, which is what the
|
|
889
|
+
* membership paywall's subscription-shaped probe needs.
|
|
890
|
+
*
|
|
891
|
+
* The legacy flat `productId` order (one line, no `lineItems`) is lifted by
|
|
892
|
+
* `liftLegacyOrder` before it gets here, so index 0 is its only line and a
|
|
893
|
+
* line-scoped refund of it behaves like a full one.
|
|
894
|
+
*/
|
|
895
|
+
export declare function orderEntitlesProduct(order: Partial<HostOrder>, productId: string | 'any'): boolean;
|
|
896
|
+
/**
|
|
897
|
+
* Product ids whose entitlement this order has withdrawn line by line
|
|
898
|
+
* (AGL-2454) — every line for the product refunded, none left standing.
|
|
899
|
+
*
|
|
900
|
+
* What `refund.ts` uses to decide which licence keys to RETIRE. Not "any line
|
|
901
|
+
* refunded": a buyer who returned one of two copies still holds the product.
|
|
902
|
+
*/
|
|
903
|
+
export declare function refundedProductIds(order: Partial<HostOrder>): string[];
|
|
904
|
+
/**
|
|
905
|
+
* The refund line the console and the merchant read (AGL-2454).
|
|
906
|
+
*
|
|
907
|
+
* Kept in the model because three surfaces show it and "partially refunded"
|
|
908
|
+
* must not mean different things on two of them. Empty for an order with
|
|
909
|
+
* nothing refunded — there is nothing to say.
|
|
910
|
+
*/
|
|
911
|
+
export declare function orderRefundSummary(order: Partial<HostOrder>): string;
|
|
912
|
+
/**
|
|
913
|
+
* Display labels for {@link OrderStatus}, and the MUI chip colour each one
|
|
914
|
+
* carries (AGL-2136). The orders screen advertised on `/product/commerce`
|
|
915
|
+
* shows the status as a COLOURED pill — `Paid`, `Fulfilled`, `Refunded` in
|
|
916
|
+
* three different colours — where the console rendered every status as the
|
|
917
|
+
* same default outlined chip, so the one column a merchant scans first
|
|
918
|
+
* carried no signal at all.
|
|
919
|
+
*
|
|
920
|
+
* Kept in the model rather than in the card because three surfaces render a
|
|
921
|
+
* status (the orders list, the detail dialog and the dashboard glance
|
|
922
|
+
* widget) and a colour that means "refunded" on one of them must not mean
|
|
923
|
+
* something else on the next.
|
|
924
|
+
*/
|
|
925
|
+
export declare const ORDER_STATUS_LABELS: Record<OrderStatus, string>;
|
|
926
|
+
/**
|
|
927
|
+
* Chip colour per status. `pending` is deliberately `default` rather than
|
|
928
|
+
* `warning`: an unpaid order is not a problem, it is simply not money yet,
|
|
929
|
+
* and reserving the alarming colours for `cancelled`/`refunded` is what
|
|
930
|
+
* makes them readable at a glance.
|
|
931
|
+
*/
|
|
932
|
+
export declare const ORDER_STATUS_COLOR: Record<OrderStatus, 'default' | 'success' | 'info' | 'warning' | 'error'>;
|
|
933
|
+
/** Display labels for {@link OrderChannel}. */
|
|
934
|
+
export declare const ORDER_CHANNEL_LABELS: Record<OrderChannel, string>;
|
|
935
|
+
/** Human label for a channel, tolerating a legacy/unknown value. */
|
|
936
|
+
export declare function orderChannelLabel(channel: string | undefined): string;
|
|
937
|
+
/**
|
|
938
|
+
* Net cents an order actually earned: the charged total less anything
|
|
939
|
+
* refunded. The three commerce surfaces each had their own inline copy of
|
|
940
|
+
* this expression; a refunded order counted as revenue on whichever one
|
|
941
|
+
* was written first.
|
|
942
|
+
*/
|
|
943
|
+
export declare function orderNetCents(order: Partial<HostOrder>): number;
|
|
944
|
+
/** Milliseconds an order was created at, across every writer's field shape. */
|
|
945
|
+
export declare function orderCreatedAtMs(order: Partial<HostOrder> & {
|
|
946
|
+
createdAtMs?: number;
|
|
947
|
+
createdAt?: {
|
|
948
|
+
seconds?: number;
|
|
949
|
+
toDate?: () => Date;
|
|
950
|
+
};
|
|
951
|
+
}): number;
|
|
952
|
+
/** One window's totals, plus how it moved against the window before it. */
|
|
953
|
+
export interface OrderWindowSummary {
|
|
954
|
+
/** Net revenue in cents over the window. */
|
|
955
|
+
revenueCents: number;
|
|
956
|
+
/** Orders counted in the window. */
|
|
957
|
+
orders: number;
|
|
958
|
+
/** Average order value in cents, 0 when the window is empty. */
|
|
959
|
+
aovCents: number;
|
|
960
|
+
/**
|
|
961
|
+
* Percentage change vs the immediately preceding window of the same
|
|
962
|
+
* length, rounded to one decimal. `null` when the prior window is EMPTY —
|
|
963
|
+
* "+100%" against zero is not a growth rate, it is a first sale, and the
|
|
964
|
+
* tile must say nothing rather than say something false.
|
|
965
|
+
*/
|
|
966
|
+
revenueDeltaPct: number | null;
|
|
967
|
+
ordersDeltaPct: number | null;
|
|
968
|
+
aovDeltaPct: number | null;
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Summarises a window of orders and the window before it (AGL-2136).
|
|
972
|
+
*
|
|
973
|
+
* Every commerce mockup we advertise shows the money tiles carrying a
|
|
974
|
+
* period-over-period delta — `Revenue $26,540 +8.1%` — and the product had
|
|
975
|
+
* no prior-window computation anywhere in the repo, so no surface could
|
|
976
|
+
* have rendered one.
|
|
977
|
+
*
|
|
978
|
+
* `pending` and `cancelled` orders are excluded, matching the analytics
|
|
979
|
+
* card: neither is money. Refunds are subtracted rather than dropped, so a
|
|
980
|
+
* refund inside the window pushes the delta DOWN, which is the whole point
|
|
981
|
+
* of showing it.
|
|
982
|
+
*/
|
|
983
|
+
export declare function summarizeOrderWindow(orders: readonly (Partial<HostOrder> & {
|
|
984
|
+
createdAtMs?: number;
|
|
985
|
+
createdAt?: {
|
|
986
|
+
seconds?: number;
|
|
987
|
+
toDate?: () => Date;
|
|
988
|
+
};
|
|
989
|
+
})[], options: {
|
|
990
|
+
nowMs: number;
|
|
991
|
+
days?: number;
|
|
992
|
+
}): OrderWindowSummary;
|
|
993
|
+
/**
|
|
994
|
+
* Header for {@link buildOrdersCsv}. The original seven columns (AGL-96) keep
|
|
995
|
+
* their names AND their positions, so a saved import mapping — by name or by
|
|
996
|
+
* index — still resolves; the four reconciliation columns are appended.
|
|
997
|
+
*/
|
|
998
|
+
export declare const ORDERS_CSV_HEADER: string;
|
|
999
|
+
/**
|
|
1000
|
+
* The orders console's `orders.csv` (AGL-1747).
|
|
1001
|
+
*
|
|
1002
|
+
* ## What was wrong
|
|
1003
|
+
*
|
|
1004
|
+
* The export read `amountCents`, `feeCents` and `productId` — the legacy
|
|
1005
|
+
* Commerce Starter flat fields (AGL-90) — and nothing else. Checked writer by
|
|
1006
|
+
* writer, only the two buy-now-shaped Stripe paths write them:
|
|
1007
|
+
*
|
|
1008
|
+
* | Order path | `amountCents` | `productId` |
|
|
1009
|
+
* | -- | -- | -- |
|
|
1010
|
+
* | buy-now (`commerce-order`, `billing-webhook.ts`) | yes | yes |
|
|
1011
|
+
* | cart (`commerce-cart`, `billing-webhook.ts`) | yes | **no** |
|
|
1012
|
+
* | POS cash and POS card (`pos-order.ts`) | **no** | **no** |
|
|
1013
|
+
* | draft (`draft-order.ts`, paid by `commerce-draft`) | **no** | **no** |
|
|
1014
|
+
*
|
|
1015
|
+
* So every POS and draft order exported as `$0.00` and every cart order
|
|
1016
|
+
* exported with a blank product, each beside a plausible date, email and order
|
|
1017
|
+
* id — nothing in the file signals that the number is missing rather than
|
|
1018
|
+
* genuinely zero. The console screen was right the whole time: the table row
|
|
1019
|
+
* beside the export button, the detail dialog, the analytics card and lifetime
|
|
1020
|
+
* purchases all read `totals` with the flat field only as a fallback. The
|
|
1021
|
+
* export was the sole reader that had the precedence backwards, and a CSV is
|
|
1022
|
+
* the artefact that reaches a bookkeeper.
|
|
1023
|
+
*
|
|
1024
|
+
* ## What "correct" means
|
|
1025
|
+
*
|
|
1026
|
+
* Per AGL-1711's lesson, the useful test is not "do the parts sum" but "does
|
|
1027
|
+
* each column match what was actually charged" — a total-only assertion passes
|
|
1028
|
+
* against a row whose every component is wrong. The spec therefore pins each
|
|
1029
|
+
* cell of a worked example individually.
|
|
1030
|
+
*
|
|
1031
|
+
* ## Refunds
|
|
1032
|
+
*
|
|
1033
|
+
* `amountUsd` stays gross, which is what it has always meant, and the appended
|
|
1034
|
+
* `refundedUsd`/`netUsd` carry the rest. A refunded order previously exported
|
|
1035
|
+
* at its gross with nothing beside it to say so — the same class of error, in
|
|
1036
|
+
* that the file understated nothing but overstated revenue.
|
|
1037
|
+
*/
|
|
1038
|
+
export declare function buildOrdersCsv(orders: OrderExportRow[], productNames?: Record<string, string>): string;
|
|
1039
|
+
/** Appends a timeline event immutably (webhook + console share this). */
|
|
1040
|
+
export declare function appendOrderEvent(order: Pick<HostOrder, 'timeline'>, event: string, detail?: string, atMs?: number): OrderTimelineEvent[];
|