@aglyn/plugins-commerce 1.0.0-beta.230 → 1.0.0-beta.232

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (609) hide show
  1. package/package.json +13 -13
  2. package/src/index.d.ts +0 -1
  3. package/src/index.js +0 -1
  4. package/src/index.js.map +1 -1
  5. package/src/lib/barcode/barcode-decode.d.ts +71 -0
  6. package/src/lib/barcode/barcode-decode.js +498 -0
  7. package/src/lib/barcode/barcode-decode.js.map +1 -0
  8. package/src/lib/barcode/barcode-encode.d.ts +44 -0
  9. package/src/lib/barcode/barcode-encode.js +138 -0
  10. package/src/lib/barcode/barcode-encode.js.map +1 -0
  11. package/src/lib/barcode/barcode-scanner.component.d.ts +23 -0
  12. package/src/lib/barcode/barcode-scanner.component.js +260 -0
  13. package/src/lib/barcode/barcode-scanner.component.js.map +1 -0
  14. package/src/lib/barcode/scan-button.component.d.ts +10 -0
  15. package/src/lib/barcode/scan-button.component.js +62 -0
  16. package/src/lib/barcode/scan-button.component.js.map +1 -0
  17. package/src/lib/barcode/scanner-wedge.d.ts +35 -0
  18. package/src/lib/barcode/scanner-wedge.js +108 -0
  19. package/src/lib/barcode/scanner-wedge.js.map +1 -0
  20. package/src/lib/components/account.js +10 -1
  21. package/src/lib/components/account.js.map +1 -1
  22. package/src/lib/components/cart-extras.d.ts +45 -0
  23. package/src/lib/components/cart-extras.js +127 -0
  24. package/src/lib/components/cart-extras.js.map +1 -0
  25. package/src/lib/components/cart.js +82 -15
  26. package/src/lib/components/cart.js.map +1 -1
  27. package/src/lib/components/checkout-return-notice.d.ts +26 -0
  28. package/src/lib/components/checkout-return-notice.js +48 -0
  29. package/src/lib/components/checkout-return-notice.js.map +1 -0
  30. package/src/lib/components/commerce-console-page.js +124 -0
  31. package/src/lib/components/commerce-console-page.js.map +1 -1
  32. package/src/lib/components/commerce-console-sections.d.ts +1 -1
  33. package/src/lib/components/commerce-console-sections.js +4 -0
  34. package/src/lib/components/commerce-console-sections.js.map +1 -1
  35. package/src/lib/components/console/bulk-fulfill.d.ts +44 -0
  36. package/src/lib/components/console/bulk-fulfill.js +84 -0
  37. package/src/lib/components/console/bulk-fulfill.js.map +1 -0
  38. package/src/lib/components/console/catalog-organization-card.component.js +1 -0
  39. package/src/lib/components/console/catalog-organization-card.component.js.map +1 -1
  40. package/src/lib/components/console/customer-notifications-card.component.d.ts +19 -0
  41. package/src/lib/components/console/customer-notifications-card.component.js +149 -0
  42. package/src/lib/components/console/customer-notifications-card.component.js.map +1 -0
  43. package/src/lib/components/console/host-orders-card.component.js +88 -6
  44. package/src/lib/components/console/host-orders-card.component.js.map +1 -1
  45. package/src/lib/components/console/locations-card.component.js +164 -57
  46. package/src/lib/components/console/locations-card.component.js.map +1 -1
  47. package/src/lib/components/console/order-detail-dialog.component.js +209 -61
  48. package/src/lib/components/console/order-detail-dialog.component.js.map +1 -1
  49. package/src/lib/components/console/order-fulfillment-panel.component.d.ts +48 -0
  50. package/src/lib/components/console/order-fulfillment-panel.component.js +542 -0
  51. package/src/lib/components/console/order-fulfillment-panel.component.js.map +1 -0
  52. package/src/lib/components/console/order-invoice.component.d.ts +33 -0
  53. package/src/lib/components/console/order-invoice.component.js +81 -0
  54. package/src/lib/components/console/order-invoice.component.js.map +1 -0
  55. package/src/lib/components/console/order-receipt-resend.component.d.ts +21 -0
  56. package/src/lib/components/console/order-receipt-resend.component.js +203 -0
  57. package/src/lib/components/console/order-receipt-resend.component.js.map +1 -0
  58. package/src/lib/components/console/order-returns.component.d.ts +36 -0
  59. package/src/lib/components/console/order-returns.component.js +142 -0
  60. package/src/lib/components/console/order-returns.component.js.map +1 -0
  61. package/src/lib/components/console/order-shipping-actions.component.d.ts +54 -0
  62. package/src/lib/components/console/order-shipping-actions.component.js +149 -0
  63. package/src/lib/components/console/order-shipping-actions.component.js.map +1 -0
  64. package/src/lib/components/console/order-webhooks-card.component.d.ts +50 -0
  65. package/src/lib/components/console/order-webhooks-card.component.js +623 -0
  66. package/src/lib/components/console/order-webhooks-card.component.js.map +1 -0
  67. package/src/lib/components/console/order-zones.d.ts +155 -0
  68. package/src/lib/components/console/order-zones.js +40 -0
  69. package/src/lib/components/console/order-zones.js.map +1 -0
  70. package/src/lib/components/console/payment-methods-card.component.d.ts +67 -0
  71. package/src/lib/components/console/payment-methods-card.component.js +395 -0
  72. package/src/lib/components/console/payment-methods-card.component.js.map +1 -0
  73. package/src/lib/components/console/pos/pos-api.d.ts +124 -0
  74. package/src/lib/components/console/pos/pos-api.js +101 -0
  75. package/src/lib/components/console/pos/pos-api.js.map +1 -0
  76. package/src/lib/components/console/pos/pos-cart-panel.component.d.ts +36 -0
  77. package/src/lib/components/console/pos/pos-cart-panel.component.js +160 -0
  78. package/src/lib/components/console/pos/pos-cart-panel.component.js.map +1 -0
  79. package/src/lib/components/console/pos/pos-item-dialog.component.d.ts +39 -0
  80. package/src/lib/components/console/pos/pos-item-dialog.component.js +352 -0
  81. package/src/lib/components/console/pos/pos-item-dialog.component.js.map +1 -0
  82. package/src/lib/components/console/pos/pos-product-grid.component.d.ts +47 -0
  83. package/src/lib/components/console/pos/pos-product-grid.component.js +272 -0
  84. package/src/lib/components/console/pos/pos-product-grid.component.js.map +1 -0
  85. package/src/lib/components/console/pos/pos-receipt-panel.component.d.ts +27 -0
  86. package/src/lib/components/console/pos/pos-receipt-panel.component.js +282 -0
  87. package/src/lib/components/console/pos/pos-receipt-panel.component.js.map +1 -0
  88. package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +53 -0
  89. package/src/lib/components/console/pos/pos-tender-dialogs.component.js +445 -0
  90. package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -0
  91. package/src/lib/components/console/pos/pos-tender-panel.component.d.ts +31 -0
  92. package/src/lib/components/console/pos/pos-tender-panel.component.js +640 -0
  93. package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -0
  94. package/src/lib/components/console/pos/use-pos-display.d.ts +43 -0
  95. package/src/lib/components/console/pos/use-pos-display.js +161 -0
  96. package/src/lib/components/console/pos/use-pos-display.js.map +1 -0
  97. package/src/lib/components/console/pos-devices-card.component.d.ts +14 -0
  98. package/src/lib/components/console/pos-devices-card.component.js +546 -0
  99. package/src/lib/components/console/pos-devices-card.component.js.map +1 -0
  100. package/src/lib/components/console/pos-display/brand-screen.d.ts +33 -0
  101. package/src/lib/components/console/pos-display/brand-screen.js +85 -0
  102. package/src/lib/components/console/pos-display/brand-screen.js.map +1 -0
  103. package/src/lib/components/console/pos-display/cart-screen.d.ts +29 -0
  104. package/src/lib/components/console/pos-display/cart-screen.js +166 -0
  105. package/src/lib/components/console/pos-display/cart-screen.js.map +1 -0
  106. package/src/lib/components/console/pos-display/pairing-screen.d.ts +24 -0
  107. package/src/lib/components/console/pos-display/pairing-screen.js +127 -0
  108. package/src/lib/components/console/pos-display/pairing-screen.js.map +1 -0
  109. package/src/lib/components/console/pos-display/pos-display-api.d.ts +90 -0
  110. package/src/lib/components/console/pos-display/pos-display-api.js +140 -0
  111. package/src/lib/components/console/pos-display/pos-display-api.js.map +1 -0
  112. package/src/lib/components/console/pos-display/receipt-screen.d.ts +35 -0
  113. package/src/lib/components/console/pos-display/receipt-screen.js +200 -0
  114. package/src/lib/components/console/pos-display/receipt-screen.js.map +1 -0
  115. package/src/lib/components/console/pos-display/tip-screen.d.ts +36 -0
  116. package/src/lib/components/console/pos-display/tip-screen.js +211 -0
  117. package/src/lib/components/console/pos-display/tip-screen.js.map +1 -0
  118. package/src/lib/components/console/pos-display-page.component.d.ts +16 -0
  119. package/src/lib/components/console/pos-display-page.component.js +407 -0
  120. package/src/lib/components/console/pos-display-page.component.js.map +1 -0
  121. package/src/lib/components/console/pos-ops/pos-customer-lookup.component.d.ts +40 -0
  122. package/src/lib/components/console/pos-ops/pos-customer-lookup.component.js +289 -0
  123. package/src/lib/components/console/pos-ops/pos-customer-lookup.component.js.map +1 -0
  124. package/src/lib/components/console/pos-ops/pos-last-receipt.component.d.ts +34 -0
  125. package/src/lib/components/console/pos-ops/pos-last-receipt.component.js +61 -0
  126. package/src/lib/components/console/pos-ops/pos-last-receipt.component.js.map +1 -0
  127. package/src/lib/components/console/pos-ops/pos-operations-bar.component.d.ts +38 -0
  128. package/src/lib/components/console/pos-ops/pos-operations-bar.component.js +129 -0
  129. package/src/lib/components/console/pos-ops/pos-operations-bar.component.js.map +1 -0
  130. package/src/lib/components/console/pos-ops/pos-ops-api.d.ts +37 -0
  131. package/src/lib/components/console/pos-ops/pos-ops-api.js +60 -0
  132. package/src/lib/components/console/pos-ops/pos-ops-api.js.map +1 -0
  133. package/src/lib/components/console/pos-ops/pos-pin-pad.component.d.ts +48 -0
  134. package/src/lib/components/console/pos-ops/pos-pin-pad.component.js +220 -0
  135. package/src/lib/components/console/pos-ops/pos-pin-pad.component.js.map +1 -0
  136. package/src/lib/components/console/pos-ops/pos-receipt-actions.component.d.ts +63 -0
  137. package/src/lib/components/console/pos-ops/pos-receipt-actions.component.js +186 -0
  138. package/src/lib/components/console/pos-ops/pos-receipt-actions.component.js.map +1 -0
  139. package/src/lib/components/console/pos-ops/pos-receipt.d.ts +39 -0
  140. package/src/lib/components/console/pos-ops/pos-receipt.js +182 -0
  141. package/src/lib/components/console/pos-ops/pos-receipt.js.map +1 -0
  142. package/src/lib/components/console/pos-ops/pos-return-dialog.component.d.ts +40 -0
  143. package/src/lib/components/console/pos-ops/pos-return-dialog.component.js +465 -0
  144. package/src/lib/components/console/pos-ops/pos-return-dialog.component.js.map +1 -0
  145. package/src/lib/components/console/pos-ops/pos-shift-history-card.component.d.ts +29 -0
  146. package/src/lib/components/console/pos-ops/pos-shift-history-card.component.js +253 -0
  147. package/src/lib/components/console/pos-ops/pos-shift-history-card.component.js.map +1 -0
  148. package/src/lib/components/console/pos-ops/pos-shift-panel.component.d.ts +34 -0
  149. package/src/lib/components/console/pos-ops/pos-shift-panel.component.js +494 -0
  150. package/src/lib/components/console/pos-ops/pos-shift-panel.component.js.map +1 -0
  151. package/src/lib/components/console/pos-ops/pos-shift-report.component.d.ts +37 -0
  152. package/src/lib/components/console/pos-ops/pos-shift-report.component.js +102 -0
  153. package/src/lib/components/console/pos-ops/pos-shift-report.component.js.map +1 -0
  154. package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.d.ts +30 -0
  155. package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.js +277 -0
  156. package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.js.map +1 -0
  157. package/src/lib/components/console/pos-ops/register-ops.d.ts +28 -0
  158. package/src/lib/components/console/pos-ops/register-ops.js +28 -0
  159. package/src/lib/components/console/pos-ops/register-ops.js.map +1 -0
  160. package/src/lib/components/console/pos-ops/use-pos-cashier.d.ts +46 -0
  161. package/src/lib/components/console/pos-ops/use-pos-cashier.js +128 -0
  162. package/src/lib/components/console/pos-ops/use-pos-cashier.js.map +1 -0
  163. package/src/lib/components/console/pos-ops/use-pos-sale-receipt.d.ts +36 -0
  164. package/src/lib/components/console/pos-ops/use-pos-sale-receipt.js +64 -0
  165. package/src/lib/components/console/pos-ops/use-pos-sale-receipt.js.map +1 -0
  166. package/src/lib/components/console/pos-page.component.d.ts +13 -5
  167. package/src/lib/components/console/pos-page.component.js +756 -654
  168. package/src/lib/components/console/pos-page.component.js.map +1 -1
  169. package/src/lib/components/console/pos-zones.d.ts +23 -0
  170. package/src/lib/components/console/pos-zones.js +31 -0
  171. package/src/lib/components/console/pos-zones.js.map +1 -0
  172. package/src/lib/components/console/product-editor-dialog.component.js +61 -71
  173. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  174. package/src/lib/components/console/product-labels-dialog.component.d.ts +13 -0
  175. package/src/lib/components/console/product-labels-dialog.component.js +197 -0
  176. package/src/lib/components/console/product-labels-dialog.component.js.map +1 -0
  177. package/src/lib/components/console/product-register-fields.component.d.ts +19 -0
  178. package/src/lib/components/console/product-register-fields.component.js +241 -0
  179. package/src/lib/components/console/product-register-fields.component.js.map +1 -0
  180. package/src/lib/components/console/product-zones.d.ts +44 -0
  181. package/src/lib/components/console/product-zones.js.map +1 -1
  182. package/src/lib/components/console/products-hub-card.component.js +23 -20
  183. package/src/lib/components/console/products-hub-card.component.js.map +1 -1
  184. package/src/lib/components/console/register-hardware-card.component.d.ts +33 -0
  185. package/src/lib/components/console/register-hardware-card.component.js +826 -0
  186. package/src/lib/components/console/register-hardware-card.component.js.map +1 -0
  187. package/src/lib/components/console/registers-card.component.js +24 -5
  188. package/src/lib/components/console/registers-card.component.js.map +1 -1
  189. package/src/lib/components/console/return-actions.d.ts +38 -0
  190. package/src/lib/components/console/return-actions.js +76 -0
  191. package/src/lib/components/console/return-actions.js.map +1 -0
  192. package/src/lib/components/console/return-detail-dialog.component.d.ts +34 -0
  193. package/src/lib/components/console/return-detail-dialog.component.js +718 -0
  194. package/src/lib/components/console/return-detail-dialog.component.js.map +1 -0
  195. package/src/lib/components/console/return-settings-card.component.d.ts +34 -0
  196. package/src/lib/components/console/return-settings-card.component.js +195 -0
  197. package/src/lib/components/console/return-settings-card.component.js.map +1 -0
  198. package/src/lib/components/console/return-zones.d.ts +87 -0
  199. package/src/lib/components/console/return-zones.js +31 -0
  200. package/src/lib/components/console/return-zones.js.map +1 -0
  201. package/src/lib/components/console/returns-card.component.d.ts +45 -0
  202. package/src/lib/components/console/returns-card.component.js +159 -0
  203. package/src/lib/components/console/returns-card.component.js.map +1 -0
  204. package/src/lib/components/console/shipping-settings-card.component.js +161 -5
  205. package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
  206. package/src/lib/components/console/shippingeasy-card.component.d.ts +59 -0
  207. package/src/lib/components/console/shippingeasy-card.component.js +378 -0
  208. package/src/lib/components/console/shippingeasy-card.component.js.map +1 -0
  209. package/src/lib/components/console/shipstation-card.component.d.ts +35 -0
  210. package/src/lib/components/console/shipstation-card.component.js +345 -0
  211. package/src/lib/components/console/shipstation-card.component.js.map +1 -0
  212. package/src/lib/components/console/start-return-dialog.component.d.ts +40 -0
  213. package/src/lib/components/console/start-return-dialog.component.js +243 -0
  214. package/src/lib/components/console/start-return-dialog.component.js.map +1 -0
  215. package/src/lib/components/console/stock-movements-card.component.js +2 -1
  216. package/src/lib/components/console/stock-movements-card.component.js.map +1 -1
  217. package/src/lib/components/console/store-settings-card.component.js +2 -66
  218. package/src/lib/components/console/store-settings-card.component.js.map +1 -1
  219. package/src/lib/components/console/store-zones.d.ts +42 -0
  220. package/src/lib/components/console/store-zones.js +39 -0
  221. package/src/lib/components/console/store-zones.js.map +1 -0
  222. package/src/lib/components/console/storefront-tax-summary-card.component.js +1 -0
  223. package/src/lib/components/console/storefront-tax-summary-card.component.js.map +1 -1
  224. package/src/lib/components/order-status.d.ts +36 -0
  225. package/src/lib/components/order-status.js +502 -0
  226. package/src/lib/components/order-status.js.map +1 -0
  227. package/src/lib/components/product-detail.js +41 -2
  228. package/src/lib/components/product-detail.js.map +1 -1
  229. package/src/lib/components/return-request.d.ts +32 -0
  230. package/src/lib/components/return-request.js +576 -0
  231. package/src/lib/components/return-request.js.map +1 -0
  232. package/src/lib/components/storefront-payment-appearance.d.ts +32 -0
  233. package/src/lib/components/storefront-payment-appearance.js +114 -0
  234. package/src/lib/components/storefront-payment-appearance.js.map +1 -0
  235. package/src/lib/components/storefront-payment-element.d.ts +57 -1
  236. package/src/lib/components/storefront-payment-element.js +332 -33
  237. package/src/lib/components/storefront-payment-element.js.map +1 -1
  238. package/src/lib/constants/order-status.d.ts +22 -0
  239. package/src/lib/constants/order-status.js +22 -0
  240. package/src/lib/constants/order-status.js.map +1 -0
  241. package/src/lib/constants/return-request.d.ts +27 -0
  242. package/src/lib/constants/return-request.js +32 -0
  243. package/src/lib/constants/return-request.js.map +1 -0
  244. package/src/lib/constants/stock-movement-query.js +2 -1
  245. package/src/lib/constants/stock-movement-query.js.map +1 -1
  246. package/src/lib/declarations.console-server.js +9 -0
  247. package/src/lib/declarations.console-server.js.map +1 -1
  248. package/src/lib/declarations.server.d.ts +2 -1
  249. package/src/lib/declarations.server.js +68 -1
  250. package/src/lib/declarations.server.js.map +1 -1
  251. package/src/lib/model/buyer-notifications.d.ts +59 -0
  252. package/src/lib/model/buyer-notifications.js +97 -0
  253. package/src/lib/model/buyer-notifications.js.map +1 -0
  254. package/src/lib/model/commerce-orders.d.ts +171 -2
  255. package/src/lib/model/commerce-orders.js +26 -16
  256. package/src/lib/model/commerce-orders.js.map +1 -1
  257. package/src/lib/model/commerce-payment-methods.d.ts +146 -0
  258. package/src/lib/model/commerce-payment-methods.js +247 -0
  259. package/src/lib/model/commerce-payment-methods.js.map +1 -0
  260. package/src/lib/model/commerce-pos-ops.d.ts +437 -0
  261. package/src/lib/model/commerce-pos-ops.js +721 -0
  262. package/src/lib/model/commerce-pos-ops.js.map +1 -0
  263. package/src/lib/model/commerce-pos.d.ts +263 -0
  264. package/src/lib/model/commerce-pos.js +375 -0
  265. package/src/lib/model/commerce-pos.js.map +1 -0
  266. package/src/lib/model/commerce-printers.d.ts +211 -0
  267. package/src/lib/model/commerce-printers.js +181 -0
  268. package/src/lib/model/commerce-printers.js.map +1 -0
  269. package/src/lib/model/commerce-receipt.d.ts +97 -0
  270. package/src/lib/model/commerce-receipt.js +180 -0
  271. package/src/lib/model/commerce-receipt.js.map +1 -0
  272. package/src/lib/model/commerce-returns.d.ts +207 -0
  273. package/src/lib/model/commerce-returns.js +300 -0
  274. package/src/lib/model/commerce-returns.js.map +1 -0
  275. package/src/lib/model/commerce-shipping.d.ts +44 -1
  276. package/src/lib/model/commerce-shipping.js +53 -9
  277. package/src/lib/model/commerce-shipping.js.map +1 -1
  278. package/src/lib/model/commerce-tax-engine.d.ts +90 -0
  279. package/src/lib/model/commerce-tax-engine.js +129 -0
  280. package/src/lib/model/commerce-tax-engine.js.map +1 -0
  281. package/src/lib/model/commerce.d.ts +91 -2
  282. package/src/lib/model/commerce.js +89 -1
  283. package/src/lib/model/commerce.js.map +1 -1
  284. package/src/lib/model/index.d.ts +16 -0
  285. package/src/lib/model/index.js +16 -0
  286. package/src/lib/model/index.js.map +1 -1
  287. package/src/lib/model/order-events.d.ts +154 -0
  288. package/src/lib/model/order-events.js +153 -0
  289. package/src/lib/model/order-events.js.map +1 -0
  290. package/src/lib/model/order-fulfillment.d.ts +117 -0
  291. package/src/lib/model/order-fulfillment.js +217 -0
  292. package/src/lib/model/order-fulfillment.js.map +1 -0
  293. package/src/lib/model/order-history.d.ts +58 -0
  294. package/src/lib/model/order-history.js +22 -0
  295. package/src/lib/model/order-history.js.map +1 -0
  296. package/src/lib/model/order-list-fields.d.ts +9 -1
  297. package/src/lib/model/order-list-fields.js +7 -1
  298. package/src/lib/model/order-list-fields.js.map +1 -1
  299. package/src/lib/model/order-shipping-export.d.ts +91 -0
  300. package/src/lib/model/order-shipping-export.js +192 -0
  301. package/src/lib/model/order-shipping-export.js.map +1 -0
  302. package/src/lib/model/order-status-view.d.ts +103 -0
  303. package/src/lib/model/order-status-view.js +156 -0
  304. package/src/lib/model/order-status-view.js.map +1 -0
  305. package/src/lib/model/order-webhooks.d.ts +142 -0
  306. package/src/lib/model/order-webhooks.js +91 -0
  307. package/src/lib/model/order-webhooks.js.map +1 -0
  308. package/src/lib/model/product-channel.d.ts +56 -0
  309. package/src/lib/model/product-channel.js +86 -0
  310. package/src/lib/model/product-channel.js.map +1 -0
  311. package/src/lib/model/product-modifiers.d.ts +80 -0
  312. package/src/lib/model/product-modifiers.js +140 -0
  313. package/src/lib/model/product-modifiers.js.map +1 -0
  314. package/src/lib/model/product-write.d.ts +186 -0
  315. package/src/lib/model/product-write.js +116 -0
  316. package/src/lib/model/product-write.js.map +1 -0
  317. package/src/lib/model/shippingeasy.d.ts +94 -0
  318. package/src/lib/model/shippingeasy.js +267 -0
  319. package/src/lib/model/shippingeasy.js.map +1 -0
  320. package/src/lib/model/shipstation.d.ts +125 -0
  321. package/src/lib/model/shipstation.js +399 -0
  322. package/src/lib/model/shipstation.js.map +1 -0
  323. package/src/lib/model/smart-collection-reads.d.ts +32 -0
  324. package/src/lib/model/smart-collection-reads.js +63 -0
  325. package/src/lib/model/smart-collection-reads.js.map +1 -0
  326. package/src/lib/model/tracking-url.d.ts +74 -0
  327. package/src/lib/model/tracking-url.js +159 -0
  328. package/src/lib/model/tracking-url.js.map +1 -0
  329. package/src/lib/plugin-config.d.ts +13 -0
  330. package/src/lib/plugin-config.js +77 -5
  331. package/src/lib/plugin-config.js.map +1 -1
  332. package/src/lib/plugin.js +26 -0
  333. package/src/lib/plugin.js.map +1 -1
  334. package/src/lib/pos-ops-config.d.ts +39 -0
  335. package/src/lib/pos-ops-config.js +88 -0
  336. package/src/lib/pos-ops-config.js.map +1 -0
  337. package/src/lib/printing/print-document.d.ts +106 -0
  338. package/src/lib/printing/print-document.js +464 -0
  339. package/src/lib/printing/print-document.js.map +1 -0
  340. package/src/lib/printing/product-labels.d.ts +58 -0
  341. package/src/lib/printing/product-labels.js +116 -0
  342. package/src/lib/printing/product-labels.js.map +1 -0
  343. package/src/lib/printing/render-epson.d.ts +57 -0
  344. package/src/lib/printing/render-epson.js +135 -0
  345. package/src/lib/printing/render-epson.js.map +1 -0
  346. package/src/lib/printing/render-star.d.ts +45 -0
  347. package/src/lib/printing/render-star.js +100 -0
  348. package/src/lib/printing/render-star.js.map +1 -0
  349. package/src/lib/printing/render-text.d.ts +25 -0
  350. package/src/lib/printing/render-text.js +53 -0
  351. package/src/lib/printing/render-text.js.map +1 -0
  352. package/src/lib/server/api-v1/openapi.js +27 -4
  353. package/src/lib/server/api-v1/openapi.js.map +1 -1
  354. package/src/lib/server/api-v1/order-view.d.ts +67 -0
  355. package/src/lib/server/api-v1/order-view.js +120 -0
  356. package/src/lib/server/api-v1/order-view.js.map +1 -0
  357. package/src/lib/server/api-v1/orders-and-products.js +58 -65
  358. package/src/lib/server/api-v1/orders-and-products.js.map +1 -1
  359. package/src/lib/server/billing-webhook.js +135 -28
  360. package/src/lib/server/billing-webhook.js.map +1 -1
  361. package/src/lib/server/cancel-order.js +29 -0
  362. package/src/lib/server/cancel-order.js.map +1 -1
  363. package/src/lib/server/carrier-rates-availability.d.ts +26 -0
  364. package/src/lib/server/carrier-rates-availability.js +76 -0
  365. package/src/lib/server/carrier-rates-availability.js.map +1 -0
  366. package/src/lib/server/carrier-shipping.d.ts +84 -0
  367. package/src/lib/server/carrier-shipping.js +135 -0
  368. package/src/lib/server/carrier-shipping.js.map +1 -0
  369. package/src/lib/server/cart-checkout.d.ts +2 -0
  370. package/src/lib/server/cart-checkout.js +226 -22
  371. package/src/lib/server/cart-checkout.js.map +1 -1
  372. package/src/lib/server/channel-order-updates.d.ts +50 -0
  373. package/src/lib/server/channel-order-updates.js +290 -0
  374. package/src/lib/server/channel-order-updates.js.map +1 -0
  375. package/src/lib/server/channel-orders.d.ts +85 -0
  376. package/src/lib/server/channel-orders.js +543 -0
  377. package/src/lib/server/channel-orders.js.map +1 -0
  378. package/src/lib/server/checkout-extras.d.ts +64 -0
  379. package/src/lib/server/checkout-extras.js +157 -0
  380. package/src/lib/server/checkout-extras.js.map +1 -0
  381. package/src/lib/server/{feed.d.ts → checkout-status.d.ts} +2 -7
  382. package/src/lib/server/checkout-status.js +111 -0
  383. package/src/lib/server/checkout-status.js.map +1 -0
  384. package/src/lib/server/checkout.js +86 -9
  385. package/src/lib/server/checkout.js.map +1 -1
  386. package/src/lib/server/draft-order.js +34 -5
  387. package/src/lib/server/draft-order.js.map +1 -1
  388. package/src/lib/server/fulfill-order.d.ts +127 -10
  389. package/src/lib/server/fulfill-order.js +451 -49
  390. package/src/lib/server/fulfill-order.js.map +1 -1
  391. package/src/lib/server/legacy-feed.d.ts +28 -0
  392. package/src/lib/server/legacy-feed.js +52 -0
  393. package/src/lib/server/legacy-feed.js.map +1 -0
  394. package/src/lib/server/native-checkout.d.ts +34 -15
  395. package/src/lib/server/native-checkout.js +32 -17
  396. package/src/lib/server/native-checkout.js.map +1 -1
  397. package/src/lib/server/order-event-host-emit.d.ts +23 -0
  398. package/src/lib/server/order-event-host-emit.js +30 -0
  399. package/src/lib/server/order-event-host-emit.js.map +1 -0
  400. package/src/lib/server/order-event-triggers.d.ts +37 -0
  401. package/src/lib/server/order-event-triggers.js +119 -0
  402. package/src/lib/server/order-event-triggers.js.map +1 -0
  403. package/src/lib/server/order-events.d.ts +62 -0
  404. package/src/lib/server/order-events.js +109 -0
  405. package/src/lib/server/order-events.js.map +1 -0
  406. package/src/lib/server/order-history.d.ts +23 -0
  407. package/src/lib/server/order-history.js +65 -0
  408. package/src/lib/server/order-history.js.map +1 -0
  409. package/src/lib/server/order-notifications.d.ts +185 -0
  410. package/src/lib/server/order-notifications.js +567 -0
  411. package/src/lib/server/order-notifications.js.map +1 -0
  412. package/src/lib/server/order-receipt-send.d.ts +39 -0
  413. package/src/lib/server/order-receipt-send.js +151 -0
  414. package/src/lib/server/order-receipt-send.js.map +1 -0
  415. package/src/lib/server/order-status-token.d.ts +31 -0
  416. package/src/lib/server/order-status-token.js +75 -0
  417. package/src/lib/server/order-status-token.js.map +1 -0
  418. package/src/lib/server/order-status.d.ts +58 -0
  419. package/src/lib/server/order-status.js +141 -0
  420. package/src/lib/server/order-status.js.map +1 -0
  421. package/src/lib/server/order-webhooks.d.ts +108 -0
  422. package/src/lib/server/order-webhooks.js +622 -0
  423. package/src/lib/server/order-webhooks.js.map +1 -0
  424. package/src/lib/server/orders-shipping-prepare.d.ts +26 -0
  425. package/src/lib/server/orders-shipping-prepare.js +121 -0
  426. package/src/lib/server/orders-shipping-prepare.js.map +1 -0
  427. package/src/lib/server/payment-method-domains.d.ts +209 -0
  428. package/src/lib/server/payment-method-domains.js +444 -0
  429. package/src/lib/server/payment-method-domains.js.map +1 -0
  430. package/src/lib/server/payment-methods.d.ts +77 -0
  431. package/src/lib/server/payment-methods.js +284 -0
  432. package/src/lib/server/payment-methods.js.map +1 -0
  433. package/src/lib/server/pos-auth.d.ts +50 -0
  434. package/src/lib/server/pos-auth.js +121 -0
  435. package/src/lib/server/pos-auth.js.map +1 -0
  436. package/src/lib/server/pos-customer.d.ts +49 -0
  437. package/src/lib/server/pos-customer.js +257 -0
  438. package/src/lib/server/pos-customer.js.map +1 -0
  439. package/src/lib/server/pos-display.d.ts +57 -0
  440. package/src/lib/server/pos-display.js +419 -0
  441. package/src/lib/server/pos-display.js.map +1 -0
  442. package/src/lib/server/pos-fee-month.d.ts +34 -0
  443. package/src/lib/server/pos-fee-month.js +36 -0
  444. package/src/lib/server/pos-fee-month.js.map +1 -0
  445. package/src/lib/server/pos-ops-gate.d.ts +161 -0
  446. package/src/lib/server/pos-ops-gate.js +295 -0
  447. package/src/lib/server/pos-ops-gate.js.map +1 -0
  448. package/src/lib/server/pos-ops-routes.d.ts +22 -0
  449. package/src/lib/server/pos-ops-routes.js +36 -0
  450. package/src/lib/server/pos-ops-routes.js.map +1 -0
  451. package/src/lib/server/pos-order.d.ts +1 -18
  452. package/src/lib/server/pos-order.js +222 -42
  453. package/src/lib/server/pos-order.js.map +1 -1
  454. package/src/lib/server/pos-payment.d.ts +39 -0
  455. package/src/lib/server/pos-payment.js +922 -0
  456. package/src/lib/server/pos-payment.js.map +1 -0
  457. package/src/lib/server/pos-print.d.ts +82 -0
  458. package/src/lib/server/pos-print.js +193 -0
  459. package/src/lib/server/pos-print.js.map +1 -0
  460. package/src/lib/server/pos-readers.d.ts +27 -0
  461. package/src/lib/server/pos-readers.js +276 -0
  462. package/src/lib/server/pos-readers.js.map +1 -0
  463. package/src/lib/server/pos-refund-authority.d.ts +60 -0
  464. package/src/lib/server/pos-refund-authority.js +72 -0
  465. package/src/lib/server/pos-refund-authority.js.map +1 -0
  466. package/src/lib/server/pos-return.d.ts +58 -0
  467. package/src/lib/server/pos-return.js +891 -0
  468. package/src/lib/server/pos-return.js.map +1 -0
  469. package/src/lib/server/pos-sale-stamp.d.ts +66 -0
  470. package/src/lib/server/pos-sale-stamp.js +84 -0
  471. package/src/lib/server/pos-sale-stamp.js.map +1 -0
  472. package/src/lib/server/pos-sale.d.ts +170 -0
  473. package/src/lib/server/pos-sale.js +461 -0
  474. package/src/lib/server/pos-sale.js.map +1 -0
  475. package/src/lib/server/pos-shift.d.ts +45 -0
  476. package/src/lib/server/pos-shift.js +484 -0
  477. package/src/lib/server/pos-shift.js.map +1 -0
  478. package/src/lib/server/pos-staff-pin.d.ts +26 -0
  479. package/src/lib/server/pos-staff-pin.js +339 -0
  480. package/src/lib/server/pos-staff-pin.js.map +1 -0
  481. package/src/lib/server/pos-stripe.d.ts +91 -0
  482. package/src/lib/server/pos-stripe.js +129 -0
  483. package/src/lib/server/pos-stripe.js.map +1 -0
  484. package/src/lib/server/pos-terminal-connection-token.d.ts +48 -0
  485. package/src/lib/server/pos-terminal-connection-token.js +166 -0
  486. package/src/lib/server/pos-terminal-connection-token.js.map +1 -0
  487. package/src/lib/server/pos-terminal.d.ts +218 -0
  488. package/src/lib/server/pos-terminal.js +1014 -0
  489. package/src/lib/server/pos-terminal.js.map +1 -0
  490. package/src/lib/server/print-queue.d.ts +124 -0
  491. package/src/lib/server/print-queue.js +301 -0
  492. package/src/lib/server/print-queue.js.map +1 -0
  493. package/src/lib/server/printer-poll.d.ts +75 -0
  494. package/src/lib/server/printer-poll.js +325 -0
  495. package/src/lib/server/printer-poll.js.map +1 -0
  496. package/src/lib/server/printer-secret.d.ts +39 -0
  497. package/src/lib/server/printer-secret.js +56 -0
  498. package/src/lib/server/printer-secret.js.map +1 -0
  499. package/src/lib/server/printers.d.ts +114 -0
  500. package/src/lib/server/printers.js +546 -0
  501. package/src/lib/server/printers.js.map +1 -0
  502. package/src/lib/server/product-catalog.d.ts +42 -0
  503. package/src/lib/server/product-catalog.js +309 -0
  504. package/src/lib/server/product-catalog.js.map +1 -0
  505. package/src/lib/server/product-drafts.d.ts +5 -1
  506. package/src/lib/server/product-drafts.js +3 -3
  507. package/src/lib/server/product-drafts.js.map +1 -1
  508. package/src/lib/server/product-writer.d.ts +19 -0
  509. package/src/lib/server/product-writer.js +261 -0
  510. package/src/lib/server/product-writer.js.map +1 -0
  511. package/src/lib/server/products-write.d.ts +61 -0
  512. package/src/lib/server/products-write.js +375 -0
  513. package/src/lib/server/products-write.js.map +1 -0
  514. package/src/lib/server/refund.js +110 -45
  515. package/src/lib/server/refund.js.map +1 -1
  516. package/src/lib/server/reserve.js +2 -0
  517. package/src/lib/server/reserve.js.map +1 -1
  518. package/src/lib/server/return-status-action.d.ts +37 -0
  519. package/src/lib/server/return-status-action.js +57 -0
  520. package/src/lib/server/return-status-action.js.map +1 -0
  521. package/src/lib/server/returns.d.ts +119 -0
  522. package/src/lib/server/returns.js +938 -0
  523. package/src/lib/server/returns.js.map +1 -0
  524. package/src/lib/server/shipment-records.d.ts +36 -0
  525. package/src/lib/server/shipment-records.js +289 -0
  526. package/src/lib/server/shipment-records.js.map +1 -0
  527. package/src/lib/server/shipping-connector-gates.d.ts +40 -0
  528. package/src/lib/server/shipping-connector-gates.js +97 -0
  529. package/src/lib/server/shipping-connector-gates.js.map +1 -0
  530. package/src/lib/server/shipping-connectors.d.ts +29 -0
  531. package/src/lib/server/shipping-connectors.js +236 -0
  532. package/src/lib/server/shipping-connectors.js.map +1 -0
  533. package/src/lib/server/shippingeasy.d.ts +238 -0
  534. package/src/lib/server/shippingeasy.js +787 -0
  535. package/src/lib/server/shippingeasy.js.map +1 -0
  536. package/src/lib/server/shipstation.d.ts +129 -0
  537. package/src/lib/server/shipstation.js +483 -0
  538. package/src/lib/server/shipstation.js.map +1 -0
  539. package/src/lib/server/site-page-resolver.d.ts +5 -0
  540. package/src/lib/server/site-page-resolver.js +156 -1
  541. package/src/lib/server/site-page-resolver.js.map +1 -1
  542. package/src/lib/server/stock-levels.d.ts +21 -0
  543. package/src/lib/server/stock-levels.js +263 -0
  544. package/src/lib/server/stock-levels.js.map +1 -0
  545. package/src/lib/server/stripe-refund.d.ts +47 -0
  546. package/src/lib/server/stripe-refund.js +87 -0
  547. package/src/lib/server/stripe-refund.js.map +1 -0
  548. package/src/lib/server/supplier-update.js +46 -5
  549. package/src/lib/server/supplier-update.js.map +1 -1
  550. package/src/lib/server/tax-engine-quote.d.ts +47 -0
  551. package/src/lib/server/tax-engine-quote.js +105 -0
  552. package/src/lib/server/tax-engine-quote.js.map +1 -0
  553. package/src/lib/server.js +143 -2
  554. package/src/lib/server.js.map +1 -1
  555. package/src/lib/site.js +12 -0
  556. package/src/lib/site.js.map +1 -1
  557. package/src/lib/subprocessors.d.ts +26 -0
  558. package/src/lib/subprocessors.js +50 -0
  559. package/src/lib/subprocessors.js.map +1 -0
  560. package/src/lib/tenant-emails.js +461 -3
  561. package/src/lib/tenant-emails.js.map +1 -1
  562. package/src/lib/testing/fake-firestore.d.ts +45 -0
  563. package/src/lib/testing/fake-firestore.js +189 -0
  564. package/src/lib/testing/fake-firestore.js.map +1 -0
  565. package/src/lib/testing/memory-firestore.d.ts +136 -0
  566. package/src/lib/testing/memory-firestore.js +282 -0
  567. package/src/lib/testing/memory-firestore.js.map +1 -0
  568. package/src/lib/testing/pos-ops-harness.d.ts +50 -0
  569. package/src/lib/testing/pos-ops-harness.js +184 -0
  570. package/src/lib/testing/pos-ops-harness.js.map +1 -0
  571. package/src/lib/testing/pos-ops-memory-firestore.d.ts +55 -0
  572. package/src/lib/testing/pos-ops-memory-firestore.js +376 -0
  573. package/src/lib/testing/pos-ops-memory-firestore.js.map +1 -0
  574. package/src/lib/transfer/products.server.d.ts +5 -0
  575. package/src/lib/transfer/products.server.js +2 -2
  576. package/src/lib/transfer/products.server.js.map +1 -1
  577. package/src/lib/transfer/records-transfer.d.ts +11 -1
  578. package/src/lib/transfer/records-transfer.js +127 -5
  579. package/src/lib/transfer/records-transfer.js.map +1 -1
  580. package/src/lib/transfer/records.server.d.ts +9 -2
  581. package/src/lib/transfer/records.server.js +58 -7
  582. package/src/lib/transfer/records.server.js.map +1 -1
  583. package/src/lib/transfer/register-transfer-resources.js +40 -1
  584. package/src/lib/transfer/register-transfer-resources.js.map +1 -1
  585. package/src/lib/transfer/register-transfer-ui.js +4 -1
  586. package/src/lib/transfer/register-transfer-ui.js.map +1 -1
  587. package/src/lib/transfer/shipping-presets.d.ts +23 -0
  588. package/src/lib/transfer/shipping-presets.js +156 -0
  589. package/src/lib/transfer/shipping-presets.js.map +1 -0
  590. package/src/lib/transfer/tracking-transfer.d.ts +101 -0
  591. package/src/lib/transfer/tracking-transfer.js +546 -0
  592. package/src/lib/transfer/tracking-transfer.js.map +1 -0
  593. package/src/lib/transfer/tracking.server.d.ts +37 -0
  594. package/src/lib/transfer/tracking.server.js +393 -0
  595. package/src/lib/transfer/tracking.server.js.map +1 -0
  596. package/src/lib/transfer/transfer-keys.d.ts +2 -1
  597. package/src/lib/transfer/transfer-keys.js +6 -2
  598. package/src/lib/transfer/transfer-keys.js.map +1 -1
  599. package/src/lib/utils/code128.d.ts +37 -0
  600. package/src/lib/utils/code128.js +199 -0
  601. package/src/lib/utils/code128.js.map +1 -0
  602. package/src/lib/utils/order-invoice.d.ts +55 -0
  603. package/src/lib/utils/order-invoice.js +127 -0
  604. package/src/lib/utils/order-invoice.js.map +1 -0
  605. package/src/lib/utils/use-checkout-return-notice.d.ts +34 -0
  606. package/src/lib/utils/use-checkout-return-notice.js +78 -0
  607. package/src/lib/utils/use-checkout-return-notice.js.map +1 -0
  608. package/src/lib/server/feed.js +0 -69
  609. package/src/lib/server/feed.js.map +0 -1
@@ -0,0 +1,284 @@
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 { checkEntitlement, pluginRequestFromWeb } from "@aglyn/aglyn/server";
18
+ import { emailUnverifiedResponse, firebaseAdmin, getOrgForHost, isImpersonationSession, lockdownRefusal } from "@aglyn/tenant-data-admin";
19
+ import { invalidIdTokenResponse } from "@aglyn/tenant-data-admin/server/id-token-refusal";
20
+ import { isStorefrontPaymentMethodOn, normalizeStorefrontPaymentMethodSettings, STOREFRONT_PAYMENT_METHODS } from "../model/commerce-payment-methods.js";
21
+ import { readSiteDomainRecords } from "./payment-method-domains.js";
22
+ /** How long the platform's configuration is trusted in memory. */ const PLATFORM_CONFIGURATION_TTL_MS = 10 * 60 * 1000;
23
+ let platformCache = null;
24
+ /** Test seam: forget the cached platform configuration. */ export function resetPlatformPaymentMethodCacheForTests() {
25
+ platformCache = null;
26
+ }
27
+ async function stripe(method, path, params, idempotencyKey) {
28
+ const query = method === 'GET' && params ? `?${params}` : '';
29
+ const response = await fetch(`https://api.stripe.com/v1/${path}${query}`, _extends({
30
+ method,
31
+ headers: _extends({
32
+ Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`
33
+ }, method === 'POST' && {
34
+ 'Content-Type': 'application/x-www-form-urlencoded'
35
+ }, idempotencyKey && {
36
+ 'Idempotency-Key': idempotencyKey
37
+ })
38
+ }, method === 'POST' && params && {
39
+ body: params.toString()
40
+ }));
41
+ const payload = await response.json().catch(()=>({}));
42
+ if (!response.ok) {
43
+ var _ref;
44
+ var _payload_error;
45
+ throw new Error((_ref = payload == null ? void 0 : (_payload_error = payload.error) == null ? void 0 : _payload_error.message) != null ? _ref : `Stripe ${path} failed (${response.status})`);
46
+ }
47
+ return payload;
48
+ }
49
+ /**
50
+ * Which methods the platform's own default configuration offers. The list
51
+ * also returns configurations OTHER Connect applications made for this
52
+ * account (`application` set); those do not govern our sessions and are
53
+ * skipped. `null` per method when Stripe could not be asked — the card then
54
+ * shows the toggle without a verdict rather than hiding a method that may work.
55
+ */ export async function platformPaymentMethodAvailability() {
56
+ if (platformCache && Date.now() - platformCache.at < PLATFORM_CONFIGURATION_TTL_MS) {
57
+ return platformCache.value;
58
+ }
59
+ const value = {};
60
+ try {
61
+ var _ref, _ref1;
62
+ var _list_data, _list_data1;
63
+ const list = await stripe('GET', 'payment_method_configurations', new URLSearchParams({
64
+ limit: '20'
65
+ }));
66
+ const own = (_ref = (_ref1 = (_list_data = list.data) == null ? void 0 : _list_data.find((entry)=>entry.is_default && !entry.application)) != null ? _ref1 : (_list_data1 = list.data) == null ? void 0 : _list_data1.find((entry)=>!entry.application)) != null ? _ref : null;
67
+ for (const method of STOREFRONT_PAYMENT_METHODS){
68
+ var _entry_display_preference;
69
+ if (!own) {
70
+ value[method.id] = null;
71
+ continue;
72
+ }
73
+ const entry = own[method.configurationKey];
74
+ value[method.id] = (entry == null ? void 0 : entry.available) === true && (entry == null ? void 0 : (_entry_display_preference = entry.display_preference) == null ? void 0 : _entry_display_preference.value) === 'on' ? 'on' : 'unavailable';
75
+ }
76
+ platformCache = {
77
+ at: Date.now(),
78
+ value
79
+ };
80
+ } catch (error) {
81
+ console.warn('[commerce] payment method configuration unreadable', error);
82
+ for (const method of STOREFRONT_PAYMENT_METHODS)value[method.id] = null;
83
+ }
84
+ return value;
85
+ }
86
+ function capabilityStatus(capabilities, key) {
87
+ if (!key) return null;
88
+ const status = capabilities == null ? void 0 : capabilities[key];
89
+ if (status === 'active' || status === 'pending' || status === 'inactive') return status;
90
+ return 'unrequested';
91
+ }
92
+ async function readAccountCapabilities(accountId) {
93
+ if (!accountId) return undefined;
94
+ try {
95
+ var _account_capabilities;
96
+ const account = await stripe('GET', `accounts/${encodeURIComponent(accountId)}`);
97
+ return (_account_capabilities = account.capabilities) != null ? _account_capabilities : {};
98
+ } catch (error) {
99
+ console.warn('[commerce] connected account unreadable', error);
100
+ return undefined;
101
+ }
102
+ }
103
+ /** The capabilities a save asks Stripe for: on, offered, not yet requested. */ export function capabilitiesToRequest(settings, platform, capabilities) {
104
+ return STOREFRONT_PAYMENT_METHODS.filter((method)=>method.capability && isStorefrontPaymentMethodOn(settings, method.id) && platform[method.id] !== 'unavailable' && capabilityStatus(capabilities, method.capability) === 'unrequested').map((method)=>method.capability);
105
+ }
106
+ export function buildPaymentMethodRows(settings, platform, capabilities) {
107
+ return STOREFRONT_PAYMENT_METHODS.map((method)=>{
108
+ var _platform_method_id;
109
+ return {
110
+ id: method.id,
111
+ on: isStorefrontPaymentMethodOn(settings, method.id),
112
+ platform: (_platform_method_id = platform[method.id]) != null ? _platform_method_id : null,
113
+ capability: capabilities ? capabilityStatus(capabilities, method.capability) : null
114
+ };
115
+ });
116
+ }
117
+ const json = (body, status = 200)=>Response.json(body, {
118
+ status
119
+ });
120
+ /**
121
+ * Where Stripe sends the owner back: the console page they pressed the button
122
+ * on, judged against the request's own origin so a forged `Referer` cannot
123
+ * turn the link into a redirect to somewhere else.
124
+ */ export function consoleReturnUrl(headers) {
125
+ var _headers_referer;
126
+ const origin = headers.origin || (headers.host ? `https://${headers.host}` : '');
127
+ const referer = (_headers_referer = headers.referer) != null ? _headers_referer : '';
128
+ try {
129
+ if (origin && referer && new URL(referer).origin === new URL(origin).origin) {
130
+ return referer;
131
+ }
132
+ } catch (unused) {
133
+ // Unparseable: fall through to the origin.
134
+ }
135
+ return origin || 'https://localhost/';
136
+ }
137
+ export async function paymentMethodsHandler(request) {
138
+ var _headers_authorization, _ref;
139
+ const { method, headers: rawHeaders, query, body } = await pluginRequestFromWeb(request);
140
+ const headers = rawHeaders;
141
+ if (method !== 'GET' && method !== 'POST') {
142
+ return json({
143
+ error: 'Method not allowed'
144
+ }, 405);
145
+ }
146
+ if (!process.env.STRIPE_SECRET_KEY) {
147
+ return json({
148
+ error: 'Payments are not configured (STRIPE_SECRET_KEY).'
149
+ }, 501);
150
+ }
151
+ const authorization = (_headers_authorization = headers.authorization) != null ? _headers_authorization : '';
152
+ const idToken = authorization.startsWith('Bearer ') ? authorization.slice('Bearer '.length) : undefined;
153
+ if (!idToken) return json({
154
+ error: 'Unauthenticated'
155
+ }, 401);
156
+ const parsed = typeof body === 'string' ? JSON.parse(body || '{}') : body != null ? body : {};
157
+ const hostId = String((_ref = method === 'GET' ? query == null ? void 0 : query['hostId'] : parsed['hostId']) != null ? _ref : '');
158
+ if (!hostId) return json({
159
+ error: 'Missing hostId'
160
+ }, 400);
161
+ try {
162
+ var _hostSnapshot_get, _ref1, _ref2, _get;
163
+ var _owner_org;
164
+ const decoded = await firebaseAdmin.app().auth().verifyIdToken(idToken);
165
+ if (!decoded.email_verified && !isImpersonationSession(decoded)) {
166
+ return emailUnverifiedResponse();
167
+ }
168
+ const firestore = firebaseAdmin.app().firestore();
169
+ const hostRef = firestore.collection('hosts').doc(hostId);
170
+ const hostSnapshot = await hostRef.get();
171
+ if (!hostSnapshot.exists) return json({
172
+ error: 'Not found'
173
+ }, 404);
174
+ // An allowlist. Reading the card is for whoever manages the store; a
175
+ // change asks Stripe for capabilities on the owner's payout account, so it
176
+ // is an admin's, like connecting that account is the owner's.
177
+ const role = ((_hostSnapshot_get = hostSnapshot.get('memberRoles')) != null ? _hostSnapshot_get : {})[decoded.uid];
178
+ const mayRead = role === 'admin' || role === 'editor';
179
+ if (!mayRead) return json({
180
+ error: 'Not found'
181
+ }, 404);
182
+ if (method === 'POST' && role !== 'admin') {
183
+ return json({
184
+ error: 'Only a site admin can change payment methods'
185
+ }, 403);
186
+ }
187
+ const owner = await getOrgForHost(hostId);
188
+ const locked = await lockdownRefusal({
189
+ request,
190
+ staff: decoded['staff'] === true,
191
+ uid: decoded.uid,
192
+ org: owner == null ? void 0 : owner.org,
193
+ host: hostSnapshot.data()
194
+ });
195
+ if (locked) return locked;
196
+ if (!checkEntitlement((_ref1 = owner == null ? void 0 : owner.org) != null ? _ref1 : {}, 'commerce')) {
197
+ return json({
198
+ error: 'Selling is not included on this plan'
199
+ }, 402);
200
+ }
201
+ const ownerUid = String((_ref2 = owner == null ? void 0 : (_owner_org = owner.org) == null ? void 0 : _owner_org.ownerUid) != null ? _ref2 : '');
202
+ const accountId = ownerUid ? (_get = (await firestore.collection('profiles').doc(ownerUid).get()).get('stripeAccountId')) != null ? _get : null : null;
203
+ const storeRef = hostRef.collection('settings').doc('store');
204
+ let settings = normalizeStorefrontPaymentMethodSettings((await storeRef.get()).get('paymentMethods'));
205
+ const platform = await platformPaymentMethodAvailability();
206
+ let capabilities = await readAccountCapabilities(accountId);
207
+ const warnings = [];
208
+ // FINISH IN STRIPE: a capability Stripe holds `inactive` needs details
209
+ // only the account holder can give, and an Express account has no login of
210
+ // its own, so a link minted here is the only way in. The owner's alone,
211
+ // as connecting the account is (`connect.ts`): the link opens the owner's
212
+ // identity and bank details.
213
+ if (method === 'POST' && parsed['action'] === 'finish') {
214
+ var _link_url;
215
+ if (!accountId || decoded.uid !== ownerUid) {
216
+ return json({
217
+ error: 'Only the organization owner can finish this in Stripe'
218
+ }, 403);
219
+ }
220
+ const back = consoleReturnUrl(headers);
221
+ const link = await stripe('POST', 'account_links', new URLSearchParams({
222
+ account: accountId,
223
+ type: 'account_onboarding',
224
+ 'collection_options[fields]': 'currently_due',
225
+ refresh_url: back,
226
+ return_url: back
227
+ }));
228
+ return json({
229
+ url: (_link_url = link.url) != null ? _link_url : null
230
+ });
231
+ }
232
+ if (method === 'POST') {
233
+ const requested = normalizeStorefrontPaymentMethodSettings(parsed['methods']);
234
+ if (!Object.keys(requested).length) {
235
+ return json({
236
+ error: 'Nothing to save'
237
+ }, 400);
238
+ }
239
+ settings = _extends({}, settings, requested);
240
+ await storeRef.set({
241
+ paymentMethods: settings,
242
+ paymentMethodsUpdatedAtMs: Date.now(),
243
+ paymentMethodsUpdatedBy: decoded.uid
244
+ }, {
245
+ merge: true
246
+ });
247
+ const wanted = accountId ? capabilitiesToRequest(settings, platform, capabilities) : [];
248
+ if (accountId && wanted.length) {
249
+ const params = new URLSearchParams();
250
+ for (const capability of wanted){
251
+ params.set(`capabilities[${capability}][requested]`, 'true');
252
+ }
253
+ try {
254
+ var _account_capabilities;
255
+ const account = await stripe('POST', `accounts/${encodeURIComponent(accountId)}`, params, `aglyn-pm-capabilities:${accountId}:${[
256
+ ...wanted
257
+ ].sort().join(',')}`);
258
+ capabilities = (_account_capabilities = account.capabilities) != null ? _account_capabilities : capabilities;
259
+ } catch (error) {
260
+ const message = error instanceof Error ? error.message : String(error);
261
+ warnings.push(`Stripe did not accept the request to enable ${wanted.join(', ')} on your payout account: ${message}`);
262
+ }
263
+ }
264
+ }
265
+ const answer = {
266
+ methods: buildPaymentMethodRows(settings, platform, capabilities),
267
+ domains: await readSiteDomainRecords(hostSnapshot.data()),
268
+ accountConnected: Boolean(accountId),
269
+ canEdit: role === 'admin',
270
+ canFinish: Boolean(accountId) && decoded.uid === ownerUid,
271
+ warnings
272
+ };
273
+ return json(answer);
274
+ } catch (error) {
275
+ const unauthenticated = invalidIdTokenResponse(error);
276
+ if (unauthenticated) return unauthenticated;
277
+ console.error(error);
278
+ return json({
279
+ error: 'Payment methods could not be loaded'
280
+ }, 500);
281
+ }
282
+ }
283
+
284
+ //# sourceMappingURL=payment-methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/payment-methods.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 { checkEntitlement, pluginRequestFromWeb } from '@aglyn/aglyn/server'\nimport type { SiteReturnHost } from '@aglyn/aglyn/app-utils/site-return-url'\nimport {\n emailUnverifiedResponse,\n firebaseAdmin,\n getOrgForHost,\n isImpersonationSession,\n lockdownRefusal,\n} from '@aglyn/tenant-data-admin'\nimport { invalidIdTokenResponse } from '@aglyn/tenant-data-admin/server/id-token-refusal'\nimport {\n isStorefrontPaymentMethodOn,\n normalizeStorefrontPaymentMethodSettings,\n STOREFRONT_PAYMENT_METHODS,\n type StorefrontPaymentMethodId,\n type StorefrontPaymentMethodSettings,\n} from '../model/commerce-payment-methods'\nimport {\n type PaymentMethodDomainRecord,\n readSiteDomainRecords,\n} from './payment-method-domains'\n\n/**\n * The merchant's payment methods card (AGL-3629):\n * `GET|POST /api/commerce/payment-methods?hostId=…`, served by the console.\n *\n * GET answers, per method, three facts the card needs and no client can read:\n *\n * - whether the PLATFORM offers it (its default payment method configuration\n * — storefront charges are destination charges with the platform as\n * merchant of record, so that configuration is the ceiling). A method the\n * platform has not turned on, or that Stripe has not made available to it,\n * is reported `unavailable` and the card does not show it at all;\n * - the connected account's capability for it, which Stripe asks platforms to\n * request before an account accepts BNPL, Cash App, Amazon Pay or crypto;\n * - the site's domain registrations, which Apple Pay depends on.\n *\n * POST saves the toggles to `hosts/{hostId}/settings/store.paymentMethods` and\n * requests the capability of each method turned on, in one account update with\n * an idempotency key. Server-side, because the toggle and the capability are\n * one decision: a toggle saved by the browser with no capability behind it\n * would read as on and never appear.\n */\n\nexport type PlatformAvailability = 'on' | 'unavailable' | null\n\nexport type CapabilityStatus = 'active' | 'pending' | 'inactive' | 'unrequested' | null\n\nexport interface PaymentMethodRow {\n id: StorefrontPaymentMethodId\n on: boolean\n platform: PlatformAvailability\n capability: CapabilityStatus\n}\n\nexport interface PaymentMethodsAnswer {\n methods: PaymentMethodRow[]\n domains: PaymentMethodDomainRecord[]\n accountConnected: boolean\n /** The caller may save toggles: a site admin. */\n canEdit: boolean\n /** The caller may open Stripe to finish a method: the organization owner. */\n canFinish: boolean\n warnings: string[]\n}\n\n/** How long the platform's configuration is trusted in memory. */\nconst PLATFORM_CONFIGURATION_TTL_MS = 10 * 60 * 1000\n\nlet platformCache: { at: number; value: Record<string, PlatformAvailability> } | null = null\n\n/** Test seam: forget the cached platform configuration. */\nexport function resetPlatformPaymentMethodCacheForTests(): void {\n platformCache = null\n}\n\nasync function stripe<T>(\n method: 'GET' | 'POST',\n path: string,\n params?: URLSearchParams,\n idempotencyKey?: string,\n): Promise<T> {\n const query = method === 'GET' && params ? `?${params}` : ''\n const response = await fetch(`https://api.stripe.com/v1/${path}${query}`, {\n method,\n headers: {\n Authorization: `Bearer ${process.env.STRIPE_SECRET_KEY}`,\n ...(method === 'POST' && { 'Content-Type': 'application/x-www-form-urlencoded' }),\n ...(idempotencyKey && { 'Idempotency-Key': idempotencyKey }),\n },\n ...(method === 'POST' && params && { body: params.toString() }),\n })\n const payload = (await response.json().catch(() => ({}))) as T & {\n error?: { message?: string }\n }\n if (!response.ok) {\n throw new Error(payload?.error?.message ?? `Stripe ${path} failed (${response.status})`)\n }\n return payload\n}\n\ninterface StripeConfiguration {\n is_default?: boolean\n application?: string | null\n active?: boolean\n [key: string]: unknown\n}\n\n/**\n * Which methods the platform's own default configuration offers. The list\n * also returns configurations OTHER Connect applications made for this\n * account (`application` set); those do not govern our sessions and are\n * skipped. `null` per method when Stripe could not be asked — the card then\n * shows the toggle without a verdict rather than hiding a method that may work.\n */\nexport async function platformPaymentMethodAvailability(): Promise<\n Record<string, PlatformAvailability>\n> {\n if (platformCache && Date.now() - platformCache.at < PLATFORM_CONFIGURATION_TTL_MS) {\n return platformCache.value\n }\n const value: Record<string, PlatformAvailability> = {}\n try {\n const list = await stripe<{ data?: StripeConfiguration[] }>(\n 'GET',\n 'payment_method_configurations',\n new URLSearchParams({ limit: '20' }),\n )\n const own =\n list.data?.find((entry) => entry.is_default && !entry.application) ??\n list.data?.find((entry) => !entry.application) ??\n null\n for (const method of STOREFRONT_PAYMENT_METHODS) {\n if (!own) {\n value[method.id] = null\n continue\n }\n const entry = own[method.configurationKey] as\n | { available?: boolean; display_preference?: { value?: string } }\n | undefined\n value[method.id] =\n entry?.available === true && entry?.display_preference?.value === 'on'\n ? 'on'\n : 'unavailable'\n }\n platformCache = { at: Date.now(), value }\n } catch (error) {\n console.warn('[commerce] payment method configuration unreadable', error)\n for (const method of STOREFRONT_PAYMENT_METHODS) value[method.id] = null\n }\n return value\n}\n\nfunction capabilityStatus(\n capabilities: Record<string, string> | undefined,\n key: string | undefined,\n): CapabilityStatus {\n if (!key) return null\n const status = capabilities?.[key]\n if (status === 'active' || status === 'pending' || status === 'inactive') return status\n return 'unrequested'\n}\n\nasync function readAccountCapabilities(\n accountId: string | null,\n): Promise<Record<string, string> | undefined> {\n if (!accountId) return undefined\n try {\n const account = await stripe<{ capabilities?: Record<string, string> }>(\n 'GET',\n `accounts/${encodeURIComponent(accountId)}`,\n )\n return account.capabilities ?? {}\n } catch (error) {\n console.warn('[commerce] connected account unreadable', error)\n return undefined\n }\n}\n\n/** The capabilities a save asks Stripe for: on, offered, not yet requested. */\nexport function capabilitiesToRequest(\n settings: StorefrontPaymentMethodSettings,\n platform: Record<string, PlatformAvailability>,\n capabilities: Record<string, string> | undefined,\n): string[] {\n return STOREFRONT_PAYMENT_METHODS.filter(\n (method) =>\n method.capability &&\n isStorefrontPaymentMethodOn(settings, method.id) &&\n platform[method.id] !== 'unavailable' &&\n capabilityStatus(capabilities, method.capability) === 'unrequested',\n ).map((method) => method.capability as string)\n}\n\nexport function buildPaymentMethodRows(\n settings: StorefrontPaymentMethodSettings,\n platform: Record<string, PlatformAvailability>,\n capabilities: Record<string, string> | undefined,\n): PaymentMethodRow[] {\n return STOREFRONT_PAYMENT_METHODS.map((method) => ({\n id: method.id,\n on: isStorefrontPaymentMethodOn(settings, method.id),\n platform: platform[method.id] ?? null,\n capability: capabilities ? capabilityStatus(capabilities, method.capability) : null,\n }))\n}\n\nconst json = (body: unknown, status = 200) => Response.json(body, { status })\n\n/**\n * Where Stripe sends the owner back: the console page they pressed the button\n * on, judged against the request's own origin so a forged `Referer` cannot\n * turn the link into a redirect to somewhere else.\n */\nexport function consoleReturnUrl(headers: Partial<Record<string, string>>): string {\n const origin = headers.origin || (headers.host ? `https://${headers.host}` : '')\n const referer = headers.referer ?? ''\n try {\n if (origin && referer && new URL(referer).origin === new URL(origin).origin) {\n return referer\n }\n } catch {\n // Unparseable: fall through to the origin.\n }\n return origin || 'https://localhost/'\n}\n\nexport async function paymentMethodsHandler(request: Request): Promise<Response> {\n const { method, headers: rawHeaders, query, body } = await pluginRequestFromWeb(request)\n const headers = rawHeaders as Partial<Record<string, string>>\n if (method !== 'GET' && method !== 'POST') {\n return json({ error: 'Method not allowed' }, 405)\n }\n if (!process.env.STRIPE_SECRET_KEY) {\n return json({ error: 'Payments are not configured (STRIPE_SECRET_KEY).' }, 501)\n }\n const authorization = headers.authorization ?? ''\n const idToken = authorization.startsWith('Bearer ')\n ? authorization.slice('Bearer '.length)\n : undefined\n if (!idToken) return json({ error: 'Unauthenticated' }, 401)\n\n const parsed =\n typeof body === 'string' ? (JSON.parse(body || '{}') as Record<string, unknown>) : (body ?? {})\n const hostId = String(\n (method === 'GET' ? query?.['hostId'] : (parsed as Record<string, unknown>)['hostId']) ?? '',\n )\n if (!hostId) return json({ error: 'Missing hostId' }, 400)\n\n try {\n const decoded = await firebaseAdmin.app().auth().verifyIdToken(idToken)\n if (!decoded.email_verified && !isImpersonationSession(decoded)) {\n return emailUnverifiedResponse()\n }\n const firestore = firebaseAdmin.app().firestore()\n const hostRef = firestore.collection('hosts').doc(hostId)\n const hostSnapshot = await hostRef.get()\n if (!hostSnapshot.exists) return json({ error: 'Not found' }, 404)\n\n // An allowlist. Reading the card is for whoever manages the store; a\n // change asks Stripe for capabilities on the owner's payout account, so it\n // is an admin's, like connecting that account is the owner's.\n const role = (hostSnapshot.get('memberRoles') ?? {})[decoded.uid]\n const mayRead = role === 'admin' || role === 'editor'\n if (!mayRead) return json({ error: 'Not found' }, 404)\n if (method === 'POST' && role !== 'admin') {\n return json({ error: 'Only a site admin can change payment methods' }, 403)\n }\n\n const owner = await getOrgForHost(hostId)\n const locked = await lockdownRefusal({\n request,\n staff: decoded['staff'] === true,\n uid: decoded.uid,\n org: owner?.org,\n host: hostSnapshot.data(),\n })\n if (locked) return locked\n if (!checkEntitlement((owner?.org ?? {}) as never, 'commerce')) {\n return json({ error: 'Selling is not included on this plan' }, 402)\n }\n\n const ownerUid = String(owner?.org?.ownerUid ?? '')\n const accountId = ownerUid\n ? (((await firestore.collection('profiles').doc(ownerUid).get()).get(\n 'stripeAccountId',\n ) as string | undefined) ?? null)\n : null\n\n const storeRef = hostRef.collection('settings').doc('store')\n let settings = normalizeStorefrontPaymentMethodSettings(\n (await storeRef.get()).get('paymentMethods'),\n )\n const platform = await platformPaymentMethodAvailability()\n let capabilities = await readAccountCapabilities(accountId)\n const warnings: string[] = []\n\n // FINISH IN STRIPE: a capability Stripe holds `inactive` needs details\n // only the account holder can give, and an Express account has no login of\n // its own, so a link minted here is the only way in. The owner's alone,\n // as connecting the account is (`connect.ts`): the link opens the owner's\n // identity and bank details.\n if (method === 'POST' && (parsed as Record<string, unknown>)['action'] === 'finish') {\n if (!accountId || decoded.uid !== ownerUid) {\n return json({ error: 'Only the organization owner can finish this in Stripe' }, 403)\n }\n const back = consoleReturnUrl(headers)\n const link = await stripe<{ url?: string }>(\n 'POST',\n 'account_links',\n new URLSearchParams({\n account: accountId,\n type: 'account_onboarding',\n 'collection_options[fields]': 'currently_due',\n refresh_url: back,\n return_url: back,\n }),\n )\n return json({ url: link.url ?? null })\n }\n\n if (method === 'POST') {\n const requested = normalizeStorefrontPaymentMethodSettings(\n (parsed as Record<string, unknown>)['methods'],\n )\n if (!Object.keys(requested).length) {\n return json({ error: 'Nothing to save' }, 400)\n }\n settings = { ...settings, ...requested }\n await storeRef.set(\n { paymentMethods: settings, paymentMethodsUpdatedAtMs: Date.now(), paymentMethodsUpdatedBy: decoded.uid },\n { merge: true },\n )\n const wanted = accountId ? capabilitiesToRequest(settings, platform, capabilities) : []\n if (accountId && wanted.length) {\n const params = new URLSearchParams()\n for (const capability of wanted) {\n params.set(`capabilities[${capability}][requested]`, 'true')\n }\n try {\n const account = await stripe<{ capabilities?: Record<string, string> }>(\n 'POST',\n `accounts/${encodeURIComponent(accountId)}`,\n params,\n `aglyn-pm-capabilities:${accountId}:${[...wanted].sort().join(',')}`,\n )\n capabilities = account.capabilities ?? capabilities\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n warnings.push(\n `Stripe did not accept the request to enable ${wanted.join(', ')} on your payout account: ${message}`,\n )\n }\n }\n }\n\n const answer: PaymentMethodsAnswer = {\n methods: buildPaymentMethodRows(settings, platform, capabilities),\n domains: await readSiteDomainRecords(hostSnapshot.data() as SiteReturnHost | undefined),\n accountConnected: Boolean(accountId),\n canEdit: role === 'admin',\n canFinish: Boolean(accountId) && decoded.uid === ownerUid,\n warnings,\n }\n return json(answer)\n } catch (error) {\n const unauthenticated = invalidIdTokenResponse(error)\n if (unauthenticated) return unauthenticated\n console.error(error)\n return json({ error: 'Payment methods could not be loaded' }, 500)\n }\n}\n"],"names":["checkEntitlement","pluginRequestFromWeb","emailUnverifiedResponse","firebaseAdmin","getOrgForHost","isImpersonationSession","lockdownRefusal","invalidIdTokenResponse","isStorefrontPaymentMethodOn","normalizeStorefrontPaymentMethodSettings","STOREFRONT_PAYMENT_METHODS","readSiteDomainRecords","PLATFORM_CONFIGURATION_TTL_MS","platformCache","resetPlatformPaymentMethodCacheForTests","stripe","method","path","params","idempotencyKey","query","response","fetch","headers","Authorization","process","env","STRIPE_SECRET_KEY","body","toString","payload","json","catch","ok","Error","error","message","status","platformPaymentMethodAvailability","Date","now","at","value","list","URLSearchParams","limit","own","data","find","entry","is_default","application","id","configurationKey","available","display_preference","console","warn","capabilityStatus","capabilities","key","readAccountCapabilities","accountId","undefined","account","encodeURIComponent","capabilitiesToRequest","settings","platform","filter","capability","map","buildPaymentMethodRows","on","Response","consoleReturnUrl","origin","host","referer","URL","paymentMethodsHandler","request","rawHeaders","authorization","idToken","startsWith","slice","length","parsed","JSON","parse","hostId","String","hostSnapshot","owner","decoded","app","auth","verifyIdToken","email_verified","firestore","hostRef","collection","doc","get","exists","role","uid","mayRead","locked","staff","org","ownerUid","storeRef","warnings","link","back","type","refresh_url","return_url","url","requested","Object","keys","set","paymentMethods","paymentMethodsUpdatedAtMs","paymentMethodsUpdatedBy","merge","wanted","sort","join","push","answer","methods","domains","accountConnected","Boolean","canEdit","canFinish","unauthenticated"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,EAAEC,oBAAoB,QAAQ,sBAAqB;AAE5E,SACEC,uBAAuB,EACvBC,aAAa,EACbC,aAAa,EACbC,sBAAsB,EACtBC,eAAe,QACV,2BAA0B;AACjC,SAASC,sBAAsB,QAAQ,mDAAkD;AACzF,SACEC,2BAA2B,EAC3BC,wCAAwC,EACxCC,0BAA0B,QAGrB,uCAAmC;AAC1C,SAEEC,qBAAqB,QAChB,8BAA0B;AA8CjC,gEAAgE,GAChE,MAAMC,gCAAgC,KAAK,KAAK;AAEhD,IAAIC,gBAAoF;AAExF,yDAAyD,GACzD,OAAO,SAASC;IACdD,gBAAgB;AAClB;AAEA,eAAeE,OACbC,MAAsB,EACtBC,IAAY,EACZC,MAAwB,EACxBC,cAAuB;IAEvB,MAAMC,QAAQJ,WAAW,SAASE,SAAS,CAAC,CAAC,EAAEA,QAAQ,GAAG;IAC1D,MAAMG,WAAW,MAAMC,MAAM,CAAC,0BAA0B,EAAEL,OAAOG,OAAO,EAAE;QACxEJ;QACAO,SAAS;YACPC,eAAe,CAAC,OAAO,EAAEC,QAAQC,GAAG,CAACC,iBAAiB,EAAE;WACpDX,WAAW,UAAU;YAAE,gBAAgB;QAAoC,GAC3EG,kBAAkB;YAAE,mBAAmBA;QAAe;OAExDH,WAAW,UAAUE,UAAU;QAAEU,MAAMV,OAAOW,QAAQ;IAAG;IAE/D,MAAMC,UAAW,MAAMT,SAASU,IAAI,GAAGC,KAAK,CAAC,IAAO,CAAA,CAAC,CAAA;IAGrD,IAAI,CAACX,SAASY,EAAE,EAAE;;YACAH;QAAhB,MAAM,IAAII,cAAMJ,4BAAAA,iBAAAA,QAASK,KAAK,qBAAdL,eAAgBM,OAAO,mBAAI,CAAC,OA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AO;QACd,MAAMyG,kBAAkBrI,uBAAuB4B;QAC/C,IAAIyG,iBAAiB,OAAOA;QAC5BpF,QAAQrB,KAAK,CAACA;QACd,OAAOJ,KAAK;YAAEI,OAAO;QAAsC,GAAG;IAChE;AACF"}
@@ -0,0 +1,50 @@
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 { PluginApiRequest } from '@aglyn/aglyn/server';
18
+ /** Who is working the register, once the gate has admitted them. */
19
+ export interface PosStaff {
20
+ uid: string;
21
+ hostId: string;
22
+ orgId: string;
23
+ org: Record<string, any> | null;
24
+ }
25
+ export type PosStaffGate = {
26
+ ok: true;
27
+ staff: PosStaff;
28
+ } | {
29
+ ok: false;
30
+ status: number;
31
+ error: string;
32
+ };
33
+ /**
34
+ * The register's gate, shared by every POS route (AGL-3607): the same three
35
+ * questions `pos-order.ts` asks, in the same order, so a payment, a reader or
36
+ * a display pairing is refused to exactly the people a sale is refused to.
37
+ *
38
+ * 1. A Firebase ID token.
39
+ * 2. `admin` or `editor` on THIS site (`memberRoles`), an allowlist so a role
40
+ * added later is refused until someone decides otherwise (AGL-2262).
41
+ * 3. `managePos` on the member's resolved permissions (AGL-2474), and the
42
+ * `pos` plan entitlement on the org that owns the site.
43
+ */
44
+ export declare function authorizePosStaff(req: PluginApiRequest, hostId: string): Promise<PosStaffGate>;
45
+ /** A JSON body, whether the dispatcher parsed it or not. */
46
+ export declare function posRequestBody(req: PluginApiRequest): Record<string, any>;
47
+ /** A GET request's query as a flat body, first value of each key. */
48
+ export declare function posQueryBody(req: PluginApiRequest): Record<string, any>;
49
+ /** The request's Idempotency-Key header, trimmed and bounded. */
50
+ export declare function posIdempotencyKey(req: PluginApiRequest): string;
@@ -0,0 +1,121 @@
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
+ */ import * as Aglyn from "@aglyn/aglyn/server";
17
+ import { firebaseAdmin, getOrgForHost } from "@aglyn/tenant-data-admin";
18
+ import { resolveOrgPermissions } from "@aglyn/tenant-runtime/org-permissions";
19
+ import { isRefusedIdToken } from "@aglyn/tenant-data-admin/server/id-token-refusal";
20
+ /**
21
+ * The register's gate, shared by every POS route (AGL-3607): the same three
22
+ * questions `pos-order.ts` asks, in the same order, so a payment, a reader or
23
+ * a display pairing is refused to exactly the people a sale is refused to.
24
+ *
25
+ * 1. A Firebase ID token.
26
+ * 2. `admin` or `editor` on THIS site (`memberRoles`), an allowlist so a role
27
+ * added later is refused until someone decides otherwise (AGL-2262).
28
+ * 3. `managePos` on the member's resolved permissions (AGL-2474), and the
29
+ * `pos` plan entitlement on the org that owns the site.
30
+ */ export async function authorizePosStaff(req, hostId) {
31
+ var _req_headers_authorization, _hostSnapshot_get, _ref, _ref1, _ref2;
32
+ var _ownerOrg_org;
33
+ const authorization = String((_req_headers_authorization = req.headers.authorization) != null ? _req_headers_authorization : '');
34
+ const idToken = authorization.startsWith('Bearer ') ? authorization.slice('Bearer '.length) : '';
35
+ if (!idToken) return {
36
+ ok: false,
37
+ status: 401,
38
+ error: 'Unauthenticated'
39
+ };
40
+ if (!hostId) return {
41
+ ok: false,
42
+ status: 400,
43
+ error: 'Missing hostId'
44
+ };
45
+ let uid;
46
+ try {
47
+ uid = (await firebaseAdmin.app().auth().verifyIdToken(idToken)).uid;
48
+ } catch (error) {
49
+ if (!isRefusedIdToken(error)) throw error;
50
+ return {
51
+ ok: false,
52
+ status: 401,
53
+ error: 'Unauthenticated'
54
+ };
55
+ }
56
+ const hostSnapshot = await firebaseAdmin.app().firestore().collection('hosts').doc(hostId).get();
57
+ if (!hostSnapshot.exists) return {
58
+ ok: false,
59
+ status: 404,
60
+ error: 'Unknown site'
61
+ };
62
+ const memberRole = ((_hostSnapshot_get = hostSnapshot.get('memberRoles')) != null ? _hostSnapshot_get : {})[uid];
63
+ if (memberRole !== 'admin' && memberRole !== 'editor') {
64
+ return {
65
+ ok: false,
66
+ status: 403,
67
+ error: 'Not permitted'
68
+ };
69
+ }
70
+ const membership = await resolveOrgPermissions(uid, {
71
+ hostId
72
+ });
73
+ if (!membership.permissions.managePos) {
74
+ return {
75
+ ok: false,
76
+ status: 403,
77
+ error: 'Not permitted'
78
+ };
79
+ }
80
+ const ownerOrg = await getOrgForHost(hostId);
81
+ if (!Aglyn.checkEntitlement(ownerOrg == null ? void 0 : ownerOrg.org, 'pos')) {
82
+ return {
83
+ ok: false,
84
+ status: 403,
85
+ error: 'POS requires the Pro plan or above'
86
+ };
87
+ }
88
+ return {
89
+ ok: true,
90
+ staff: {
91
+ uid,
92
+ hostId,
93
+ orgId: String((_ref = (_ref1 = ownerOrg == null ? void 0 : (_ownerOrg_org = ownerOrg.org) == null ? void 0 : _ownerOrg_org.id) != null ? _ref1 : ownerOrg == null ? void 0 : ownerOrg.orgId) != null ? _ref : ''),
94
+ org: (_ref2 = ownerOrg == null ? void 0 : ownerOrg.org) != null ? _ref2 : null
95
+ }
96
+ };
97
+ }
98
+ /** A JSON body, whether the dispatcher parsed it or not. */ export function posRequestBody(req) {
99
+ if (typeof req.body === 'string') {
100
+ try {
101
+ const parsed = JSON.parse(req.body);
102
+ return parsed && typeof parsed === 'object' ? parsed : {};
103
+ } catch (unused) {
104
+ return {};
105
+ }
106
+ }
107
+ return req.body && typeof req.body === 'object' ? req.body : {};
108
+ }
109
+ /** A GET request's query as a flat body, first value of each key. */ export function posQueryBody(req) {
110
+ var _req_query;
111
+ return Object.fromEntries(Object.entries((_req_query = req.query) != null ? _req_query : {}).map(([key, value])=>[
112
+ key,
113
+ Array.isArray(value) ? value[0] : value
114
+ ]));
115
+ }
116
+ /** The request's Idempotency-Key header, trimmed and bounded. */ export function posIdempotencyKey(req) {
117
+ var _ref, _req_headers_idempotencykey;
118
+ return String((_ref = (_req_headers_idempotencykey = req.headers['idempotency-key']) != null ? _req_headers_idempotencykey : req.headers['Idempotency-Key']) != null ? _ref : '').trim().slice(0, 200);
119
+ }
120
+
121
+ //# sourceMappingURL=pos-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/pos-auth.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport * as Aglyn from '@aglyn/aglyn/server'\nimport type { PluginApiRequest } from '@aglyn/aglyn/server'\nimport { firebaseAdmin, getOrgForHost } from '@aglyn/tenant-data-admin'\nimport { resolveOrgPermissions } from '@aglyn/tenant-runtime/org-permissions'\nimport { isRefusedIdToken } from '@aglyn/tenant-data-admin/server/id-token-refusal'\n\n/** Who is working the register, once the gate has admitted them. */\nexport interface PosStaff {\n uid: string\n hostId: string\n orgId: string\n org: Record<string, any> | null\n}\n\nexport type PosStaffGate =\n | { ok: true; staff: PosStaff }\n | { ok: false; status: number; error: string }\n\n/**\n * The register's gate, shared by every POS route (AGL-3607): the same three\n * questions `pos-order.ts` asks, in the same order, so a payment, a reader or\n * a display pairing is refused to exactly the people a sale is refused to.\n *\n * 1. A Firebase ID token.\n * 2. `admin` or `editor` on THIS site (`memberRoles`), an allowlist so a role\n * added later is refused until someone decides otherwise (AGL-2262).\n * 3. `managePos` on the member's resolved permissions (AGL-2474), and the\n * `pos` plan entitlement on the org that owns the site.\n */\nexport async function authorizePosStaff(\n req: PluginApiRequest,\n hostId: string,\n): Promise<PosStaffGate> {\n const authorization = String(req.headers.authorization ?? '')\n const idToken = authorization.startsWith('Bearer ')\n ? authorization.slice('Bearer '.length)\n : ''\n if (!idToken) return { ok: false, status: 401, error: 'Unauthenticated' }\n if (!hostId) return { ok: false, status: 400, error: 'Missing hostId' }\n let uid: string\n try {\n uid = (await firebaseAdmin.app().auth().verifyIdToken(idToken)).uid\n } catch (error) {\n if (!isRefusedIdToken(error)) throw error\n return { ok: false, status: 401, error: 'Unauthenticated' }\n }\n const hostSnapshot = await firebaseAdmin\n .app()\n .firestore()\n .collection('hosts')\n .doc(hostId)\n .get()\n if (!hostSnapshot.exists) return { ok: false, status: 404, error: 'Unknown site' }\n const memberRole = (hostSnapshot.get('memberRoles') ?? {})[uid]\n if (memberRole !== 'admin' && memberRole !== 'editor') {\n return { ok: false, status: 403, error: 'Not permitted' }\n }\n const membership = await resolveOrgPermissions(uid, { hostId })\n if (!membership.permissions.managePos) {\n return { ok: false, status: 403, error: 'Not permitted' }\n }\n const ownerOrg = await getOrgForHost(hostId)\n if (!Aglyn.checkEntitlement(ownerOrg?.org as any, 'pos')) {\n return { ok: false, status: 403, error: 'POS requires the Pro plan or above' }\n }\n return {\n ok: true,\n staff: {\n uid,\n hostId,\n orgId: String(ownerOrg?.org?.id ?? ownerOrg?.orgId ?? ''),\n org: (ownerOrg?.org as Record<string, any>) ?? null,\n },\n }\n}\n\n/** A JSON body, whether the dispatcher parsed it or not. */\nexport function posRequestBody(req: PluginApiRequest): Record<string, any> {\n if (typeof req.body === 'string') {\n try {\n const parsed = JSON.parse(req.body)\n return parsed && typeof parsed === 'object' ? parsed : {}\n } catch {\n return {}\n }\n }\n return req.body && typeof req.body === 'object' ? req.body : {}\n}\n\n/** A GET request's query as a flat body, first value of each key. */\nexport function posQueryBody(req: PluginApiRequest): Record<string, any> {\n return Object.fromEntries(\n Object.entries(req.query ?? {}).map(([key, value]) => [\n key,\n Array.isArray(value) ? value[0] : value,\n ]),\n )\n}\n\n/** The request's Idempotency-Key header, trimmed and bounded. */\nexport function posIdempotencyKey(req: PluginApiRequest): string {\n return String(\n req.headers['idempotency-key'] ?? req.headers['Idempotency-Key'] ?? '',\n )\n .trim()\n .slice(0, 200)\n}\n"],"names":["Aglyn","firebaseAdmin","getOrgForHost","resolveOrgPermissions","isRefusedIdToken","authorizePosStaff","req","hostId","hostSnapshot","ownerOrg","authorization","String","headers","idToken","startsWith","slice","length","ok","status","error","uid","app","auth","verifyIdToken","firestore","collection","doc","get","exists","memberRole","membership","permissions","managePos","checkEntitlement","org","staff","orgId","id","posRequestBody","body","parsed","JSON","parse","posQueryBody","Object","fromEntries","entries","query","map","key","value","Array","isArray","posIdempotencyKey","trim"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,sBAAqB;AAE5C,SAASC,aAAa,EAAEC,aAAa,QAAQ,2BAA0B;AACvE,SAASC,qBAAqB,QAAQ,wCAAuC;AAC7E,SAASC,gBAAgB,QAAQ,mDAAkD;AAcnF;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,kBACpBC,GAAqB,EACrBC,MAAc;QAEeD,4BAoBTE,mBAiBFC;QAAAA;IArClB,MAAMC,gBAAgBC,QAAOL,6BAAAA,IAAIM,OAAO,CAACF,aAAa,YAAzBJ,6BAA6B;IAC1D,MAAMO,UAAUH,cAAcI,UAAU,CAAC,a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,IAAI;QACJkB,OAAO;YACLf;YACAb;YACA6B,OAAOzB,QAAOF,gBAAAA,6BAAAA,gBAAAA,SAAUyB,GAAG,qBAAbzB,cAAe4B,EAAE,oBAAI5B,4BAAAA,SAAU2B,KAAK,YAApC3B,OAAwC;YACtDyB,GAAG,WAAGzB,4BAAAA,SAAUyB,GAAG,oBAA4B;QACjD;IACF;AACF;AAEA,0DAA0D,GAC1D,OAAO,SAASI,eAAehC,GAAqB;IAClD,IAAI,OAAOA,IAAIiC,IAAI,KAAK,UAAU;QAChC,IAAI;YACF,MAAMC,SAASC,KAAKC,KAAK,CAACpC,IAAIiC,IAAI;YAClC,OAAOC,UAAU,OAAOA,WAAW,WAAWA,SAAS,CAAC;QAC1D,EAAE,eAAM;YACN,OAAO,CAAC;QACV;IACF;IACA,OAAOlC,IAAIiC,IAAI,IAAI,OAAOjC,IAAIiC,IAAI,KAAK,WAAWjC,IAAIiC,IAAI,GAAG,CAAC;AAChE;AAEA,mEAAmE,GACnE,OAAO,SAASI,aAAarC,GAAqB;QAE/BA;IADjB,OAAOsC,OAAOC,WAAW,CACvBD,OAAOE,OAAO,EAACxC,aAAAA,IAAIyC,KAAK,YAATzC,aAAa,CAAC,GAAG0C,GAAG,CAAC,CAAC,CAACC,KAAKC,MAAM,GAAK;YACpDD;YACAE,MAAMC,OAAO,CAACF,SAASA,KAAK,CAAC,EAAE,GAAGA;SACnC;AAEL;AAEA,+DAA+D,GAC/D,OAAO,SAASG,kBAAkB/C,GAAqB;QAEnDA,MAAAA;IADF,OAAOK,QACLL,QAAAA,8BAAAA,IAAIM,OAAO,CAAC,kBAAkB,YAA9BN,8BAAkCA,IAAIM,OAAO,CAAC,kBAAkB,YAAhEN,OAAoE,IAEnEgD,IAAI,GACJvC,KAAK,CAAC,GAAG;AACd"}
@@ -0,0 +1,49 @@
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 { PluginApiHandler, PluginApiRequest } from '@aglyn/aglyn/server';
18
+ import type { PluginContactCaptureRequest, PluginContactCaptured } from '@aglyn/aglyn/plugin-manager/plugin-contact-capture';
19
+ import { type PluginPersonRecord, type PluginPersonSearchRequest } from '@aglyn/aglyn/plugin-manager/plugin-person-records';
20
+ import { type PosOpsDeps } from './pos-ops-gate';
21
+ /** The statuses a customer actually paid in. A refund is netted, not excluded. */
22
+ export declare const POS_CUSTOMER_PAID_STATUSES: readonly ["paid", "partially_fulfilled", "fulfilled", "delivered", "refunded"];
23
+ export interface PosCustomerDeps extends PosOpsDeps {
24
+ searchPeople(request: PluginPersonSearchRequest): Promise<PluginPersonRecord[] | null>;
25
+ captureContact(request: PluginContactCaptureRequest): Promise<PluginContactCaptured | null>;
26
+ /** Orders, spend and refunds for one address on one site, by aggregate. */
27
+ orderStats(hostRef: FirebaseFirestore.DocumentReference, emailLower: string): Promise<{
28
+ orderCount: number;
29
+ spentCents: number;
30
+ refundedCents: number;
31
+ }>;
32
+ }
33
+ export declare function defaultPosCustomerDeps(): PosCustomerDeps;
34
+ /** One person as the register lists them. */
35
+ export interface PosCustomer {
36
+ kind: string;
37
+ id: string;
38
+ name: string;
39
+ email: string | null;
40
+ phone: string | null;
41
+ }
42
+ type Outcome = {
43
+ status: number;
44
+ body: Record<string, unknown>;
45
+ };
46
+ export declare function handlePosCustomer(deps: PosCustomerDeps, req: PluginApiRequest): Promise<Outcome>;
47
+ export declare function createPosCustomerHandler(deps?: () => PosCustomerDeps): PluginApiHandler;
48
+ export declare const posCustomerHandler: PluginApiHandler;
49
+ export {};