@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 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/commerce.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 { nameSearchFields } from '@aglyn/aglyn/app-utils/name-search'\n\n/**\n * Commerce catalog v1 (AGL-276): products with options/variants,\n * hierarchical categories, tags, and manual/smart collections. Pure\n * model + helpers — no I/O; the products hub and storefront APIs operate\n * over these shapes. Documents live under `hosts/{hostId}/products`,\n * `.../productCategories`, and `.../collections`; the legacy Commerce\n * Starter product doc (AGL-90: name/priceUsd/inventory) lifts into this\n * shape via `liftLegacyProduct`, so existing docs keep working.\n */\n\n/*\n * THERE IS NO STOREFRONT FEE CONSTANT, and that absence is load-bearing\n * (AGL-2295).\n *\n * `COMMERCE_PLATFORM_FEE_PERCENT = 2` lived here with ZERO call sites. It\n * asserted a flat 2% that agrees with the plan table for exactly one cell\n * (Starter, physical) and disagrees with the other fifteen — Starter digital\n * is 5%, Pro digital 3%, Business 2%, Scale 1%, and every physical rate above\n * Starter is 0%. Nothing was wrong while nothing read it; the cost was that\n * the next reader wiring it up would silently re-price every plan, and a\n * constant sitting in the model beside the types reads like the answer.\n *\n * The single source is `resolveTransactionFeePct(org, productType)` in\n * `plan-entitlements.ts`, resolved PER REQUEST from the org — because it\n * depends on the plan, on per-org staff overrides, and on whether the\n * subscription is still alive. A constant cannot express any of that.\n * `commerce-fee-single-source.spec.ts` fails the build if one comes back.\n */\n/** Product price ceiling (whole USD). */\nexport const COMMERCE_MAX_PRICE_USD = 10000\n\nexport type ProductType = 'physical' | 'digital' | 'service'\nexport type ProductStatus = 'draft' | 'active' | 'archived'\n\n/** One axis of variation, e.g. { name: 'Size', values: ['S','M','L'] }. */\nexport interface ProductOption {\n name: string\n values: string[]\n}\n\n/** A sellable configuration of a product (every product has ≥ 1). */\nexport interface ProductVariant {\n /** Stable id unique within the product (never reused after delete). */\n id: string\n /** Option selections keyed by option name; {} for the default variant. */\n options?: Record<string, string>\n sku?: string\n barcode?: string\n priceUsd: number\n /** Strike-through price; a sale badge shows when > priceUsd. */\n compareAtPriceUsd?: number\n weightGrams?: number\n /** null/undefined = untracked; 0 = sold out (matches AGL-96). */\n inventory?: number | null\n /**\n * Per-location stock (AGL-286); `inventory` stays the summed\n * denormalization. Absent = single default location.\n */\n inventoryByLocation?: Record<string, number>\n /** Media-library image URL shown when this variant is selected. */\n imageUrl?: string\n}\n\n/** `hosts/{hostId}/locations/{id}` doc (AGL-286). */\nexport interface InventoryLocation {\n name: string\n isDefault?: boolean\n address?: string\n}\n\n/**\n * `hosts/{hostId}/registers/{id}` doc (AGL-472): a named point-of-sale\n * register. Creation is capped by the plan's `posRegisters` quota (Pro 1,\n * Business 2, Advanced 5; raised by a per-org entitlement override for the\n * $89/mo add-on), enforced server-side by the resources route. Each POS\n * sale stamps its `registerId` so takings are attributable per register.\n */\nexport interface PosRegister {\n name: string\n /** Optional default inventory location this register sells from. */\n locationId?: string\n}\n\n/**\n * The register ids within the plan's `posRegisters` cap (AGL-482), ranked\n * by creation order — the same ordering `pos-order.ts` enforces at sale\n * time. Registers beyond the cap (e.g. after a Business→Pro downgrade) are\n * excluded so the console/POS can dim or hide them instead of surfacing a\n * checkout 403. `cap` of `Infinity` returns all.\n */\nexport function registersWithinCap(\n registers: Array<{ $id: string; createdAt?: any }>,\n cap: number,\n): Set<string> {\n const createdMs = (r: { createdAt?: any }) =>\n r.createdAt?.toMillis?.() ?? r.createdAt?.seconds ?? 0\n const ranked = [...registers].sort(\n (a, b) => createdMs(a) - createdMs(b) || a.$id.localeCompare(b.$id),\n )\n return new Set(ranked.slice(0, Math.max(0, cap)).map((r) => r.$id))\n}\n\n/**\n * `hosts/{hostId}/suppliers/{id}` doc (AGL-289): where dropshipped\n * order lines route on payment. Email and webhook are both optional but\n * one must be set for routing to do anything; webhook payloads are\n * HMAC-SHA256-signed with `webhookSecret`.\n */\nexport interface HostSupplier {\n name: string\n email?: string\n webhookUrl?: string\n webhookSecret?: string\n}\n\n/** `hosts/{hostId}/products/{id}` doc. */\nexport interface HostProduct {\n name: string\n /** Host-unique URL segment for /products/{slug}. */\n slug: string\n description?: string\n type: ProductType\n status: ProductStatus\n /** Ordered media-library image URLs (first = primary). */\n mediaUrls?: string[]\n categoryIds?: string[]\n tags?: string[]\n options?: ProductOption[]\n variants: ProductVariant[]\n /** Per-product overrides for PDP meta tags (AGL-299 consumes). */\n seo?: { title?: string; description?: string; imageUrl?: string }\n /** Supplier for dropship routing (AGL-289). */\n supplierId?: string\n /** Out-of-stock behavior (AGL-281): deny (default) or allow backorder. */\n oversellPolicy?: 'deny' | 'backorder'\n /** Never taxed regardless of tax settings (AGL-285). */\n taxExempt?: boolean\n /**\n * Digital delivery (AGL-302): downloadable files for `digital`\n * products. Buyers always download the CURRENT list, so uploading a\n * new version re-delivers to everyone.\n */\n digitalFiles?: Array<{ url: string; fileName: string; version?: string }>\n /** Max download attempts per order line; absent = unlimited. */\n downloadLimit?: number\n /**\n * Recurring billing (AGL-303): buyers subscribe instead of buying\n * once; an active subscription is the entitlement content gating\n * checks (AGL-309).\n */\n subscription?: { interval: 'month' | 'year'; trialDays?: number }\n /**\n * Buyer-chosen billing (AGL-545): with `subscription` set, true lets\n * the buyer pick one-time OR subscribe on the PDP (default one-time);\n * absent/false keeps the product subscription-only.\n */\n subscriptionOptional?: boolean\n /** Members-only videos (AGL-315), streamed via short-TTL links. */\n gatedVideos?: Array<{ url: string; title?: string }>\n /** Manual related products for the upsell block (AGL-325). */\n relatedProductIds?: string[]\n /** Buying this issues a gift-card code for its price (AGL-322). */\n giftCard?: boolean\n /** Tracked-total at/below this alerts host managers (AGL-281). */\n lowStockThreshold?: number\n createdAtMs?: number\n updatedAtMs?: number\n deletedAt?: number | null\n /** Legacy Commerce Starter fields kept so old docs read back (AGL-90). */\n priceUsd?: number\n inventory?: number | null\n imageUrl?: string\n}\n\n/** `hosts/{hostId}/productCategories/{id}` doc (tree via parentId). */\nexport interface ProductCategory {\n name: string\n slug: string\n parentId?: string | null\n order?: number\n}\n\nexport type CollectionRuleField =\n | 'tag'\n | 'categoryId'\n | 'priceUsd'\n | 'name'\n | 'type'\nexport type CollectionRuleOp = 'eq' | 'neq' | 'lt' | 'gt' | 'contains'\n\nexport interface CollectionRule {\n field: CollectionRuleField\n op: CollectionRuleOp\n value: string | number\n}\n\n/** `hosts/{hostId}/collections/{id}` doc. */\nexport interface HostCollection {\n name: string\n slug: string\n description?: string\n mode: 'manual' | 'smart'\n /** Manual mode: explicit ordered membership. */\n productIds?: string[]\n /** Smart mode: rules evaluated over active products. */\n rules?: CollectionRule[]\n /** Smart mode: true = every rule must match (default), false = any. */\n matchAll?: boolean\n /** Media-library image URL for the collection card/landing hero. */\n imageUrl?: string\n order?: number\n}\n\n/**\n * Payment-provider seam (AGL-284): checkout/session creation goes\n * through a provider id so PayPal (etc.) can slot in without reworking\n * callers. Stripe is the only implementation today; store settings\n * (AGL-295) will carry the selection when a second provider exists.\n */\nexport type PaymentProviderId = 'stripe'\n\nexport interface PaymentCheckoutRequest {\n provider: PaymentProviderId\n hostId: string\n amountCents: number\n feeCents: number\n productName: string\n successUrl: string\n cancelUrl: string\n metadata?: Record<string, string>\n}\n\n/** Variant ceiling per product (Shopify parity). */\nexport const COMMERCE_MAX_VARIANTS = 100\nexport const COMMERCE_MAX_OPTIONS = 3\nexport const COMMERCE_MAX_OPTION_VALUES = 25\nexport const COMMERCE_SLUG_MAX_LENGTH = 80\n\n/** Lowercase-kebab slug from a product/category/collection name. */\nexport function commerceSlug(name: string): string {\n return String(name ?? '')\n .normalize('NFKD')\n .replace(/[̀-ͯ]/g, '')\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '-')\n .replace(/^-+|-+$/g, '')\n .slice(0, COMMERCE_SLUG_MAX_LENGTH)\n}\n\n/**\n * The search keys a product write carries, so the catalog can be searched by\n * the QUERY rather than by the rows a listener happened to fetch (AGL-2501).\n *\n * The hub lists `limit(500)`, and the search compared what that returned — so\n * a product past the window answered \"no products match\", which reads as the\n * product not existing rather than as the search not reaching it. Filtering\n * server-side needs fields Firestore can index, and neither of the two things\n * a merchant searches by is one:\n *\n * - A NAME needs case-insensitive contains, which Firestore has no operator\n * for. `nameSearchFields` denormalizes it into the three shapes that are\n * indexable — an exact key, word-prefix tokens for `array-contains`, and\n * the key reversed so \"ends with\" becomes a prefix range.\n * - A SKU lives inside `variants`, an array of OBJECTS, and Firestore cannot\n * query a field inside one. Flattened here into a top-level array so a SKU\n * is one `array-contains`.\n *\n * ⛔ A SKU therefore matches WHOLE, not as a substring: \"abc-123\" finds it and\n * \"123\" does not. That is the right way round for a SKU, which is a value\n * somebody copies rather than half-remembers — unlike a name, where the tokens\n * above buy word-prefix matching precisely because names are half-remembered.\n *\n * `barcodes` is the same flattening for the same reason, and it is the one the\n * register depends on: a keyboard-wedge scanner types the code and presses\n * Enter, so the lookup has to be exact and has to reach the whole catalog. A\n * scan is never a half-remembered value.\n *\n * Lower-cased because the translator lower-cases the typed query before it\n * builds the `array-contains`; stored and typed have to be normalized the same\n * way or the two silently disagree.\n *\n * ⚠️ Each array is OMITTED when a product has none, rather than written as\n * `[]`. `isNotEmpty` is served as `!= null`, and an empty array is not null —\n * so a product with no SKUs at all would answer \"has a SKU\" for every row.\n *\n * ⚠️ Spread this at EVERY write that sets a product's name or variants. A\n * write that sets the name without it leaves the keys describing the previous\n * name, and the product becomes findable only by what it used to be called.\n */\nexport function productSearchFields(product: {\n name: string\n variants?: ProductVariant[]\n}): {\n name: string\n nameLower: string\n nameTokens: string[]\n nameReversed: string\n skus?: string[]\n barcodes?: string[]\n} {\n const flatten = (read: (variant: ProductVariant) => string | undefined) => [\n ...new Set(\n (product.variants ?? [])\n .map((variant) => (read(variant) ?? '').trim().toLowerCase())\n .filter(Boolean),\n ),\n ]\n const skus = flatten((variant) => variant.sku)\n const barcodes = flatten((variant) => variant.barcode)\n return {\n ...nameSearchFields(product.name),\n ...(skus.length ? { skus } : {}),\n ...(barcodes.length ? { barcodes } : {}),\n }\n}\n\n/**\n * Cartesian product of option values → the variant option combinations\n * the products hub materializes into a variants matrix. Empty/absent\n * options yield a single default combination ({}).\n */\nexport function expandVariantMatrix(\n options: ProductOption[] | undefined,\n): Array<Record<string, string>> {\n const usable = (options ?? []).filter(\n (option) => option.name && (option.values?.length ?? 0) > 0,\n )\n if (usable.length === 0) return [{}]\n let combos: Array<Record<string, string>> = [{}]\n for (const option of usable) {\n const next: Array<Record<string, string>> = []\n for (const combo of combos) {\n for (const value of option.values) {\n next.push({ ...combo, [option.name]: value })\n }\n }\n combos = next\n if (combos.length > COMMERCE_MAX_VARIANTS) {\n return combos.slice(0, COMMERCE_MAX_VARIANTS)\n }\n }\n return combos\n}\n\n/**\n * The option axes renamed, with every variant's selection carried to the new\n * name in place (AGL-3066).\n *\n * A variant keeps its selections keyed by option NAME, so a rename has to move\n * each key rather than rebuild the matrix: a rebuild matches variants by name\n * and value, finds none under the new name, and replaces every variant with a\n * new id holding the first variant's price and stock and no SKU, barcode,\n * compare-at price or weight. Moving the key keeps the id every order line\n * and stock movement refers to, and every field a person set.\n *\n * `names` holds one entry per option, in order; an entry that is not a string\n * keeps that option's name. Each selection keeps its position among a\n * variant's selections, because a variant is labeled by them in order.\n *\n * Two options may share a name for a moment while a person types. A variant\n * cannot hold two selections under one name, so while the new names are not\n * all different nothing is moved, and `validateProduct` refuses the product.\n * The selection left under the old name is found again by its value once the\n * names differ, so typing through a duplicate loses nothing.\n */\nexport function renameProductOptions(\n product: Pick<HostProduct, 'options' | 'variants'>,\n names: ReadonlyArray<string | null | undefined>,\n): Pick<HostProduct, 'options' | 'variants'> {\n const current = product.options ?? []\n const options = current.map((option, index) => {\n const name = names[index]\n return typeof name === 'string' ? { ...option, name } : option\n })\n const next = options.map((option) => option.name)\n if (new Set(next).size !== next.length) return { options, variants: product.variants }\n const variants = (product.variants ?? []).map((variant) => {\n const selections = variant.options\n if (!selections) return variant\n const axisOf = optionAxesOf(current, selections)\n const moved: Record<string, string> = {}\n let changed = false\n for (const [key, value] of Object.entries(selections)) {\n const axis = axisOf.get(key)\n const name = axis === undefined ? key : next[axis]\n if (name !== key) changed = true\n moved[name] = value\n }\n return changed ? { ...variant, options: moved } : variant\n })\n return { options, variants }\n}\n\n/**\n * Which option each of a variant's selections belongs to: the option of the\n * same name first, and then, for a selection under a name no option has any\n * longer, the one remaining option whose values hold its value. A selection\n * that fits neither belongs to no option and is left as it is.\n */\nfunction optionAxesOf(\n options: readonly ProductOption[],\n selections: Readonly<Record<string, string>>,\n): Map<string, number> {\n const axisOf = new Map<string, number>()\n const taken = new Set<number>()\n options.forEach((option, index) => {\n if (Object.prototype.hasOwnProperty.call(selections, option.name) && !axisOf.has(option.name)) {\n axisOf.set(option.name, index)\n taken.add(index)\n }\n })\n for (const [key, value] of Object.entries(selections)) {\n if (axisOf.has(key)) continue\n const axis = options.findIndex(\n (option, index) => !taken.has(index) && (option.values ?? []).includes(value),\n )\n if (axis === -1) continue\n axisOf.set(key, axis)\n taken.add(axis)\n }\n return axisOf\n}\n\n/**\n * Whether a variant has a price a sale can charge (AGL-2916).\n *\n * A product proposed by AI is created with every price left empty for the\n * merchant to set, so a stored variant can lack one. `Number(undefined)` is\n * no price, and neither is `null`, which `Number` reads as zero: a sale door\n * that priced either would charge nothing, or fail at the processor.\n */\nexport function variantHasPrice(variant: object | null | undefined): boolean {\n const price = (variant as { priceUsd?: unknown } | null | undefined)?.priceUsd\n return typeof price === 'number' && Number.isFinite(price) && price >= 0\n}\n\n/** Whether any variant of a product still needs its price set (AGL-2916). */\nexport function productPriceMissing(product: { variants?: readonly object[] }): boolean {\n return (product.variants ?? []).some((variant) => !variantHasPrice(variant))\n}\n\n/** Copy proposed for a product, by field (AGL-2916). A field left out is left alone. */\nexport interface ProductCopyValues {\n description?: string\n tags?: string[]\n categoryIds?: string[]\n /** One name per option the product has, in order. */\n optionNames?: string[]\n seoTitle?: string\n seoDescription?: string\n}\n\n/**\n * The fields proposed copy changes on a product (AGL-2916), in the shape the\n * editor stores them: only the fields `values` names. Tags and categories are\n * each kept once; the search listing keeps its share image; and option names\n * rename the product's options through `renameProductOptions`, keeping every\n * variant, only when they name each option once with a name of its own.\n */\nexport function productCopyPatch(\n product: Pick<HostProduct, 'options' | 'variants' | 'seo'>,\n values: ProductCopyValues,\n): Partial<Pick<HostProduct, 'description' | 'tags' | 'categoryIds' | 'seo' | 'options' | 'variants'>> {\n const patch: Partial<\n Pick<HostProduct, 'description' | 'tags' | 'categoryIds' | 'seo' | 'options' | 'variants'>\n > = {}\n if (typeof values.description === 'string') patch.description = values.description\n if (Array.isArray(values.tags)) {\n patch.tags = [...new Set(values.tags.map((tag) => tag.trim()).filter(Boolean))]\n }\n if (Array.isArray(values.categoryIds)) {\n patch.categoryIds = [...new Set(values.categoryIds.filter(Boolean))]\n }\n if (typeof values.seoTitle === 'string' || typeof values.seoDescription === 'string') {\n patch.seo = {\n ...product.seo,\n ...(typeof values.seoTitle === 'string' ? { title: values.seoTitle } : {}),\n ...(typeof values.seoDescription === 'string' ? { description: values.seoDescription } : {}),\n }\n }\n const options = product.options ?? []\n const names = values.optionNames?.map((name) => name.trim())\n if (\n names &&\n options.length > 0 &&\n names.length === options.length &&\n names.every(Boolean) &&\n new Set(names).size === names.length &&\n names.some((name, index) => name !== options[index].name)\n ) {\n Object.assign(patch, renameProductOptions(product, names))\n }\n return patch\n}\n\n/** A product proposed for a store, before anyone has priced it (AGL-2916). */\nexport interface ProposedProduct {\n name: string\n type: ProductType\n description: string\n tags: string[]\n options: ProductOption[]\n seoTitle: string\n seoDescription: string\n}\n\n/** A new product whose variants carry no price yet. */\nexport type UnpricedProductDraft = Omit<HostProduct, 'variants'> & {\n variants: Array<Omit<ProductVariant, 'priceUsd'>>\n}\n\n/**\n * The document a proposed product is created as (AGL-2916): a `draft`, under\n * a slug no product in `takenSlugs` has, with one variant for each\n * combination of its options and NO price on any of them. Prices are the\n * merchant's to set: the editor refuses to save the product until every\n * variant has one, and no sale door sells a variant without one\n * (`variantHasPrice`). The search keys travel with the name, as on every\n * create path.\n */\nexport function unpricedProductDraft(\n proposal: ProposedProduct,\n takenSlugs: ReadonlySet<string>,\n nowMs: number,\n): UnpricedProductDraft {\n const name = proposal.name.trim().slice(0, 120)\n const base = commerceSlug(name) || 'product'\n let slug = base\n for (let suffix = 2; takenSlugs.has(slug); suffix += 1) slug = `${base}-${suffix}`\n const seen = new Set<string>()\n const options = proposal.options\n .map((option) => ({\n name: option.name.trim(),\n values: [...new Set(option.values.map((value) => value.trim()).filter(Boolean))].slice(\n 0,\n COMMERCE_MAX_OPTION_VALUES,\n ),\n }))\n .filter((option) => {\n if (!option.name || !option.values.length || seen.has(option.name)) return false\n seen.add(option.name)\n return true\n })\n .slice(0, COMMERCE_MAX_OPTIONS)\n const variants = options.length\n ? expandVariantMatrix(options).map((combo, index) => ({\n id: `v${nowMs.toString(36)}${index}`,\n options: combo,\n }))\n : [{ id: 'default' }]\n const seoTitle = proposal.seoTitle.trim()\n const seoDescription = proposal.seoDescription.trim()\n return {\n ...productSearchFields({ name }),\n slug,\n type: proposal.type,\n status: 'draft',\n description: proposal.description,\n tags: [...new Set(proposal.tags.map((tag) => tag.trim()).filter(Boolean))],\n ...(options.length ? { options } : {}),\n variants,\n ...(seoTitle || seoDescription\n ? { seo: { ...(seoTitle ? { title: seoTitle } : {}), ...(seoDescription ? { description: seoDescription } : {}) } }\n : {}),\n createdAtMs: nowMs,\n updatedAtMs: nowMs,\n }\n}\n\n/** Variant whose option selections match exactly; undefined if none. */\nexport function findVariant(\n product: Pick<HostProduct, 'variants'>,\n selections: Record<string, string>,\n): ProductVariant | undefined {\n return product.variants?.find((variant) => {\n const options = variant.options ?? {}\n const keys = new Set([...Object.keys(options), ...Object.keys(selections)])\n for (const key of keys) {\n if (options[key] !== selections[key]) return false\n }\n return true\n })\n}\n\n/** [min, max] price across variants; [0, 0] when there are none. */\nexport function productPriceRange(\n product: Pick<HostProduct, 'variants'>,\n): [number, number] {\n const prices = (product.variants ?? [])\n .map((variant) => Number(variant.priceUsd))\n .filter((price) => Number.isFinite(price) && price >= 0)\n if (prices.length === 0) return [0, 0]\n return [Math.min(...prices), Math.max(...prices)]\n}\n\n/** Sum of tracked inventory; null when every variant is untracked. */\nexport function productInventory(\n product: Pick<HostProduct, 'variants'>,\n): number | null {\n let total: number | null = null\n for (const variant of product.variants ?? []) {\n if (variant.inventory == null) continue\n total = (total ?? 0) + Number(variant.inventory)\n }\n return total\n}\n\n/**\n * Reasons an inventory adjustment doc may carry (AGL-281).\n *\n * `cancellation` is the only one written automatically in the PLUS direction\n * (AGL-1808): cancelling an order the transition rules prove was never\n * fulfilled puts back exactly what the sale took. It is deliberately not\n * `refund` — no money moved — and not `correction`, which is what a merchant\n * picks when the count disagreed with the shelf for a reason nobody recorded.\n * Kept out of the \"Adjust stock\" dialog's menu on purpose: a merchant reaching\n * for it by hand means something else happened.\n */\nexport type InventoryAdjustmentReason =\n 'sale' | 'refund' | 'restock' | 'correction' | 'damage' | 'cancellation'\n\n/** `hosts/{hostId}/inventoryAdjustments/{id}` doc. */\nexport interface InventoryAdjustment {\n productId: string\n variantId: string\n /** Positive = stock added, negative = removed. */\n delta: number\n /**\n * What the count ACTUALLY moved by, when the floor in\n * `adjustVariantInventory` absorbed part of `delta` (AGL-2149). Written only\n * when the two differ, which for a sale means a backorder product that sold\n * past zero: `delta` stays the units sold — that is the merchant's stock\n * history and it must keep saying \"3 went out the door\" — while this says how\n * many of them the count could give up.\n *\n * A REVERSAL MUST READ THIS, NOT `delta`. Restoring `delta` on a backorder\n * sale that the floor swallowed invents inventory that never existed: 0 sells\n * 3, the count stays 0, and a `+3` on cancellation leaves 3 units nobody has.\n * Absent on every row written before AGL-2149 and on every row where nothing\n * was clamped, so `appliedDelta ?? delta` is the reader.\n */\n appliedDelta?: number\n reason: InventoryAdjustmentReason\n /** Order id for sale/refund adjustments. */\n orderId?: string\n /** Location for multi-location stock (AGL-286); absent = default. */\n locationId?: string\n atMs: number\n}\n\n/**\n * Whether `quantity` of a variant is purchasable (AGL-281): untracked\n * stock always is; tracked stock honors the product's oversell policy.\n */\nexport function canPurchase(\n product: Pick<HostProduct, 'variants' | 'oversellPolicy'>,\n variantId: string | undefined,\n quantity = 1,\n): boolean {\n const variant = variantId\n ? product.variants?.find((item) => item.id === variantId)\n : product.variants?.[0]\n if (!variant) return false\n if (variant.inventory == null) return true\n if (product.oversellPolicy === 'backorder') return true\n return Number(variant.inventory) >= quantity\n}\n\n/**\n * What the register has to SAY about a line it is about to sell (AGL-2357).\n *\n * ## The defect\n *\n * `pos-order.ts` contains no `canPurchase` call. Every storefront door gates on\n * it; the register does not, so a merchant who set `oversellPolicy: 'deny'` in\n * the product editor silently got `backorder` at the counter — the count floors\n * at zero underneath and nothing anywhere says so.\n *\n * ## The decision, and why it is a shortfall and not a refusal\n *\n * Warn, never block. A till is the wrong place for a stale number to stop a\n * real sale: the cashier is holding the goods, the physical shelf is the truth,\n * and refusing loses a sale over data that is behind. But \"deny\" must at least\n * SAY something. So this reports the shortfall and the caller sells anyway.\n * Honouring the policy with a manager-level override is the post-launch shape\n * (AGL-2372) and wants an audit trail this deliberately does not build.\n *\n * ## Why the test is `canPurchase`\n *\n * Exactly the gate the register was missing, and no wider. An untracked variant\n * has no number to be short against, and a `backorder` product's merchant chose\n * to sell past zero — warning them would be noise about a setting they set on\n * purpose. So a shortfall is reported only where a purchase would have been\n * refused anywhere else in the product.\n */\nexport interface StockShortfall {\n productId: string\n variantId?: string\n /** Product name at the time of sale, for a message the cashier can read. */\n name: string\n variantLabel?: string\n /** Units the cashier is ringing up. */\n requested: number\n /** Units the count says are on the shelf; never negative. */\n available: number\n}\n\nexport function stockShortfall(\n product: Pick<HostProduct, 'variants' | 'oversellPolicy'>,\n variantId: string | undefined,\n quantity = 1,\n): { available: number } | null {\n if (canPurchase(product, variantId, quantity)) return null\n const variant = variantId\n ? product.variants?.find((item) => item.id === variantId)\n : product.variants?.[0]\n // `canPurchase` answers false for a variant that does not exist at all. That\n // is not a stock shortfall and must not be reported as \"0 in stock\" — the\n // register's own line builder falls back to `variants[0]`, so the case is\n // unreachable from the counter, and inventing a count for it would be the\n // one failure mode this feature must not have.\n if (!variant || variant.inventory == null) return null\n return { available: Math.max(0, Math.round(Number(variant.inventory) || 0)) }\n}\n\n/**\n * Whether stock tracking MEANS anything on a product (AGL-1744).\n *\n * `canPurchase` above gates every checkout on stock, subscription sessions\n * included, but nothing ever decrements for a subscription — not on the\n * initial charge (the `commerce-subscription` webhook branch deliberately\n * writes no order and touches no inventory, AGL-1732) and not on renewal\n * (`invoice.payment_succeeded` is unhandled repo-wide, AGL-1743). So on a\n * subscription-only product that gate is permanently satisfied: one unit of\n * stock sells an unlimited number of subscriptions, and the count never\n * moves however many boxes ship. The merchant set a number, the system\n * checks it on every sale, and the number is never true.\n *\n * AGL-1750 resolved the half AGL-1744 had to leave open: every paid invoice\n * of a PHYSICAL subscription now mints an order and decrements its variant's\n * stock (the `invoice.paid` branch of the commerce webhook), opening cycle\n * included. So the honest split is now three-way:\n *\n * - `subscriptionOptional` (\"Both\") products have a real one-time path —\n * the cart only ever builds `mode: 'payment'` sessions, and buy-now with\n * `billing: 'once'` records a plain order — and that path decrements\n * honestly. Withdrawing stock tracking there would delete a working\n * control and re-open the AGL-1711 oversell on the half that works.\n * - a PHYSICAL subscription box consumes a unit every cycle, and since\n * AGL-1750 the cycle's own order decrements it — the count moves as the\n * boxes ship, so the number the merchant sets is kept true again.\n * - a DIGITAL or SERVICE subscription-only product still has no\n * decrementing path anywhere, so the field stays withdrawn there: one\n * unit would still sell unlimited subscriptions.\n *\n * This says nothing about what `canPurchase` returns — that is the gate for\n * every other purchase path and is deliberately untouched. This is a console\n * predicate: it stops the editor inviting a merchant to set a number the\n * system will never keep true.\n */\nexport function stockTrackingApplies(\n product: Pick<HostProduct, 'subscription' | 'subscriptionOptional' | 'type'>,\n): boolean {\n return (\n !product.subscription ||\n product.subscriptionOptional === true ||\n product.type === 'physical'\n )\n}\n\n/** Buyer's requested billing mode on a checkout POST (AGL-545). */\nexport type CheckoutBillingChoice = 'once' | 'subscribe'\n\n/**\n * Resolves the Stripe Checkout mode for a product + the buyer's\n * requested billing choice (AGL-545). The product doc is authoritative:\n * - no `subscription` → always one-time (the request field is ignored)\n * - `subscription` without `subscriptionOptional` → always subscription\n * (a forged `billing: 'once'` cannot buy a subscription product once)\n * - `subscriptionOptional` → the buyer chooses; absent/invalid choices\n * default to one-time, matching the PDP default.\n */\nexport function resolveCheckoutBillingMode(\n product: Pick<HostProduct, 'subscription' | 'subscriptionOptional'>,\n requested?: string | null,\n): 'payment' | 'subscription' {\n if (!product.subscription) return 'payment'\n if (!product.subscriptionOptional) return 'subscription'\n return requested === 'subscribe' ? 'subscription' : 'payment'\n}\n\n/**\n * Applies a stock delta to one variant, flooring at zero (race-window\n * sales can't drive the display negative), and returns the new variants\n * array — callers persist it plus the `productInventory` denormalization.\n * With `locationId`, the delta lands in that location's bucket and the\n * flat `inventory` re-sums across locations (AGL-286).\n */\nexport function adjustVariantInventory(\n product: Pick<HostProduct, 'variants'>,\n variantId: string,\n delta: number,\n locationId?: string,\n): ProductVariant[] {\n return (product.variants ?? []).map((variant) => {\n if (variant.id !== variantId || variant.inventory == null) return variant\n if (locationId && variant.inventoryByLocation) {\n const buckets = {\n ...variant.inventoryByLocation,\n [locationId]: Math.max(\n 0,\n Number(variant.inventoryByLocation[locationId] ?? 0) + delta,\n ),\n }\n return {\n ...variant,\n inventoryByLocation: buckets,\n inventory: Object.values(buckets).reduce(\n (sum, count) => sum + Number(count),\n 0,\n ),\n }\n }\n return {\n ...variant,\n inventory: Math.max(0, Number(variant.inventory) + delta),\n }\n })\n}\n\n/**\n * What `adjustVariantInventory` will ACTUALLY move the count by (AGL-2149).\n *\n * The floor in that helper is not a rounding detail, it is a silent absorber. A\n * backorder product (`oversellPolicy: 'backorder'`, which `canPurchase` admits\n * at any stock level) sitting at 0 sells 3: `Math.max(0, 0 + -3)` is 0, so the\n * count does not move — correctly, since inventory is a shelf count and shelves\n * do not go negative — but the ledger row said `-3` and every reversal read it\n * as three units to put back. Cancelling that order handed the merchant 3 units\n * that never existed and a stock badge that offers them for sale.\n *\n * Removing the floor is not the alternative: every reader of `inventory` — the\n * badges, `canPurchase`, `productInventory`, `isLowStock` — assumes it cannot\n * go negative, and a negative count would be a far wider change than the bug.\n * So the clamp stays and the amount it absorbed is recorded instead.\n *\n * Deliberately mirrors `adjustVariantInventory`'s own arithmetic, including\n * which field the clamp applies to in the location-tracked case, so the two\n * cannot disagree about what happened.\n */\nexport function appliedVariantInventoryDelta(\n product: Pick<HostProduct, 'variants'>,\n variantId: string,\n delta: number,\n locationId?: string,\n): number {\n const variant = (product.variants ?? []).find(\n (item) => item.id === variantId,\n )\n if (!variant || variant.inventory == null) return 0\n if (locationId && variant.inventoryByLocation) {\n const before = Number(variant.inventoryByLocation[locationId] ?? 0)\n return Math.max(0, before + delta) - before\n }\n const before = Number(variant.inventory)\n return Math.max(0, before + delta) - before\n}\n\n/**\n * Moves stock between two locations of a tracked variant (AGL-286).\n * Quantity clamps to what the source location holds; the flat total is\n * unchanged by construction.\n */\nexport function transferVariantInventory(\n product: Pick<HostProduct, 'variants'>,\n variantId: string,\n fromLocationId: string,\n toLocationId: string,\n quantity: number,\n): ProductVariant[] {\n return (product.variants ?? []).map((variant) => {\n if (variant.id !== variantId || variant.inventory == null) return variant\n const buckets = { ...(variant.inventoryByLocation ?? {}) }\n const available = Math.max(0, Number(buckets[fromLocationId] ?? 0))\n const moved = Math.min(available, Math.max(0, Math.round(quantity)))\n if (moved === 0) return variant\n buckets[fromLocationId] = available - moved\n buckets[toLocationId] = Math.max(0, Number(buckets[toLocationId] ?? 0)) + moved\n return { ...variant, inventoryByLocation: buckets }\n })\n}\n\n/** True when tracked stock is at/below the product's alert threshold. */\nexport function isLowStock(\n product: Pick<HostProduct, 'variants' | 'lowStockThreshold'>,\n): boolean {\n const threshold = product.lowStockThreshold\n if (threshold == null || !(threshold >= 0)) return false\n const total = productInventory(product)\n return total != null && total <= threshold\n}\n\nfunction ruleMatches(product: HostProduct, rule: CollectionRule): boolean {\n const value = rule.value\n switch (rule.field) {\n case 'tag': {\n const tags = product.tags ?? []\n const has = tags.includes(String(value))\n return rule.op === 'neq' ? !has : has\n }\n case 'categoryId': {\n const ids = product.categoryIds ?? []\n const has = ids.includes(String(value))\n return rule.op === 'neq' ? !has : has\n }\n case 'priceUsd': {\n const [min, max] = productPriceRange(product)\n const numeric = Number(value)\n if (!Number.isFinite(numeric)) return false\n if (rule.op === 'lt') return min < numeric\n if (rule.op === 'gt') return max > numeric\n if (rule.op === 'neq') return min !== numeric || max !== numeric\n return min <= numeric && numeric <= max\n }\n case 'name': {\n const name = (product.name ?? '').toLowerCase()\n const needle = String(value).toLowerCase()\n if (rule.op === 'contains') return name.includes(needle)\n if (rule.op === 'neq') return name !== needle\n return name === needle\n }\n case 'type': {\n const matches = product.type === value\n return rule.op === 'neq' ? !matches : matches\n }\n default:\n return false\n }\n}\n\n/**\n * Smart-collection membership: draft/archived/deleted products never\n * match; manual collections answer from productIds.\n */\nexport function matchesCollection(\n product: HostProduct,\n collection: HostCollection,\n productId?: string,\n): boolean {\n if (product.deletedAt || product.status !== 'active') return false\n if (collection.mode === 'manual') {\n return productId != null &&\n (collection.productIds ?? []).includes(productId)\n }\n const rules = collection.rules ?? []\n if (rules.length === 0) return false\n const matcher = (rule: CollectionRule) => ruleMatches(product, rule)\n return collection.matchAll === false\n ? rules.some(matcher)\n : rules.every(matcher)\n}\n\n/**\n * Lifts a legacy Commerce Starter doc (AGL-90: flat name/priceUsd/\n * inventory/imageUrl) into the catalog shape with a single default\n * variant. Already-lifted docs pass through unchanged.\n */\nexport function liftLegacyProduct(\n raw: Partial<HostProduct> & { name?: string },\n): HostProduct {\n if (Array.isArray(raw.variants) && raw.variants.length > 0) {\n return raw as HostProduct\n }\n const priceUsd = Number(raw.priceUsd ?? 0)\n return {\n ...raw,\n name: raw.name ?? 'Product',\n slug: raw.slug || commerceSlug(raw.name ?? 'product'),\n type: raw.type ?? 'physical',\n status: raw.status ?? 'active',\n variants: [\n {\n id: 'default',\n priceUsd: Number.isFinite(priceUsd) ? priceUsd : 0,\n inventory: raw.inventory ?? null,\n },\n ],\n }\n}\n\n/** Actionable error, or null when the product is storable. */\nexport function validateProduct(product: HostProduct): string | null {\n if (!product.name?.trim()) return 'Product name is required'\n if (!product.slug || product.slug !== commerceSlug(product.slug)) {\n return 'Slug must be lowercase letters, numbers, and dashes'\n }\n if (!['physical', 'digital', 'service'].includes(product.type)) {\n return 'Unknown product type'\n }\n if (!['draft', 'active', 'archived'].includes(product.status)) {\n return 'Unknown product status'\n }\n const options = product.options ?? []\n if (options.length > COMMERCE_MAX_OPTIONS) {\n return `At most ${COMMERCE_MAX_OPTIONS} options per product`\n }\n for (const option of options) {\n if (!option.name?.trim()) return 'Option names are required'\n if ((option.values?.length ?? 0) === 0) {\n return `Option \"${option.name}\" needs at least one value`\n }\n if (option.values.length > COMMERCE_MAX_OPTION_VALUES) {\n return `Option \"${option.name}\" has too many values`\n }\n if (new Set(option.values).size !== option.values.length) {\n return `Option \"${option.name}\" has duplicate values`\n }\n }\n // A variant keys its selections by option name, so two options with one\n // name cannot both be selected (AGL-3066).\n if (new Set(options.map((option) => option.name.trim())).size !== options.length) {\n return 'Each option needs its own name'\n }\n const variants = product.variants ?? []\n if (variants.length === 0) return 'Products need at least one variant'\n if (variants.length > COMMERCE_MAX_VARIANTS) {\n return `At most ${COMMERCE_MAX_VARIANTS} variants per product`\n }\n const ids = new Set<string>()\n const skus = new Set<string>()\n for (const variant of variants) {\n if (!variant.id) return 'Variants need stable ids'\n if (ids.has(variant.id)) return 'Variant ids must be unique'\n ids.add(variant.id)\n if (variant.priceUsd === undefined || variant.priceUsd === null) {\n return 'Set a price for every variant'\n }\n const price = Number(variant.priceUsd)\n if (!Number.isFinite(price) || price < 0) {\n return 'Variant prices must be zero or more'\n }\n if (price > COMMERCE_MAX_PRICE_USD) {\n return `Prices are capped at $${COMMERCE_MAX_PRICE_USD}`\n }\n if (variant.sku) {\n if (skus.has(variant.sku)) return 'Variant SKUs must be unique'\n skus.add(variant.sku)\n }\n if (\n variant.compareAtPriceUsd != null &&\n Number(variant.compareAtPriceUsd) <= price\n ) {\n return 'Compare-at price must exceed the price'\n }\n }\n return null\n}\n\n/** Actionable error, or null when the collection is storable. */\nexport function validateCollection(collection: HostCollection): string | null {\n if (!collection.name?.trim()) return 'Collection name is required'\n if (\n !collection.slug ||\n collection.slug !== commerceSlug(collection.slug)\n ) {\n return 'Slug must be lowercase letters, numbers, and dashes'\n }\n if (collection.mode !== 'manual' && collection.mode !== 'smart') {\n return 'Unknown collection mode'\n }\n if (collection.mode === 'smart') {\n const rules = collection.rules ?? []\n if (rules.length === 0) return 'Smart collections need at least one rule'\n for (const rule of rules) {\n if (\n !['tag', 'categoryId', 'priceUsd', 'name', 'type'].includes(rule.field)\n ) {\n return 'Unknown rule field'\n }\n if (!['eq', 'neq', 'lt', 'gt', 'contains'].includes(rule.op)) {\n return 'Unknown rule operator'\n }\n if (rule.value === '' || rule.value == null) {\n return 'Rule values are required'\n }\n }\n }\n return null\n}\n"],"names":["nameSearchFields","COMMERCE_MAX_PRICE_USD","registersWithinCap","registers","cap","createdMs","r","createdAt","toMillis","seconds","ranked","sort","a","b","$id","localeCompare","Set","slice","Math","max","map","COMMERCE_MAX_VARIANTS","COMMERCE_MAX_OPTIONS","COMMERCE_MAX_OPTION_VALUES","COMMERCE_SLUG_MAX_LENGTH","commerceSlug","name","String","normalize","replace","toLowerCase","productSearchFields","product","flatten","read","variants","variant","trim","filter","Boolean","skus","sku","barcodes","barcode","length","expandVariantMatrix","options","usable","option","values","combos","next","combo","value","push","renameProductOptions","names","current","index","size","selections","axisOf","optionAxesOf","moved","changed","key","Object","entries","axis","get","undefined","Map","taken","forEach","prototype","hasOwnProperty","call","has","set","add","findIndex","includes","variantHasPrice","price","priceUsd","Number","isFinite","productPriceMissing","some","productCopyPatch","patch","description","Array","isArray","tags","tag","categoryIds","seoTitle","seoDescription","seo","title","optionNames","every","assign","unpricedProductDraft","proposal","takenSlugs","nowMs","base","slug","suffix","seen","id","toString","type","status","createdAtMs","updatedAtMs","findVariant","find","keys","productPriceRange","prices","min","productInventory","total","inventory","canPurchase","variantId","quantity","item","oversellPolicy","stockShortfall","available","round","stockTrackingApplies","subscription","subscriptionOptional","resolveCheckoutBillingMode","requested","adjustVariantInventory","delta","locationId","inventoryByLocation","buckets","reduce","sum","count","appliedVariantInventoryDelta","before","transferVariantInventory","fromLocationId","toLocationId","isLowStock","threshold","lowStockThreshold","ruleMatches","rule","field","op","ids","numeric","needle","matches","matchesCollection","collection","productId","deletedAt","mode","productIds","rules","matcher","matchAll","liftLegacyProduct","raw","validateProduct","compareAtPriceUsd","validateCollection"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,QAAQ,qCAAoC;AAErE;;;;;;;;CAQC,GAED;;;;;;;;;;;;;;;;;CAiBC,GACD,uCAAuC,GACvC,OAAO,MAAMC,yBAAyB,MAAK;AAsD3C;;;;;;CAMC,GACD,OAAO,SAASC,mBACdC,SAAkD,EAClDC,GAAW;IAEX,MAAMC,YAAY,CAACC;YACjBA;YAAAA,uBAAAA,cAA6BA;gBAA7BA,iBAAAA,eAAAA,EAAEC,SAAS,sBAAXD,wBAAAA,aAAaE,QAAQ,qBAArBF,2BAAAA,kCAA6BA,gBAAAA,EAAEC,SAAS,qBAAXD,cAAaG,OAAO,YAAjDH,OAAqD;;IACvD,MAAMI,SAAS;WAAIP;KAAU,CAACQ,IAAI,CAChC,CAACC,GAAGC,IAAMR,UAAUO,KAAKP,UAAUQ,MAAMD,EAAEE,GAAG,CAACC,aAAa,CAACF,EAAEC,GAAG;IAEpE,OAAO,IAAIE,IAAIN,OAAOO,KAAK,CAAC,GAAGC,KAAKC,GAAG,CAAC,GAAGf,MAAMgB,GAAG,CAAC,CAACd,IAAMA,EAAEQ,GAAG;AACnE;AAoIA,kDAAkD,GAClD,OAAO,MAAMO,wBAAwB,IAAG;AACxC,OAAO,MAAMC,uBAAuB,EAAC;AACrC,OAAO,MAAMC,6BAA6B,GAAE;AAC5C,OAAO,MAAMC,2BAA2B,GAAE;AAE1C,kEAAkE,GAClE,OAAO,SAASC,aAAaC,IAAY;IACvC,OAAOC,OAAOD,eAAAA,OAAQ,IACnBE,SAAS,CAAC,QACVC,OAAO,CA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;YACjBH;QAAd,MAAMK,SAAQL,oBAAAA,WAAWK,KAAK,YAAhBL,oBAAoB,EAAE;QACpC,IAAIK,MAAM9H,MAAM,KAAK,GAAG,OAAO;QAC/B,KAAK,MAAMiH,QAAQa,MAAO;YACxB,IACE,CAAC;gBAAC;gBAAO;gBAAc;gBAAY;gBAAQ;aAAO,CAACzF,QAAQ,CAAC4E,KAAKC,KAAK,GACtE;gBACA,OAAO;YACT;YACA,IAAI,CAAC;gBAAC;gBAAM;gBAAO;gBAAM;gBAAM;aAAW,CAAC7E,QAAQ,CAAC4E,KAAKE,EAAE,GAAG;gBAC5D,OAAO;YACT;YACA,IAAIF,KAAKxG,KAAK,KAAK,MAAMwG,KAAKxG,KAAK,IAAI,MAAM;gBAC3C,OAAO;YACT;QACF;IACF;IACA,OAAO;AACT"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Commerce domain model (AGL-411): pure types + logic relocated from the
|
|
19
|
+
* core `@aglyn/aglyn` app-utils — the commerce plugin owns its domain.
|
|
20
|
+
* Context-free and framework-free, so both the plugin's client components
|
|
21
|
+
* and its `/server` handlers (and other plugins/apps via
|
|
22
|
+
* `@aglyn/plugins-commerce/model`) can import it.
|
|
23
|
+
*/
|
|
24
|
+
export * from './commerce';
|
|
25
|
+
export * from './commerce-cart';
|
|
26
|
+
export * from './commerce-connect-transfer';
|
|
27
|
+
export * from './commerce-discounts';
|
|
28
|
+
export * from './commerce-dispute';
|
|
29
|
+
export * from './commerce-gift-cards';
|
|
30
|
+
export * from './commerce-io';
|
|
31
|
+
export * from './commerce-orders';
|
|
32
|
+
export * from './commerce-promotions';
|
|
33
|
+
export * from './commerce-reservations';
|
|
34
|
+
export * from './commerce-shipping';
|
|
35
|
+
export * from './commerce-stock-holds';
|
|
36
|
+
export * from './commerce-subscription-status';
|
|
37
|
+
export * from './commerce-tax';
|
|
38
|
+
export * from './commerce-tax-decision';
|
|
39
|
+
export * from './order-figures';
|
|
40
|
+
export * from './purchase-analytics';
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
* Commerce domain model (AGL-411): pure types + logic relocated from the
|
|
18
|
+
* core `@aglyn/aglyn` app-utils — the commerce plugin owns its domain.
|
|
19
|
+
* Context-free and framework-free, so both the plugin's client components
|
|
20
|
+
* and its `/server` handlers (and other plugins/apps via
|
|
21
|
+
* `@aglyn/plugins-commerce/model`) can import it.
|
|
22
|
+
*/ export * from "./commerce.js";
|
|
23
|
+
export * from "./commerce-cart.js";
|
|
24
|
+
export * from "./commerce-connect-transfer.js";
|
|
25
|
+
export * from "./commerce-discounts.js";
|
|
26
|
+
export * from "./commerce-dispute.js";
|
|
27
|
+
export * from "./commerce-gift-cards.js";
|
|
28
|
+
export * from "./commerce-io.js";
|
|
29
|
+
export * from "./commerce-orders.js";
|
|
30
|
+
export * from "./commerce-promotions.js";
|
|
31
|
+
export * from "./commerce-reservations.js";
|
|
32
|
+
export * from "./commerce-shipping.js";
|
|
33
|
+
export * from "./commerce-stock-holds.js";
|
|
34
|
+
export * from "./commerce-subscription-status.js";
|
|
35
|
+
export * from "./commerce-tax.js";
|
|
36
|
+
export * from "./commerce-tax-decision.js";
|
|
37
|
+
export * from "./order-figures.js";
|
|
38
|
+
export * from "./purchase-analytics.js";
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/index.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\n/**\n * Commerce domain model (AGL-411): pure types + logic relocated from the\n * core `@aglyn/aglyn` app-utils — the commerce plugin owns its domain.\n * Context-free and framework-free, so both the plugin's client components\n * and its `/server` handlers (and other plugins/apps via\n * `@aglyn/plugins-commerce/model`) can import it.\n */\nexport * from './commerce'\nexport * from './commerce-cart'\nexport * from './commerce-connect-transfer'\nexport * from './commerce-discounts'\nexport * from './commerce-dispute'\nexport * from './commerce-gift-cards'\nexport * from './commerce-io'\nexport * from './commerce-orders'\nexport * from './commerce-promotions'\nexport * from './commerce-reservations'\nexport * from './commerce-shipping'\nexport * from './commerce-stock-holds'\nexport * from './commerce-subscription-status'\nexport * from './commerce-tax'\nexport * from './commerce-tax-decision'\nexport * from './order-figures'\nexport * from './purchase-analytics'\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;CAMC,GACD,cAAc,gBAAY;AAC1B,cAAc,qBAAiB;AAC/B,cAAc,iCAA6B;AAC3C,cAAc,0BAAsB;AACpC,cAAc,wBAAoB;AAClC,cAAc,2BAAuB;AACrC,cAAc,mBAAe;AAC7B,cAAc,uBAAmB;AACjC,cAAc,2BAAuB;AACrC,cAAc,6BAAyB;AACvC,cAAc,yBAAqB;AACnC,cAAc,4BAAwB;AACtC,cAAc,oCAAgC;AAC9C,cAAc,oBAAgB;AAC9B,cAAc,6BAAyB;AACvC,cAAc,qBAAiB;AAC/B,cAAc,0BAAsB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Which orders are money, and how much each is (AGL-327, AGL-2915).
|
|
19
|
+
*
|
|
20
|
+
* The rules the Analytics tab's card and the insight readers both sum by, in
|
|
21
|
+
* one place: a pending or canceled order is not money, a rehearsal checkout is
|
|
22
|
+
* not revenue, and a refund comes off what an order brought in.
|
|
23
|
+
*/
|
|
24
|
+
/** An order as a figure reads it: the stored document with its id. */
|
|
25
|
+
export type OrderFigureSource = Record<string, unknown> & {
|
|
26
|
+
$id?: string;
|
|
27
|
+
createdAtMs?: number;
|
|
28
|
+
};
|
|
29
|
+
/** Whether an order counts toward sales figures at all. */
|
|
30
|
+
export declare function orderCountsAsSale(order: OrderFigureSource): boolean;
|
|
31
|
+
/** What an order brought in, in cents: its total less what was refunded. */
|
|
32
|
+
export declare function orderPaidCents(order: OrderFigureSource): number;
|
|
33
|
+
export interface OrderWindowFigures {
|
|
34
|
+
orders: number;
|
|
35
|
+
revenueCents: number;
|
|
36
|
+
/** Revenue over orders, rounded to the cent; 0 with no orders. */
|
|
37
|
+
averageCents: number;
|
|
38
|
+
}
|
|
39
|
+
/** The sales figures of the orders placed in `[startMs, endMs)`. */
|
|
40
|
+
export declare function orderWindowFigures(orders: readonly OrderFigureSource[], startMs: number, endMs: number): OrderWindowFigures;
|
|
41
|
+
export interface ProductSales {
|
|
42
|
+
productId: string;
|
|
43
|
+
name: string;
|
|
44
|
+
units: number;
|
|
45
|
+
cents: number;
|
|
46
|
+
}
|
|
47
|
+
/** Each product's units and line revenue across counted orders, largest revenue first. */
|
|
48
|
+
export declare function productSales(orders: readonly OrderFigureSource[]): ProductSales[];
|
|
@@ -0,0 +1,74 @@
|
|
|
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 { liftLegacyOrder, orderIsTestMode } from "./commerce-orders.js";
|
|
18
|
+
/** Whether an order counts toward sales figures at all. */ export function orderCountsAsSale(order) {
|
|
19
|
+
var _lifted_status;
|
|
20
|
+
const lifted = liftLegacyOrder(order);
|
|
21
|
+
return ![
|
|
22
|
+
'pending',
|
|
23
|
+
'cancelled'
|
|
24
|
+
].includes(String((_lifted_status = lifted['status']) != null ? _lifted_status : '')) && !orderIsTestMode(_extends({}, lifted, {
|
|
25
|
+
$id: order.$id
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
/** What an order brought in, in cents: its total less what was refunded. */ export function orderPaidCents(order) {
|
|
29
|
+
var _ref, _ref1, _lifted_refundedCents;
|
|
30
|
+
var _lifted_totals;
|
|
31
|
+
const lifted = liftLegacyOrder(order);
|
|
32
|
+
return ((_ref = (_ref1 = (_lifted_totals = lifted.totals) == null ? void 0 : _lifted_totals.totalCents) != null ? _ref1 : lifted.amountCents) != null ? _ref : 0) - ((_lifted_refundedCents = lifted.refundedCents) != null ? _lifted_refundedCents : 0);
|
|
33
|
+
}
|
|
34
|
+
/** The sales figures of the orders placed in `[startMs, endMs)`. */ export function orderWindowFigures(orders, startMs, endMs) {
|
|
35
|
+
const counted = orders.filter((order)=>{
|
|
36
|
+
const at = Number(order.createdAtMs);
|
|
37
|
+
return Number.isFinite(at) && at >= startMs && at < endMs && orderCountsAsSale(order);
|
|
38
|
+
});
|
|
39
|
+
const revenueCents = counted.reduce((sum, order)=>sum + orderPaidCents(order), 0);
|
|
40
|
+
return {
|
|
41
|
+
orders: counted.length,
|
|
42
|
+
revenueCents,
|
|
43
|
+
averageCents: counted.length ? Math.round(revenueCents / counted.length) : 0
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Each product's units and line revenue across counted orders, largest revenue first. */ export function productSales(orders) {
|
|
47
|
+
const byProduct = new Map();
|
|
48
|
+
for (const order of orders){
|
|
49
|
+
var _order_lineItems;
|
|
50
|
+
if (!orderCountsAsSale(order)) continue;
|
|
51
|
+
const lines = (_order_lineItems = order['lineItems']) != null ? _order_lineItems : [];
|
|
52
|
+
for (const line of lines){
|
|
53
|
+
var _line_productId, _line_quantity, _line_unitAmountCents, _byProduct_get, _line_name;
|
|
54
|
+
const productId = String((_line_productId = line['productId']) != null ? _line_productId : '');
|
|
55
|
+
if (!productId) continue;
|
|
56
|
+
const quantity = Number((_line_quantity = line['quantity']) != null ? _line_quantity : 0);
|
|
57
|
+
const unit = Number((_line_unitAmountCents = line['unitAmountCents']) != null ? _line_unitAmountCents : 0);
|
|
58
|
+
const entry = (_byProduct_get = byProduct.get(productId)) != null ? _byProduct_get : {
|
|
59
|
+
productId,
|
|
60
|
+
name: String((_line_name = line['name']) != null ? _line_name : productId),
|
|
61
|
+
units: 0,
|
|
62
|
+
cents: 0
|
|
63
|
+
};
|
|
64
|
+
entry.units += Number.isFinite(quantity) ? quantity : 0;
|
|
65
|
+
entry.cents += Number.isFinite(unit) && Number.isFinite(quantity) ? unit * quantity : 0;
|
|
66
|
+
byProduct.set(productId, entry);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return [
|
|
70
|
+
...byProduct.values()
|
|
71
|
+
].sort((a, b)=>b.cents - a.cents || a.name.localeCompare(b.name));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=order-figures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/order-figures.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 { liftLegacyOrder, orderIsTestMode } from './commerce-orders'\n\n/**\n * Which orders are money, and how much each is (AGL-327, AGL-2915).\n *\n * The rules the Analytics tab's card and the insight readers both sum by, in\n * one place: a pending or canceled order is not money, a rehearsal checkout is\n * not revenue, and a refund comes off what an order brought in.\n */\n\n/** An order as a figure reads it: the stored document with its id. */\nexport type OrderFigureSource = Record<string, unknown> & { $id?: string; createdAtMs?: number }\n\n/** Whether an order counts toward sales figures at all. */\nexport function orderCountsAsSale(order: OrderFigureSource): boolean {\n const lifted = liftLegacyOrder(order as never) as unknown as Record<string, unknown>\n return (\n !['pending', 'cancelled'].includes(String(lifted['status'] ?? '')) &&\n !orderIsTestMode({ ...lifted, $id: order.$id } as never)\n )\n}\n\n/** What an order brought in, in cents: its total less what was refunded. */\nexport function orderPaidCents(order: OrderFigureSource): number {\n const lifted = liftLegacyOrder(order as never) as unknown as {\n totals?: { totalCents?: number }\n amountCents?: number\n refundedCents?: number\n }\n return (lifted.totals?.totalCents ?? lifted.amountCents ?? 0) - (lifted.refundedCents ?? 0)\n}\n\nexport interface OrderWindowFigures {\n orders: number\n revenueCents: number\n /** Revenue over orders, rounded to the cent; 0 with no orders. */\n averageCents: number\n}\n\n/** The sales figures of the orders placed in `[startMs, endMs)`. */\nexport function orderWindowFigures(\n orders: readonly OrderFigureSource[],\n startMs: number,\n endMs: number,\n): OrderWindowFigures {\n const counted = orders.filter((order) => {\n const at = Number(order.createdAtMs)\n return Number.isFinite(at) && at >= startMs && at < endMs && orderCountsAsSale(order)\n })\n const revenueCents = counted.reduce((sum, order) => sum + orderPaidCents(order), 0)\n return {\n orders: counted.length,\n revenueCents,\n averageCents: counted.length ? Math.round(revenueCents / counted.length) : 0,\n }\n}\n\nexport interface ProductSales {\n productId: string\n name: string\n units: number\n cents: number\n}\n\n/** Each product's units and line revenue across counted orders, largest revenue first. */\nexport function productSales(orders: readonly OrderFigureSource[]): ProductSales[] {\n const byProduct = new Map<string, ProductSales>()\n for (const order of orders) {\n if (!orderCountsAsSale(order)) continue\n const lines = (order['lineItems'] ?? []) as Array<Record<string, unknown>>\n for (const line of lines) {\n const productId = String(line['productId'] ?? '')\n if (!productId) continue\n const quantity = Number(line['quantity'] ?? 0)\n const unit = Number(line['unitAmountCents'] ?? 0)\n const entry = byProduct.get(productId) ?? {\n productId,\n name: String(line['name'] ?? productId),\n units: 0,\n cents: 0,\n }\n entry.units += Number.isFinite(quantity) ? quantity : 0\n entry.cents += Number.isFinite(unit) && Number.isFinite(quantity) ? unit * quantity : 0\n byProduct.set(productId, entry)\n }\n }\n return [...byProduct.values()].sort((a, b) => b.cents - a.cents || a.name.localeCompare(b.name))\n}\n"],"names":["liftLegacyOrder","orderIsTestMode","orderCountsAsSale","order","lifted","includes","String","$id","orderPaidCents","totals","totalCents","amountCents","refundedCents","orderWindowFigures","orders","startMs","endMs","counted","filter","at","Number","createdAtMs","isFinite","revenueCents","reduce","sum","length","averageCents","Math","round","productSales","byProduct","Map","lines","line","productId","quantity","unit","entry","get","name","units","cents","set","values","sort","a","b","localeCompare"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,eAAe,EAAEC,eAAe,QAAQ,uBAAmB;AAapE,yDAAyD,GACzD,OAAO,SAASC,kBAAkBC,KAAwB;QAGZC;IAF5C,MAAMA,SAASJ,gBAAgBG;IAC/B,OACE,CAAC;QAAC;QAAW;KAAY,CAACE,QAAQ,CAACC,QAAOF,iBAAAA,MAAM,CAAC,SAAS,YAAhBA,iBAAoB,QAC9D,CAACH,gBAAgB,aAAKG;QAAQG,KAAKJ,MAAMI,GAAG;;AAEhD;AAEA,0EAA0E,GAC1E,OAAO,SAASC,eAAeL,KAAwB;QAM7CC,aAAyDA;QAAzDA;IALR,MAAMA,SAASJ,gB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AAdJ,iBAA4B;gBACxCI;gBACAK,MAAMlC,QAAO4B,aAAAA,IAAI,CAAC,OAAO,YAAZA,aAAgBC;gBAC7BM,OAAO;gBACPC,OAAO;YACT;YACAJ,MAAMG,KAAK,IAAIrB,OAAOE,QAAQ,CAACc,YAAYA,WAAW;YACtDE,MAAMI,KAAK,IAAItB,OAAOE,QAAQ,CAACe,SAASjB,OAAOE,QAAQ,CAACc,YAAYC,OAAOD,WAAW;YACtFL,UAAUY,GAAG,CAACR,WAAWG;QAC3B;IACF;IACA,OAAO;WAAIP,UAAUa,MAAM;KAAG,CAACC,IAAI,CAAC,CAACC,GAAGC,IAAMA,EAAEL,KAAK,GAAGI,EAAEJ,KAAK,IAAII,EAAEN,IAAI,CAACQ,aAAa,CAACD,EAAEP,IAAI;AAChG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { PluginPermission } from '@aglyn/aglyn';
|
|
18
|
+
/**
|
|
19
|
+
* Commerce's plugin-declared permissions (AGL-435) — the reference
|
|
20
|
+
* adopter. Pure data: the client barrel and /server entry both register
|
|
21
|
+
* it, so console gating and API-side resolution agree.
|
|
22
|
+
*/
|
|
23
|
+
export declare const COMMERCE_PERMISSIONS: readonly PluginPermission[];
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
* Commerce's plugin-declared permissions (AGL-435) — the reference
|
|
18
|
+
* adopter. Pure data: the client barrel and /server entry both register
|
|
19
|
+
* it, so console gating and API-side resolution agree.
|
|
20
|
+
*/ export const COMMERCE_PERMISSIONS = [
|
|
21
|
+
{
|
|
22
|
+
key: 'managePos',
|
|
23
|
+
pluginId: 'commerce',
|
|
24
|
+
label: 'Use the point of sale',
|
|
25
|
+
description: 'Open the POS page and record in-person sales.',
|
|
26
|
+
defaults: {
|
|
27
|
+
admin: true,
|
|
28
|
+
editor: true,
|
|
29
|
+
viewer: false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=plugin-permissions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/plugin-permissions.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { PluginPermission } from '@aglyn/aglyn'\n\n/**\n * Commerce's plugin-declared permissions (AGL-435) — the reference\n * adopter. Pure data: the client barrel and /server entry both register\n * it, so console gating and API-side resolution agree.\n */\nexport const COMMERCE_PERMISSIONS: readonly PluginPermission[] = [\n {\n key: 'managePos',\n pluginId: 'commerce',\n label: 'Use the point of sale',\n description: 'Open the POS page and record in-person sales.',\n defaults: { admin: true, editor: true, viewer: false },\n },\n]\n"],"names":["COMMERCE_PERMISSIONS","key","pluginId","label","description","defaults","admin","editor","viewer"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAID;;;;CAIC,GACD,OAAO,MAAMA,uBAAoD;IAC/D;QACEC,KAAK;QACLC,UAAU;QACVC,OAAO;QACPC,aAAa;QACbC,UAAU;YAAEC,OAAO;YAAMC,QAAQ;YAAMC,QAAQ;QAAM;IACvD;CACD,CAAA"}
|
|
@@ -0,0 +1,186 @@
|
|
|
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 { AnalyticsEventParams } from '@aglyn/aglyn/app-utils/analytics-events';
|
|
18
|
+
import type { HostOrder } from './commerce-orders';
|
|
19
|
+
/**
|
|
20
|
+
* The GA-safe projection of a storefront order (AGL-1641). Deliberately NOT
|
|
21
|
+
* `HostOrder`: this shape crosses the wire to a shopper's browser, so it can
|
|
22
|
+
* only ever hold what a `purchase` event needs. `customerEmail`,
|
|
23
|
+
* `customerName`, `shippingAddress` and `billingAddress` are absent by
|
|
24
|
+
* construction rather than by a `delete` somebody has to remember.
|
|
25
|
+
*/
|
|
26
|
+
export interface StorefrontPurchaseSource {
|
|
27
|
+
/** Stripe Checkout Session id — also the order doc id. */
|
|
28
|
+
transactionId: string;
|
|
29
|
+
totalCents: number;
|
|
30
|
+
taxCents: number;
|
|
31
|
+
/**
|
|
32
|
+
* Stripe's `total_details.amount_shipping` as the webhook stored it — or
|
|
33
|
+
* `shipping_cost.amount_total` on a subscription invoice, which has no
|
|
34
|
+
* `total_details`. Reported as GA4's `shipping`, NOT subtracted from
|
|
35
|
+
* `value`: it is part of what the merchant sold.
|
|
36
|
+
*/
|
|
37
|
+
shippingCents: number;
|
|
38
|
+
lineItems: {
|
|
39
|
+
productId: string;
|
|
40
|
+
name: string;
|
|
41
|
+
quantity: number;
|
|
42
|
+
unitAmountCents: number;
|
|
43
|
+
}[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build the `purchase` a TENANT STOREFRONT reports to the MERCHANT's GA4
|
|
47
|
+
* property (AGL-1641).
|
|
48
|
+
*
|
|
49
|
+
* ## Whose revenue this is — the decision, not an inference
|
|
50
|
+
*
|
|
51
|
+
* This is the exact inverse of the marketplace call in AGL-1639, and the
|
|
52
|
+
* reason is the property the hit lands in. There, the GA property is OURS, the
|
|
53
|
+
* platform fee IS what Aglyn was paid, and `value` had to be platform net so
|
|
54
|
+
* that a marketplace sale and a subscription meant the same thing when GA
|
|
55
|
+
* added them up. Here the property is the MERCHANT's — `gtag` on a tenant site
|
|
56
|
+
* is loaded with `host.analytics.gaMeasurementId`, their measurement id — and
|
|
57
|
+
* on their storefront the merchant is the seller. Aglyn's cut is not a share
|
|
58
|
+
* of this sale from their side; it is a cost of making it.
|
|
59
|
+
*
|
|
60
|
+
* So `feeCents` is NOT subtracted. Subtracting it would report the merchant's
|
|
61
|
+
* gross margin after our fee as though it were their sales revenue, which is
|
|
62
|
+
* not a number any merchant's books, tax return or ad platform recognises.
|
|
63
|
+
*
|
|
64
|
+
* Getting this backwards is the expensive mistake: reporting platform net into
|
|
65
|
+
* a merchant's property would show every merchant on Aglyn a revenue figure a
|
|
66
|
+
* few percent of their real one.
|
|
67
|
+
*
|
|
68
|
+
* ## Tax is excluded, and no `tax` param is sent
|
|
69
|
+
*
|
|
70
|
+
* Tax collected is money held for a taxing authority, not revenue, whoever
|
|
71
|
+
* holds it — and on a storefront that is often Aglyn rather than the merchant,
|
|
72
|
+
* since Terms §10.7 makes Aglyn a marketplace facilitator where applicable law
|
|
73
|
+
* gives it a collection obligation (AGL-1956). Either way it is not the
|
|
74
|
+
* merchant's sales revenue. Every mature ecommerce integration reports revenue
|
|
75
|
+
* ex-tax and so do we.
|
|
76
|
+
*
|
|
77
|
+
* No GA4 `tax` param either, following AGL-1639 for the same reason it applied
|
|
78
|
+
* there: `value` already EXCLUDES tax, and GA4's `tax` is documented as a cost
|
|
79
|
+
* associated with the transaction — a component of the value beside it. Sent
|
|
80
|
+
* next to an ex-tax `value` it asserts a relationship that does not hold, and
|
|
81
|
+
* invites exactly the subtraction that would double-remove it.
|
|
82
|
+
*
|
|
83
|
+
* ## Why `value` derives from `totalCents` and not from the parts
|
|
84
|
+
*
|
|
85
|
+
* `totalCents` is overwritten with Stripe's `amount_total` when the webhook
|
|
86
|
+
* writes the order (`billing-webhook.ts`), so it is the one field that
|
|
87
|
+
* reconciles with Stripe by construction: it is Stripe's own number, verbatim.
|
|
88
|
+
*
|
|
89
|
+
* `taxCents` was described here as likewise `total_details.amount_tax`, Stripe's
|
|
90
|
+
* own. On the cart path it is. On the BUY-NOW path it was 0 on every order,
|
|
91
|
+
* because `checkout.ts` sends manual destination tax as an ordinary
|
|
92
|
+
* `line_items[1]` product line that Stripe never classifies as tax — so this
|
|
93
|
+
* `value` reported tax-inclusive gross into the merchant's property, the
|
|
94
|
+
* AGL-1639 overstatement, live. AGL-1711 composes the stored `taxCents` from
|
|
95
|
+
* `amount_tax` plus that line-item tax, and fixes `quantity` and
|
|
96
|
+
* `unitAmountCents` (hardcoded to 1 and to the whole charge) in the same place.
|
|
97
|
+
* Nothing here changed: the three fields this reads are simply true now.
|
|
98
|
+
*
|
|
99
|
+
* The parts used NOT to reconcile, and that is why this derivation exists.
|
|
100
|
+
* `computeOrderTotals` was called with `feeCents`, `taxCents` and
|
|
101
|
+
* `discountCents` but **never `shippingCents`**, so a stored `OrderTotals`
|
|
102
|
+
* recorded `shippingCents: 0` on every online order while the shipping the
|
|
103
|
+
* shopper paid sat inside `amount_total`. Building `value` from
|
|
104
|
+
* `itemsCents + shippingCents - discountCents` would therefore have silently
|
|
105
|
+
* dropped all shipping revenue, understating orders that carried it and
|
|
106
|
+
* leaving orders that did not looking correct. Same failure shape as the
|
|
107
|
+
* AGL-1639 overstatement, opposite sign.
|
|
108
|
+
*
|
|
109
|
+
* AGL-1698 fixed the storage — `computeCheckoutSessionTotals` passes
|
|
110
|
+
* `total_details.amount_shipping`, and the parts now sum to the total. The
|
|
111
|
+
* derivation stays on `totalCents` anyway, for a reason that outlives the bug:
|
|
112
|
+
* `totalCents` is Stripe's `amount_total` verbatim, whereas `itemsCents` is
|
|
113
|
+
* priced from the host's product docs, so a price edit between session
|
|
114
|
+
* creation and webhook delivery would make our sum disagree with the charge.
|
|
115
|
+
*
|
|
116
|
+
* ## A GA4 `shipping` param IS sent — and a `tax` one still is not
|
|
117
|
+
*
|
|
118
|
+
* These two look like an inconsistency and are not. Do not tidy them into
|
|
119
|
+
* agreement in either direction (AGL-1722).
|
|
120
|
+
*
|
|
121
|
+
* `shipping` is a COMPONENT of the `value` reported beside it: `value` is
|
|
122
|
+
* `totalCents - taxCents`, and the shipping the shopper paid is inside that
|
|
123
|
+
* number. GA4's `shipping` is documented as exactly that — shipping charged
|
|
124
|
+
* ON the transaction — so sending it decomposes the value rather than
|
|
125
|
+
* contradicting it, and a merchant can read "of the $105 you sold, $10 was
|
|
126
|
+
* shipping" without any figure being counted twice.
|
|
127
|
+
*
|
|
128
|
+
* `tax` is the opposite: `value` already EXCLUDES it. Sending a `tax` beside
|
|
129
|
+
* an ex-tax `value` asserts a relationship that does not hold and invites the
|
|
130
|
+
* subtraction that removes tax a second time. AGL-1639 and AGL-1641 both
|
|
131
|
+
* declined it for that reason and this change does not disturb them.
|
|
132
|
+
*
|
|
133
|
+
* The param was withheld until now for a truthfulness reason that has since
|
|
134
|
+
* expired twice. AGL-1641 left it out because the stored `shippingCents` was
|
|
135
|
+
* structurally 0 — sending it would have asserted FREE SHIPPING on every
|
|
136
|
+
* order rather than saying nothing. AGL-1698 fixed the storage but the Stripe
|
|
137
|
+
* figure was still structurally 0, because no Checkout Session we created
|
|
138
|
+
* declared `shipping_options`. AGL-1707 wired the merchant's configured zones
|
|
139
|
+
* and rates into the cart session and AGL-1720 into the buy-now one, so
|
|
140
|
+
* `amount_shipping` is a real number on both storefront paths for a merchant
|
|
141
|
+
* who set shipping up. Only the plumbing was left, and it is built here:
|
|
142
|
+
* `shippingCents` rides `StorefrontPurchaseSource` to the wire shape.
|
|
143
|
+
*
|
|
144
|
+
* A 0 now means what it says. A download ships nothing, a merchant who saved
|
|
145
|
+
* no rates charges nothing, and POS and draft orders resolve no shipping — on
|
|
146
|
+
* all of those `shipping: 0` is a true statement about that order, not the old
|
|
147
|
+
* structural zero, so it is sent rather than omitted. Omitting it would leave
|
|
148
|
+
* the merchant's shipping column sparse for a reason GA cannot tell apart from
|
|
149
|
+
* "not tracked".
|
|
150
|
+
*
|
|
151
|
+
* ## Worked example — the spec fixture
|
|
152
|
+
*
|
|
153
|
+
* A $100 item, a $5 coupon, $10 shipping chosen at Stripe Checkout, $9.08 tax,
|
|
154
|
+
* and a 5% Aglyn fee:
|
|
155
|
+
*
|
|
156
|
+
* itemsCents 10000 line snapshot
|
|
157
|
+
* - discountCents 500 Stripe `total_details.amount_discount`
|
|
158
|
+
* + shippingCents 1000 Stripe `total_details.amount_shipping`
|
|
159
|
+
* + taxCents 908 Stripe `total_details.amount_tax`
|
|
160
|
+
* = totalCents 11408 Stripe `amount_total`, verbatim
|
|
161
|
+
* - taxCents - 908 held for the state, not revenue
|
|
162
|
+
* = GA `value` 10500 sent as 105.00 (goods 95.00 + shipping 10.00)
|
|
163
|
+
* GA `shipping` 1000 sent as 10.00 — INSIDE the 105.00 above, a
|
|
164
|
+
* decomposition of it and not an addition
|
|
165
|
+
* GA `tax` — not sent; `value` is already ex-tax
|
|
166
|
+
*
|
|
167
|
+
* feeCents 475 Aglyn's cut — NOT subtracted; the merchant's
|
|
168
|
+
* cost of sale, and our revenue is reported in
|
|
169
|
+
* OUR property by the subscription/marketplace
|
|
170
|
+
* `purchase`, not by this one.
|
|
171
|
+
*
|
|
172
|
+
* Before AGL-1698 the stored parts summed to 10408, not 11408: the 1000 gap was
|
|
173
|
+
* the shipping, and it is exactly what a parts-based `value` would have lost.
|
|
174
|
+
* They reconcile now, which `commerce-orders.spec.ts` pins; the guard below
|
|
175
|
+
* survives as a guard, since the derivation must not drift back to the parts.
|
|
176
|
+
*
|
|
177
|
+
* Returns `null` when there is nothing truthful to send — no transaction id,
|
|
178
|
+
* or a non-positive value. A dropped event is a gap in the merchant's report;
|
|
179
|
+
* a fabricated one is a wrong number in it, and the second is worse.
|
|
180
|
+
*/
|
|
181
|
+
export declare function buildStorefrontPurchaseParams(source: StorefrontPurchaseSource): AnalyticsEventParams['purchase'] | null;
|
|
182
|
+
/**
|
|
183
|
+
* Reduce a stored order to the wire shape above. Server-side only — it reads
|
|
184
|
+
* fields the projection exists to withhold.
|
|
185
|
+
*/
|
|
186
|
+
export declare function toStorefrontPurchaseSource(transactionId: string, order: Pick<HostOrder, 'totals' | 'lineItems'>): StorefrontPurchaseSource;
|