@aglyn/plugins-commerce 1.0.0-beta.229 → 1.0.0-beta.231

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 (590) 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/customer-notifications-card.component.d.ts +19 -0
  39. package/src/lib/components/console/customer-notifications-card.component.js +149 -0
  40. package/src/lib/components/console/customer-notifications-card.component.js.map +1 -0
  41. package/src/lib/components/console/host-orders-card.component.js +84 -5
  42. package/src/lib/components/console/host-orders-card.component.js.map +1 -1
  43. package/src/lib/components/console/locations-card.component.js +164 -57
  44. package/src/lib/components/console/locations-card.component.js.map +1 -1
  45. package/src/lib/components/console/order-detail-dialog.component.js +209 -61
  46. package/src/lib/components/console/order-detail-dialog.component.js.map +1 -1
  47. package/src/lib/components/console/order-fulfillment-panel.component.d.ts +48 -0
  48. package/src/lib/components/console/order-fulfillment-panel.component.js +542 -0
  49. package/src/lib/components/console/order-fulfillment-panel.component.js.map +1 -0
  50. package/src/lib/components/console/order-invoice.component.d.ts +33 -0
  51. package/src/lib/components/console/order-invoice.component.js +81 -0
  52. package/src/lib/components/console/order-invoice.component.js.map +1 -0
  53. package/src/lib/components/console/order-receipt-resend.component.d.ts +21 -0
  54. package/src/lib/components/console/order-receipt-resend.component.js +203 -0
  55. package/src/lib/components/console/order-receipt-resend.component.js.map +1 -0
  56. package/src/lib/components/console/order-returns.component.d.ts +36 -0
  57. package/src/lib/components/console/order-returns.component.js +142 -0
  58. package/src/lib/components/console/order-returns.component.js.map +1 -0
  59. package/src/lib/components/console/order-shipping-actions.component.d.ts +54 -0
  60. package/src/lib/components/console/order-shipping-actions.component.js +149 -0
  61. package/src/lib/components/console/order-shipping-actions.component.js.map +1 -0
  62. package/src/lib/components/console/order-webhooks-card.component.d.ts +50 -0
  63. package/src/lib/components/console/order-webhooks-card.component.js +623 -0
  64. package/src/lib/components/console/order-webhooks-card.component.js.map +1 -0
  65. package/src/lib/components/console/order-zones.d.ts +155 -0
  66. package/src/lib/components/console/order-zones.js +40 -0
  67. package/src/lib/components/console/order-zones.js.map +1 -0
  68. package/src/lib/components/console/payment-methods-card.component.d.ts +67 -0
  69. package/src/lib/components/console/payment-methods-card.component.js +395 -0
  70. package/src/lib/components/console/payment-methods-card.component.js.map +1 -0
  71. package/src/lib/components/console/pos/pos-api.d.ts +124 -0
  72. package/src/lib/components/console/pos/pos-api.js +101 -0
  73. package/src/lib/components/console/pos/pos-api.js.map +1 -0
  74. package/src/lib/components/console/pos/pos-cart-panel.component.d.ts +36 -0
  75. package/src/lib/components/console/pos/pos-cart-panel.component.js +160 -0
  76. package/src/lib/components/console/pos/pos-cart-panel.component.js.map +1 -0
  77. package/src/lib/components/console/pos/pos-item-dialog.component.d.ts +39 -0
  78. package/src/lib/components/console/pos/pos-item-dialog.component.js +352 -0
  79. package/src/lib/components/console/pos/pos-item-dialog.component.js.map +1 -0
  80. package/src/lib/components/console/pos/pos-product-grid.component.d.ts +47 -0
  81. package/src/lib/components/console/pos/pos-product-grid.component.js +272 -0
  82. package/src/lib/components/console/pos/pos-product-grid.component.js.map +1 -0
  83. package/src/lib/components/console/pos/pos-receipt-panel.component.d.ts +27 -0
  84. package/src/lib/components/console/pos/pos-receipt-panel.component.js +282 -0
  85. package/src/lib/components/console/pos/pos-receipt-panel.component.js.map +1 -0
  86. package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +53 -0
  87. package/src/lib/components/console/pos/pos-tender-dialogs.component.js +445 -0
  88. package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -0
  89. package/src/lib/components/console/pos/pos-tender-panel.component.d.ts +31 -0
  90. package/src/lib/components/console/pos/pos-tender-panel.component.js +640 -0
  91. package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -0
  92. package/src/lib/components/console/pos/use-pos-display.d.ts +43 -0
  93. package/src/lib/components/console/pos/use-pos-display.js +161 -0
  94. package/src/lib/components/console/pos/use-pos-display.js.map +1 -0
  95. package/src/lib/components/console/pos-devices-card.component.d.ts +14 -0
  96. package/src/lib/components/console/pos-devices-card.component.js +546 -0
  97. package/src/lib/components/console/pos-devices-card.component.js.map +1 -0
  98. package/src/lib/components/console/pos-display/brand-screen.d.ts +33 -0
  99. package/src/lib/components/console/pos-display/brand-screen.js +85 -0
  100. package/src/lib/components/console/pos-display/brand-screen.js.map +1 -0
  101. package/src/lib/components/console/pos-display/cart-screen.d.ts +29 -0
  102. package/src/lib/components/console/pos-display/cart-screen.js +166 -0
  103. package/src/lib/components/console/pos-display/cart-screen.js.map +1 -0
  104. package/src/lib/components/console/pos-display/pairing-screen.d.ts +24 -0
  105. package/src/lib/components/console/pos-display/pairing-screen.js +127 -0
  106. package/src/lib/components/console/pos-display/pairing-screen.js.map +1 -0
  107. package/src/lib/components/console/pos-display/pos-display-api.d.ts +90 -0
  108. package/src/lib/components/console/pos-display/pos-display-api.js +140 -0
  109. package/src/lib/components/console/pos-display/pos-display-api.js.map +1 -0
  110. package/src/lib/components/console/pos-display/receipt-screen.d.ts +35 -0
  111. package/src/lib/components/console/pos-display/receipt-screen.js +200 -0
  112. package/src/lib/components/console/pos-display/receipt-screen.js.map +1 -0
  113. package/src/lib/components/console/pos-display/tip-screen.d.ts +36 -0
  114. package/src/lib/components/console/pos-display/tip-screen.js +211 -0
  115. package/src/lib/components/console/pos-display/tip-screen.js.map +1 -0
  116. package/src/lib/components/console/pos-display-page.component.d.ts +16 -0
  117. package/src/lib/components/console/pos-display-page.component.js +407 -0
  118. package/src/lib/components/console/pos-display-page.component.js.map +1 -0
  119. package/src/lib/components/console/pos-ops/pos-customer-lookup.component.d.ts +40 -0
  120. package/src/lib/components/console/pos-ops/pos-customer-lookup.component.js +289 -0
  121. package/src/lib/components/console/pos-ops/pos-customer-lookup.component.js.map +1 -0
  122. package/src/lib/components/console/pos-ops/pos-last-receipt.component.d.ts +34 -0
  123. package/src/lib/components/console/pos-ops/pos-last-receipt.component.js +61 -0
  124. package/src/lib/components/console/pos-ops/pos-last-receipt.component.js.map +1 -0
  125. package/src/lib/components/console/pos-ops/pos-operations-bar.component.d.ts +38 -0
  126. package/src/lib/components/console/pos-ops/pos-operations-bar.component.js +129 -0
  127. package/src/lib/components/console/pos-ops/pos-operations-bar.component.js.map +1 -0
  128. package/src/lib/components/console/pos-ops/pos-ops-api.d.ts +37 -0
  129. package/src/lib/components/console/pos-ops/pos-ops-api.js +60 -0
  130. package/src/lib/components/console/pos-ops/pos-ops-api.js.map +1 -0
  131. package/src/lib/components/console/pos-ops/pos-pin-pad.component.d.ts +48 -0
  132. package/src/lib/components/console/pos-ops/pos-pin-pad.component.js +220 -0
  133. package/src/lib/components/console/pos-ops/pos-pin-pad.component.js.map +1 -0
  134. package/src/lib/components/console/pos-ops/pos-receipt-actions.component.d.ts +63 -0
  135. package/src/lib/components/console/pos-ops/pos-receipt-actions.component.js +186 -0
  136. package/src/lib/components/console/pos-ops/pos-receipt-actions.component.js.map +1 -0
  137. package/src/lib/components/console/pos-ops/pos-receipt.d.ts +39 -0
  138. package/src/lib/components/console/pos-ops/pos-receipt.js +182 -0
  139. package/src/lib/components/console/pos-ops/pos-receipt.js.map +1 -0
  140. package/src/lib/components/console/pos-ops/pos-return-dialog.component.d.ts +40 -0
  141. package/src/lib/components/console/pos-ops/pos-return-dialog.component.js +465 -0
  142. package/src/lib/components/console/pos-ops/pos-return-dialog.component.js.map +1 -0
  143. package/src/lib/components/console/pos-ops/pos-shift-history-card.component.d.ts +29 -0
  144. package/src/lib/components/console/pos-ops/pos-shift-history-card.component.js +253 -0
  145. package/src/lib/components/console/pos-ops/pos-shift-history-card.component.js.map +1 -0
  146. package/src/lib/components/console/pos-ops/pos-shift-panel.component.d.ts +34 -0
  147. package/src/lib/components/console/pos-ops/pos-shift-panel.component.js +494 -0
  148. package/src/lib/components/console/pos-ops/pos-shift-panel.component.js.map +1 -0
  149. package/src/lib/components/console/pos-ops/pos-shift-report.component.d.ts +37 -0
  150. package/src/lib/components/console/pos-ops/pos-shift-report.component.js +102 -0
  151. package/src/lib/components/console/pos-ops/pos-shift-report.component.js.map +1 -0
  152. package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.d.ts +30 -0
  153. package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.js +277 -0
  154. package/src/lib/components/console/pos-ops/pos-staff-pins-card.component.js.map +1 -0
  155. package/src/lib/components/console/pos-ops/register-ops.d.ts +28 -0
  156. package/src/lib/components/console/pos-ops/register-ops.js +28 -0
  157. package/src/lib/components/console/pos-ops/register-ops.js.map +1 -0
  158. package/src/lib/components/console/pos-ops/use-pos-cashier.d.ts +46 -0
  159. package/src/lib/components/console/pos-ops/use-pos-cashier.js +128 -0
  160. package/src/lib/components/console/pos-ops/use-pos-cashier.js.map +1 -0
  161. package/src/lib/components/console/pos-ops/use-pos-sale-receipt.d.ts +36 -0
  162. package/src/lib/components/console/pos-ops/use-pos-sale-receipt.js +64 -0
  163. package/src/lib/components/console/pos-ops/use-pos-sale-receipt.js.map +1 -0
  164. package/src/lib/components/console/pos-page.component.d.ts +13 -5
  165. package/src/lib/components/console/pos-page.component.js +729 -657
  166. package/src/lib/components/console/pos-page.component.js.map +1 -1
  167. package/src/lib/components/console/product-editor-dialog.component.js +51 -7
  168. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  169. package/src/lib/components/console/product-labels-dialog.component.d.ts +13 -0
  170. package/src/lib/components/console/product-labels-dialog.component.js +197 -0
  171. package/src/lib/components/console/product-labels-dialog.component.js.map +1 -0
  172. package/src/lib/components/console/product-register-fields.component.d.ts +19 -0
  173. package/src/lib/components/console/product-register-fields.component.js +241 -0
  174. package/src/lib/components/console/product-register-fields.component.js.map +1 -0
  175. package/src/lib/components/console/product-zones.d.ts +58 -2
  176. package/src/lib/components/console/product-zones.js +10 -2
  177. package/src/lib/components/console/product-zones.js.map +1 -1
  178. package/src/lib/components/console/products-hub-card.component.js +51 -11
  179. package/src/lib/components/console/products-hub-card.component.js.map +1 -1
  180. package/src/lib/components/console/register-hardware-card.component.d.ts +33 -0
  181. package/src/lib/components/console/register-hardware-card.component.js +826 -0
  182. package/src/lib/components/console/register-hardware-card.component.js.map +1 -0
  183. package/src/lib/components/console/registers-card.component.js +24 -5
  184. package/src/lib/components/console/registers-card.component.js.map +1 -1
  185. package/src/lib/components/console/return-actions.d.ts +38 -0
  186. package/src/lib/components/console/return-actions.js +76 -0
  187. package/src/lib/components/console/return-actions.js.map +1 -0
  188. package/src/lib/components/console/return-detail-dialog.component.d.ts +34 -0
  189. package/src/lib/components/console/return-detail-dialog.component.js +718 -0
  190. package/src/lib/components/console/return-detail-dialog.component.js.map +1 -0
  191. package/src/lib/components/console/return-settings-card.component.d.ts +34 -0
  192. package/src/lib/components/console/return-settings-card.component.js +195 -0
  193. package/src/lib/components/console/return-settings-card.component.js.map +1 -0
  194. package/src/lib/components/console/return-zones.d.ts +87 -0
  195. package/src/lib/components/console/return-zones.js +31 -0
  196. package/src/lib/components/console/return-zones.js.map +1 -0
  197. package/src/lib/components/console/returns-card.component.d.ts +45 -0
  198. package/src/lib/components/console/returns-card.component.js +159 -0
  199. package/src/lib/components/console/returns-card.component.js.map +1 -0
  200. package/src/lib/components/console/shipping-settings-card.component.js +161 -5
  201. package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
  202. package/src/lib/components/console/shippingeasy-card.component.d.ts +59 -0
  203. package/src/lib/components/console/shippingeasy-card.component.js +378 -0
  204. package/src/lib/components/console/shippingeasy-card.component.js.map +1 -0
  205. package/src/lib/components/console/shipstation-card.component.d.ts +35 -0
  206. package/src/lib/components/console/shipstation-card.component.js +345 -0
  207. package/src/lib/components/console/shipstation-card.component.js.map +1 -0
  208. package/src/lib/components/console/start-return-dialog.component.d.ts +40 -0
  209. package/src/lib/components/console/start-return-dialog.component.js +243 -0
  210. package/src/lib/components/console/start-return-dialog.component.js.map +1 -0
  211. package/src/lib/components/console/stock-movements-card.component.js +2 -1
  212. package/src/lib/components/console/stock-movements-card.component.js.map +1 -1
  213. package/src/lib/components/console/store-settings-card.component.js +2 -66
  214. package/src/lib/components/console/store-settings-card.component.js.map +1 -1
  215. package/src/lib/components/console/store-zones.d.ts +42 -0
  216. package/src/lib/components/console/store-zones.js +39 -0
  217. package/src/lib/components/console/store-zones.js.map +1 -0
  218. package/src/lib/components/order-status.d.ts +36 -0
  219. package/src/lib/components/order-status.js +502 -0
  220. package/src/lib/components/order-status.js.map +1 -0
  221. package/src/lib/components/product-detail.js +44 -2
  222. package/src/lib/components/product-detail.js.map +1 -1
  223. package/src/lib/components/return-request.d.ts +32 -0
  224. package/src/lib/components/return-request.js +576 -0
  225. package/src/lib/components/return-request.js.map +1 -0
  226. package/src/lib/components/storefront-payment-appearance.d.ts +32 -0
  227. package/src/lib/components/storefront-payment-appearance.js +114 -0
  228. package/src/lib/components/storefront-payment-appearance.js.map +1 -0
  229. package/src/lib/components/storefront-payment-element.d.ts +57 -1
  230. package/src/lib/components/storefront-payment-element.js +332 -33
  231. package/src/lib/components/storefront-payment-element.js.map +1 -1
  232. package/src/lib/constants/order-status.d.ts +22 -0
  233. package/src/lib/constants/order-status.js +22 -0
  234. package/src/lib/constants/order-status.js.map +1 -0
  235. package/src/lib/constants/return-request.d.ts +27 -0
  236. package/src/lib/constants/return-request.js +32 -0
  237. package/src/lib/constants/return-request.js.map +1 -0
  238. package/src/lib/constants/stock-movement-query.js +2 -1
  239. package/src/lib/constants/stock-movement-query.js.map +1 -1
  240. package/src/lib/declarations.console-server.js +9 -0
  241. package/src/lib/declarations.console-server.js.map +1 -1
  242. package/src/lib/declarations.server.d.ts +2 -1
  243. package/src/lib/declarations.server.js +47 -1
  244. package/src/lib/declarations.server.js.map +1 -1
  245. package/src/lib/model/buyer-notifications.d.ts +59 -0
  246. package/src/lib/model/buyer-notifications.js +97 -0
  247. package/src/lib/model/buyer-notifications.js.map +1 -0
  248. package/src/lib/model/commerce-orders.d.ts +127 -1
  249. package/src/lib/model/commerce-orders.js +24 -15
  250. package/src/lib/model/commerce-orders.js.map +1 -1
  251. package/src/lib/model/commerce-payment-methods.d.ts +146 -0
  252. package/src/lib/model/commerce-payment-methods.js +247 -0
  253. package/src/lib/model/commerce-payment-methods.js.map +1 -0
  254. package/src/lib/model/commerce-pos-ops.d.ts +437 -0
  255. package/src/lib/model/commerce-pos-ops.js +721 -0
  256. package/src/lib/model/commerce-pos-ops.js.map +1 -0
  257. package/src/lib/model/commerce-pos.d.ts +263 -0
  258. package/src/lib/model/commerce-pos.js +375 -0
  259. package/src/lib/model/commerce-pos.js.map +1 -0
  260. package/src/lib/model/commerce-printers.d.ts +211 -0
  261. package/src/lib/model/commerce-printers.js +181 -0
  262. package/src/lib/model/commerce-printers.js.map +1 -0
  263. package/src/lib/model/commerce-receipt.d.ts +97 -0
  264. package/src/lib/model/commerce-receipt.js +180 -0
  265. package/src/lib/model/commerce-receipt.js.map +1 -0
  266. package/src/lib/model/commerce-returns.d.ts +207 -0
  267. package/src/lib/model/commerce-returns.js +300 -0
  268. package/src/lib/model/commerce-returns.js.map +1 -0
  269. package/src/lib/model/commerce-shipping.d.ts +44 -1
  270. package/src/lib/model/commerce-shipping.js +53 -9
  271. package/src/lib/model/commerce-shipping.js.map +1 -1
  272. package/src/lib/model/commerce-tax-engine.d.ts +90 -0
  273. package/src/lib/model/commerce-tax-engine.js +129 -0
  274. package/src/lib/model/commerce-tax-engine.js.map +1 -0
  275. package/src/lib/model/commerce.d.ts +88 -2
  276. package/src/lib/model/commerce.js +89 -1
  277. package/src/lib/model/commerce.js.map +1 -1
  278. package/src/lib/model/index.d.ts +15 -0
  279. package/src/lib/model/index.js +15 -0
  280. package/src/lib/model/index.js.map +1 -1
  281. package/src/lib/model/order-events.d.ts +154 -0
  282. package/src/lib/model/order-events.js +153 -0
  283. package/src/lib/model/order-events.js.map +1 -0
  284. package/src/lib/model/order-fulfillment.d.ts +117 -0
  285. package/src/lib/model/order-fulfillment.js +217 -0
  286. package/src/lib/model/order-fulfillment.js.map +1 -0
  287. package/src/lib/model/order-history.d.ts +58 -0
  288. package/src/lib/model/order-history.js +22 -0
  289. package/src/lib/model/order-history.js.map +1 -0
  290. package/src/lib/model/order-list-fields.d.ts +9 -1
  291. package/src/lib/model/order-list-fields.js +7 -1
  292. package/src/lib/model/order-list-fields.js.map +1 -1
  293. package/src/lib/model/order-shipping-export.d.ts +91 -0
  294. package/src/lib/model/order-shipping-export.js +192 -0
  295. package/src/lib/model/order-shipping-export.js.map +1 -0
  296. package/src/lib/model/order-status-view.d.ts +103 -0
  297. package/src/lib/model/order-status-view.js +156 -0
  298. package/src/lib/model/order-status-view.js.map +1 -0
  299. package/src/lib/model/order-webhooks.d.ts +142 -0
  300. package/src/lib/model/order-webhooks.js +91 -0
  301. package/src/lib/model/order-webhooks.js.map +1 -0
  302. package/src/lib/model/product-channel.d.ts +56 -0
  303. package/src/lib/model/product-channel.js +86 -0
  304. package/src/lib/model/product-channel.js.map +1 -0
  305. package/src/lib/model/product-modifiers.d.ts +80 -0
  306. package/src/lib/model/product-modifiers.js +140 -0
  307. package/src/lib/model/product-modifiers.js.map +1 -0
  308. package/src/lib/model/shippingeasy.d.ts +94 -0
  309. package/src/lib/model/shippingeasy.js +267 -0
  310. package/src/lib/model/shippingeasy.js.map +1 -0
  311. package/src/lib/model/shipstation.d.ts +125 -0
  312. package/src/lib/model/shipstation.js +399 -0
  313. package/src/lib/model/shipstation.js.map +1 -0
  314. package/src/lib/model/smart-collection-reads.d.ts +32 -0
  315. package/src/lib/model/smart-collection-reads.js +63 -0
  316. package/src/lib/model/smart-collection-reads.js.map +1 -0
  317. package/src/lib/model/tracking-url.d.ts +74 -0
  318. package/src/lib/model/tracking-url.js +159 -0
  319. package/src/lib/model/tracking-url.js.map +1 -0
  320. package/src/lib/plugin-config.d.ts +13 -0
  321. package/src/lib/plugin-config.js +77 -5
  322. package/src/lib/plugin-config.js.map +1 -1
  323. package/src/lib/plugin.js +23 -0
  324. package/src/lib/plugin.js.map +1 -1
  325. package/src/lib/pos-ops-config.d.ts +39 -0
  326. package/src/lib/pos-ops-config.js +88 -0
  327. package/src/lib/pos-ops-config.js.map +1 -0
  328. package/src/lib/printing/print-document.d.ts +106 -0
  329. package/src/lib/printing/print-document.js +464 -0
  330. package/src/lib/printing/print-document.js.map +1 -0
  331. package/src/lib/printing/product-labels.d.ts +58 -0
  332. package/src/lib/printing/product-labels.js +116 -0
  333. package/src/lib/printing/product-labels.js.map +1 -0
  334. package/src/lib/printing/render-epson.d.ts +57 -0
  335. package/src/lib/printing/render-epson.js +135 -0
  336. package/src/lib/printing/render-epson.js.map +1 -0
  337. package/src/lib/printing/render-star.d.ts +45 -0
  338. package/src/lib/printing/render-star.js +100 -0
  339. package/src/lib/printing/render-star.js.map +1 -0
  340. package/src/lib/printing/render-text.d.ts +25 -0
  341. package/src/lib/printing/render-text.js +53 -0
  342. package/src/lib/printing/render-text.js.map +1 -0
  343. package/src/lib/server/api-v1/openapi.js +27 -4
  344. package/src/lib/server/api-v1/openapi.js.map +1 -1
  345. package/src/lib/server/api-v1/order-view.d.ts +67 -0
  346. package/src/lib/server/api-v1/order-view.js +120 -0
  347. package/src/lib/server/api-v1/order-view.js.map +1 -0
  348. package/src/lib/server/api-v1/orders-and-products.js +58 -65
  349. package/src/lib/server/api-v1/orders-and-products.js.map +1 -1
  350. package/src/lib/server/billing-webhook.js +135 -28
  351. package/src/lib/server/billing-webhook.js.map +1 -1
  352. package/src/lib/server/cancel-order.js +29 -0
  353. package/src/lib/server/cancel-order.js.map +1 -1
  354. package/src/lib/server/carrier-rates-availability.d.ts +26 -0
  355. package/src/lib/server/carrier-rates-availability.js +76 -0
  356. package/src/lib/server/carrier-rates-availability.js.map +1 -0
  357. package/src/lib/server/carrier-shipping.d.ts +84 -0
  358. package/src/lib/server/carrier-shipping.js +135 -0
  359. package/src/lib/server/carrier-shipping.js.map +1 -0
  360. package/src/lib/server/cart-checkout.d.ts +2 -0
  361. package/src/lib/server/cart-checkout.js +226 -22
  362. package/src/lib/server/cart-checkout.js.map +1 -1
  363. package/src/lib/server/checkout-extras.d.ts +64 -0
  364. package/src/lib/server/checkout-extras.js +157 -0
  365. package/src/lib/server/checkout-extras.js.map +1 -0
  366. package/src/lib/server/{feed.d.ts → checkout-status.d.ts} +2 -7
  367. package/src/lib/server/checkout-status.js +111 -0
  368. package/src/lib/server/checkout-status.js.map +1 -0
  369. package/src/lib/server/checkout.js +86 -9
  370. package/src/lib/server/checkout.js.map +1 -1
  371. package/src/lib/server/draft-order.js +34 -5
  372. package/src/lib/server/draft-order.js.map +1 -1
  373. package/src/lib/server/fulfill-order.d.ts +127 -10
  374. package/src/lib/server/fulfill-order.js +451 -49
  375. package/src/lib/server/fulfill-order.js.map +1 -1
  376. package/src/lib/server/legacy-feed.d.ts +28 -0
  377. package/src/lib/server/legacy-feed.js +52 -0
  378. package/src/lib/server/legacy-feed.js.map +1 -0
  379. package/src/lib/server/native-checkout.d.ts +34 -15
  380. package/src/lib/server/native-checkout.js +32 -17
  381. package/src/lib/server/native-checkout.js.map +1 -1
  382. package/src/lib/server/order-event-host-emit.d.ts +23 -0
  383. package/src/lib/server/order-event-host-emit.js +30 -0
  384. package/src/lib/server/order-event-host-emit.js.map +1 -0
  385. package/src/lib/server/order-event-triggers.d.ts +37 -0
  386. package/src/lib/server/order-event-triggers.js +119 -0
  387. package/src/lib/server/order-event-triggers.js.map +1 -0
  388. package/src/lib/server/order-events.d.ts +62 -0
  389. package/src/lib/server/order-events.js +109 -0
  390. package/src/lib/server/order-events.js.map +1 -0
  391. package/src/lib/server/order-history.d.ts +23 -0
  392. package/src/lib/server/order-history.js +65 -0
  393. package/src/lib/server/order-history.js.map +1 -0
  394. package/src/lib/server/order-notifications.d.ts +185 -0
  395. package/src/lib/server/order-notifications.js +567 -0
  396. package/src/lib/server/order-notifications.js.map +1 -0
  397. package/src/lib/server/order-receipt-send.d.ts +39 -0
  398. package/src/lib/server/order-receipt-send.js +151 -0
  399. package/src/lib/server/order-receipt-send.js.map +1 -0
  400. package/src/lib/server/order-status-token.d.ts +31 -0
  401. package/src/lib/server/order-status-token.js +75 -0
  402. package/src/lib/server/order-status-token.js.map +1 -0
  403. package/src/lib/server/order-status.d.ts +58 -0
  404. package/src/lib/server/order-status.js +141 -0
  405. package/src/lib/server/order-status.js.map +1 -0
  406. package/src/lib/server/order-webhooks.d.ts +108 -0
  407. package/src/lib/server/order-webhooks.js +622 -0
  408. package/src/lib/server/order-webhooks.js.map +1 -0
  409. package/src/lib/server/orders-shipping-prepare.d.ts +26 -0
  410. package/src/lib/server/orders-shipping-prepare.js +121 -0
  411. package/src/lib/server/orders-shipping-prepare.js.map +1 -0
  412. package/src/lib/server/payment-method-domains.d.ts +209 -0
  413. package/src/lib/server/payment-method-domains.js +444 -0
  414. package/src/lib/server/payment-method-domains.js.map +1 -0
  415. package/src/lib/server/payment-methods.d.ts +77 -0
  416. package/src/lib/server/payment-methods.js +284 -0
  417. package/src/lib/server/payment-methods.js.map +1 -0
  418. package/src/lib/server/pos-auth.d.ts +50 -0
  419. package/src/lib/server/pos-auth.js +121 -0
  420. package/src/lib/server/pos-auth.js.map +1 -0
  421. package/src/lib/server/pos-customer.d.ts +49 -0
  422. package/src/lib/server/pos-customer.js +257 -0
  423. package/src/lib/server/pos-customer.js.map +1 -0
  424. package/src/lib/server/pos-display.d.ts +57 -0
  425. package/src/lib/server/pos-display.js +419 -0
  426. package/src/lib/server/pos-display.js.map +1 -0
  427. package/src/lib/server/pos-fee-month.d.ts +34 -0
  428. package/src/lib/server/pos-fee-month.js +36 -0
  429. package/src/lib/server/pos-fee-month.js.map +1 -0
  430. package/src/lib/server/pos-ops-gate.d.ts +161 -0
  431. package/src/lib/server/pos-ops-gate.js +295 -0
  432. package/src/lib/server/pos-ops-gate.js.map +1 -0
  433. package/src/lib/server/pos-ops-routes.d.ts +22 -0
  434. package/src/lib/server/pos-ops-routes.js +36 -0
  435. package/src/lib/server/pos-ops-routes.js.map +1 -0
  436. package/src/lib/server/pos-order.d.ts +1 -18
  437. package/src/lib/server/pos-order.js +222 -42
  438. package/src/lib/server/pos-order.js.map +1 -1
  439. package/src/lib/server/pos-payment.d.ts +39 -0
  440. package/src/lib/server/pos-payment.js +922 -0
  441. package/src/lib/server/pos-payment.js.map +1 -0
  442. package/src/lib/server/pos-print.d.ts +82 -0
  443. package/src/lib/server/pos-print.js +193 -0
  444. package/src/lib/server/pos-print.js.map +1 -0
  445. package/src/lib/server/pos-readers.d.ts +27 -0
  446. package/src/lib/server/pos-readers.js +276 -0
  447. package/src/lib/server/pos-readers.js.map +1 -0
  448. package/src/lib/server/pos-refund-authority.d.ts +60 -0
  449. package/src/lib/server/pos-refund-authority.js +72 -0
  450. package/src/lib/server/pos-refund-authority.js.map +1 -0
  451. package/src/lib/server/pos-return.d.ts +58 -0
  452. package/src/lib/server/pos-return.js +891 -0
  453. package/src/lib/server/pos-return.js.map +1 -0
  454. package/src/lib/server/pos-sale-stamp.d.ts +66 -0
  455. package/src/lib/server/pos-sale-stamp.js +84 -0
  456. package/src/lib/server/pos-sale-stamp.js.map +1 -0
  457. package/src/lib/server/pos-sale.d.ts +170 -0
  458. package/src/lib/server/pos-sale.js +461 -0
  459. package/src/lib/server/pos-sale.js.map +1 -0
  460. package/src/lib/server/pos-shift.d.ts +45 -0
  461. package/src/lib/server/pos-shift.js +484 -0
  462. package/src/lib/server/pos-shift.js.map +1 -0
  463. package/src/lib/server/pos-staff-pin.d.ts +26 -0
  464. package/src/lib/server/pos-staff-pin.js +339 -0
  465. package/src/lib/server/pos-staff-pin.js.map +1 -0
  466. package/src/lib/server/pos-stripe.d.ts +91 -0
  467. package/src/lib/server/pos-stripe.js +129 -0
  468. package/src/lib/server/pos-stripe.js.map +1 -0
  469. package/src/lib/server/pos-terminal-connection-token.d.ts +48 -0
  470. package/src/lib/server/pos-terminal-connection-token.js +166 -0
  471. package/src/lib/server/pos-terminal-connection-token.js.map +1 -0
  472. package/src/lib/server/pos-terminal.d.ts +218 -0
  473. package/src/lib/server/pos-terminal.js +1014 -0
  474. package/src/lib/server/pos-terminal.js.map +1 -0
  475. package/src/lib/server/print-queue.d.ts +124 -0
  476. package/src/lib/server/print-queue.js +301 -0
  477. package/src/lib/server/print-queue.js.map +1 -0
  478. package/src/lib/server/printer-poll.d.ts +75 -0
  479. package/src/lib/server/printer-poll.js +325 -0
  480. package/src/lib/server/printer-poll.js.map +1 -0
  481. package/src/lib/server/printer-secret.d.ts +39 -0
  482. package/src/lib/server/printer-secret.js +56 -0
  483. package/src/lib/server/printer-secret.js.map +1 -0
  484. package/src/lib/server/printers.d.ts +114 -0
  485. package/src/lib/server/printers.js +546 -0
  486. package/src/lib/server/printers.js.map +1 -0
  487. package/src/lib/server/product-ai-capability.d.ts +42 -0
  488. package/src/lib/server/product-ai-capability.js +159 -0
  489. package/src/lib/server/product-ai-capability.js.map +1 -0
  490. package/src/lib/server/product-catalog.d.ts +42 -0
  491. package/src/lib/server/product-catalog.js +305 -0
  492. package/src/lib/server/product-catalog.js.map +1 -0
  493. package/src/lib/server/product-drafts.d.ts +119 -0
  494. package/src/lib/server/product-drafts.js +384 -0
  495. package/src/lib/server/product-drafts.js.map +1 -0
  496. package/src/lib/server/refund.js +110 -45
  497. package/src/lib/server/refund.js.map +1 -1
  498. package/src/lib/server/reserve.js +2 -0
  499. package/src/lib/server/reserve.js.map +1 -1
  500. package/src/lib/server/return-status-action.d.ts +37 -0
  501. package/src/lib/server/return-status-action.js +57 -0
  502. package/src/lib/server/return-status-action.js.map +1 -0
  503. package/src/lib/server/returns.d.ts +119 -0
  504. package/src/lib/server/returns.js +938 -0
  505. package/src/lib/server/returns.js.map +1 -0
  506. package/src/lib/server/shipment-records.d.ts +36 -0
  507. package/src/lib/server/shipment-records.js +289 -0
  508. package/src/lib/server/shipment-records.js.map +1 -0
  509. package/src/lib/server/shipping-connector-gates.d.ts +40 -0
  510. package/src/lib/server/shipping-connector-gates.js +97 -0
  511. package/src/lib/server/shipping-connector-gates.js.map +1 -0
  512. package/src/lib/server/shipping-connectors.d.ts +29 -0
  513. package/src/lib/server/shipping-connectors.js +236 -0
  514. package/src/lib/server/shipping-connectors.js.map +1 -0
  515. package/src/lib/server/shippingeasy.d.ts +238 -0
  516. package/src/lib/server/shippingeasy.js +787 -0
  517. package/src/lib/server/shippingeasy.js.map +1 -0
  518. package/src/lib/server/shipstation.d.ts +129 -0
  519. package/src/lib/server/shipstation.js +483 -0
  520. package/src/lib/server/shipstation.js.map +1 -0
  521. package/src/lib/server/site-page-resolver.d.ts +5 -0
  522. package/src/lib/server/site-page-resolver.js +156 -1
  523. package/src/lib/server/site-page-resolver.js.map +1 -1
  524. package/src/lib/server/stock-levels.d.ts +21 -0
  525. package/src/lib/server/stock-levels.js +263 -0
  526. package/src/lib/server/stock-levels.js.map +1 -0
  527. package/src/lib/server/stripe-refund.d.ts +47 -0
  528. package/src/lib/server/stripe-refund.js +87 -0
  529. package/src/lib/server/stripe-refund.js.map +1 -0
  530. package/src/lib/server/supplier-update.js +46 -5
  531. package/src/lib/server/supplier-update.js.map +1 -1
  532. package/src/lib/server/tax-engine-quote.d.ts +47 -0
  533. package/src/lib/server/tax-engine-quote.js +105 -0
  534. package/src/lib/server/tax-engine-quote.js.map +1 -0
  535. package/src/lib/server.js +146 -2
  536. package/src/lib/server.js.map +1 -1
  537. package/src/lib/site.js +12 -0
  538. package/src/lib/site.js.map +1 -1
  539. package/src/lib/subprocessors.d.ts +26 -0
  540. package/src/lib/subprocessors.js +50 -0
  541. package/src/lib/subprocessors.js.map +1 -0
  542. package/src/lib/tenant-emails.js +461 -3
  543. package/src/lib/tenant-emails.js.map +1 -1
  544. package/src/lib/testing/fake-firestore.d.ts +45 -0
  545. package/src/lib/testing/fake-firestore.js +189 -0
  546. package/src/lib/testing/fake-firestore.js.map +1 -0
  547. package/src/lib/testing/memory-firestore.d.ts +123 -0
  548. package/src/lib/testing/memory-firestore.js +274 -0
  549. package/src/lib/testing/memory-firestore.js.map +1 -0
  550. package/src/lib/testing/pos-ops-harness.d.ts +50 -0
  551. package/src/lib/testing/pos-ops-harness.js +184 -0
  552. package/src/lib/testing/pos-ops-harness.js.map +1 -0
  553. package/src/lib/testing/pos-ops-memory-firestore.d.ts +55 -0
  554. package/src/lib/testing/pos-ops-memory-firestore.js +376 -0
  555. package/src/lib/testing/pos-ops-memory-firestore.js.map +1 -0
  556. package/src/lib/transfer/records-transfer.d.ts +11 -1
  557. package/src/lib/transfer/records-transfer.js +127 -5
  558. package/src/lib/transfer/records-transfer.js.map +1 -1
  559. package/src/lib/transfer/records.server.d.ts +9 -2
  560. package/src/lib/transfer/records.server.js +58 -7
  561. package/src/lib/transfer/records.server.js.map +1 -1
  562. package/src/lib/transfer/register-transfer-resources.js +40 -1
  563. package/src/lib/transfer/register-transfer-resources.js.map +1 -1
  564. package/src/lib/transfer/register-transfer-ui.js +4 -1
  565. package/src/lib/transfer/register-transfer-ui.js.map +1 -1
  566. package/src/lib/transfer/shipping-presets.d.ts +23 -0
  567. package/src/lib/transfer/shipping-presets.js +156 -0
  568. package/src/lib/transfer/shipping-presets.js.map +1 -0
  569. package/src/lib/transfer/tracking-transfer.d.ts +101 -0
  570. package/src/lib/transfer/tracking-transfer.js +546 -0
  571. package/src/lib/transfer/tracking-transfer.js.map +1 -0
  572. package/src/lib/transfer/tracking.server.d.ts +37 -0
  573. package/src/lib/transfer/tracking.server.js +393 -0
  574. package/src/lib/transfer/tracking.server.js.map +1 -0
  575. package/src/lib/transfer/transfer-keys.d.ts +2 -1
  576. package/src/lib/transfer/transfer-keys.js +6 -2
  577. package/src/lib/transfer/transfer-keys.js.map +1 -1
  578. package/src/lib/utils/code128.d.ts +37 -0
  579. package/src/lib/utils/code128.js +199 -0
  580. package/src/lib/utils/code128.js.map +1 -0
  581. package/src/lib/utils/order-invoice.d.ts +55 -0
  582. package/src/lib/utils/order-invoice.js +127 -0
  583. package/src/lib/utils/order-invoice.js.map +1 -0
  584. package/src/lib/utils/use-checkout-return-notice.d.ts +34 -0
  585. package/src/lib/utils/use-checkout-return-notice.js +78 -0
  586. package/src/lib/utils/use-checkout-return-notice.js.map +1 -0
  587. package/src/lib/utils/use-storefront-purchase-event.js +4 -0
  588. package/src/lib/utils/use-storefront-purchase-event.js.map +1 -1
  589. package/src/lib/server/feed.js +0 -69
  590. package/src/lib/server/feed.js.map +0 -1
@@ -0,0 +1,384 @@
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 { hostRoleCanWrite } from "@aglyn/aglyn/app-utils/organizations";
18
+ import { checkEntitlement, checkQuota } from "@aglyn/aglyn/app-utils/plan-entitlements";
19
+ import { registerPluginResourceDraftWriter } from "@aglyn/aglyn/plugin-manager/plugin-resource-drafts";
20
+ import { firebaseAdmin } from "@aglyn/tenant-data-admin";
21
+ import { BUNDLE_ID } from "../constants/bundle-common.js";
22
+ import { COMMERCE_MAX_OPTION_VALUES, COMMERCE_MAX_OPTIONS, COMMERCE_MAX_PRICE_USD, COMMERCE_MAX_VARIANTS, commerceSlug, productCollectionIds, productPriceMissing, productSearchFields, unpricedProductDraft, validateProduct } from "../model/commerce.js";
23
+ /** The resource name this writer is registered under. */ export const PRODUCT_DRAFT_RESOURCE = 'product';
24
+ /** The longest product name the proposals and the editor keep. */ export const PRODUCT_DRAFT_NAME_MAX = 120;
25
+ /** The longest description a draft keeps. */ export const PRODUCT_DRAFT_DESCRIPTION_MAX = 5000;
26
+ /** The most tags a draft keeps, and the longest one. */ export const PRODUCT_DRAFT_TAGS_MAX = 20;
27
+ export const PRODUCT_DRAFT_TAG_MAX = 40;
28
+ /** The most categories a draft is filed under. */ export const PRODUCT_DRAFT_CATEGORIES_MAX = 10;
29
+ /** The longest search-listing title and description a draft keeps. */ export const PRODUCT_DRAFT_SEO_TITLE_MAX = 120;
30
+ export const PRODUCT_DRAFT_SEO_DESCRIPTION_MAX = 320;
31
+ /** The resources route's refusal for a member who may not write the site. */ export const PRODUCT_DRAFT_ROLE_REFUSAL = 'Editing requires the editor role';
32
+ /** The resources route's refusal for a plan without the feature. */ export const PRODUCT_DRAFT_PLAN_REFUSAL = 'This feature is not included in your plan — see Billing';
33
+ /** The resources route's refusal at the plan's allowance. */ export function productDraftLimitRefusal(limit) {
34
+ return `Your plan includes ${limit} ${limit === 1 ? 'product' : 'products'} — ` + 'upgrade in Billing for more';
35
+ }
36
+ const PRODUCT_TYPES = [
37
+ 'physical',
38
+ 'digital',
39
+ 'service'
40
+ ];
41
+ function isRecord(value) {
42
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
43
+ }
44
+ /** Text on one line: controls and runs of space folded to one space. */ function line(value) {
45
+ return typeof value === 'string' ? value.replace(RegExp("[\\u0000-\\u001F\\u007F-\\u009F\\s]+", "gu"), ' ').trim() : '';
46
+ }
47
+ function strings(label, value, problems) {
48
+ if (value === undefined) return [];
49
+ if (!Array.isArray(value) || value.some((entry)=>typeof entry !== 'string')) {
50
+ problems.push(`${label} are a list of words`);
51
+ return [];
52
+ }
53
+ return [
54
+ ...new Set(value.map(line).filter(Boolean))
55
+ ];
56
+ }
57
+ /** The content as the writer reads it, or every problem that stops it. */ export function readProductDraftContent(content) {
58
+ var _content_type, _content_options;
59
+ const problems = [];
60
+ const name = line(content['name']);
61
+ if (!name) problems.push('The product needs a name');
62
+ else if (name.length > PRODUCT_DRAFT_NAME_MAX) {
63
+ problems.push(`The name is longer than ${PRODUCT_DRAFT_NAME_MAX} characters`);
64
+ }
65
+ const rawType = (_content_type = content['type']) != null ? _content_type : 'physical';
66
+ if (!PRODUCT_TYPES.includes(rawType)) {
67
+ problems.push('The type is physical, digital or service');
68
+ }
69
+ const rawDescription = content['description'];
70
+ const description = typeof rawDescription === 'string' ? rawDescription.trim() : '';
71
+ if (rawDescription !== undefined && typeof rawDescription !== 'string') {
72
+ problems.push('The description is text');
73
+ } else if (description.length > PRODUCT_DRAFT_DESCRIPTION_MAX) {
74
+ problems.push(`The description is longer than ${PRODUCT_DRAFT_DESCRIPTION_MAX} characters`);
75
+ }
76
+ const tags = strings('Tags', content['tags'], problems);
77
+ if (tags.length > PRODUCT_DRAFT_TAGS_MAX) problems.push(`A product keeps at most ${PRODUCT_DRAFT_TAGS_MAX} tags`);
78
+ if (tags.some((tag)=>tag.length > PRODUCT_DRAFT_TAG_MAX)) {
79
+ problems.push(`A tag is longer than ${PRODUCT_DRAFT_TAG_MAX} characters`);
80
+ }
81
+ const categoryIds = strings('Categories', content['categoryIds'], problems);
82
+ if (categoryIds.length > PRODUCT_DRAFT_CATEGORIES_MAX) {
83
+ problems.push(`A product is filed under at most ${PRODUCT_DRAFT_CATEGORIES_MAX} categories`);
84
+ }
85
+ const seoTitle = line(content['seoTitle']);
86
+ const seoDescription = line(content['seoDescription']);
87
+ if (seoTitle.length > PRODUCT_DRAFT_SEO_TITLE_MAX) {
88
+ problems.push(`The search title is longer than ${PRODUCT_DRAFT_SEO_TITLE_MAX} characters`);
89
+ }
90
+ if (seoDescription.length > PRODUCT_DRAFT_SEO_DESCRIPTION_MAX) {
91
+ problems.push(`The search description is longer than ${PRODUCT_DRAFT_SEO_DESCRIPTION_MAX} characters`);
92
+ }
93
+ // Options are held here before the draft expands them: a matrix past the
94
+ // variant ceiling is refused, never built.
95
+ const rawOptions = (_content_options = content['options']) != null ? _content_options : [];
96
+ const options = [];
97
+ if (!Array.isArray(rawOptions)) {
98
+ problems.push('Options are a list of a name and its values');
99
+ } else {
100
+ if (rawOptions.length > COMMERCE_MAX_OPTIONS) {
101
+ problems.push(`At most ${COMMERCE_MAX_OPTIONS} options per product`);
102
+ }
103
+ for (const option of rawOptions){
104
+ const optionName = isRecord(option) ? line(option['name']) : '';
105
+ const values = isRecord(option) ? strings(`The values of "${optionName}"`, option['values'], problems) : [];
106
+ if (!optionName || !values.length) {
107
+ problems.push('Each option needs a name and at least one value');
108
+ continue;
109
+ }
110
+ if (values.length > COMMERCE_MAX_OPTION_VALUES) {
111
+ problems.push(`Option "${optionName}" has too many values`);
112
+ continue;
113
+ }
114
+ options.push({
115
+ name: optionName,
116
+ values
117
+ });
118
+ }
119
+ if (new Set(options.map((option)=>option.name)).size !== options.length) {
120
+ problems.push('Each option needs its own name');
121
+ }
122
+ const combinations = options.reduce((count, option)=>count * option.values.length, 1);
123
+ if (combinations > COMMERCE_MAX_VARIANTS) {
124
+ problems.push(`Those options make ${combinations} variants; a product holds at most ${COMMERCE_MAX_VARIANTS}`);
125
+ }
126
+ }
127
+ // No price unless one is stated: the merchant sets it otherwise.
128
+ const rawPrice = content['priceUsd'];
129
+ let priceUsd = null;
130
+ if (rawPrice !== undefined && rawPrice !== null) {
131
+ if (typeof rawPrice !== 'number' || !Number.isFinite(rawPrice) || rawPrice < 0 || rawPrice > COMMERCE_MAX_PRICE_USD || Math.round(rawPrice * 100) !== rawPrice * 100) {
132
+ problems.push(`A stated price is dollars and cents from 0 to ${COMMERCE_MAX_PRICE_USD}`);
133
+ } else {
134
+ priceUsd = rawPrice;
135
+ }
136
+ }
137
+ if (problems.length) return {
138
+ ok: false,
139
+ problems: [
140
+ ...new Set(problems)
141
+ ]
142
+ };
143
+ return {
144
+ ok: true,
145
+ value: {
146
+ proposal: {
147
+ name,
148
+ type: rawType,
149
+ description,
150
+ tags,
151
+ options,
152
+ seoTitle,
153
+ seoDescription
154
+ },
155
+ priceUsd,
156
+ categoryIds
157
+ }
158
+ };
159
+ }
160
+ /** The product document a read builds, under `slug`, at `nowMs`. */ export function productDraftDocument(read, slug, nowMs) {
161
+ const draft = unpricedProductDraft(read.proposal, new Set(), nowMs);
162
+ const priced = read.priceUsd === null ? draft : _extends({}, draft, {
163
+ variants: draft.variants.map((variant)=>_extends({}, variant, {
164
+ priceUsd: read.priceUsd
165
+ }))
166
+ });
167
+ return _extends({}, priced, productSearchFields(priced), {
168
+ slug
169
+ }, read.categoryIds.length ? {
170
+ categoryIds: read.categoryIds
171
+ } : {});
172
+ }
173
+ /** What the owner's product rule says about a draft, a placeholder price standing in for none. */ function productProblem(product) {
174
+ return validateProduct(_extends({}, product, {
175
+ variants: product.variants.map((variant)=>{
176
+ var _variant_priceUsd;
177
+ return _extends({}, variant, {
178
+ priceUsd: (_variant_priceUsd = variant.priceUsd) != null ? _variant_priceUsd : 0
179
+ });
180
+ })
181
+ }));
182
+ }
183
+ function factsOf(product) {
184
+ var _product_status, _product_slug, _product_type, _ref, _product_variants;
185
+ var _product_variants1;
186
+ return {
187
+ status: (_product_status = product.status) != null ? _product_status : 'draft',
188
+ slug: (_product_slug = product.slug) != null ? _product_slug : '',
189
+ type: (_product_type = product.type) != null ? _product_type : 'physical',
190
+ variants: (_ref = (_product_variants1 = product.variants) == null ? void 0 : _product_variants1.length) != null ? _ref : 0,
191
+ priceMissing: productPriceMissing({
192
+ variants: (_product_variants = product.variants) != null ? _product_variants : []
193
+ })
194
+ };
195
+ }
196
+ /** Whether content is a product this plugin would store, with what it says about it. Pure. */ export function checkProductDraftContent(content) {
197
+ const read = readProductDraftContent(content);
198
+ if (read.ok === false) return read;
199
+ const slug = commerceSlug(read.value.proposal.name) || 'product';
200
+ const product = productDraftDocument(read.value, slug, 0);
201
+ const problem = productProblem(product);
202
+ return problem ? {
203
+ ok: false,
204
+ problems: [
205
+ problem
206
+ ]
207
+ } : {
208
+ ok: true,
209
+ facts: factsOf(product)
210
+ };
211
+ }
212
+ function recordOf(product) {
213
+ var _product_data, _data_name;
214
+ const data = (_product_data = product.data()) != null ? _product_data : {};
215
+ return {
216
+ id: product.id,
217
+ name: String((_data_name = data.name) != null ? _data_name : ''),
218
+ versionId: null,
219
+ facts: factsOf(data)
220
+ };
221
+ }
222
+ function roleRefusal(host, uid) {
223
+ var _host_get;
224
+ const role = ((_host_get = host.get('memberRoles')) != null ? _host_get : {})[uid];
225
+ return hostRoleCanWrite(role) ? null : {
226
+ status: 403,
227
+ error: PRODUCT_DRAFT_ROLE_REFUSAL
228
+ };
229
+ }
230
+ function planRefusal(org) {
231
+ return checkEntitlement(org, 'commerce') ? null : {
232
+ status: 403,
233
+ error: PRODUCT_DRAFT_PLAN_REFUSAL
234
+ };
235
+ }
236
+ /** The allowance, counted as the resources route and the importer count a product create. */ function roomRefusal(org, used) {
237
+ const quota = checkQuota(org, 'productsPerHost', used);
238
+ return quota.allowed ? null : {
239
+ status: 403,
240
+ error: productDraftLimitRefusal(quota.limit)
241
+ };
242
+ }
243
+ /** Candidates asked of the store at once, as the console's slug ledger probes. */ const SLUG_PROBE = 10;
244
+ /**
245
+ * The first of `base`, `base-2`, `base-3`, … that no product holds, live or
246
+ * deleted — a soft-deleted product still answers its slug on the storefront
247
+ * (`productSlugLedger`, AGL-3321). Asked inside the transaction.
248
+ */ async function freeSlug(products, base, read) {
249
+ const candidate = (suffix)=>suffix < 2 ? base : `${base}-${suffix}`;
250
+ for(let first = 1;; first += SLUG_PROBE){
251
+ const batch = Array.from({
252
+ length: SLUG_PROBE
253
+ }, (_, offset)=>candidate(first + offset));
254
+ const held = new Set((await read(products.where('slug', 'in', batch))).docs.map((doc)=>{
255
+ var _doc_get;
256
+ return String((_doc_get = doc.get('slug')) != null ? _doc_get : '');
257
+ }));
258
+ const free = batch.find((slug)=>!held.has(slug));
259
+ if (free) return free;
260
+ }
261
+ }
262
+ export function createProductDraftWriter(deps = {}) {
263
+ var _deps_firestore;
264
+ const firestore = (_deps_firestore = deps.firestore) != null ? _deps_firestore : ()=>firebaseAdmin.app().firestore();
265
+ return {
266
+ refusal: async (context)=>{
267
+ var _roleRefusal;
268
+ const hostRef = firestore().collection('hosts').doc(context.hostId);
269
+ const host = await hostRef.get();
270
+ if (!host.exists) return {
271
+ status: 404,
272
+ error: 'Unknown site'
273
+ };
274
+ const early = (_roleRefusal = roleRefusal(host, context.uid)) != null ? _roleRefusal : planRefusal(context.org);
275
+ if (early) return early;
276
+ const used = (await hostRef.collection('products').count().get()).data().count;
277
+ return roomRefusal(context.org, Number(used) || 0);
278
+ },
279
+ check: (content)=>checkProductDraftContent(content),
280
+ read: async ({ hostId, id })=>{
281
+ const product = await firestore().collection('hosts').doc(hostId).collection('products').doc(id).get();
282
+ return product.exists ? recordOf(product) : null;
283
+ },
284
+ write: async (request)=>{
285
+ // The request's name is the one asked for; the content's stands in.
286
+ const asked = line(request.name);
287
+ const read = readProductDraftContent(asked ? _extends({}, request.content, {
288
+ name: asked
289
+ }) : request.content);
290
+ if (read.ok === false) return {
291
+ ok: false,
292
+ status: 400,
293
+ error: read.problems[0]
294
+ };
295
+ const db = firestore();
296
+ const hostRef = db.collection('hosts').doc(request.hostId);
297
+ const products = hostRef.collection('products');
298
+ const productRef = products.doc(request.id);
299
+ return db.runTransaction(async (tx)=>{
300
+ var _roleRefusal;
301
+ // Every read before any write, which Firestore requires.
302
+ const [host, existing] = await Promise.all([
303
+ tx.get(hostRef),
304
+ tx.get(productRef)
305
+ ]);
306
+ if (!host.exists) return {
307
+ ok: false,
308
+ status: 404,
309
+ error: 'Unknown site'
310
+ };
311
+ // Asked again under the same id: the draft it already wrote.
312
+ if (existing.exists) return _extends({
313
+ ok: true,
314
+ replayed: true
315
+ }, recordOf(existing));
316
+ const early = (_roleRefusal = roleRefusal(host, request.uid)) != null ? _roleRefusal : planRefusal(request.org);
317
+ if (early) return _extends({
318
+ ok: false
319
+ }, early);
320
+ const used = (await tx.get(products.count())).data().count;
321
+ const room = roomRefusal(request.org, Number(used) || 0);
322
+ if (room) return _extends({
323
+ ok: false
324
+ }, room);
325
+ const base = commerceSlug(read.value.proposal.name) || 'product';
326
+ const [slug, categories, smart] = await Promise.all([
327
+ freeSlug(products, base, (query)=>tx.get(query)),
328
+ // A category the site does not have is dropped, not stored.
329
+ read.value.categoryIds.length ? Promise.all(read.value.categoryIds.map((id)=>tx.get(hostRef.collection('productCategories').doc(id)))) : Promise.resolve([]),
330
+ tx.get(hostRef.collection('collections').where('kind', '==', 'catalog').where('mode', '==', 'smart'))
331
+ ]);
332
+ const categoryIds = categories.filter((category)=>category.exists).map((category)=>category.id);
333
+ const nowMs = request.now.getTime();
334
+ const product = productDraftDocument(_extends({}, read.value, {
335
+ categoryIds
336
+ }), slug, nowMs);
337
+ const problem = productProblem(product);
338
+ if (problem) return {
339
+ ok: false,
340
+ status: 400,
341
+ error: problem
342
+ };
343
+ const rules = smart.docs.map((doc)=>{
344
+ var _doc_get;
345
+ return {
346
+ id: doc.id,
347
+ rules: (_doc_get = doc.get('rules')) != null ? _doc_get : [],
348
+ matchAll: doc.get('matchAll')
349
+ };
350
+ });
351
+ const priced = read.value.priceUsd !== null;
352
+ tx.create(productRef, _extends({}, product, {
353
+ collectionIds: productCollectionIds(product, rules)
354
+ }, priced ? {
355
+ priceUsd: read.value.priceUsd
356
+ } : {}, {
357
+ deletedAt: null,
358
+ createdAt: request.now,
359
+ updatedAt: request.now,
360
+ createdBy: request.uid
361
+ }));
362
+ return {
363
+ ok: true,
364
+ replayed: false,
365
+ id: request.id,
366
+ name: product.name,
367
+ versionId: null,
368
+ facts: factsOf(product)
369
+ };
370
+ });
371
+ }
372
+ };
373
+ }
374
+ export const productDraftWriter = createProductDraftWriter();
375
+ /**
376
+ * Registers the writer; the console surface calls it, since only the console
377
+ * runs AI jobs (AGL-3026). Idempotent: a second call replaces the first.
378
+ */ export function registerProductDraftWriter() {
379
+ registerPluginResourceDraftWriter(PRODUCT_DRAFT_RESOURCE, productDraftWriter, {
380
+ pluginId: BUNDLE_ID
381
+ });
382
+ }
383
+
384
+ //# sourceMappingURL=product-drafts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/product-drafts.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 { hostRoleCanWrite } from '@aglyn/aglyn/app-utils/organizations'\nimport { checkEntitlement, checkQuota } from '@aglyn/aglyn/app-utils/plan-entitlements'\nimport {\n registerPluginResourceDraftWriter,\n type PluginDraftCheck,\n type PluginDraftContext,\n type PluginDraftRecord,\n type PluginDraftRefusal,\n type PluginDraftWrite,\n type PluginResourceDraftWriter,\n} from '@aglyn/aglyn/plugin-manager/plugin-resource-drafts'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin'\nimport { BUNDLE_ID } from '../constants/bundle-common'\nimport {\n COMMERCE_MAX_OPTION_VALUES,\n COMMERCE_MAX_OPTIONS,\n COMMERCE_MAX_PRICE_USD,\n COMMERCE_MAX_VARIANTS,\n commerceSlug,\n type HostProduct,\n productCollectionIds,\n productPriceMissing,\n productSearchFields,\n type ProductType,\n type ProposedProduct,\n type SmartCollectionRules,\n unpricedProductDraft,\n type UnpricedProductDraft,\n validateProduct,\n} from '../model/commerce'\n\n/**\n * A PRODUCT ANOTHER PLUGIN ASKS FOR (AGL-3616).\n *\n * The draft writer this plugin registers for the `product` resource on the\n * core's resource-drafts seam. A plugin that sets a store up from a brief\n * asks for the writer by name and gets this plugin's rules:\n *\n * - THE DOCUMENT is the one the products card makes from an accepted AI\n * proposal (`unpricedProductDraft`): a `draft` — off the storefront, and\n * refused by every sale door — with one variant per combination of its\n * options, no photo, and the search, stock and smart-collection keys every\n * product write derives. Born live (`deletedAt: null`), as the product\n * resource stamps it, so the products table lists it.\n * - THE PRICE is left empty unless the content states one. An unpriced\n * product is marked for the merchant to price: the editor will not save it\n * and the card will not activate it until every variant has a price.\n * - THE ROOM is the `productsPerHost` allowance, counted the way the\n * resources route and the importer count it, inside the transaction that\n * creates. THE PLAN is the `commerce` feature, and THE ROLE a member who\n * may write the site's content — refused in the resources route's words.\n * - THE CHECK is `validateProduct`, the rule every product write is held to,\n * with a placeholder price standing in where none was stated.\n *\n * Nothing is published, priced or sold. The writer touches the one new\n * product document.\n */\n\ntype Firestore = FirebaseFirestore.Firestore\n\n/** The resource name this writer is registered under. */\nexport const PRODUCT_DRAFT_RESOURCE = 'product'\n\n/** The longest product name the proposals and the editor keep. */\nexport const PRODUCT_DRAFT_NAME_MAX = 120\n/** The longest description a draft keeps. */\nexport const PRODUCT_DRAFT_DESCRIPTION_MAX = 5_000\n/** The most tags a draft keeps, and the longest one. */\nexport const PRODUCT_DRAFT_TAGS_MAX = 20\nexport const PRODUCT_DRAFT_TAG_MAX = 40\n/** The most categories a draft is filed under. */\nexport const PRODUCT_DRAFT_CATEGORIES_MAX = 10\n/** The longest search-listing title and description a draft keeps. */\nexport const PRODUCT_DRAFT_SEO_TITLE_MAX = 120\nexport const PRODUCT_DRAFT_SEO_DESCRIPTION_MAX = 320\n\n/** The resources route's refusal for a member who may not write the site. */\nexport const PRODUCT_DRAFT_ROLE_REFUSAL = 'Editing requires the editor role'\n/** The resources route's refusal for a plan without the feature. */\nexport const PRODUCT_DRAFT_PLAN_REFUSAL = 'This feature is not included in your plan — see Billing'\n\n/** The resources route's refusal at the plan's allowance. */\nexport function productDraftLimitRefusal(limit: number): string {\n return `Your plan includes ${limit} ${limit === 1 ? 'product' : 'products'} — ` +\n 'upgrade in Billing for more'\n}\n\n/**\n * What a caller sends as `content`: a proposed product, as the AI products\n * job proposes one, with an optional stated price for every variant and the\n * ids of categories the site already has. A photo is never taken: the\n * merchant adds pictures in the editor.\n */\nexport interface ProductDraftContent {\n name: string\n type?: ProductType\n description?: string\n tags?: string[]\n options?: Array<{ name: string; values: string[] }>\n seoTitle?: string\n seoDescription?: string\n /** One price for every variant, in dollars; absent leaves them unpriced. */\n priceUsd?: number\n /** Ids of the site's product categories; one the site lacks is dropped. */\n categoryIds?: string[]\n}\n\nconst PRODUCT_TYPES: readonly ProductType[] = ['physical', 'digital', 'service']\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n/** Text on one line: controls and runs of space folded to one space. */\nfunction line(value: unknown): string {\n return typeof value === 'string' ? value.replace(/[\\p{Cc}\\s]+/gu, ' ').trim() : ''\n}\n\nfunction strings(label: string, value: unknown, problems: string[]): string[] {\n if (value === undefined) return []\n if (!Array.isArray(value) || value.some((entry) => typeof entry !== 'string')) {\n problems.push(`${label} are a list of words`)\n return []\n }\n return [...new Set(value.map(line).filter(Boolean))]\n}\n\n/** A draft as the writer will store it, before its slug and keys are settled. */\nexport interface ProductDraftRead {\n proposal: ProposedProduct\n /** The price stated for every variant, or `null` for the merchant to set. */\n priceUsd: number | null\n categoryIds: string[]\n}\n\nexport type ProductDraftContentRead =\n | { ok: true; value: ProductDraftRead }\n | { ok: false; problems: string[] }\n\n/** The content as the writer reads it, or every problem that stops it. */\nexport function readProductDraftContent(\n content: Readonly<Record<string, unknown>>,\n): ProductDraftContentRead {\n const problems: string[] = []\n const name = line(content['name'])\n if (!name) problems.push('The product needs a name')\n else if (name.length > PRODUCT_DRAFT_NAME_MAX) {\n problems.push(`The name is longer than ${PRODUCT_DRAFT_NAME_MAX} characters`)\n }\n const rawType = content['type'] ?? 'physical'\n if (!(PRODUCT_TYPES as readonly unknown[]).includes(rawType)) {\n problems.push('The type is physical, digital or service')\n }\n const rawDescription = content['description']\n const description = typeof rawDescription === 'string' ? rawDescription.trim() : ''\n if (rawDescription !== undefined && typeof rawDescription !== 'string') {\n problems.push('The description is text')\n } else if (description.length > PRODUCT_DRAFT_DESCRIPTION_MAX) {\n problems.push(`The description is longer than ${PRODUCT_DRAFT_DESCRIPTION_MAX} characters`)\n }\n const tags = strings('Tags', content['tags'], problems)\n if (tags.length > PRODUCT_DRAFT_TAGS_MAX) problems.push(`A product keeps at most ${PRODUCT_DRAFT_TAGS_MAX} tags`)\n if (tags.some((tag) => tag.length > PRODUCT_DRAFT_TAG_MAX)) {\n problems.push(`A tag is longer than ${PRODUCT_DRAFT_TAG_MAX} characters`)\n }\n const categoryIds = strings('Categories', content['categoryIds'], problems)\n if (categoryIds.length > PRODUCT_DRAFT_CATEGORIES_MAX) {\n problems.push(`A product is filed under at most ${PRODUCT_DRAFT_CATEGORIES_MAX} categories`)\n }\n const seoTitle = line(content['seoTitle'])\n const seoDescription = line(content['seoDescription'])\n if (seoTitle.length > PRODUCT_DRAFT_SEO_TITLE_MAX) {\n problems.push(`The search title is longer than ${PRODUCT_DRAFT_SEO_TITLE_MAX} characters`)\n }\n if (seoDescription.length > PRODUCT_DRAFT_SEO_DESCRIPTION_MAX) {\n problems.push(`The search description is longer than ${PRODUCT_DRAFT_SEO_DESCRIPTION_MAX} characters`)\n }\n\n // Options are held here before the draft expands them: a matrix past the\n // variant ceiling is refused, never built.\n const rawOptions = content['options'] ?? []\n const options: ProposedProduct['options'] = []\n if (!Array.isArray(rawOptions)) {\n problems.push('Options are a list of a name and its values')\n } else {\n if (rawOptions.length > COMMERCE_MAX_OPTIONS) {\n problems.push(`At most ${COMMERCE_MAX_OPTIONS} options per product`)\n }\n for (const option of rawOptions) {\n const optionName = isRecord(option) ? line(option['name']) : ''\n const values = isRecord(option) ? strings(`The values of \"${optionName}\"`, option['values'], problems) : []\n if (!optionName || !values.length) {\n problems.push('Each option needs a name and at least one value')\n continue\n }\n if (values.length > COMMERCE_MAX_OPTION_VALUES) {\n problems.push(`Option \"${optionName}\" has too many values`)\n continue\n }\n options.push({ name: optionName, values })\n }\n if (new Set(options.map((option) => option.name)).size !== options.length) {\n problems.push('Each option needs its own name')\n }\n const combinations = options.reduce((count, option) => count * option.values.length, 1)\n if (combinations > COMMERCE_MAX_VARIANTS) {\n problems.push(`Those options make ${combinations} variants; a product holds at most ${COMMERCE_MAX_VARIANTS}`)\n }\n }\n\n // No price unless one is stated: the merchant sets it otherwise.\n const rawPrice = content['priceUsd']\n let priceUsd: number | null = null\n if (rawPrice !== undefined && rawPrice !== null) {\n if (\n typeof rawPrice !== 'number' ||\n !Number.isFinite(rawPrice) ||\n rawPrice < 0 ||\n rawPrice > COMMERCE_MAX_PRICE_USD ||\n Math.round(rawPrice * 100) !== rawPrice * 100\n ) {\n problems.push(`A stated price is dollars and cents from 0 to ${COMMERCE_MAX_PRICE_USD}`)\n } else {\n priceUsd = rawPrice\n }\n }\n if (problems.length) return { ok: false, problems: [...new Set(problems)] }\n return {\n ok: true,\n value: {\n proposal: {\n name,\n type: rawType as ProductType,\n description,\n tags,\n options,\n seoTitle,\n seoDescription,\n },\n priceUsd,\n categoryIds,\n },\n }\n}\n\n/** The product document a read builds, under `slug`, at `nowMs`. */\nexport function productDraftDocument(\n read: ProductDraftRead,\n slug: string,\n nowMs: number,\n): UnpricedProductDraft | HostProduct {\n const draft = unpricedProductDraft(read.proposal, new Set(), nowMs)\n const priced =\n read.priceUsd === null\n ? draft\n : ({\n ...draft,\n variants: draft.variants.map((variant) => ({ ...variant, priceUsd: read.priceUsd as number })),\n } as HostProduct)\n return {\n ...priced,\n // The search keys travel with every create; recomputed for the price.\n ...productSearchFields(priced as HostProduct),\n slug,\n ...(read.categoryIds.length ? { categoryIds: read.categoryIds } : {}),\n }\n}\n\n/** What the owner's product rule says about a draft, a placeholder price standing in for none. */\nfunction productProblem(product: UnpricedProductDraft | HostProduct): string | null {\n return validateProduct({\n ...product,\n variants: product.variants.map((variant) => ({\n ...variant,\n priceUsd: (variant as { priceUsd?: number }).priceUsd ?? 0,\n })),\n } as HostProduct)\n}\n\nfunction factsOf(product: Partial<HostProduct>) {\n return {\n status: product.status ?? 'draft',\n slug: product.slug ?? '',\n type: product.type ?? 'physical',\n variants: product.variants?.length ?? 0,\n priceMissing: productPriceMissing({ variants: product.variants ?? [] }),\n }\n}\n\n/** Whether content is a product this plugin would store, with what it says about it. Pure. */\nexport function checkProductDraftContent(content: Readonly<Record<string, unknown>>): PluginDraftCheck {\n const read = readProductDraftContent(content)\n if (read.ok === false) return read\n const slug = commerceSlug(read.value.proposal.name) || 'product'\n const product = productDraftDocument(read.value, slug, 0)\n const problem = productProblem(product)\n return problem ? { ok: false, problems: [problem] } : { ok: true, facts: factsOf(product as HostProduct) }\n}\n\nfunction recordOf(product: FirebaseFirestore.DocumentSnapshot): PluginDraftRecord {\n const data = (product.data() ?? {}) as Partial<HostProduct>\n return { id: product.id, name: String(data.name ?? ''), versionId: null, facts: factsOf(data) }\n}\n\nfunction roleRefusal(host: FirebaseFirestore.DocumentSnapshot, uid: string): PluginDraftRefusal | null {\n const role = (host.get('memberRoles') ?? {})[uid]\n return hostRoleCanWrite(role) ? null : { status: 403, error: PRODUCT_DRAFT_ROLE_REFUSAL }\n}\n\nfunction planRefusal(org: PluginDraftContext['org']): PluginDraftRefusal | null {\n return checkEntitlement(org as never, 'commerce') ? null : { status: 403, error: PRODUCT_DRAFT_PLAN_REFUSAL }\n}\n\n/** The allowance, counted as the resources route and the importer count a product create. */\nfunction roomRefusal(org: PluginDraftContext['org'], used: number): PluginDraftRefusal | null {\n const quota = checkQuota(org as never, 'productsPerHost', used)\n return quota.allowed ? null : { status: 403, error: productDraftLimitRefusal(quota.limit) }\n}\n\n/** Candidates asked of the store at once, as the console's slug ledger probes. */\nconst SLUG_PROBE = 10\n\n/**\n * The first of `base`, `base-2`, `base-3`, … that no product holds, live or\n * deleted — a soft-deleted product still answers its slug on the storefront\n * (`productSlugLedger`, AGL-3321). Asked inside the transaction.\n */\nasync function freeSlug(\n products: FirebaseFirestore.CollectionReference,\n base: string,\n read: (query: FirebaseFirestore.Query) => Promise<FirebaseFirestore.QuerySnapshot>,\n): Promise<string> {\n const candidate = (suffix: number) => (suffix < 2 ? base : `${base}-${suffix}`)\n for (let first = 1; ; first += SLUG_PROBE) {\n const batch = Array.from({ length: SLUG_PROBE }, (_, offset) => candidate(first + offset))\n const held = new Set(\n (await read(products.where('slug', 'in', batch))).docs.map((doc) => String(doc.get('slug') ?? '')),\n )\n const free = batch.find((slug) => !held.has(slug))\n if (free) return free\n }\n}\n\nexport interface ProductDraftWriterDeps {\n /** The Admin SDK handle; specs hand in a double. */\n firestore?: () => Firestore\n}\n\nexport function createProductDraftWriter(deps: ProductDraftWriterDeps = {}): PluginResourceDraftWriter {\n const firestore = deps.firestore ?? (() => firebaseAdmin.app().firestore() as unknown as Firestore)\n return {\n refusal: async (context) => {\n const hostRef = firestore().collection('hosts').doc(context.hostId)\n const host = await hostRef.get()\n if (!host.exists) return { status: 404, error: 'Unknown site' }\n const early = roleRefusal(host, context.uid) ?? planRefusal(context.org)\n if (early) return early\n const used = (await hostRef.collection('products').count().get()).data().count\n return roomRefusal(context.org, Number(used) || 0)\n },\n\n check: (content) => checkProductDraftContent(content),\n\n read: async ({ hostId, id }) => {\n const product = await firestore().collection('hosts').doc(hostId).collection('products').doc(id).get()\n return product.exists ? recordOf(product) : null\n },\n\n write: async (request): Promise<PluginDraftWrite> => {\n // The request's name is the one asked for; the content's stands in.\n const asked = line(request.name)\n const read = readProductDraftContent(asked ? { ...request.content, name: asked } : request.content)\n if (read.ok === false) return { ok: false, status: 400, error: read.problems[0] }\n const db = firestore()\n const hostRef = db.collection('hosts').doc(request.hostId)\n const products = hostRef.collection('products')\n const productRef = products.doc(request.id)\n return db.runTransaction(async (tx): Promise<PluginDraftWrite> => {\n // Every read before any write, which Firestore requires.\n const [host, existing] = await Promise.all([tx.get(hostRef), tx.get(productRef)])\n if (!host.exists) return { ok: false, status: 404, error: 'Unknown site' }\n // Asked again under the same id: the draft it already wrote.\n if (existing.exists) return { ok: true, replayed: true, ...recordOf(existing) }\n const early = roleRefusal(host, request.uid) ?? planRefusal(request.org)\n if (early) return { ok: false, ...early }\n const used = (await tx.get(products.count())).data().count\n const room = roomRefusal(request.org, Number(used) || 0)\n if (room) return { ok: false, ...room }\n const base = commerceSlug(read.value.proposal.name) || 'product'\n const [slug, categories, smart] = await Promise.all([\n freeSlug(products, base, (query) => tx.get(query)),\n // A category the site does not have is dropped, not stored.\n read.value.categoryIds.length\n ? Promise.all(read.value.categoryIds.map((id) => tx.get(hostRef.collection('productCategories').doc(id))))\n : Promise.resolve([]),\n tx.get(hostRef.collection('collections').where('kind', '==', 'catalog').where('mode', '==', 'smart')),\n ])\n const categoryIds = categories.filter((category) => category.exists).map((category) => category.id)\n const nowMs = request.now.getTime()\n const product = productDraftDocument({ ...read.value, categoryIds }, slug, nowMs)\n const problem = productProblem(product)\n if (problem) return { ok: false, status: 400, error: problem }\n const rules: SmartCollectionRules[] = smart.docs.map((doc) => ({\n id: doc.id,\n rules: doc.get('rules') ?? [],\n matchAll: doc.get('matchAll'),\n }))\n const priced = read.value.priceUsd !== null\n tx.create(productRef, {\n ...product,\n collectionIds: productCollectionIds(product as HostProduct, rules),\n // The legacy flat price every create path still writes, only where\n // there is one: an unpriced draft is not a free one.\n ...(priced ? { priceUsd: read.value.priceUsd } : {}),\n deletedAt: null,\n createdAt: request.now,\n updatedAt: request.now,\n createdBy: request.uid,\n })\n return {\n ok: true,\n replayed: false,\n id: request.id,\n name: product.name,\n versionId: null,\n facts: factsOf(product as HostProduct),\n }\n })\n },\n }\n}\n\nexport const productDraftWriter = createProductDraftWriter()\n\n/**\n * Registers the writer; the console surface calls it, since only the console\n * runs AI jobs (AGL-3026). Idempotent: a second call replaces the first.\n */\nexport function registerProductDraftWriter(): void {\n registerPluginResourceDraftWriter(PRODUCT_DRAFT_RESOURCE, productDraftWriter, { pluginId: BUNDLE_ID })\n}\n"],"names":["hostRoleCanWrite","checkEntitlement","checkQuota","registerPluginResourceDraftWriter","firebaseAdmin","BUNDLE_ID","COMMERCE_MAX_OPTION_VALUES","COMMERCE_MAX_OPTIONS","COMMERCE_MAX_PRICE_USD","COMMERCE_MAX_VARIANTS","commerceSlug","productCollectionIds","productPriceMissing","productSearchFields","unpricedProductDraft","validateProduct","PRODUCT_DRAFT_RESOURCE","PRODUCT_DRAFT_NAME_MAX","PRODUCT_DRAFT_DESCRIPTION_MAX","PRODUCT_DRAFT_TAGS_MAX","PRODUCT_DRAFT_TAG_MAX","PRODUCT_DRAFT_CATEGORIES_MAX","PRODUCT_DRAFT_SEO_TITLE_MAX","PRODUCT_DRAFT_SEO_DESCRIPTION_MAX","PRODUCT_DRAFT_ROLE_REFUSAL","PRODUCT_DRAFT_PLAN_REFUSAL","productDraftLimitRefusal","limit","PRODUCT_TYPES","isRecord","value","Array","isArray","line","replace","trim","strings","label","problems","undefined","some","entry","push","Set","map","filter","Boolean","readProductDraftContent","content","name","length","rawType","includes","rawDescription","description","tags","tag","categoryIds","seoTitle","seoDescription","rawOptions","options","option","optionName","values","size","combinations","reduce","count","rawPrice","priceUsd","Number","isFinite","Math","round","ok","proposal","type","productDraftDocument","read","slug","nowMs","draft","priced","variants","variant","productProblem","product","factsOf","status","priceMissing","checkProductDraftContent","problem","facts","recordOf","data","id","String","versionId","roleRefusal","host","uid","role","get","error","planRefusal","org","roomRefusal","used","quota","allowed","SLUG_PROBE","freeSlug","products","base","candidate","suffix","first","batch","from","_","offset","held","where","docs","doc","free","find","has","createProductDraftWriter","deps","firestore","app","refusal","context","hostRef","collection","hostId","exists","early","check","write","request","asked","db","productRef","runTransaction","tx","existing","Promise","all","replayed","room","categories","smart","query","resolve","category","now","getTime","rules","matchAll","create","collectionIds","deletedAt","createdAt","updatedAt","createdBy","productDraftWriter","registerProductDraftWriter","pluginId"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,gBAAgB,QAAQ,uCAAsC;AACvE,SAASC,gBAAgB,EAAEC,UAAU,QAAQ,2CAA0C;AACvF,SACEC,iCAAiC,QAO5B,qDAAoD;AAC3D,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,SAAS,QAAQ,gCAA4B;AACtD,SACEC,0BAA0B,EAC1BC,oBAAoB,EACpBC,sBAAsB,EACtBC,qBAAqB,EACrBC,YAAY,EAE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