@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.
Files changed (417) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +10 -0
  3. package/package.json +57 -0
  4. package/src/index.d.ts +38 -0
  5. package/src/index.js +38 -0
  6. package/src/index.js.map +1 -0
  7. package/src/lib/components/account.d.ts +31 -0
  8. package/src/lib/components/account.js +645 -0
  9. package/src/lib/components/account.js.map +1 -0
  10. package/src/lib/components/cart.d.ts +38 -0
  11. package/src/lib/components/cart.js +851 -0
  12. package/src/lib/components/cart.js.map +1 -0
  13. package/src/lib/components/commerce-console-page.d.ts +32 -0
  14. package/src/lib/components/commerce-console-page.js +296 -0
  15. package/src/lib/components/commerce-console-page.js.map +1 -0
  16. package/src/lib/components/commerce-console-sections.d.ts +34 -0
  17. package/src/lib/components/commerce-console-sections.js +62 -0
  18. package/src/lib/components/commerce-console-sections.js.map +1 -0
  19. package/src/lib/components/console/catalog-organization-card.component.d.ts +14 -0
  20. package/src/lib/components/console/catalog-organization-card.component.js +1087 -0
  21. package/src/lib/components/console/catalog-organization-card.component.js.map +1 -0
  22. package/src/lib/components/console/commerce-analytics-card.component.d.ts +27 -0
  23. package/src/lib/components/console/commerce-analytics-card.component.js +310 -0
  24. package/src/lib/components/console/commerce-analytics-card.component.js.map +1 -0
  25. package/src/lib/components/console/commerce-glance-card.component.d.ts +20 -0
  26. package/src/lib/components/console/commerce-glance-card.component.js +340 -0
  27. package/src/lib/components/console/commerce-glance-card.component.js.map +1 -0
  28. package/src/lib/components/console/commerce-stat-tile.component.d.ts +37 -0
  29. package/src/lib/components/console/commerce-stat-tile.component.js +72 -0
  30. package/src/lib/components/console/commerce-stat-tile.component.js.map +1 -0
  31. package/src/lib/components/console/discounts-card.component.d.ts +14 -0
  32. package/src/lib/components/console/discounts-card.component.js +443 -0
  33. package/src/lib/components/console/discounts-card.component.js.map +1 -0
  34. package/src/lib/components/console/entitlement-gate.component.d.ts +76 -0
  35. package/src/lib/components/console/entitlement-gate.component.js +115 -0
  36. package/src/lib/components/console/entitlement-gate.component.js.map +1 -0
  37. package/src/lib/components/console/gift-cards-card.component.d.ts +29 -0
  38. package/src/lib/components/console/gift-cards-card.component.js +379 -0
  39. package/src/lib/components/console/gift-cards-card.component.js.map +1 -0
  40. package/src/lib/components/console/host-coupons-card.component.d.ts +14 -0
  41. package/src/lib/components/console/host-coupons-card.component.js +252 -0
  42. package/src/lib/components/console/host-coupons-card.component.js.map +1 -0
  43. package/src/lib/components/console/host-orders-card.component.d.ts +13 -0
  44. package/src/lib/components/console/host-orders-card.component.js +861 -0
  45. package/src/lib/components/console/host-orders-card.component.js.map +1 -0
  46. package/src/lib/components/console/locations-card.component.d.ts +14 -0
  47. package/src/lib/components/console/locations-card.component.js +256 -0
  48. package/src/lib/components/console/locations-card.component.js.map +1 -0
  49. package/src/lib/components/console/member-posts-card.component.d.ts +8 -0
  50. package/src/lib/components/console/member-posts-card.component.js +283 -0
  51. package/src/lib/components/console/member-posts-card.component.js.map +1 -0
  52. package/src/lib/components/console/newest-site-users-card.component.d.ts +36 -0
  53. package/src/lib/components/console/newest-site-users-card.component.js +126 -0
  54. package/src/lib/components/console/newest-site-users-card.component.js.map +1 -0
  55. package/src/lib/components/console/order-detail-dialog.component.d.ts +28 -0
  56. package/src/lib/components/console/order-detail-dialog.component.js +976 -0
  57. package/src/lib/components/console/order-detail-dialog.component.js.map +1 -0
  58. package/src/lib/components/console/paid-media.d.ts +127 -0
  59. package/src/lib/components/console/paid-media.js +397 -0
  60. package/src/lib/components/console/paid-media.js.map +1 -0
  61. package/src/lib/components/console/payments-settings-card.component.d.ts +13 -0
  62. package/src/lib/components/console/payments-settings-card.component.js +295 -0
  63. package/src/lib/components/console/payments-settings-card.component.js.map +1 -0
  64. package/src/lib/components/console/pos-page.component.d.ts +13 -0
  65. package/src/lib/components/console/pos-page.component.js +916 -0
  66. package/src/lib/components/console/pos-page.component.js.map +1 -0
  67. package/src/lib/components/console/product-editor-dialog.component.d.ts +32 -0
  68. package/src/lib/components/console/product-editor-dialog.component.js +1374 -0
  69. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -0
  70. package/src/lib/components/console/products-hub-card.component.d.ts +16 -0
  71. package/src/lib/components/console/products-hub-card.component.js +1280 -0
  72. package/src/lib/components/console/products-hub-card.component.js.map +1 -0
  73. package/src/lib/components/console/products-hub-zone.component.d.ts +50 -0
  74. package/src/lib/components/console/products-hub-zone.component.js +200 -0
  75. package/src/lib/components/console/products-hub-zone.component.js.map +1 -0
  76. package/src/lib/components/console/recovery-queue-card.component.d.ts +39 -0
  77. package/src/lib/components/console/recovery-queue-card.component.js +262 -0
  78. package/src/lib/components/console/recovery-queue-card.component.js.map +1 -0
  79. package/src/lib/components/console/registers-card.component.d.ts +21 -0
  80. package/src/lib/components/console/registers-card.component.js +296 -0
  81. package/src/lib/components/console/registers-card.component.js.map +1 -0
  82. package/src/lib/components/console/reservations-card.component.d.ts +14 -0
  83. package/src/lib/components/console/reservations-card.component.js +650 -0
  84. package/src/lib/components/console/reservations-card.component.js.map +1 -0
  85. package/src/lib/components/console/reviews-moderation-card.component.d.ts +8 -0
  86. package/src/lib/components/console/reviews-moderation-card.component.js +235 -0
  87. package/src/lib/components/console/reviews-moderation-card.component.js.map +1 -0
  88. package/src/lib/components/console/shipping-settings-card.component.d.ts +38 -0
  89. package/src/lib/components/console/shipping-settings-card.component.js +560 -0
  90. package/src/lib/components/console/shipping-settings-card.component.js.map +1 -0
  91. package/src/lib/components/console/stock-movements-card.component.d.ts +31 -0
  92. package/src/lib/components/console/stock-movements-card.component.js +333 -0
  93. package/src/lib/components/console/stock-movements-card.component.js.map +1 -0
  94. package/src/lib/components/console/store-settings-card.component.d.ts +14 -0
  95. package/src/lib/components/console/store-settings-card.component.js +300 -0
  96. package/src/lib/components/console/store-settings-card.component.js.map +1 -0
  97. package/src/lib/components/console/storefront-tax-summary-card.component.d.ts +73 -0
  98. package/src/lib/components/console/storefront-tax-summary-card.component.js +408 -0
  99. package/src/lib/components/console/storefront-tax-summary-card.component.js.map +1 -0
  100. package/src/lib/components/console/suppliers-card.component.d.ts +8 -0
  101. package/src/lib/components/console/suppliers-card.component.js +328 -0
  102. package/src/lib/components/console/suppliers-card.component.js.map +1 -0
  103. package/src/lib/components/console/tax-settings-card.component.d.ts +14 -0
  104. package/src/lib/components/console/tax-settings-card.component.js +473 -0
  105. package/src/lib/components/console/tax-settings-card.component.js.map +1 -0
  106. package/src/lib/components/gate.d.ts +39 -0
  107. package/src/lib/components/gate.js +202 -0
  108. package/src/lib/components/gate.js.map +1 -0
  109. package/src/lib/components/gated-video.d.ts +40 -0
  110. package/src/lib/components/gated-video.js +366 -0
  111. package/src/lib/components/gated-video.js.map +1 -0
  112. package/src/lib/components/member-feed.d.ts +32 -0
  113. package/src/lib/components/member-feed.js +198 -0
  114. package/src/lib/components/member-feed.js.map +1 -0
  115. package/src/lib/components/member-recovery.d.ts +35 -0
  116. package/src/lib/components/member-recovery.js +313 -0
  117. package/src/lib/components/member-recovery.js.map +1 -0
  118. package/src/lib/components/member-signin.d.ts +35 -0
  119. package/src/lib/components/member-signin.js +257 -0
  120. package/src/lib/components/member-signin.js.map +1 -0
  121. package/src/lib/components/member-signup.d.ts +34 -0
  122. package/src/lib/components/member-signup.js +287 -0
  123. package/src/lib/components/member-signup.js.map +1 -0
  124. package/src/lib/components/newsletter-signup.d.ts +39 -0
  125. package/src/lib/components/newsletter-signup.js +229 -0
  126. package/src/lib/components/newsletter-signup.js.map +1 -0
  127. package/src/lib/components/product-detail.d.ts +38 -0
  128. package/src/lib/components/product-detail.js +1022 -0
  129. package/src/lib/components/product-detail.js.map +1 -0
  130. package/src/lib/components/product-grid.d.ts +67 -0
  131. package/src/lib/components/product-grid.js +909 -0
  132. package/src/lib/components/product-grid.js.map +1 -0
  133. package/src/lib/components/product-reviews.d.ts +32 -0
  134. package/src/lib/components/product-reviews.js +349 -0
  135. package/src/lib/components/product-reviews.js.map +1 -0
  136. package/src/lib/components/related-products.d.ts +33 -0
  137. package/src/lib/components/related-products.js +232 -0
  138. package/src/lib/components/related-products.js.map +1 -0
  139. package/src/lib/components/reservation-widget.d.ts +33 -0
  140. package/src/lib/components/reservation-widget.js +418 -0
  141. package/src/lib/components/reservation-widget.js.map +1 -0
  142. package/src/lib/components/storefront-payment-element-fallback.d.ts +18 -0
  143. package/src/lib/components/storefront-payment-element-fallback.js +51 -0
  144. package/src/lib/components/storefront-payment-element-fallback.js.map +1 -0
  145. package/src/lib/components/storefront-payment-element.d.ts +78 -0
  146. package/src/lib/components/storefront-payment-element.js +156 -0
  147. package/src/lib/components/storefront-payment-element.js.map +1 -0
  148. package/src/lib/components/wishlist.d.ts +46 -0
  149. package/src/lib/components/wishlist.js +304 -0
  150. package/src/lib/components/wishlist.js.map +1 -0
  151. package/src/lib/constants/bundle-common.d.ts +18 -0
  152. package/src/lib/constants/bundle-common.js +18 -0
  153. package/src/lib/constants/bundle-common.js.map +1 -0
  154. package/src/lib/constants/product-filters.d.ts +35 -0
  155. package/src/lib/constants/product-filters.js +109 -0
  156. package/src/lib/constants/product-filters.js.map +1 -0
  157. package/src/lib/model/commerce-cart.d.ts +52 -0
  158. package/src/lib/model/commerce-cart.js +102 -0
  159. package/src/lib/model/commerce-cart.js.map +1 -0
  160. package/src/lib/model/commerce-connect-transfer.d.ts +243 -0
  161. package/src/lib/model/commerce-connect-transfer.js +231 -0
  162. package/src/lib/model/commerce-connect-transfer.js.map +1 -0
  163. package/src/lib/model/commerce-discounts.d.ts +164 -0
  164. package/src/lib/model/commerce-discounts.js +231 -0
  165. package/src/lib/model/commerce-discounts.js.map +1 -0
  166. package/src/lib/model/commerce-dispute.d.ts +124 -0
  167. package/src/lib/model/commerce-dispute.js +225 -0
  168. package/src/lib/model/commerce-dispute.js.map +1 -0
  169. package/src/lib/model/commerce-gift-cards.d.ts +107 -0
  170. package/src/lib/model/commerce-gift-cards.js +121 -0
  171. package/src/lib/model/commerce-gift-cards.js.map +1 -0
  172. package/src/lib/model/commerce-io.d.ts +36 -0
  173. package/src/lib/model/commerce-io.js +245 -0
  174. package/src/lib/model/commerce-io.js.map +1 -0
  175. package/src/lib/model/commerce-orders.d.ts +1040 -0
  176. package/src/lib/model/commerce-orders.js +1022 -0
  177. package/src/lib/model/commerce-orders.js.map +1 -0
  178. package/src/lib/model/commerce-promotions.d.ts +188 -0
  179. package/src/lib/model/commerce-promotions.js +199 -0
  180. package/src/lib/model/commerce-promotions.js.map +1 -0
  181. package/src/lib/model/commerce-reservations.d.ts +175 -0
  182. package/src/lib/model/commerce-reservations.js +157 -0
  183. package/src/lib/model/commerce-reservations.js.map +1 -0
  184. package/src/lib/model/commerce-shipping.d.ts +316 -0
  185. package/src/lib/model/commerce-shipping.js +484 -0
  186. package/src/lib/model/commerce-shipping.js.map +1 -0
  187. package/src/lib/model/commerce-stock-holds.d.ts +199 -0
  188. package/src/lib/model/commerce-stock-holds.js +190 -0
  189. package/src/lib/model/commerce-stock-holds.js.map +1 -0
  190. package/src/lib/model/commerce-subscription-status.d.ts +67 -0
  191. package/src/lib/model/commerce-subscription-status.js +76 -0
  192. package/src/lib/model/commerce-subscription-status.js.map +1 -0
  193. package/src/lib/model/commerce-tax-decision.d.ts +222 -0
  194. package/src/lib/model/commerce-tax-decision.js +165 -0
  195. package/src/lib/model/commerce-tax-decision.js.map +1 -0
  196. package/src/lib/model/commerce-tax.d.ts +176 -0
  197. package/src/lib/model/commerce-tax.js +92 -0
  198. package/src/lib/model/commerce-tax.js.map +1 -0
  199. package/src/lib/model/commerce.d.ts +551 -0
  200. package/src/lib/model/commerce.js +739 -0
  201. package/src/lib/model/commerce.js.map +1 -0
  202. package/src/lib/model/index.d.ts +40 -0
  203. package/src/lib/model/index.js +40 -0
  204. package/src/lib/model/index.js.map +1 -0
  205. package/src/lib/model/order-figures.d.ts +48 -0
  206. package/src/lib/model/order-figures.js +74 -0
  207. package/src/lib/model/order-figures.js.map +1 -0
  208. package/src/lib/model/plugin-permissions.d.ts +23 -0
  209. package/src/lib/model/plugin-permissions.js +34 -0
  210. package/src/lib/model/plugin-permissions.js.map +1 -0
  211. package/src/lib/model/purchase-analytics.d.ts +186 -0
  212. package/src/lib/model/purchase-analytics.js +216 -0
  213. package/src/lib/model/purchase-analytics.js.map +1 -0
  214. package/src/lib/plugin-config.d.ts +62 -0
  215. package/src/lib/plugin-config.js +78 -0
  216. package/src/lib/plugin-config.js.map +1 -0
  217. package/src/lib/plugin.d.ts +28 -0
  218. package/src/lib/plugin.js +147 -0
  219. package/src/lib/plugin.js.map +1 -0
  220. package/src/lib/server/billing-webhook.d.ts +26 -0
  221. package/src/lib/server/billing-webhook.js +4011 -0
  222. package/src/lib/server/billing-webhook.js.map +1 -0
  223. package/src/lib/server/cancel-order.d.ts +87 -0
  224. package/src/lib/server/cancel-order.js +368 -0
  225. package/src/lib/server/cancel-order.js.map +1 -0
  226. package/src/lib/server/cart-checkout.d.ts +25 -0
  227. package/src/lib/server/cart-checkout.js +976 -0
  228. package/src/lib/server/cart-checkout.js.map +1 -0
  229. package/src/lib/server/cart-cookie.d.ts +32 -0
  230. package/src/lib/server/cart-cookie.js +77 -0
  231. package/src/lib/server/cart-cookie.js.map +1 -0
  232. package/src/lib/server/cart.d.ts +34 -0
  233. package/src/lib/server/cart.js +181 -0
  234. package/src/lib/server/cart.js.map +1 -0
  235. package/src/lib/server/catalog.d.ts +127 -0
  236. package/src/lib/server/catalog.js +277 -0
  237. package/src/lib/server/catalog.js.map +1 -0
  238. package/src/lib/server/checkout.d.ts +36 -0
  239. package/src/lib/server/checkout.js +915 -0
  240. package/src/lib/server/checkout.js.map +1 -0
  241. package/src/lib/server/connect.d.ts +26 -0
  242. package/src/lib/server/connect.js +238 -0
  243. package/src/lib/server/connect.js.map +1 -0
  244. package/src/lib/server/contact-refund.d.ts +117 -0
  245. package/src/lib/server/contact-refund.js +196 -0
  246. package/src/lib/server/contact-refund.js.map +1 -0
  247. package/src/lib/server/download.d.ts +39 -0
  248. package/src/lib/server/download.js +206 -0
  249. package/src/lib/server/download.js.map +1 -0
  250. package/src/lib/server/draft-order.d.ts +26 -0
  251. package/src/lib/server/draft-order.js +706 -0
  252. package/src/lib/server/draft-order.js.map +1 -0
  253. package/src/lib/server/feed.d.ts +24 -0
  254. package/src/lib/server/feed.js +59 -0
  255. package/src/lib/server/feed.js.map +1 -0
  256. package/src/lib/server/fulfill-order.d.ts +97 -0
  257. package/src/lib/server/fulfill-order.js +235 -0
  258. package/src/lib/server/fulfill-order.js.map +1 -0
  259. package/src/lib/server/gate.d.ts +36 -0
  260. package/src/lib/server/gate.js +112 -0
  261. package/src/lib/server/gate.js.map +1 -0
  262. package/src/lib/server/gift-cards.d.ts +42 -0
  263. package/src/lib/server/gift-cards.js +219 -0
  264. package/src/lib/server/gift-cards.js.map +1 -0
  265. package/src/lib/server/low-stock.d.ts +49 -0
  266. package/src/lib/server/low-stock.js +60 -0
  267. package/src/lib/server/low-stock.js.map +1 -0
  268. package/src/lib/server/manual-tax-rate.d.ts +82 -0
  269. package/src/lib/server/manual-tax-rate.js +113 -0
  270. package/src/lib/server/manual-tax-rate.js.map +1 -0
  271. package/src/lib/server/member-feed.d.ts +24 -0
  272. package/src/lib/server/member-feed.js +72 -0
  273. package/src/lib/server/member-feed.js.map +1 -0
  274. package/src/lib/server/member-name-search.d.ts +37 -0
  275. package/src/lib/server/member-name-search.js +42 -0
  276. package/src/lib/server/member-name-search.js.map +1 -0
  277. package/src/lib/server/member-post.d.ts +23 -0
  278. package/src/lib/server/member-post.js +166 -0
  279. package/src/lib/server/member-post.js.map +1 -0
  280. package/src/lib/server/membership-account.d.ts +37 -0
  281. package/src/lib/server/membership-account.js +148 -0
  282. package/src/lib/server/membership-account.js.map +1 -0
  283. package/src/lib/server/membership-admin-password.d.ts +33 -0
  284. package/src/lib/server/membership-admin-password.js +202 -0
  285. package/src/lib/server/membership-admin-password.js.map +1 -0
  286. package/src/lib/server/membership-content.d.ts +23 -0
  287. package/src/lib/server/membership-content.js +105 -0
  288. package/src/lib/server/membership-content.js.map +1 -0
  289. package/src/lib/server/membership-login.d.ts +19 -0
  290. package/src/lib/server/membership-login.js +137 -0
  291. package/src/lib/server/membership-login.js.map +1 -0
  292. package/src/lib/server/membership-logout.d.ts +19 -0
  293. package/src/lib/server/membership-logout.js +35 -0
  294. package/src/lib/server/membership-logout.js.map +1 -0
  295. package/src/lib/server/membership-recover.d.ts +60 -0
  296. package/src/lib/server/membership-recover.js +244 -0
  297. package/src/lib/server/membership-recover.js.map +1 -0
  298. package/src/lib/server/membership-register.d.ts +22 -0
  299. package/src/lib/server/membership-register.js +241 -0
  300. package/src/lib/server/membership-register.js.map +1 -0
  301. package/src/lib/server/membership-reset.d.ts +26 -0
  302. package/src/lib/server/membership-reset.js +88 -0
  303. package/src/lib/server/membership-reset.js.map +1 -0
  304. package/src/lib/server/membership-wishlist.d.ts +23 -0
  305. package/src/lib/server/membership-wishlist.js +89 -0
  306. package/src/lib/server/membership-wishlist.js.map +1 -0
  307. package/src/lib/server/membership.d.ts +96 -0
  308. package/src/lib/server/membership.js +222 -0
  309. package/src/lib/server/membership.js.map +1 -0
  310. package/src/lib/server/native-checkout.d.ts +170 -0
  311. package/src/lib/server/native-checkout.js +193 -0
  312. package/src/lib/server/native-checkout.js.map +1 -0
  313. package/src/lib/server/newsletter.d.ts +23 -0
  314. package/src/lib/server/newsletter.js +323 -0
  315. package/src/lib/server/newsletter.js.map +1 -0
  316. package/src/lib/server/notify-restock.d.ts +22 -0
  317. package/src/lib/server/notify-restock.js +84 -0
  318. package/src/lib/server/notify-restock.js.map +1 -0
  319. package/src/lib/server/order-analytics.d.ts +134 -0
  320. package/src/lib/server/order-analytics.js +263 -0
  321. package/src/lib/server/order-analytics.js.map +1 -0
  322. package/src/lib/server/order-figures.d.ts +33 -0
  323. package/src/lib/server/order-figures.js +220 -0
  324. package/src/lib/server/order-figures.js.map +1 -0
  325. package/src/lib/server/paid-media-delivery.d.ts +173 -0
  326. package/src/lib/server/paid-media-delivery.js +212 -0
  327. package/src/lib/server/paid-media-delivery.js.map +1 -0
  328. package/src/lib/server/pos-order.d.ts +54 -0
  329. package/src/lib/server/pos-order.js +1137 -0
  330. package/src/lib/server/pos-order.js.map +1 -0
  331. package/src/lib/server/process-abandoned.d.ts +54 -0
  332. package/src/lib/server/process-abandoned.js +222 -0
  333. package/src/lib/server/process-abandoned.js.map +1 -0
  334. package/src/lib/server/process-restock.d.ts +42 -0
  335. package/src/lib/server/process-restock.js +219 -0
  336. package/src/lib/server/process-restock.js.map +1 -0
  337. package/src/lib/server/product-card.d.ts +29 -0
  338. package/src/lib/server/product-card.js +54 -0
  339. package/src/lib/server/product-card.js.map +1 -0
  340. package/src/lib/server/product.d.ts +70 -0
  341. package/src/lib/server/product.js +105 -0
  342. package/src/lib/server/product.js.map +1 -0
  343. package/src/lib/server/promotion-hold.d.ts +144 -0
  344. package/src/lib/server/promotion-hold.js +174 -0
  345. package/src/lib/server/promotion-hold.js.map +1 -0
  346. package/src/lib/server/reconcile-stock.d.ts +106 -0
  347. package/src/lib/server/reconcile-stock.js +349 -0
  348. package/src/lib/server/reconcile-stock.js.map +1 -0
  349. package/src/lib/server/refund.d.ts +45 -0
  350. package/src/lib/server/refund.js +607 -0
  351. package/src/lib/server/refund.js.map +1 -0
  352. package/src/lib/server/related.d.ts +24 -0
  353. package/src/lib/server/related.js +104 -0
  354. package/src/lib/server/related.js.map +1 -0
  355. package/src/lib/server/reservation-availability.d.ts +23 -0
  356. package/src/lib/server/reservation-availability.js +111 -0
  357. package/src/lib/server/reservation-availability.js.map +1 -0
  358. package/src/lib/server/reserve-stock.d.ts +156 -0
  359. package/src/lib/server/reserve-stock.js +146 -0
  360. package/src/lib/server/reserve-stock.js.map +1 -0
  361. package/src/lib/server/reserve.d.ts +25 -0
  362. package/src/lib/server/reserve.js +426 -0
  363. package/src/lib/server/reserve.js.map +1 -0
  364. package/src/lib/server/restock-flag.d.ts +202 -0
  365. package/src/lib/server/restock-flag.js +449 -0
  366. package/src/lib/server/restock-flag.js.map +1 -0
  367. package/src/lib/server/reviews.d.ts +51 -0
  368. package/src/lib/server/reviews.js +132 -0
  369. package/src/lib/server/reviews.js.map +1 -0
  370. package/src/lib/server/site-page-enricher.d.ts +42 -0
  371. package/src/lib/server/site-page-enricher.js +149 -0
  372. package/src/lib/server/site-page-enricher.js.map +1 -0
  373. package/src/lib/server/site-page-resolver.d.ts +26 -0
  374. package/src/lib/server/site-page-resolver.js +223 -0
  375. package/src/lib/server/site-page-resolver.js.map +1 -0
  376. package/src/lib/server/stock-hold.d.ts +127 -0
  377. package/src/lib/server/stock-hold.js +258 -0
  378. package/src/lib/server/stock-hold.js.map +1 -0
  379. package/src/lib/server/storefront-tax-record.d.ts +22 -0
  380. package/src/lib/server/storefront-tax-record.js +218 -0
  381. package/src/lib/server/storefront-tax-record.js.map +1 -0
  382. package/src/lib/server/storefront-tax.d.ts +197 -0
  383. package/src/lib/server/storefront-tax.js +245 -0
  384. package/src/lib/server/storefront-tax.js.map +1 -0
  385. package/src/lib/server/stream.d.ts +25 -0
  386. package/src/lib/server/stream.js +191 -0
  387. package/src/lib/server/stream.js.map +1 -0
  388. package/src/lib/server/subscription-portal.d.ts +24 -0
  389. package/src/lib/server/subscription-portal.js +91 -0
  390. package/src/lib/server/subscription-portal.js.map +1 -0
  391. package/src/lib/server/supplier-outbox.d.ts +190 -0
  392. package/src/lib/server/supplier-outbox.js +342 -0
  393. package/src/lib/server/supplier-outbox.js.map +1 -0
  394. package/src/lib/server/supplier-update.d.ts +23 -0
  395. package/src/lib/server/supplier-update.js +289 -0
  396. package/src/lib/server/supplier-update.js.map +1 -0
  397. package/src/lib/server/tax-profile.d.ts +29 -0
  398. package/src/lib/server/tax-profile.js +40 -0
  399. package/src/lib/server/tax-profile.js.map +1 -0
  400. package/src/lib/server.d.ts +32 -0
  401. package/src/lib/server.js +311 -0
  402. package/src/lib/server.js.map +1 -0
  403. package/src/lib/site.d.ts +27 -0
  404. package/src/lib/site.js +134 -0
  405. package/src/lib/site.js.map +1 -0
  406. package/src/lib/utils/escape-html.d.ts +41 -0
  407. package/src/lib/utils/escape-html.js +41 -0
  408. package/src/lib/utils/escape-html.js.map +1 -0
  409. package/src/lib/utils/generate-preset-id.d.ts +19 -0
  410. package/src/lib/utils/generate-preset-id.js +25 -0
  411. package/src/lib/utils/generate-preset-id.js.map +1 -0
  412. package/src/lib/utils/member-continue.d.ts +45 -0
  413. package/src/lib/utils/member-continue.js +49 -0
  414. package/src/lib/utils/member-continue.js.map +1 -0
  415. package/src/lib/utils/use-storefront-purchase-event.d.ts +60 -0
  416. package/src/lib/utils/use-storefront-purchase-event.js +142 -0
  417. package/src/lib/utils/use-storefront-purchase-event.js.map +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/reserve.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 { AttemptClaim, PluginApiHandler } from '@aglyn/aglyn/server'\nimport * as Aglyn from '@aglyn/aglyn/server'\nimport * as CommerceModel from '../model'\nimport { claimAttempt } from '@aglyn/aglyn/server'\nimport { firebaseAdmin, getOrgForHost } from '@aglyn/tenant-data-admin'\nimport { connectLinkageIsReady } from '@aglyn/tenant-data-admin/server/stripe-account-mode'\n\n/**\n * Reserve a stay (AGL-310): server-side quote + availability check,\n * pending reservation doc, then a Stripe session for the deposit (or\n * full amount) on the merchant's account. Webhook completion confirms\n * the reservation; abandoned pending holds expire after 30 minutes and\n * stop blocking the calendar.\n */\nexport const reserveHandler: PluginApiHandler = async (req, res) => {\n if (req.method !== 'POST') {\n return res.status(405).json({ error: 'Method not allowed' })\n }\n if (!process.env.STRIPE_SECRET_KEY) {\n return res.status(501).json({ error: 'Payments are not configured.' })\n }\n const body =\n typeof req.body === 'string' ? JSON.parse(req.body) : (req.body ?? {})\n const hostId = String(body.hostId ?? '')\n const resourceId = String(body.resourceId ?? '')\n const checkInDayMs = CommerceModel.toDayMs(Number(body.checkInDayMs ?? 0))\n const checkOutDayMs = CommerceModel.toDayMs(Number(body.checkOutDayMs ?? 0))\n const guestName = String(body.guestName ?? '').trim().slice(0, 120)\n const guestEmail = String(body.guestEmail ?? '').trim().toLowerCase().slice(0, 120)\n // One reservation attempt, minted by the widget (AGL-1697). Node lowercases\n // incoming headers, but read both spellings — the plugin API request type\n // makes no promise about casing.\n const idempotencyKey = String(\n req.headers['idempotency-key'] ?? req.headers['Idempotency-Key'] ?? '',\n ).trim().slice(0, 200)\n if (!hostId || !resourceId || !checkInDayMs || !checkOutDayMs) {\n return res.status(400).json({ error: 'Missing reservation details' })\n }\n\n let claim: AttemptClaim | null = null\n try {\n const firestore = firebaseAdmin.app().firestore()\n const hostRef = firestore.collection('hosts').doc(hostId)\n // Owner + payment readiness, HOISTED above the claim (AGL-1697): both are\n // deterministic refusals a merchant fixes out of band, and neither should\n // burn the guest's attempt key.\n const ownerOrg = await getOrgForHost(hostId)\n // Plan gate, re-asked per request exactly as the storefront checkout\n // asks it (AGL-1873, the AGL-481 pattern): a lapsed org's storefront\n // must not keep taking reservation deposits — at the free plan's 0%\n // transaction fee — through the one shopper-facing commerce door that\n // skipped the entitlement. Deterministic and merchant-side, so it sits\n // here above the claim with the readiness check.\n if (!Aglyn.checkEntitlement(ownerOrg?.org as any, 'commerce')) {\n return res.status(403).json({ error: 'Reservations are not enabled' })\n }\n const ownerId = ownerOrg?.org?.ownerUid\n const ownerProfile = ownerId\n ? await firestore.collection('profiles').doc(String(ownerId)).get()\n : null\n const accountId = ownerProfile?.get('stripeAccountId')\n if (\n !connectLinkageIsReady(\n {\n accountId,\n chargesEnabled: ownerProfile?.get('stripeChargesEnabled'),\n accountLivemode: ownerProfile?.get('stripeAccountLivemode'),\n },\n { subject: `reserve host ${hostId}` },\n )\n ) {\n return res.status(409).json({ error: 'Payments are not set up yet' })\n }\n\n // The claim sits ABOVE the availability read, and that placement is the\n // fix for this handler's particular lie (AGL-1697): a retried attempt used\n // to collide with its OWN 30-minute pending hold and be told \"Those dates\n // just sold out\" — about dates the guest was holding — where the correct\n // answer was the original session URL. Replaying here means the retry\n // never reaches the availability check at all. Every refusal below the\n // claim releases it, because each is deterministic and retryable.\n const claimed = await claimAttempt(firestore, {\n kind: 'commerce-reserve',\n scopeId: hostId,\n orgId: String(ownerOrg?.org?.id ?? ''),\n key: idempotencyKey,\n busyMessage: 'This reservation is already being processed',\n })\n if ('replay' in claimed) {\n return res.status(claimed.replay.status).json(claimed.replay.body)\n }\n claim = claimed.claim\n\n // ONLY STAYS THAT COULD STILL OVERLAP, NEAREST FIRST (AGL-2159).\n //\n // This was `.where('resourceId','==',resourceId).limit(500)` with no\n // ordering, so Firestore returned 500 documents in `__name__` order — an\n // arbitrary slice of the resource's ENTIRE booking history. Every stay the\n // resource has ever had competed for those 500 slots on equal terms with\n // the ones that matter, so a cottage that had taken 500 bookings began\n // silently dropping LIVE reservations out of its own availability check\n // and confirming a second guest into an occupied room. Nothing about that\n // failure is visible: `isRangeAvailable` is handed a short list and\n // answers, correctly, that the range is free.\n //\n // `checkOutDayMs > checkInDayMs` is the one inequality that removes the\n // whole of the past — a stay that ended before the requested arrival\n // cannot overlap it — and ordering by the same field puts the stays\n // nearest the requested window at the front of the limit rather than\n // whichever ones happen to sort early by id. Needs the composite index\n // `reservations (resourceId ASC, checkOutDayMs ASC)`, added to\n // `cloud/firebase-firestore.indexes.json` and pinned by\n // `reserve-availability-indexes.spec.ts` — an equality plus an `orderBy`\n // on a second field is exactly the shape that reads as free and is not\n // (AGL-1793), and here a missing index throws rather than under-reporting.\n //\n // RESIDUAL, stated: the cap can still bite when a single resource holds\n // more than 500 stays that all end between the requested arrival and the\n // end of a genuinely overlapping one. That is a far narrower window than\n // \"500 bookings in this resource's lifetime\", but it is not zero, and the\n // sweep that would keep expired `pending` holds from filling those slots\n // is a scheduled job this change does not add (see the commit).\n const availabilityQuery = hostRef\n .collection('reservations')\n .where('resourceId', '==', resourceId)\n .where('checkOutDayMs', '>', checkInDayMs)\n .orderBy('checkOutDayMs')\n .limit(500)\n const [resourceSnapshot, reservationsSnapshot, storeSnapshot] =\n await Promise.all([\n hostRef.collection('resources').doc(resourceId).get(),\n availabilityQuery.get(),\n // The merchant's own lodging rate (AGL-1969). Read in the SAME round\n // trip as the availability query rather than as a fourth sequential\n // await — this path already runs three reads before it can answer, and\n // a tax lookup is not a reason to make a guest wait for a fourth.\n hostRef.collection('settings').doc('store').get(),\n ])\n const resource = resourceSnapshot.data() as CommerceModel.HostResource | undefined\n if (!resource) {\n await claim.release()\n return res.status(404).json({ error: 'Unknown resource' })\n }\n\n // Pending holds block for 30 minutes only, so abandoned checkouts\n // release the dates. The lapse itself lives in\n // `reservationHoldsDates`, which `isRangeAvailable` applies — this reads\n // the fields that rule needs and leaves the rule to the model, so the\n // storefront's date-picker cannot answer a different question from the\n // door that takes the money.\n //\n // Extracted so the pre-read below and the re-read inside the booking\n // transaction cannot drift apart (AGL-2450). Two copies of a filter that\n // decides whether a room is free is exactly the shape where one of them\n // quietly stops matching the other.\n const readLive = (snapshot: {\n docs: any[]\n }): CommerceModel.HostReservation[] =>\n snapshot.docs.map((docSnapshot) => ({\n checkInDayMs: Number(docSnapshot.get('checkInDayMs')),\n checkOutDayMs: Number(docSnapshot.get('checkOutDayMs')),\n status: String(\n docSnapshot.get('status'),\n ) as CommerceModel.ReservationStatus,\n createdAtMs: Number(docSnapshot.get('createdAtMs') ?? 0),\n })) as CommerceModel.HostReservation[]\n const now = Date.now()\n const live = readLive(reservationsSnapshot)\n if (\n !CommerceModel.isRangeAvailable(\n resource,\n live,\n checkInDayMs,\n checkOutDayMs,\n now,\n )\n ) {\n // A GENUINE sold-out (a keyed retry replayed before reaching here). The\n // guest picks other dates or the blocking stay is cancelled; either way\n // the key must survive the refusal.\n await claim.release()\n return res.status(409).json({ error: 'Those dates just sold out' })\n }\n const quote = CommerceModel.computeReservationQuote(\n resource,\n checkInDayMs,\n checkOutDayMs,\n )\n if (quote.problem) {\n await claim.release()\n return res.status(400).json({ error: quote.problem })\n }\n\n const chargeCents = quote.depositCents || quote.totalCents\n\n // NO DISCOUNT IS APPLIED HERE, AND THAT IS AN OPEN QUESTION RATHER THAN AN\n // OVERSIGHT (AGL-305).\n //\n // `hosts/{hostId}/discounts` reaches the cart, buy-now, the draft-order\n // payment link and the register. This door was deliberately left out,\n // because unlike those four it does not take a payment for goods — it takes\n // a DEPOSIT against a stay that is settled later, and \"apply 10% off\" has\n // three different meanings against that shape:\n //\n // 1. Discount the STAY. `quote.totalCents` falls, the deposit falls with\n // it because it is a percentage of the subtotal, and the balance falls\n // too. This is the only reading that is actually a discount on the\n // booking — and it reprices a merchant's lodging inventory from a\n // storefront promo code, which is a larger claim than any of the four\n // goods doors makes.\n // 2. Discount the DEPOSIT only. Strictly worse than doing nothing: the\n // balance is computed downstream as `totalCents - paidCents`, so every\n // cent taken off at booking is billed straight back at check-out. The\n // guest would be shown a discount and then charged for it, which is\n // the silent-reversal shape this codebase refuses elsewhere.\n // 3. Discount the BALANCE. Nothing visible at booking; the guest finds\n // out at the register. A promotion nobody can see when they buy is not\n // a promotion.\n //\n // What makes this a product decision and not an implementation one is that\n // the balance is not collected by any door this repo can teach. It is read\n // off the console's reservations card as `totalCents - paidCents` and\n // collected BY A HUMAN at the till, so option 1 is the only one that\n // survives the hand-off — and it survives it by changing the stay's stored\n // price, which is the merchant's revenue basis and what their analytics,\n // their folio and their register all read.\n //\n // The tax makes it sharper still. `lodgingTax` below is an occupancy rate,\n // not a sales rate, and its basis here is already a STATED LIMITATION — it\n // is charged on what is collected (the deposit) rather than on the stay.\n // Layering a discount on top asks whether occupancy tax is owed on the\n // discounted room rate or the gross one, which differs by jurisdiction, is\n // the merchant's own regime to answer, and is not a question this handler\n // can decide from a promo code.\n //\n // So: refusing to guess. A shopper who types a code here is not told it\n // worked — this path never reads one, so there is nothing to fall through\n // silently, which is the failure mode that mattered. When the owner picks\n // a reading, option 1 is the one the machinery already supports: reduce\n // `quote.subtotalCents` before the deposit is derived from it, and the\n // deposit, the balance, the fee and the tax all follow without further\n // change.\n\n // LODGING TAX: the MERCHANT'S OWN RATE, off unless they set one\n // (AGL-1969, answering the decision AGL-1953 recorded here).\n //\n // What this path used to do, and why it was only ever a holding position:\n // it computed no tax in either store mode, on two stated grounds. The\n // first is still true and is the reason for the shape below — a stay is\n // not goods. The AGL-285 zone editor configures a SALES rate, lodging is\n // an occupancy/hotel regime with its own rates, its own registration and\n // its own return, and reading `rates[]` for a night would be confidently\n // wrong rather than merely absent. Stripe Tax has the mirror problem: it\n // needs a lodging tax code this handler does not send, so\n // `automatic_tax` here would compute a goods rate on a room. Neither of\n // those changes, and neither is used.\n //\n // What DID change is that the merchant now has a field of their own to\n // answer in (`tax.lodging`), so \"Aglyn does not know the right number\"\n // stops being a reason to collect nothing. They type the rate, we compute\n // it, charge it, record it and stamp the regime; the settings card states\n // plainly that determining what is owed and to whom is theirs. Aglyn\n // takes no tax position here — this is the manual LODGING rate, which\n // never touches Aglyn's registrations.\n //\n // ⚠️ This comment used to say \"Terms §10.3 ... untouched by this\". §10.3\n // CHANGED on 2026-08-24 (AGL-1956): Aglyn accepts marketplace-facilitator\n // status and new §10.7 makes storefront sales tax Aglyn's where it has a\n // collection obligation. Lodging tax is still the merchant's, so this\n // handler is unaffected — but §10.3 is no longer the authority for that.\n //\n // DEFAULT OFF, and that is load-bearing: `resolveFlatTaxCents` answers\n // zero for an absent, zero, negative or out-of-range rate, so no existing\n // reservation's charge moves because this shipped.\n //\n // THE BASIS IS WHAT IS CHARGED, AND THAT IS A STATED LIMITATION RATHER\n // THAN AN ANSWER. `chargeCents` is `depositCents || totalCents`, so on a\n // deposit-taking resource the tax collected here is the rate on the\n // DEPOSIT, not on the stay. Whether a given jurisdiction wants occupancy\n // tax on the full stay at booking, on the deposit only, or on redemption\n // at check-out is a tax question, it differs by jurisdiction, and this\n // code deliberately does NOT decide it — the amount the platform actually\n // moves is the only basis available to it, the settings card says so in\n // the merchant's own view, and the residual is on AGL-1969.\n const taxSettings = ((storeSnapshot.data() as any)?.tax ??\n {}) as CommerceModel.TaxSettings\n const lodgingTax = CommerceModel.resolveFlatTaxCents(\n taxSettings.lodging,\n chargeCents,\n 'Lodging tax',\n )\n\n // Platform take PLUS Stripe's card cost at cost (AGL-2152). This is a\n // destination charge, so Stripe debits its percentage plus 30¢ from the\n // PLATFORM's balance; with the old take-only figure every tier carrying a\n // 0% service rate paid Aglyn nothing and cost it that fee on each\n // reservation.\n //\n // THE TWO BASES ARE NOW DIFFERENT NUMBERS (AGL-1969), and the split is\n // AGL-2317's rule: the platform take is computed on the ITEMS — the stay\n // — while Stripe's cost is passed through on the WHOLE charge, because\n // that is what Stripe actually debits. Taking a percentage of the lodging\n // tax would be taking a cut of the state's money, which no storefront\n // path does. The previous single-argument form is what made this a real\n // risk: it read as \"the fee base is the charge\" and would have silently\n // started taxing the tax the moment a tax line appeared.\n const feeCents = Aglyn.resolveTransactionFeeCents(\n ownerOrg?.org as any,\n 'service',\n chargeCents,\n chargeCents + lodgingTax.taxCents,\n )\n\n // THE HOLD IS TAKEN IN A TRANSACTION (AGL-2450).\n //\n // The check above is a fast refusal on a stale read, and on its own that is\n // all it ever was: the availability query ran, the quote and the fee were\n // computed, and only then did the hold land — so two guests requesting the\n // same dates both read a reservation set that lacked the other's booking,\n // both passed, and both got a `pending` row and a real payment. Nothing\n // downstream caught it. The webhook's transaction guards double-CONFIRMATION\n // of one booking against Stripe redelivery; it never re-asks availability,\n // so both holds confirmed cleanly into two guests in one room.\n //\n // `claimAttempt` does not help either, and it is worth being explicit about\n // why: it is keyed on the guest's own `Idempotency-Key`, so it dedupes\n // retries of ONE attempt. Two different guests carry two different keys and\n // never contend.\n //\n // Re-asking inside the transaction that writes is the whole guard — the\n // same shape as `decrementVariantStock` (AGL-2320), and easier to justify\n // here: the conflicting write lands BEFORE Stripe is contacted, so this\n // door can legitimately refuse rather than take the money and withhold the\n // room.\n const reservationRef = hostRef.collection('reservations').doc()\n const booked = await firestore.runTransaction(async (transaction: any) => {\n const fresh = await transaction.get(availabilityQuery)\n // Re-timed, not reusing `now`: a transaction that retries under\n // contention may run appreciably later, and the 30-minute pending window\n // has to be measured from when this attempt actually commits.\n if (\n !CommerceModel.isRangeAvailable(\n resource,\n readLive(fresh),\n checkInDayMs,\n checkOutDayMs,\n Date.now(),\n )\n ) {\n return false\n }\n // `create()`, not `set()`: the ref is freshly minted, so an id collision\n // is a bug rather than an overwrite to absorb silently.\n transaction.create(reservationRef, {\n resourceId,\n status: 'pending',\n checkInDayMs,\n checkOutDayMs,\n guestName: guestName || null,\n guestEmail: guestEmail || null,\n nights: quote.nights,\n totalCents: quote.totalCents,\n depositCents: quote.depositCents,\n paidCents: 0,\n createdAtMs: now,\n } satisfies CommerceModel.HostReservation)\n return true\n })\n if (!booked) {\n // Lost the race for these dates. Same refusal as the pre-read's, and the\n // key survives it for the same reason: the guest picks other dates or the\n // blocking stay is cancelled.\n await claim.release()\n return res.status(409).json({ error: 'Those dates just sold out' })\n }\n\n const referer = String(req.headers.referer ?? '')\n const origin = `https://${req.headers.host}`\n const backUrl = referer.startsWith('http') ? referer : origin\n const separator = backUrl.includes('?') ? '&' : '?'\n const params = new URLSearchParams({\n mode: 'payment',\n 'line_items[0][quantity]': '1',\n 'line_items[0][price_data][currency]': 'usd',\n 'line_items[0][price_data][unit_amount]': String(chargeCents),\n 'line_items[0][price_data][product_data][name]': `${resource.name} — ${\n quote.nights\n } night${quote.nights === 1 ? '' : 's'}${\n quote.depositCents && quote.depositCents < quote.totalCents\n ? ' (deposit)'\n : ''\n }`.slice(0, 120),\n // The merchant's lodging tax as an ORDINARY product line Stripe is\n // never told is tax — the AGL-1711 construction every other manual rate\n // rides. That is what makes the derived `taxMode` read `manual`: the\n // figure is the merchant's own, computed from their own rate, and never\n // against Aglyn's registrations the way `automatic_tax` would be\n // (AGL-1904). Absent entirely when no rate is set, so a default store's\n // session carries no tax parameter of any kind.\n ...(lodgingTax.taxCents > 0\n ? {\n 'line_items[1][quantity]': '1',\n 'line_items[1][price_data][currency]': 'usd',\n 'line_items[1][price_data][unit_amount]': String(\n lodgingTax.taxCents,\n ),\n 'line_items[1][price_data][product_data][name]': lodgingTax.label,\n }\n : {}),\n ...(feeCents > 0\n ? { 'payment_intent_data[application_fee_amount]': String(feeCents) }\n : {}),\n 'payment_intent_data[transfer_data][destination]': String(accountId),\n ...(guestEmail ? { customer_email: guestEmail } : {}),\n success_url: `${backUrl}${separator}reserved=1`,\n cancel_url: `${backUrl}${separator}reserved=0`,\n 'metadata[type]': 'commerce-reservation',\n 'metadata[hostId]': hostId,\n 'metadata[reservationId]': reservationRef.id,\n 'metadata[feeCents]': String(feeCents),\n // The only witness to the tax (AGL-1969). By the construction above\n // Stripe does not know the second line is tax, so it reports\n // `total_details.amount_tax: 0` — the session's own metadata is what\n // `storefront-tax-record.ts` and the confirmation branch read to record\n // the figure and derive the regime, exactly as `checkout.ts` stamps it\n // for a buy-now sale. Absent when there is no tax, never a reassuring\n // `'0'`: absent and zero are different facts on a back-book question.\n ...(lodgingTax.taxCents > 0\n ? {\n 'metadata[taxCents]': String(lodgingTax.taxCents),\n 'metadata[taxPct]': String(lodgingTax.pct),\n }\n : {}),\n })\n const response = await fetch(\n 'https://api.stripe.com/v1/checkout/sessions',\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`,\n 'Content-Type': 'application/x-www-form-urlencoded',\n // The half that costs real money (AGL-1697). Stripe replays the\n // existing session for a repeated key instead of opening a second\n // one, covering the window where the claim is written but the\n // response never arrives.\n ...(claim.stripeKey ? { 'Idempotency-Key': claim.stripeKey } : {}),\n },\n body: params.toString(),\n },\n )\n const session = (await response.json()) as { url?: string; error?: any }\n if (!response.ok || !session.url) {\n console.error('Stripe reservation error', session.error)\n await reservationRef.delete().catch(() => undefined)\n // The hold is rolled back, so the key must come back too — the guest\n // presses the same button and the retry re-derives the same digest,\n // which Stripe replays if the session did get created.\n await claim.release()\n return res.status(502).json({ error: 'Payment setup failed' })\n }\n const payload = { url: session.url }\n await claim.record(200, payload)\n return res.status(200).json(payload)\n } catch (error) {\n console.error(error)\n // Release on the way out so a transient failure does not strand the key\n // (AGL-1691's rule): the hold may or may not have landed, and it expires\n // in 30 minutes either way.\n await claim?.release()\n return res.status(500).json({ error: 'Reservation failed' })\n }\n}\n"],"names":["Aglyn","CommerceModel","claimAttempt","firebaseAdmin","getOrgForHost","connectLinkageIsReady","reserveHandler","req","res","body","method","status","json","error","process","env","STRIPE_SECRET_KEY","JSON","parse","hostId","String","resourceId","checkInDayMs","toDayMs","Number","checkOutDayMs","guestName","trim","slice","guestEmail","toLowerCase","idempotencyKey","headers","claim","ownerOrg","storeSnapshot","firestore","app","hostRef","collection","doc","checkEntitlement","org","ownerId","ownerUid","ownerProfile","get","accountId","chargesEnabled","accountLivemode","subject","claimed","kind","scopeId","orgId","id","key","busyMessage","replay","availabilityQuery","where","orderBy","limit","resourceSnapshot","reservationsSnapshot","Promise","all","resource","data","release","readLive","snapshot","docs","map","docSnapshot","createdAtMs","now","Date","live","isRangeAvailable","quote","computeReservationQuote","problem","chargeCents","depositCents","totalCents","taxSettings","tax","lodgingTax","resolveFlatTaxCents","lodging","feeCents","resolveTransactionFeeCents","taxCents","reservationRef","booked","runTransaction","transaction","fresh","create","nights","paidCents","referer","origin","host","backUrl","startsWith","separator","includes","params","URLSearchParams","mode","name","label","customer_email","success_url","cancel_url","pct","response","fetch","Authorization","stripeKey","toString","session","ok","url","console","delete","catch","undefined","payload","record"],"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AQE,GAAG;QAAC;QACnC,MAAM5F,MAAMkG,MAAM,CAAC,KAAKD;QACxB,OAAO1H,IAAIG,MAAM,CAAC,KAAKC,IAAI,CAACsH;IAC9B,EAAE,OAAOrH,OAAO;QACdiH,QAAQjH,KAAK,CAACA;QACd,wEAAwE;QACxE,yEAAyE;QACzE,4BAA4B;QAC5B,OAAMoB,yBAAAA,MAAOoC,OAAO;QACpB,OAAO7D,IAAIG,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAAqB;IAC5D;AACF,EAAC"}
@@ -0,0 +1,202 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import * as CommerceModel from '../model';
18
+ /**
19
+ * Stock left off the shelf by a reversed order (AGL-1797).
20
+ *
21
+ * The checkout webhook decrements variant inventory on a sale and NOTHING put
22
+ * it back — not `refund.ts`, not the lost-dispute handler (AGL-1787) — so a
23
+ * fully reversed order left the merchant's count permanently one lower than
24
+ * their shelf, compounding with every return.
25
+ *
26
+ * THIS FLAGS. IT DOES NOT RELEASE, and that is the decision.
27
+ *
28
+ * "Increment on reversal" is the obvious fix and it is wrong in two of the
29
+ * three cases it would fire on:
30
+ *
31
+ * - a **returned** item does come back, but only once it is RECEIVED, and no
32
+ * fulfilment event records receipt — `OrderFulfillment` has no returned
33
+ * state, so the moment an automatic increment would need does not exist;
34
+ * - a **refund with no return** (goodwill, damaged, lost in post) leaves the
35
+ * goods gone. Incrementing there invents inventory the merchant does not
36
+ * have, and that is strictly worse than the bug it replaces: the bug
37
+ * under-counts and refuses a sale that could have been made, while the
38
+ * "fix" over-counts and TAKES a sale that cannot be filled;
39
+ * - a **chargeback** is the clearest do-not-restock case there is. The shopper
40
+ * kept the item and took the money, and `product_not_received` — the most
41
+ * common reason code — asserts the goods shipped.
42
+ *
43
+ * The quantities are not always knowable on a partial. A refund requested as an
44
+ * AMOUNT selects no line — "$17 of a $62 order" names nothing — and that is
45
+ * recorded rather than papered over: `quantity` is at most the units the line
46
+ * sold, capped to what the count actually gave up, and `fullyReversed` says
47
+ * whether that bound is a tight one.
48
+ *
49
+ * A refund that NAMES ITS LINES is scoped to them (AGL-2325). When this was
50
+ * written no reversal recorded which lines it covered; AGL-2454 changed that,
51
+ * and `refund.ts` commits `refundedLineItemIds` with the money, before this
52
+ * flag re-reads the order. A one-line refund on a three-line order that still
53
+ * asked about all three was the same over-statement this module already fixed
54
+ * on the units axis, arriving by a door that opened afterwards. See
55
+ * `reversalLineScope` for the three cases that stay whole-order.
56
+ *
57
+ * So the merchant is asked. They are the only party who knows whether the
58
+ * goods came back, and by the time they read this they know it.
59
+ *
60
+ * WHAT IS DELIBERATELY NOT BUILT HERE. No stock writer and no
61
+ * `InventoryAdjustment` row: the products hub's "Adjust stock" already writes
62
+ * the variant counts and logs the adjustment with a reason, so a second writer
63
+ * for one number would be a re-implementation, not an extension. And an
64
+ * adjustment row for stock that has NOT moved would corrupt the very ledger
65
+ * that hub renders as history. This writes the question; the existing action
66
+ * answers it.
67
+ *
68
+ * WHERE THE MERCHANT SEES IT. The order timeline, which the console order
69
+ * dialog already renders, so this needs no UI change to be visible at all. The
70
+ * `restockCheck` record beside it is the structured half a badge and a
71
+ * one-click action read; that console work is filed, not smuggled in.
72
+ *
73
+ * NO NOTIFICATION. A refund is initiated BY an admin in the console, so telling
74
+ * them about their own click is noise, and the chargeback door already sends a
75
+ * manager notification for the dispute itself — a second one for the same event
76
+ * would train them to ignore both.
77
+ *
78
+ * ONLY WHAT THE SALE DECREMENTED IS FLAGGED. Tracking lives on the product
79
+ * variant, not the order line, so this reads the products and applies the sale
80
+ * path's own test (`variant.inventory != null`). A store that tracks no stock
81
+ * therefore gets NO flag rather than a prompt it can never act on, which is the
82
+ * difference between a signal and noise. It costs a handful of reads on an
83
+ * event as rare as a reversal.
84
+ *
85
+ * The `inventoryAdjustments` ledger was the tempting shortcut for SELECTING the
86
+ * lines and it is not usable for that: the buy-now/subscription sale path
87
+ * decrements stock without writing a row (`billing-webhook.ts`, the
88
+ * `productId` branch), so the ledger has holes the order's own line items do
89
+ * not. The lines are still chosen from the order.
90
+ *
91
+ * IT IS READ TO BOUND THE NUMBER, THOUGH (AGL-2325), and the holes are exactly
92
+ * why that is safe in this direction. `line.quantity` is the units the line
93
+ * SOLD, and on a backorder product the inventory floor absorbed part or all of
94
+ * the decrement, so the prompt named units the count never gave up. The sale
95
+ * rows' `appliedDelta` says how many it did, and only pairs the ledger
96
+ * DESCRIBES are capped — a line it is silent about keeps the upper bound, so a
97
+ * hole costs an over-stated question rather than stock stranded off the shelf.
98
+ * `saleReleaseCaps` and `capRestockLines` are shared with the cancellation
99
+ * writer, so what this ASKS and what that RETURNS cannot drift apart.
100
+ *
101
+ * FAILURES ARE SWALLOWED, like `recordContactRefund`'s. The money has already
102
+ * moved and the order already records it; a flag that cannot be written must
103
+ * not fail a refund that has left the merchant's account.
104
+ */
105
+ export declare function flagOrderRestock(options: {
106
+ hostId: string;
107
+ orderId: string;
108
+ /** Which door the money left by. Only the wording differs. */
109
+ kind: 'refund' | 'chargeback';
110
+ /**
111
+ * True only for the write that moved the order INTO `refunded` — the same
112
+ * signal `recordContactRefund` takes, decided by the caller from the status
113
+ * transition it made rather than from the total it read, because
114
+ * `fullyRefunded` is not a once-only signal (AGL-1754).
115
+ */
116
+ closedTheOrder: boolean;
117
+ }): Promise<void>;
118
+ /**
119
+ * Key for one product+variant pair in a release-cap map.
120
+ *
121
+ * The separator is U+0000 written as an ESCAPE, not as a raw byte (AGL-2355).
122
+ * Emitted literally it made `file(1)` call the source `data`, so grep skipped
123
+ * the whole file as binary and an AGL-2320 sweep missed a call site in it.
124
+ * Same character at runtime. NUL is still the right separator: it cannot occur
125
+ * in a Firestore document id, so no pair can collide.
126
+ */
127
+ export declare const restockCapKey: (productId: string, variantId: string) => string;
128
+ /**
129
+ * How many units of each product+variant a sale ACTUALLY took off the shelf,
130
+ * read from that order's `reason: 'sale'` ledger rows (AGL-2149).
131
+ *
132
+ * The variant inventory writer floors at zero, and that floor silently absorbs
133
+ * the overshoot on a BACKORDER product: stock 0, `canPurchase` admits the sale
134
+ * because the policy says to, three units sell, `Math.max(0, 0 + -3)` leaves
135
+ * the count at 0. The rows carry both numbers for exactly this — `delta` stays
136
+ * the units SOLD, which is the merchant's history, and `appliedDelta` says how
137
+ * many the count could give up.
138
+ *
139
+ * The writer is deliberately NOT named here: `stock-decrement-race.spec.ts`
140
+ * sweeps every server source for that identifier to prove no file outside its
141
+ * allowlist hand-rolls a stock write, and it matches the bare name, so even a
142
+ * comment mentioning it would read as a call site. This module writes no stock
143
+ * at all — it writes the question.
144
+ *
145
+ * Shared by the cancellation writer, which uses it to bound how much stock
146
+ * goes back, and by the restock flag, which uses it to bound what it CLAIMS
147
+ * went missing (AGL-2325). Extracted rather than copied: the two must not
148
+ * drift, because a flag that names more units than the cancellation would
149
+ * return is the double-count both of them exist to avoid.
150
+ */
151
+ export declare function saleReleaseCaps(saleRows: readonly {
152
+ get: (field: string) => unknown;
153
+ }[]): Map<string, number>;
154
+ /**
155
+ * Lines narrowed to what the count actually gave up, dropping any that gave up
156
+ * nothing (AGL-2149, AGL-2325).
157
+ *
158
+ * ONLY PAIRS THE LEDGER DESCRIBES ARE CAPPED, and that asymmetry is the whole
159
+ * safety argument. A pair with no row is left at the units it sold, which is
160
+ * what keeps the pre-AGL-1807 draft links — decremented with no row at all —
161
+ * and the buy-now path from being silently zeroed by a ledger that has holes
162
+ * in it. So an absent ledger degrades to the old upper bound rather than to
163
+ * saying nothing moved.
164
+ *
165
+ * The budget is consumed as it is spent, so two lines of the same
166
+ * product+variant share one rather than each claiming it whole. Takes a COPY,
167
+ * so a caller may reuse the map it passed.
168
+ */
169
+ export declare function capRestockLines(lines: readonly CommerceModel.OrderRestockLine[], caps: ReadonlyMap<string, number>): CommerceModel.OrderRestockLine[];
170
+ /** What an order's tracked lines resolved to, with the products behind them. */
171
+ export interface TrackedRestockLines {
172
+ lines: CommerceModel.OrderRestockLine[];
173
+ /**
174
+ * The product doc behind each line, by product id — read once each, and
175
+ * handed back so a caller that WRITES stock (AGL-1808) does not read them a
176
+ * second time. Only products that contributed a line appear.
177
+ */
178
+ products: Map<string, CommerceModel.HostProduct>;
179
+ }
180
+ /**
181
+ * The order's lines whose stock the sale actually took off the shelf.
182
+ *
183
+ * The test is the sale path's own — `variant.inventory != null` on the variant
184
+ * that sold — read from the product as it stands NOW, because that is the
185
+ * count a restock would be applied to. A product deleted since the sale, or a
186
+ * variant removed from it, therefore drops out: there is no number left to put
187
+ * anything back into.
188
+ *
189
+ * Products are read once each, so a three-line order of the same product costs
190
+ * one read rather than three.
191
+ *
192
+ * `read` is the caller's, and the choice is not cosmetic (AGL-1808): the flag
193
+ * passes a swallowing `get()` because a product it cannot read must not fail a
194
+ * refund that already moved, while the cancellation writer passes its
195
+ * TRANSACTION's `get` so every product it is about to increment is read under
196
+ * the same transaction that writes it — and so a read failure aborts rather
197
+ * than quietly shortening the list.
198
+ */
199
+ export declare function resolveTrackedRestockLines(hostRef: FirebaseFirestore.DocumentReference, order: CommerceModel.HostOrder, read: (ref: FirebaseFirestore.DocumentReference) => Promise<{
200
+ exists?: boolean;
201
+ data?: () => unknown;
202
+ } | null>): Promise<TrackedRestockLines>;