@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,97 @@
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 { createHash } from "crypto";
18
+ import * as Aglyn from "@aglyn/aglyn/server";
19
+ import { PLATFORM_BRAND_NAME } from "@aglyn/aglyn/app-utils/platform-brand";
20
+ import { getHostDisabledPlugins, getHostDocAdmin, getOrgForHost, getServerReleaseFlagValues, lockdownRefusal } from "@aglyn/tenant-data-admin";
21
+ /*
22
+ * THE GATES EVERY SHIPPING CONNECTOR ASKS ITSELF (AGL-3613, AGL-3633).
23
+ *
24
+ * A shipping app's servers call a connector's route with credentials of the
25
+ * site's own and name no member, so each connector route is a MACHINE route:
26
+ * the dispatcher skips its per-site enablement, release and write-limit gates
27
+ * and the route answers them here, for the site its URL names, once the
28
+ * credentials are proven. ShipStation's Custom Store and ShippingEasy's
29
+ * shipment callback both stand on these; a connector that pushes orders out
30
+ * asks `connectorSiteRefusal` before each push the same way.
31
+ */ /** SHA-256 hex of a secret or a body. */ export function digestSecret(secret) {
32
+ return createHash('sha256').update(secret, 'utf8').digest('hex');
33
+ }
34
+ /** A plain-text answer: the shipping apps show the body of a refusal to the merchant. */ export function connectorText(status, body, headers = {}) {
35
+ return new Response(body, {
36
+ status,
37
+ headers: _extends({
38
+ 'content-type': 'text/plain; charset=utf-8'
39
+ }, headers)
40
+ });
41
+ }
42
+ /**
43
+ * Whether the request arrived over HTTPS. Behind Vercel the transport is
44
+ * stated by `x-forwarded-proto`; a local or test run (`NODE_ENV` not
45
+ * production) is not held to it.
46
+ */ export function requestIsSecure(request, env = process.env) {
47
+ var _request_headers_get;
48
+ if (env['NODE_ENV'] !== 'production') return true;
49
+ const forwarded = String((_request_headers_get = request.headers.get('x-forwarded-proto')) != null ? _request_headers_get : '').split(',')[0].trim().toLowerCase();
50
+ if (forwarded) return forwarded === 'https';
51
+ try {
52
+ return new URL(request.url).protocol === 'https:';
53
+ } catch (unused) {
54
+ return false;
55
+ }
56
+ }
57
+ /** A site id as a document id may hold it. */ export const CONNECTOR_HOST_ID = /^[A-Za-z0-9_-]{1,128}$/;
58
+ /** The `:hostId` a connector route was called with, or `null` when it is not one. */ export function connectorHostIdOf(params) {
59
+ const raw = params['hostId'];
60
+ const value = Array.isArray(raw) ? raw[0] : raw;
61
+ return typeof value === 'string' && CONNECTOR_HOST_ID.test(value) ? value : null;
62
+ }
63
+ /**
64
+ * The gates a dispatcher would have asked, for a site whose connector proved
65
+ * itself: commerce switched on for it, on the plan, released for the org, and
66
+ * the site not locked down. `null` when every one passes. `request` is the
67
+ * call being answered, or `{ method: 'POST' }` for a push the platform makes
68
+ * on its own, which a read-only lockdown refuses like any write.
69
+ */ export async function connectorSiteRefusal(request, hostId) {
70
+ const [owner, disabledPlugins, host] = await Promise.all([
71
+ getOrgForHost(hostId),
72
+ getHostDisabledPlugins(hostId),
73
+ getHostDocAdmin(hostId)
74
+ ]);
75
+ if (!(owner == null ? void 0 : owner.org) || !host) return connectorText(404, `This site no longer exists in ${PLATFORM_BRAND_NAME}.`);
76
+ const org = owner.org;
77
+ if (!Aglyn.resolveHostEnabledPlugins(owner.org, {
78
+ disabledPlugins
79
+ }).includes('commerce')) {
80
+ return connectorText(403, `Commerce is switched off for this site in ${PLATFORM_BRAND_NAME}.`);
81
+ }
82
+ if (!Aglyn.checkEntitlement(owner.org, 'commerce')) {
83
+ return connectorText(403, `This site’s ${PLATFORM_BRAND_NAME} plan does not include selling.`);
84
+ }
85
+ const flags = await getServerReleaseFlagValues();
86
+ const released = Aglyn.isReleaseFlagOnForOrg('release_commerce_v2', flags['release_commerce_v2'], owner.orgId, Aglyn.parseOrgReleaseFlagOverrides(org['releaseFlags']), Aglyn.resolveEffectivePlan(owner.org));
87
+ if (!released) return connectorText(403, 'Commerce is not available for this site yet.');
88
+ return lockdownRefusal({
89
+ request,
90
+ staff: false,
91
+ uid: null,
92
+ org,
93
+ host: host
94
+ });
95
+ }
96
+
97
+ //# sourceMappingURL=shipping-connector-gates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/shipping-connector-gates.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 { createHash } from 'crypto'\nimport * as Aglyn from '@aglyn/aglyn/server'\nimport { PLATFORM_BRAND_NAME } from '@aglyn/aglyn/app-utils/platform-brand'\nimport {\n getHostDisabledPlugins,\n getHostDocAdmin,\n getOrgForHost,\n getServerReleaseFlagValues,\n lockdownRefusal,\n} from '@aglyn/tenant-data-admin'\n\n/*\n * THE GATES EVERY SHIPPING CONNECTOR ASKS ITSELF (AGL-3613, AGL-3633).\n *\n * A shipping app's servers call a connector's route with credentials of the\n * site's own and name no member, so each connector route is a MACHINE route:\n * the dispatcher skips its per-site enablement, release and write-limit gates\n * and the route answers them here, for the site its URL names, once the\n * credentials are proven. ShipStation's Custom Store and ShippingEasy's\n * shipment callback both stand on these; a connector that pushes orders out\n * asks `connectorSiteRefusal` before each push the same way.\n */\n\n/** SHA-256 hex of a secret or a body. */\nexport function digestSecret(secret: string): string {\n return createHash('sha256').update(secret, 'utf8').digest('hex')\n}\n\n/** A plain-text answer: the shipping apps show the body of a refusal to the merchant. */\nexport function connectorText(status: number, body: string, headers: Record<string, string> = {}): Response {\n return new Response(body, { status, headers: { 'content-type': 'text/plain; charset=utf-8', ...headers } })\n}\n\n/**\n * Whether the request arrived over HTTPS. Behind Vercel the transport is\n * stated by `x-forwarded-proto`; a local or test run (`NODE_ENV` not\n * production) is not held to it.\n */\nexport function requestIsSecure(request: Request, env: Record<string, string | undefined> = process.env): boolean {\n if (env['NODE_ENV'] !== 'production') return true\n const forwarded = String(request.headers.get('x-forwarded-proto') ?? '')\n .split(',')[0]\n .trim()\n .toLowerCase()\n if (forwarded) return forwarded === 'https'\n try {\n return new URL(request.url).protocol === 'https:'\n } catch {\n return false\n }\n}\n\n/** A site id as a document id may hold it. */\nexport const CONNECTOR_HOST_ID = /^[A-Za-z0-9_-]{1,128}$/\n\n/** The `:hostId` a connector route was called with, or `null` when it is not one. */\nexport function connectorHostIdOf(params: Record<string, string | string[]>): string | null {\n const raw = params['hostId']\n const value = Array.isArray(raw) ? raw[0] : raw\n return typeof value === 'string' && CONNECTOR_HOST_ID.test(value) ? value : null\n}\n\n/**\n * The gates a dispatcher would have asked, for a site whose connector proved\n * itself: commerce switched on for it, on the plan, released for the org, and\n * the site not locked down. `null` when every one passes. `request` is the\n * call being answered, or `{ method: 'POST' }` for a push the platform makes\n * on its own, which a read-only lockdown refuses like any write.\n */\nexport async function connectorSiteRefusal(request: { method?: string }, hostId: string): Promise<Response | null> {\n const [owner, disabledPlugins, host] = await Promise.all([\n getOrgForHost(hostId),\n getHostDisabledPlugins(hostId),\n getHostDocAdmin(hostId),\n ])\n if (!owner?.org || !host) return connectorText(404, `This site no longer exists in ${PLATFORM_BRAND_NAME}.`)\n const org = owner.org as Record<string, unknown>\n if (!Aglyn.resolveHostEnabledPlugins(owner.org as never, { disabledPlugins }).includes('commerce')) {\n return connectorText(403, `Commerce is switched off for this site in ${PLATFORM_BRAND_NAME}.`)\n }\n if (!Aglyn.checkEntitlement(owner.org as never, 'commerce')) {\n return connectorText(403, `This site’s ${PLATFORM_BRAND_NAME} plan does not include selling.`)\n }\n const flags = await getServerReleaseFlagValues()\n const released = Aglyn.isReleaseFlagOnForOrg(\n 'release_commerce_v2',\n flags['release_commerce_v2'],\n owner.orgId,\n Aglyn.parseOrgReleaseFlagOverrides(org['releaseFlags']),\n Aglyn.resolveEffectivePlan(owner.org as never),\n )\n if (!released) return connectorText(403, 'Commerce is not available for this site yet.')\n return lockdownRefusal({\n request,\n staff: false,\n uid: null,\n org,\n host: host as Record<string, unknown>,\n })\n}\n"],"names":["createHash","Aglyn","PLATFORM_BRAND_NAME","getHostDisabledPlugins","getHostDocAdmin","getOrgForHost","getServerReleaseFlagValues","lockdownRefusal","digestSecret","secret","update","digest","connectorText","status","body","headers","Response","requestIsSecure","request","env","process","forwarded","String","get","split","trim","toLowerCase","URL","url","protocol","CONNECTOR_HOST_ID","connectorHostIdOf","params","raw","value","Array","isArray","test","connectorSiteRefusal","hostId","owner","disabledPlugins","host","Promise","all","org","resolveHostEnabledPlugins","includes","checkEntitlement","flags","released","isReleaseFlagOnForOrg","orgId","parseOrgReleaseFlagOverrides","resolveEffectivePlan","staff","uid"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,UAAU,QAAQ,SAAQ;AACnC,YAAYC,WAAW,sBAAqB;AAC5C,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SACEC,sBAAsB,EACtBC,eAAe,EACfC,aAAa,EACbC,0BAA0B,EAC1BC,eAAe,QACV,2BAA0B;AAEjC;;;;;;;;;;CAUC,GAED,uCAAuC,GACvC,OAAO,SAASC,aAAaC,MAAc;IACzC,OAAOT,WAA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A8B,EAAEV,oBAAoB,CAAC,CAAC;IAC3G,MAAM2C,MAAML,MAAMK,GAAG;IACrB,IAAI,CAAC5C,MAAM6C,yBAAyB,CAACN,MAAMK,GAAG,EAAW;QAAEJ;IAAgB,GAAGM,QAAQ,CAAC,aAAa;QAClG,OAAOnC,cAAc,KAAK,CAAC,0CAA0C,EAAEV,oBAAoB,CAAC,CAAC;IAC/F;IACA,IAAI,CAACD,MAAM+C,gBAAgB,CAACR,MAAMK,GAAG,EAAW,aAAa;QAC3D,OAAOjC,cAAc,KAAK,CAAC,YAAY,EAAEV,oBAAoB,+BAA+B,CAAC;IAC/F;IACA,MAAM+C,QAAQ,MAAM3C;IACpB,MAAM4C,WAAWjD,MAAMkD,qBAAqB,CAC1C,uBACAF,KAAK,CAAC,sBAAsB,EAC5BT,MAAMY,KAAK,EACXnD,MAAMoD,4BAA4B,CAACR,GAAG,CAAC,eAAe,GACtD5C,MAAMqD,oBAAoB,CAACd,MAAMK,GAAG;IAEtC,IAAI,CAACK,UAAU,OAAOtC,cAAc,KAAK;IACzC,OAAOL,gBAAgB;QACrBW;QACAqC,OAAO;QACPC,KAAK;QACLX;QACAH,MAAMA;IACR;AACF"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import * as Aglyn from '@aglyn/aglyn/server';
18
+ /** What the card shows about a connection. */
19
+ export interface ShipStationConnectionStatus {
20
+ /** Whether this deployment can seal a password at all. */
21
+ available: boolean;
22
+ connected: boolean;
23
+ username?: string;
24
+ createdAtMs?: number;
25
+ rotatedAtMs?: number;
26
+ lastExportAtMs?: number;
27
+ lastShipNoticeAtMs?: number;
28
+ }
29
+ export declare const shippingConnectorsHandler: Aglyn.PluginApiHandler;
@@ -0,0 +1,236 @@
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 * as Aglyn from "@aglyn/aglyn/server";
18
+ import { firebaseAdmin, getOrgForHost, logHostActivity } from "@aglyn/tenant-data-admin";
19
+ import { readCommerceSecretKeyring } from "./order-webhooks.js";
20
+ import { prepareOpenOrders } from "./orders-shipping-prepare.js";
21
+ import { SHIPPINGEASY_ACTIONS, shippingEasyConnectorAction } from "./shippingeasy.js";
22
+ import { SHIPSTATION_CONNECTIONS, mintShipStationCredentials, openShipStationPassword, sealShipStationPassword } from "./shipstation.js";
23
+ function statusOf(connection, available) {
24
+ if (!connection) return {
25
+ available,
26
+ connected: false
27
+ };
28
+ return _extends({
29
+ available,
30
+ connected: true,
31
+ username: connection.username,
32
+ createdAtMs: connection.createdAtMs
33
+ }, connection.rotatedAtMs ? {
34
+ rotatedAtMs: connection.rotatedAtMs
35
+ } : {}, connection.lastExportAtMs ? {
36
+ lastExportAtMs: connection.lastExportAtMs
37
+ } : {}, connection.lastShipNoticeAtMs ? {
38
+ lastShipNoticeAtMs: connection.lastShipNoticeAtMs
39
+ } : {});
40
+ }
41
+ const ACTIVITY = {
42
+ type: 'commerce:shipStation',
43
+ id: 'shipstation',
44
+ name: 'ShipStation'
45
+ };
46
+ const ACTIONS = [
47
+ 'status',
48
+ 'connect',
49
+ 'rotate',
50
+ 'reveal',
51
+ 'disconnect'
52
+ ];
53
+ /** The shipping apps the card route manages. `shipstation` when a request names none. */ const CONNECTORS = [
54
+ 'shipstation',
55
+ 'shippingeasy'
56
+ ];
57
+ const CONNECTOR_NAMES = {
58
+ shipstation: 'ShipStation',
59
+ shippingeasy: 'ShippingEasy'
60
+ };
61
+ export const shippingConnectorsHandler = async (req, res)=>{
62
+ var _req_headers_authorization, _ref, _ref1, _body_action;
63
+ if (req.method !== 'GET' && req.method !== 'POST') {
64
+ return res.status(405).json({
65
+ error: 'Method not allowed'
66
+ });
67
+ }
68
+ const authorization = String((_req_headers_authorization = req.headers.authorization) != null ? _req_headers_authorization : '');
69
+ const idToken = authorization.startsWith('Bearer ') ? authorization.slice('Bearer '.length) : undefined;
70
+ if (!idToken) return res.status(401).json({
71
+ error: 'Unauthenticated'
72
+ });
73
+ let body = {};
74
+ if (req.method === 'POST') {
75
+ try {
76
+ var _req_body;
77
+ body = typeof req.body === 'string' ? JSON.parse(req.body) : (_req_body = req.body) != null ? _req_body : {};
78
+ } catch (unused) {
79
+ return res.status(400).json({
80
+ error: 'The request could not be read'
81
+ });
82
+ }
83
+ }
84
+ const hostId = String((_ref = req.method === 'GET' ? req.query['hostId'] : body['hostId']) != null ? _ref : '');
85
+ if (!/^[A-Za-z0-9_-]{1,128}$/.test(hostId)) return res.status(400).json({
86
+ error: 'Missing hostId'
87
+ });
88
+ const connector = String((_ref1 = req.method === 'GET' ? req.query['connector'] : body['connector']) != null ? _ref1 : 'shipstation');
89
+ if (!CONNECTORS.includes(connector)) return res.status(400).json({
90
+ error: 'Unknown connector'
91
+ });
92
+ const action = req.method === 'GET' ? 'status' : String((_body_action = body['action']) != null ? _body_action : '');
93
+ const known = connector === 'shippingeasy' ? SHIPPINGEASY_ACTIONS : ACTIONS;
94
+ if (!known.includes(action) || req.method === 'POST' && action === 'status') {
95
+ return res.status(400).json({
96
+ error: 'Unknown action'
97
+ });
98
+ }
99
+ try {
100
+ var _hostSnapshot_get, _decoded_email;
101
+ const decoded = await firebaseAdmin.app().auth().verifyIdToken(idToken);
102
+ const firestore = firebaseAdmin.app().firestore();
103
+ const hostSnapshot = await firestore.collection('hosts').doc(hostId).get();
104
+ if (!hostSnapshot.exists) return res.status(404).json({
105
+ error: 'Unknown site'
106
+ });
107
+ const role = ((_hostSnapshot_get = hostSnapshot.get('memberRoles')) != null ? _hostSnapshot_get : {})[decoded.uid];
108
+ // Reading the status is the order book's role; anything that makes,
109
+ // shows or ends a credential that reads it is the admin's.
110
+ const adminOnly = action !== 'status';
111
+ if (adminOnly ? role !== 'admin' : role !== 'admin' && role !== 'editor') {
112
+ return res.status(403).json({
113
+ error: adminOnly ? `Only a site admin can manage the ${CONNECTOR_NAMES[connector]} connection` : 'Not permitted'
114
+ });
115
+ }
116
+ const owner = await getOrgForHost(hostId);
117
+ if (!Aglyn.checkEntitlement(owner == null ? void 0 : owner.org, 'commerce')) {
118
+ return res.status(403).json({
119
+ error: 'Selling is not enabled'
120
+ });
121
+ }
122
+ const actor = {
123
+ uid: decoded.uid,
124
+ email: (_decoded_email = decoded.email) != null ? _decoded_email : null
125
+ };
126
+ if (connector === 'shippingeasy') {
127
+ const answer = await shippingEasyConnectorAction({
128
+ hostId,
129
+ action: action,
130
+ body,
131
+ actor,
132
+ log: (what, target)=>logHostActivity(hostId, actor, what, target),
133
+ prepareOpenOrders
134
+ });
135
+ return res.status(answer.status).json(answer.body);
136
+ }
137
+ const keyring = readCommerceSecretKeyring();
138
+ const available = keyring !== null;
139
+ const ref = firestore.collection(SHIPSTATION_CONNECTIONS).doc(hostId);
140
+ if (action === 'status') {
141
+ const doc = await ref.get();
142
+ return res.status(200).json(statusOf(doc.exists ? doc.data() : null, available));
143
+ }
144
+ if (action === 'disconnect') {
145
+ const doc = await ref.get();
146
+ if (!doc.exists) return res.status(200).json({
147
+ available,
148
+ connected: false
149
+ });
150
+ await ref.delete();
151
+ await logHostActivity(hostId, actor, 'Disconnected ShipStation', ACTIVITY);
152
+ return res.status(200).json({
153
+ available,
154
+ connected: false
155
+ });
156
+ }
157
+ if (!keyring) {
158
+ return res.status(503).json({
159
+ error: 'ShipStation cannot be connected on this deployment yet'
160
+ });
161
+ }
162
+ if (action === 'reveal') {
163
+ const doc = await ref.get();
164
+ if (!doc.exists) return res.status(409).json({
165
+ error: 'ShipStation is not connected.'
166
+ });
167
+ const connection = doc.data();
168
+ const opened = openShipStationPassword(connection, keyring);
169
+ if (!opened) {
170
+ return res.status(409).json({
171
+ error: 'The password cannot be shown. Make a new password instead.'
172
+ });
173
+ }
174
+ await logHostActivity(hostId, actor, 'Showed the ShipStation password', ACTIVITY);
175
+ return res.status(200).json(_extends({}, statusOf(connection, available), {
176
+ password: opened.password
177
+ }));
178
+ }
179
+ const { username, password } = mintShipStationCredentials();
180
+ const sealed = sealShipStationPassword(hostId, password, keyring);
181
+ const nowMs = Date.now();
182
+ const outcome = await firestore.runTransaction(async (transaction)=>{
183
+ const doc = await transaction.get(ref);
184
+ if (action === 'connect') {
185
+ if (doc.exists) return {
186
+ conflict: 'ShipStation is already connected. Make a new password instead.'
187
+ };
188
+ const connection = _extends({
189
+ hostId,
190
+ username
191
+ }, sealed, {
192
+ createdAtMs: nowMs,
193
+ createdBy: decoded.uid
194
+ });
195
+ transaction.create(ref, connection);
196
+ return {
197
+ connection
198
+ };
199
+ }
200
+ if (!doc.exists) return {
201
+ conflict: 'ShipStation is not connected.'
202
+ };
203
+ const current = doc.data();
204
+ // A new password ends the old one at once: the merchant gives
205
+ // ShipStation the new one, and anything holding the old one is refused.
206
+ const connection = _extends({}, current, sealed, {
207
+ rotatedAtMs: nowMs
208
+ });
209
+ delete connection.exportCursor;
210
+ // Documents sealed before the secret box carried a digest; drop it.
211
+ delete connection['passwordHash'];
212
+ transaction.set(ref, connection);
213
+ return {
214
+ connection
215
+ };
216
+ });
217
+ if ('conflict' in outcome) return res.status(409).json({
218
+ error: outcome.conflict
219
+ });
220
+ if (action === 'connect') {
221
+ await prepareOpenOrders(hostId).catch((error)=>console.warn('shipping-connectors: open orders not stamped', hostId, error));
222
+ }
223
+ await logHostActivity(hostId, actor, action === 'connect' ? 'Connected ShipStation' : 'Made a new ShipStation password', ACTIVITY);
224
+ const connection = outcome.connection;
225
+ return res.status(200).json(_extends({}, statusOf(connection, available), {
226
+ password
227
+ }));
228
+ } catch (error) {
229
+ console.error('shipping-connectors failed', action, error);
230
+ return res.status(500).json({
231
+ error: 'That did not work. Try again.'
232
+ });
233
+ }
234
+ };
235
+
236
+ //# sourceMappingURL=shipping-connectors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/shipping-connectors.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 { firebaseAdmin, getOrgForHost, logHostActivity } from '@aglyn/tenant-data-admin'\nimport { readCommerceSecretKeyring } from './order-webhooks'\nimport { prepareOpenOrders } from './orders-shipping-prepare'\nimport { SHIPPINGEASY_ACTIONS, shippingEasyConnectorAction, type ShippingEasyAction } from './shippingeasy'\nimport {\n SHIPSTATION_CONNECTIONS,\n mintShipStationCredentials,\n openShipStationPassword,\n sealShipStationPassword,\n type ShipStationConnection,\n} from './shipstation'\n\n/*\n * THE CONSOLE'S SIDE OF THE SHIPPING CONNECTORS (AGL-3613, AGL-3633):\n * `commerce/shipping-connectors`. One door for every connector card: it\n * proves the caller and the site once, then answers for the connector the\n * request names (`connector`, `shipstation` when absent). ShippingEasy's\n * actions are `shippingEasyConnectorAction` in `./shippingeasy`; what follows\n * is ShipStation's.\n *\n * - GET `?hostId=` — whether ShipStation can be connected on this deployment\n * (`available`: commerce's secret keyring exists), whether it is, its\n * username and when it last called. Never the password.\n * - POST `{ hostId, action: 'connect' | 'rotate' | 'reveal' | 'disconnect' }`\n * — a site's ADMINS only, because the credentials read every shippable\n * order's name and address. `connect`, `rotate` and `reveal` answer the\n * password; `rotate` ends the old one at once. `connect` also stamps the\n * open orders written before the feed's fields existed\n * (`prepareOpenOrders`), so ShipStation's first import finds them.\n */\n\n/** What the card shows about a connection. */\nexport interface ShipStationConnectionStatus {\n /** Whether this deployment can seal a password at all. */\n available: boolean\n connected: boolean\n username?: string\n createdAtMs?: number\n rotatedAtMs?: number\n lastExportAtMs?: number\n lastShipNoticeAtMs?: number\n}\n\nfunction statusOf(connection: ShipStationConnection | null, available: boolean): ShipStationConnectionStatus {\n if (!connection) return { available, connected: false }\n return {\n available,\n connected: true,\n username: connection.username,\n createdAtMs: connection.createdAtMs,\n ...(connection.rotatedAtMs ? { rotatedAtMs: connection.rotatedAtMs } : {}),\n ...(connection.lastExportAtMs ? { lastExportAtMs: connection.lastExportAtMs } : {}),\n ...(connection.lastShipNoticeAtMs ? { lastShipNoticeAtMs: connection.lastShipNoticeAtMs } : {}),\n }\n}\n\nconst ACTIVITY = { type: 'commerce:shipStation', id: 'shipstation', name: 'ShipStation' } as const\n\nconst ACTIONS = ['status', 'connect', 'rotate', 'reveal', 'disconnect'] as const\ntype Action = (typeof ACTIONS)[number] | ShippingEasyAction\n\n/** The shipping apps the card route manages. `shipstation` when a request names none. */\nconst CONNECTORS = ['shipstation', 'shippingeasy'] as const\ntype Connector = (typeof CONNECTORS)[number]\nconst CONNECTOR_NAMES: Readonly<Record<Connector, string>> = { shipstation: 'ShipStation', shippingeasy: 'ShippingEasy' }\n\nexport const shippingConnectorsHandler: Aglyn.PluginApiHandler = async (req, res) => {\n if (req.method !== 'GET' && req.method !== 'POST') {\n return res.status(405).json({ error: 'Method not allowed' })\n }\n const authorization = String(req.headers.authorization ?? '')\n const idToken = authorization.startsWith('Bearer ') ? authorization.slice('Bearer '.length) : undefined\n if (!idToken) return res.status(401).json({ error: 'Unauthenticated' })\n let body: Record<string, unknown> = {}\n if (req.method === 'POST') {\n try {\n body = typeof req.body === 'string' ? JSON.parse(req.body) : (req.body ?? {})\n } catch {\n return res.status(400).json({ error: 'The request could not be read' })\n }\n }\n const hostId = String((req.method === 'GET' ? req.query['hostId'] : body['hostId']) ?? '')\n if (!/^[A-Za-z0-9_-]{1,128}$/.test(hostId)) return res.status(400).json({ error: 'Missing hostId' })\n const connector = String((req.method === 'GET' ? req.query['connector'] : body['connector']) ?? 'shipstation') as Connector\n if (!CONNECTORS.includes(connector)) return res.status(400).json({ error: 'Unknown connector' })\n const action = (req.method === 'GET' ? 'status' : String(body['action'] ?? '')) as Action\n const known: readonly string[] = connector === 'shippingeasy' ? SHIPPINGEASY_ACTIONS : ACTIONS\n if (!known.includes(action) || (req.method === 'POST' && action === 'status')) {\n return res.status(400).json({ error: 'Unknown action' })\n }\n\n try {\n const decoded = await firebaseAdmin.app().auth().verifyIdToken(idToken)\n const firestore = firebaseAdmin.app().firestore()\n const hostSnapshot = await firestore.collection('hosts').doc(hostId).get()\n if (!hostSnapshot.exists) return res.status(404).json({ error: 'Unknown site' })\n const role = (hostSnapshot.get('memberRoles') ?? {})[decoded.uid]\n // Reading the status is the order book's role; anything that makes,\n // shows or ends a credential that reads it is the admin's.\n const adminOnly = action !== 'status'\n if (adminOnly ? role !== 'admin' : role !== 'admin' && role !== 'editor') {\n return res.status(403).json({\n error: adminOnly ? `Only a site admin can manage the ${CONNECTOR_NAMES[connector]} connection` : 'Not permitted',\n })\n }\n const owner = await getOrgForHost(hostId)\n if (!Aglyn.checkEntitlement(owner?.org as never, 'commerce')) {\n return res.status(403).json({ error: 'Selling is not enabled' })\n }\n\n const actor = { uid: decoded.uid, email: decoded.email ?? null }\n if (connector === 'shippingeasy') {\n const answer = await shippingEasyConnectorAction({\n hostId,\n action: action as ShippingEasyAction,\n body,\n actor,\n log: (what, target) => logHostActivity(hostId, actor, what, target),\n prepareOpenOrders,\n })\n return res.status(answer.status).json(answer.body)\n }\n\n const keyring = readCommerceSecretKeyring()\n const available = keyring !== null\n const ref = firestore.collection(SHIPSTATION_CONNECTIONS).doc(hostId)\n\n if (action === 'status') {\n const doc = await ref.get()\n return res.status(200).json(statusOf(doc.exists ? (doc.data() as ShipStationConnection) : null, available))\n }\n if (action === 'disconnect') {\n const doc = await ref.get()\n if (!doc.exists) return res.status(200).json({ available, connected: false })\n await ref.delete()\n await logHostActivity(hostId, actor, 'Disconnected ShipStation', ACTIVITY)\n return res.status(200).json({ available, connected: false })\n }\n if (!keyring) {\n return res.status(503).json({ error: 'ShipStation cannot be connected on this deployment yet' })\n }\n if (action === 'reveal') {\n const doc = await ref.get()\n if (!doc.exists) return res.status(409).json({ error: 'ShipStation is not connected.' })\n const connection = doc.data() as ShipStationConnection\n const opened = openShipStationPassword(connection, keyring)\n if (!opened) {\n return res.status(409).json({ error: 'The password cannot be shown. Make a new password instead.' })\n }\n await logHostActivity(hostId, actor, 'Showed the ShipStation password', ACTIVITY)\n return res.status(200).json({ ...statusOf(connection, available), password: opened.password })\n }\n\n const { username, password } = mintShipStationCredentials()\n const sealed = sealShipStationPassword(hostId, password, keyring)\n const nowMs = Date.now()\n const outcome = await firestore.runTransaction(async (transaction) => {\n const doc = await transaction.get(ref)\n if (action === 'connect') {\n if (doc.exists) return { conflict: 'ShipStation is already connected. Make a new password instead.' }\n const connection: ShipStationConnection = {\n hostId,\n username,\n ...sealed,\n createdAtMs: nowMs,\n createdBy: decoded.uid,\n }\n transaction.create(ref, connection)\n return { connection }\n }\n if (!doc.exists) return { conflict: 'ShipStation is not connected.' }\n const current = doc.data() as ShipStationConnection\n // A new password ends the old one at once: the merchant gives\n // ShipStation the new one, and anything holding the old one is refused.\n const connection: ShipStationConnection = { ...current, ...sealed, rotatedAtMs: nowMs }\n delete connection.exportCursor\n // Documents sealed before the secret box carried a digest; drop it.\n delete (connection as unknown as Record<string, unknown>)['passwordHash']\n transaction.set(ref, connection)\n return { connection }\n })\n if ('conflict' in outcome) return res.status(409).json({ error: outcome.conflict })\n if (action === 'connect') {\n await prepareOpenOrders(hostId).catch((error: unknown) =>\n console.warn('shipping-connectors: open orders not stamped', hostId, error),\n )\n }\n await logHostActivity(\n hostId,\n actor,\n action === 'connect' ? 'Connected ShipStation' : 'Made a new ShipStation password',\n ACTIVITY,\n )\n const connection = outcome.connection as ShipStationConnection\n return res.status(200).json({ ...statusOf(connection, available), password })\n } catch (error) {\n console.error('shipping-connectors failed', action, error)\n return res.status(500).json({ error: 'That did not work. Try again.' })\n }\n}\n"],"names":["Aglyn","firebaseAdmin","getOrgForHost","logHostActivity","readCommerceSecretKeyring","prepareOpenOrders","SHIPPINGEASY_ACTIONS","shippingEasyConnectorAction","SHIPSTATION_CONNECTIONS","mintShipStationCredentials","openShipStationPassword","sealShipStationPassword","statusOf","connection","available","connected","username","createdAtMs","rotatedAtMs","lastExportAtMs","lastShipNoticeAtMs","ACTIVITY","type","id","name","ACTIONS","CONNECTORS","CONNECTOR_NAMES","shipstation","shippingeasy","shippingConnectorsHandler","req","res","body","method","status","json","error","authorization","String","headers","idToken","startsWith","slice","length","undefined","JSON","parse","hostId","query","test","connector","includes","action","known","hostSnapshot","decoded","app","auth","verifyIdToken","firestore","collection","doc","get","exists","role","uid","adminOnly","owner","checkEntitlement","org","actor","email","answer","log","what","target","keyring","ref","data","delete","opened","password","sealed","nowMs","Date","now","outcome","runTransaction","transaction","conflict","createdBy","create","current","exportCursor","set","catch","console","warn"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,sBAAqB;AAC5C,SAASC,aAAa,EAAEC,aAAa,EAAEC,eAAe,QAAQ,2B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AAMlC,gBACJ6C,QACAuB,OACAlB,WAAW,YAAY,0BAA0B,mCACjDhC;QAEF,MAAMR,aAAa0E,QAAQ1E,UAAU;QACrC,OAAOmB,IAAIG,MAAM,CAAC,KAAKC,IAAI,CAAC,aAAKxB,SAASC,YAAYC;YAAYoE;;IACpE,EAAE,OAAO7C,OAAO;QACd4D,QAAQ5D,KAAK,CAAC,8BAA8BgB,QAAQhB;QACpD,OAAOL,IAAIG,MAAM,CAAC,KAAKC,IAAI,CAAC;YAAEC,OAAO;QAAgC;IACvE;AACF,EAAC"}
@@ -0,0 +1,238 @@
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 { PluginDomainEventEnvelope } from '@aglyn/aglyn/plugin-manager/plugin-domain-events';
18
+ import { type SecretBoxKeyring } from '@aglyn/shared-util-tools/secret-box';
19
+ /** Where each site's connection is kept: server-only, every client denied. */
20
+ export declare const SHIPPINGEASY_CONNECTIONS = "commerceShippingEasyConnections";
21
+ /** The per-order records under a connection. */
22
+ export declare const SHIPPINGEASY_ORDER_RECORDS = "orders";
23
+ /** Callback requests per minute, per site and per calling address. */
24
+ export declare const SHIPPINGEASY_RATE_LIMIT = 120;
25
+ /** The largest callback body read. A shipment of a few orders is tens of kilobytes. */
26
+ export declare const SHIPPINGEASY_CALLBACK_MAX_BYTES: number;
27
+ /** How long a claimed push holds its order before another may try. */
28
+ export declare const SHIPPINGEASY_CLAIM_MS: number;
29
+ /** How long one call to ShippingEasy may take. */
30
+ export declare const SHIPPINGEASY_REQUEST_TIMEOUT_MS = 15000;
31
+ /** Orders "Send open orders" pushes per click. */
32
+ export declare const SHIPPINGEASY_SYNC_LIMIT = 100;
33
+ /** How far back "Send open orders" looks: older open orders are the merchant's to handle by hand. */
34
+ export declare const SHIPPINGEASY_SYNC_WINDOW_MS: number;
35
+ /** The env var that points the connector at another ShippingEasy address. */
36
+ export declare const SHIPPINGEASY_BASE_URL_ENV = "SHIPPINGEASY_API_BASE_URL";
37
+ /** A connection as stored. */
38
+ export interface ShippingEasyConnection {
39
+ hostId: string;
40
+ /** The account's API key: sent in every query string, so not a secret on its own. */
41
+ apiKey: string;
42
+ /** The account's API secret, sealed with the secret box; never stored in the clear. */
43
+ sealedApiSecret: string;
44
+ /** The id of the key that sealed it, for rotation. */
45
+ secretKeyId: string;
46
+ /** The API store's key, from ShippingEasy's Stores & Orders page. */
47
+ storeApiKey: string;
48
+ createdAtMs: number;
49
+ createdBy: string;
50
+ updatedAtMs?: number;
51
+ lastPushAtMs?: number;
52
+ lastCallbackAtMs?: number;
53
+ /** The last thing that went wrong, for the card. Cleared by the next success. */
54
+ lastError?: {
55
+ message: string;
56
+ atMs: number;
57
+ orderNumber?: string;
58
+ } | null;
59
+ }
60
+ /** Where one order stands with ShippingEasy. */
61
+ export type ShippingEasyOrderState = 'sending' | 'sent' | 'failed' | 'canceling' | 'canceled' | 'cancel_failed';
62
+ /** One order's record under a connection. */
63
+ export interface ShippingEasyOrderRecord {
64
+ orderId: string;
65
+ externalId: string;
66
+ state: ShippingEasyOrderState;
67
+ claimedAtMs?: number;
68
+ sentAtMs?: number;
69
+ canceledAtMs?: number;
70
+ error?: string | null;
71
+ updatedAtMs: number;
72
+ }
73
+ /** The merchant's keys in the clear, for one call. */
74
+ export interface ShippingEasyCredentials {
75
+ apiKey: string;
76
+ apiSecret: string;
77
+ storeApiKey: string;
78
+ }
79
+ /** What the connector's server calls are given, so specs can stand in for the network and the clock. */
80
+ export interface ShippingEasyDeps {
81
+ fetchImpl?: typeof fetch;
82
+ now?: () => number;
83
+ env?: Record<string, string | undefined>;
84
+ }
85
+ /** A failure that may pass: the outbox retries it. */
86
+ export declare class ShippingEasyUnavailableError extends Error {
87
+ constructor(message: string);
88
+ }
89
+ /** What a key from ShippingEasy's pages looks like: their keys are hex, allowed some slack. */
90
+ export declare const SHIPPINGEASY_KEY: RegExp;
91
+ /** What binds a sealed secret to its site: a copy opens for no other. */
92
+ export declare const shippingEasySealContext: (hostId: string) => string;
93
+ /** The API secret sealed for a site, with the id of the key that sealed it. */
94
+ export declare function sealShippingEasySecret(hostId: string, apiSecret: string, keyring: SecretBoxKeyring): Pick<ShippingEasyConnection, 'sealedApiSecret' | 'secretKeyId'>;
95
+ /** A site's API secret in the clear and whether to seal it again, or `null` when it cannot be opened. */
96
+ export declare function openShippingEasySecret(connection: Pick<ShippingEasyConnection, 'hostId' | 'sealedApiSecret'> | null, keyring: SecretBoxKeyring | null): {
97
+ apiSecret: string;
98
+ reseal: boolean;
99
+ } | null;
100
+ /** The connection's keys in the clear, or `null` when the secret cannot be opened. */
101
+ export declare function shippingEasyCredentialsOf(connection: ShippingEasyConnection, keyring: SecretBoxKeyring | null): ShippingEasyCredentials | null;
102
+ /** The hex HMAC-SHA256 ShippingEasy signs with. */
103
+ export declare function signShippingEasy(apiSecret: string, plaintext: string): string;
104
+ /** ShippingEasy's API address: the env's when it is an https URL, else theirs. */
105
+ export declare function shippingEasyBaseUrl(env?: Record<string, string | undefined>): string;
106
+ /** One signed call to ShippingEasy. `path` is the full path, `/api/…`. Network failures become `ShippingEasyUnavailableError`. */
107
+ export declare function shippingEasyRequest(credentials: ShippingEasyCredentials, input: {
108
+ method: 'GET' | 'POST';
109
+ path: string;
110
+ query?: Record<string, string>;
111
+ body?: unknown;
112
+ }, deps?: ShippingEasyDeps): Promise<{
113
+ status: number;
114
+ text: string;
115
+ }>;
116
+ /** A refusal's words for the card: ShippingEasy's own message when it sent one, else its status. */
117
+ export declare function shippingEasyRefusalMessage(response: {
118
+ status: number;
119
+ text: string;
120
+ }): string;
121
+ /**
122
+ * Whether the keys work: one read of the store's orders. `refused` means
123
+ * ShippingEasy said no to these keys or this store; `unavailable` means it
124
+ * could not be asked.
125
+ */
126
+ export declare function checkShippingEasyCredentials(credentials: ShippingEasyCredentials, deps?: ShippingEasyDeps): Promise<{
127
+ ok: true;
128
+ } | {
129
+ ok: false;
130
+ reason: 'refused' | 'unavailable';
131
+ message: string;
132
+ }>;
133
+ /** What one push came to. A transient failure throws `ShippingEasyUnavailableError` instead. */
134
+ export type ShippingEasyPushOutcome = {
135
+ result: 'not_connected' | 'skipped' | 'already' | 'sent' | 'canceled';
136
+ } | {
137
+ result: 'refused';
138
+ message: string;
139
+ } | {
140
+ result: 'failed';
141
+ message: string;
142
+ };
143
+ /**
144
+ * Sends one order to ShippingEasy as it stands now, or cancels it there.
145
+ * Safe to call any number of times for the same order: see the block header.
146
+ */
147
+ export declare function pushShippingEasyOrder(hostId: string, orderId: string, deps?: ShippingEasyDeps): Promise<ShippingEasyPushOutcome>;
148
+ /**
149
+ * The `shippingeasy` subscriber to commerce's order events. Throws on a
150
+ * failure that may pass, so the outbox retries; on its last attempt the
151
+ * site's managers are told and the card shows why.
152
+ */
153
+ export declare function deliverOrderEventToShippingEasy(envelope: Pick<PluginDomainEventEnvelope, 'hostId' | 'payload' | 'attempt' | 'event'>, deps?: ShippingEasyDeps): Promise<ShippingEasyPushOutcome | null>;
154
+ /** What "Send open orders" came to. */
155
+ export interface ShippingEasySyncResult {
156
+ sent: number;
157
+ already: number;
158
+ failed: number;
159
+ /** Whether more open orders are left past this pass's limit. */
160
+ more: boolean;
161
+ }
162
+ /**
163
+ * Pushes the site's open orders from the last 90 days, a pass at a time: the
164
+ * orders paid before the connection, or while it was failing. One indexed
165
+ * query (`requiresShipping ==`, `updatedAtMs` range) — the same index the
166
+ * ShipStation feed reads.
167
+ */
168
+ export declare function syncShippingEasyOrders(hostId: string, deps?: ShippingEasyDeps): Promise<ShippingEasySyncResult>;
169
+ /**
170
+ * Whether a callback was signed with this secret: the HMAC of its method,
171
+ * path, query (without `api_signature`) and raw body, compared in constant
172
+ * time; and, when it carries `api_timestamp`, sent within the hour.
173
+ */
174
+ export declare function verifyShippingEasyCallback(input: {
175
+ apiSecret: string;
176
+ method: string;
177
+ path: string;
178
+ query: URLSearchParams;
179
+ body: string;
180
+ nowMs: number;
181
+ }): 'ok' | 'unsigned' | 'bad_signature' | 'expired';
182
+ /** `POST /api/commerce/shippingeasy/{hostId}` — ShippingEasy's shipment notification. See the block header. */
183
+ export declare function shippingEasyRoute(request: Request, context: {
184
+ params: Record<string, string | string[]>;
185
+ }, deps?: ShippingEasyDeps): Promise<Response>;
186
+ /** What the card shows about a connection. Never a key in full, never the secret. */
187
+ export interface ShippingEasyConnectionStatus {
188
+ /** Whether this deployment can seal a secret at all. */
189
+ available: boolean;
190
+ connected: boolean;
191
+ apiKeyEnding?: string;
192
+ storeApiKeyEnding?: string;
193
+ createdAtMs?: number;
194
+ updatedAtMs?: number;
195
+ lastPushAtMs?: number;
196
+ lastCallbackAtMs?: number;
197
+ lastError?: {
198
+ message: string;
199
+ atMs: number;
200
+ orderNumber?: string;
201
+ } | null;
202
+ }
203
+ export declare function shippingEasyStatusOf(connection: ShippingEasyConnection | null, available: boolean): ShippingEasyConnectionStatus;
204
+ /** The card's actions. `status` is the GET. */
205
+ export declare const SHIPPINGEASY_ACTIONS: readonly ["status", "connect", "sync", "disconnect"];
206
+ export type ShippingEasyAction = (typeof SHIPPINGEASY_ACTIONS)[number];
207
+ declare const ACTIVITY: {
208
+ readonly type: "commerce:shippingEasy";
209
+ readonly id: "shippingeasy";
210
+ readonly name: "ShippingEasy";
211
+ };
212
+ /**
213
+ * One action of the ShippingEasy card, for a caller the connectors route has
214
+ * already proven a site admin (or, for `status`, an editor) on a site with
215
+ * commerce. Answers the status and body the route sends.
216
+ *
217
+ * - `connect` saves the three keys after one read proves them, sealing the
218
+ * secret; on a site already connected it replaces them (a merchant who
219
+ * made a new secret in ShippingEasy enters it here).
220
+ * - `sync` pushes the open orders, a pass at a time.
221
+ * - `disconnect` deletes the connection; the per-order records go with it,
222
+ * so a later connect sends the open orders afresh.
223
+ */
224
+ export declare function shippingEasyConnectorAction(input: {
225
+ hostId: string;
226
+ action: ShippingEasyAction;
227
+ body: Record<string, unknown>;
228
+ actor: {
229
+ uid: string;
230
+ email: string | null;
231
+ };
232
+ log: (action: string, target: typeof ACTIVITY) => Promise<void>;
233
+ prepareOpenOrders?: (hostId: string) => Promise<unknown>;
234
+ }, deps?: ShippingEasyDeps): Promise<{
235
+ status: number;
236
+ body: Record<string, unknown>;
237
+ }>;
238
+ export {};