@aglyn/plugins-commerce 1.15.2 → 1.16.0

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 (212) hide show
  1. package/README.md +1 -1
  2. package/package.json +13 -13
  3. package/src/lib/components/cart.js +2 -1
  4. package/src/lib/components/cart.js.map +1 -1
  5. package/src/lib/components/console/payments-settings-card.component.js +6 -1
  6. package/src/lib/components/console/payments-settings-card.component.js.map +1 -1
  7. package/src/lib/components/console/pos/pos-api.d.ts +5 -0
  8. package/src/lib/components/console/pos/pos-api.js.map +1 -1
  9. package/src/lib/components/console/pos/pos-tender-dialogs.component.d.ts +2 -0
  10. package/src/lib/components/console/pos/pos-tender-dialogs.component.js +13 -6
  11. package/src/lib/components/console/pos/pos-tender-dialogs.component.js.map +1 -1
  12. package/src/lib/components/console/pos/pos-tender-panel.component.js +7 -4
  13. package/src/lib/components/console/pos/pos-tender-panel.component.js.map +1 -1
  14. package/src/lib/components/console/product-add-ons-fields.component.d.ts +13 -0
  15. package/src/lib/components/console/product-add-ons-fields.component.js +96 -3
  16. package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
  17. package/src/lib/components/console/product-builder-fields.component.d.ts +39 -0
  18. package/src/lib/components/console/product-builder-fields.component.js +195 -0
  19. package/src/lib/components/console/product-builder-fields.component.js.map +1 -0
  20. package/src/lib/components/console/product-editor-dialog.component.js +35 -2
  21. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  22. package/src/lib/components/console/quote-editor-dialog.component.js +43 -6
  23. package/src/lib/components/console/quote-editor-dialog.component.js.map +1 -1
  24. package/src/lib/components/console/quote-messages.component.d.ts +21 -0
  25. package/src/lib/components/console/quote-messages.component.js +185 -0
  26. package/src/lib/components/console/quote-messages.component.js.map +1 -0
  27. package/src/lib/components/console/quote-pay-link.component.js +1 -1
  28. package/src/lib/components/console/quote-pay-link.component.js.map +1 -1
  29. package/src/lib/components/console/quote-proofs.component.js +30 -3
  30. package/src/lib/components/console/quote-proofs.component.js.map +1 -1
  31. package/src/lib/components/console/quote-settings-card.component.d.ts +7 -3
  32. package/src/lib/components/console/quote-settings-card.component.js +154 -24
  33. package/src/lib/components/console/quote-settings-card.component.js.map +1 -1
  34. package/src/lib/components/product-builder-context.d.ts +22 -0
  35. package/src/lib/components/product-builder-context.js +21 -0
  36. package/src/lib/components/product-builder-context.js.map +1 -0
  37. package/src/lib/components/product-builder-mockup.d.ts +42 -0
  38. package/src/lib/components/product-builder-mockup.js +120 -0
  39. package/src/lib/components/product-builder-mockup.js.map +1 -0
  40. package/src/lib/components/product-builder-sample.d.ts +63 -0
  41. package/src/lib/components/product-builder-sample.js +96 -0
  42. package/src/lib/components/product-builder-sample.js.map +1 -0
  43. package/src/lib/components/product-choice-cards.d.ts +51 -0
  44. package/src/lib/components/product-choice-cards.js +311 -0
  45. package/src/lib/components/product-choice-cards.js.map +1 -0
  46. package/src/lib/components/product-detail-panels.d.ts +42 -0
  47. package/src/lib/components/product-detail-panels.js +185 -0
  48. package/src/lib/components/product-detail-panels.js.map +1 -0
  49. package/src/lib/components/product-detail.d.ts +20 -12
  50. package/src/lib/components/product-detail.js +136 -221
  51. package/src/lib/components/product-detail.js.map +1 -1
  52. package/src/lib/components/product-grid.d.ts +7 -0
  53. package/src/lib/components/product-grid.js +11 -8
  54. package/src/lib/components/product-grid.js.map +1 -1
  55. package/src/lib/components/product-options-field-body.d.ts +9 -8
  56. package/src/lib/components/product-options-field-body.js +152 -3
  57. package/src/lib/components/product-options-field-body.js.map +1 -1
  58. package/src/lib/components/product-options-field.js +1 -1
  59. package/src/lib/components/product-options-field.js.map +1 -1
  60. package/src/lib/components/product-photo-fit.d.ts +49 -0
  61. package/src/lib/components/product-photo-fit.js +58 -0
  62. package/src/lib/components/product-photo-fit.js.map +1 -0
  63. package/src/lib/components/product-restock-notify.d.ts +12 -0
  64. package/src/lib/components/product-restock-notify.js +86 -0
  65. package/src/lib/components/product-restock-notify.js.map +1 -0
  66. package/src/lib/components/quote-messages-panel.d.ts +21 -0
  67. package/src/lib/components/quote-messages-panel.js +191 -0
  68. package/src/lib/components/quote-messages-panel.js.map +1 -0
  69. package/src/lib/components/quote-page-body.js +15 -1
  70. package/src/lib/components/quote-page-body.js.map +1 -1
  71. package/src/lib/components/quote-proof-panel.d.ts +6 -3
  72. package/src/lib/components/quote-proof-panel.js +139 -14
  73. package/src/lib/components/quote-proof-panel.js.map +1 -1
  74. package/src/lib/components/related-products.d.ts +7 -0
  75. package/src/lib/components/related-products.js +8 -6
  76. package/src/lib/components/related-products.js.map +1 -1
  77. package/src/lib/constants/quote-page.d.ts +8 -0
  78. package/src/lib/constants/quote-page.js +11 -0
  79. package/src/lib/constants/quote-page.js.map +1 -1
  80. package/src/lib/model/commerce-cart.d.ts +6 -1
  81. package/src/lib/model/commerce-cart.js +5 -1
  82. package/src/lib/model/commerce-cart.js.map +1 -1
  83. package/src/lib/model/commerce-invoices.js +5 -1
  84. package/src/lib/model/commerce-invoices.js.map +1 -1
  85. package/src/lib/model/commerce-pos-ops.d.ts +3 -0
  86. package/src/lib/model/commerce-pos-ops.js +3 -0
  87. package/src/lib/model/commerce-pos-ops.js.map +1 -1
  88. package/src/lib/model/commerce-pos.d.ts +8 -0
  89. package/src/lib/model/commerce-pos.js.map +1 -1
  90. package/src/lib/model/commerce-quote-messages.d.ts +106 -0
  91. package/src/lib/model/commerce-quote-messages.js +146 -0
  92. package/src/lib/model/commerce-quote-messages.js.map +1 -0
  93. package/src/lib/model/commerce-quote-pay.d.ts +31 -2
  94. package/src/lib/model/commerce-quote-pay.js +31 -7
  95. package/src/lib/model/commerce-quote-pay.js.map +1 -1
  96. package/src/lib/model/commerce-quote-proofs.d.ts +47 -8
  97. package/src/lib/model/commerce-quote-proofs.js +73 -18
  98. package/src/lib/model/commerce-quote-proofs.js.map +1 -1
  99. package/src/lib/model/commerce-quote-request.d.ts +14 -4
  100. package/src/lib/model/commerce-quote-request.js +25 -2
  101. package/src/lib/model/commerce-quote-request.js.map +1 -1
  102. package/src/lib/model/commerce-quotes.d.ts +56 -3
  103. package/src/lib/model/commerce-quotes.js +47 -2
  104. package/src/lib/model/commerce-quotes.js.map +1 -1
  105. package/src/lib/model/commerce.d.ts +12 -1
  106. package/src/lib/model/commerce.js.map +1 -1
  107. package/src/lib/model/index.d.ts +1 -0
  108. package/src/lib/model/index.js +1 -0
  109. package/src/lib/model/index.js.map +1 -1
  110. package/src/lib/model/pos-cellular.d.ts +5 -0
  111. package/src/lib/model/pos-cellular.js.map +1 -1
  112. package/src/lib/model/product-card-rules.d.ts +41 -0
  113. package/src/lib/model/product-card-rules.js +90 -0
  114. package/src/lib/model/product-card-rules.js.map +1 -0
  115. package/src/lib/model/product-modifiers.d.ts +11 -0
  116. package/src/lib/model/product-modifiers.js +10 -0
  117. package/src/lib/model/product-modifiers.js.map +1 -1
  118. package/src/lib/model/product-write.d.ts +3 -0
  119. package/src/lib/server/billing-webhook.js +6 -2
  120. package/src/lib/server/billing-webhook.js.map +1 -1
  121. package/src/lib/server/cancel-order.js +15 -0
  122. package/src/lib/server/cancel-order.js.map +1 -1
  123. package/src/lib/server/channel-order-updates.js +15 -1
  124. package/src/lib/server/channel-order-updates.js.map +1 -1
  125. package/src/lib/server/channel-orders.js +20 -0
  126. package/src/lib/server/channel-orders.js.map +1 -1
  127. package/src/lib/server/checkout.js +1 -1
  128. package/src/lib/server/checkout.js.map +1 -1
  129. package/src/lib/server/local-fulfillment.js +1 -1
  130. package/src/lib/server/local-fulfillment.js.map +1 -1
  131. package/src/lib/server/pos-cellular-billing.d.ts +1 -1
  132. package/src/lib/server/pos-cellular-billing.js +2 -1
  133. package/src/lib/server/pos-cellular-billing.js.map +1 -1
  134. package/src/lib/server/pos-cellular.d.ts +3 -1
  135. package/src/lib/server/pos-cellular.js +15 -8
  136. package/src/lib/server/pos-cellular.js.map +1 -1
  137. package/src/lib/server/pos-offline-sync.d.ts +3 -3
  138. package/src/lib/server/pos-offline-sync.js +17 -4
  139. package/src/lib/server/pos-offline-sync.js.map +1 -1
  140. package/src/lib/server/pos-order.js +17 -6
  141. package/src/lib/server/pos-order.js.map +1 -1
  142. package/src/lib/server/pos-payment.js +27 -11
  143. package/src/lib/server/pos-payment.js.map +1 -1
  144. package/src/lib/server/pos-reader-splash.js +10 -5
  145. package/src/lib/server/pos-reader-splash.js.map +1 -1
  146. package/src/lib/server/pos-readers.js +34 -10
  147. package/src/lib/server/pos-readers.js.map +1 -1
  148. package/src/lib/server/pos-return.js +19 -3
  149. package/src/lib/server/pos-return.js.map +1 -1
  150. package/src/lib/server/pos-stripe.d.ts +14 -0
  151. package/src/lib/server/pos-stripe.js +6 -2
  152. package/src/lib/server/pos-stripe.js.map +1 -1
  153. package/src/lib/server/pos-terminal-connection-token.js +23 -9
  154. package/src/lib/server/pos-terminal-connection-token.js.map +1 -1
  155. package/src/lib/server/pos-terminal.d.ts +80 -14
  156. package/src/lib/server/pos-terminal.js +393 -123
  157. package/src/lib/server/pos-terminal.js.map +1 -1
  158. package/src/lib/server/product-drafts.d.ts +1 -1
  159. package/src/lib/server/product-drafts.js +4 -3
  160. package/src/lib/server/product-drafts.js.map +1 -1
  161. package/src/lib/server/product-writer.js +5 -4
  162. package/src/lib/server/product-writer.js.map +1 -1
  163. package/src/lib/server/product.d.ts +11 -0
  164. package/src/lib/server/product.js +18 -3
  165. package/src/lib/server/product.js.map +1 -1
  166. package/src/lib/server/products-write.js +4 -3
  167. package/src/lib/server/products-write.js.map +1 -1
  168. package/src/lib/server/quote-email.d.ts +26 -0
  169. package/src/lib/server/quote-email.js +73 -7
  170. package/src/lib/server/quote-email.js.map +1 -1
  171. package/src/lib/server/quote-messages.d.ts +72 -0
  172. package/src/lib/server/quote-messages.js +356 -0
  173. package/src/lib/server/quote-messages.js.map +1 -0
  174. package/src/lib/server/quote-pay.d.ts +42 -0
  175. package/src/lib/server/quote-pay.js +81 -4
  176. package/src/lib/server/quote-pay.js.map +1 -1
  177. package/src/lib/server/quote-proofs.d.ts +1 -1
  178. package/src/lib/server/quote-proofs.js +63 -19
  179. package/src/lib/server/quote-proofs.js.map +1 -1
  180. package/src/lib/server/quote.d.ts +12 -0
  181. package/src/lib/server/quote.js +44 -14
  182. package/src/lib/server/quote.js.map +1 -1
  183. package/src/lib/server/refund.js +3 -1
  184. package/src/lib/server/refund.js.map +1 -1
  185. package/src/lib/server/reserve-stock.js +9 -0
  186. package/src/lib/server/reserve-stock.js.map +1 -1
  187. package/src/lib/server/returns.js +15 -1
  188. package/src/lib/server/returns.js.map +1 -1
  189. package/src/lib/server/reviews.js +15 -0
  190. package/src/lib/server/reviews.js.map +1 -1
  191. package/src/lib/server/sold-out-drop.d.ts +58 -0
  192. package/src/lib/server/sold-out-drop.js +81 -0
  193. package/src/lib/server/sold-out-drop.js.map +1 -0
  194. package/src/lib/server/stock-levels.js +9 -0
  195. package/src/lib/server/stock-levels.js.map +1 -1
  196. package/src/lib/server/stripe-refund.d.ts +7 -0
  197. package/src/lib/server/stripe-refund.js +26 -7
  198. package/src/lib/server/stripe-refund.js.map +1 -1
  199. package/src/lib/server.js +2 -0
  200. package/src/lib/server.js.map +1 -1
  201. package/src/lib/tenant-emails.js +85 -2
  202. package/src/lib/tenant-emails.js.map +1 -1
  203. package/src/lib/testing/fake-seller-payment-account.d.ts +29 -0
  204. package/src/lib/testing/fake-seller-payment-account.js +40 -0
  205. package/src/lib/testing/fake-seller-payment-account.js.map +1 -0
  206. package/src/lib/transfer/product-transfer.js +6 -5
  207. package/src/lib/transfer/product-transfer.js.map +1 -1
  208. package/src/lib/transfer/products.server.js +4 -3
  209. package/src/lib/transfer/products.server.js.map +1 -1
  210. package/src/lib/utils/quote-email-content.d.ts +6 -0
  211. package/src/lib/utils/quote-email-content.js +6 -3
  212. package/src/lib/utils/quote-email-content.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/pos-terminal-connection-token.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 { firebaseAdmin } from '@aglyn/tenant-data-admin'\nimport type { PluginApiHandler } from '@aglyn/aglyn/server'\nimport { authorizePosStaff, posRequestBody, type PosStaff } from './pos-auth'\nimport { posStripeTestMode, posTerminalAvailable } from './pos-stripe'\nimport {\n createPosTerminalConnectionToken,\n ensurePosTerminalLocation,\n posMerchantAccount,\n posTerminalLocationId,\n type PosTerminalAddress,\n} from './pos-terminal'\n\n/**\n * `POST /api/commerce/pos-terminal-connection-token` (AGL-3618): what the\n * native Aglyn POS app's Stripe Terminal SDK (iOS and Android) needs to drive\n * Tap to Pay and Bluetooth readers for ONE site.\n *\n * Gated exactly like a register sale (`authorizePosStaff`): a site role that\n * may sell, `managePos`, and the `pos` entitlement. The app holds no key and\n * no privileged path. Every token is scoped to the site's own Terminal\n * Location, so the SDK can connect only to readers in that Location, and the\n * PaymentIntents it collects are the server's own (`card-present-sdk`).\n *\n * Actions:\n * - `token` (the default): the secret, the Location id, the merchant's\n * account id and display name, and test mode; or a 409 whose `code` names\n * what is missing: `terminal-unavailable`, `merchant-not-ready`,\n * `location-required`.\n * - `status`: the same readiness as booleans, minting nothing.\n * - `location`: registers the site's Location from an address, once.\n */\nexport const posTerminalConnectionTokenHandler: PluginApiHandler = async (req, res) => {\n if (req.method !== 'POST') return res.status(405).json({ error: 'Method not allowed' })\n const body = posRequestBody(req)\n const gate = await authorizePosStaff(req, String(body['hostId'] ?? ''))\n if ('error' in gate) return res.status(gate.status).json({ error: gate.error })\n const staff = gate.staff\n const action = String(body['action'] ?? 'token')\n try {\n switch (action) {\n case 'token':\n return await mintToken(staff, res)\n case 'status':\n return res.status(200).json(await terminalReadiness(staff))\n case 'location':\n return await registerLocation(staff, body, res)\n default:\n return res.status(400).json({ error: 'Unknown action' })\n }\n } catch (error) {\n console.error('[pos-terminal-connection-token]', action, error)\n return res.status(500).json({ error: 'Card readers could not be reached. Try again.' })\n }\n}\n\nasync function hostName(hostId: string): Promise<string> {\n const host = await firebaseAdmin.app().firestore().collection('hosts').doc(hostId).get()\n return String(host.get('name') ?? host.get('title') ?? '').trim().slice(0, 100) || 'Store'\n}\n\n/** Readiness as the native POS app's readers panel draws it. */\nexport async function terminalReadiness(staff: PosStaff) {\n const available = posTerminalAvailable()\n const [merchant, locationId] = await Promise.all([\n posMerchantAccount(staff.hostId, staff.org),\n posTerminalLocationId(staff.hostId),\n ])\n return {\n available,\n testMode: posStripeTestMode(),\n merchantReady: Boolean(merchant),\n locationReady: Boolean(locationId),\n }\n}\n\ntype Res = Parameters<PluginApiHandler>[1]\n\nasync function mintToken(staff: PosStaff, res: Res) {\n if (!posTerminalAvailable()) {\n return res\n .status(409)\n .json({ error: 'Card readers are not available yet.', code: 'terminal-unavailable' })\n }\n // A reader that connects for a store that cannot take card payments would\n // only fail at the first sale, in front of a customer.\n const merchantAccountId = await posMerchantAccount(staff.hostId, staff.org)\n if (!merchantAccountId) {\n return res.status(409).json({\n error: 'Finish setting up payments in the console before taking cards.',\n code: 'merchant-not-ready',\n })\n }\n const token = await createPosTerminalConnectionToken(staff.hostId)\n if (!token) {\n const locationId = await posTerminalLocationId(staff.hostId)\n return locationId\n ? res.status(502).json({ error: 'Stripe did not answer. Try again.' })\n : res.status(409).json({\n error: 'Add the store address card readers are used at.',\n code: 'location-required',\n })\n }\n return res.status(200).json({\n secret: token.secret,\n locationId: token.locationId,\n // Identifies the merchant only. It is never the SDK's `onBehalfOf`:\n // card-present charges settle on Aglyn's platform account (AGL-3607), and\n // an intent collected under a different account would be refused.\n merchantAccountId,\n merchantDisplayName: await hostName(staff.hostId),\n testMode: posStripeTestMode(),\n })\n}\n\n/** An address from the native POS app, bounded the way `pos-readers` bounds it. */\nexport function readPosTerminalAddress(raw: unknown): PosTerminalAddress | undefined {\n if (!raw || typeof raw !== 'object') return undefined\n const address = raw as Record<string, unknown>\n const text = (value: unknown, max: number) => String(value ?? '').trim().slice(0, max)\n return {\n line1: text(address['line1'], 200),\n ...(text(address['line2'], 200) ? { line2: text(address['line2'], 200) } : {}),\n city: text(address['city'], 100),\n ...(text(address['state'], 100) ? { state: text(address['state'], 100) } : {}),\n postalCode: text(address['postalCode'], 20),\n country: text(address['country'], 2).toUpperCase(),\n }\n}\n\nasync function registerLocation(staff: PosStaff, body: Record<string, unknown>, res: Res) {\n if (!posTerminalAvailable()) {\n return res\n .status(409)\n .json({ error: 'Card readers are not available yet.', code: 'terminal-unavailable' })\n }\n const address = readPosTerminalAddress(body['address'])\n const location = await ensurePosTerminalLocation({\n hostId: staff.hostId,\n orgId: staff.orgId,\n displayName: await hostName(staff.hostId),\n ...(address ? { address } : {}),\n })\n if ('error' in location) return res.status(location.status).json({ error: location.error })\n return res.status(200).json({ locationId: location.locationId })\n}\n"],"names":["firebaseAdmin","authorizePosStaff","posRequestBody","posStripeTestMode","posTerminalAvailable","createPosTerminalConnectionToken","ensurePosTerminalLocation","posMerchantAccount","posTerminalLocationId","posTerminalConnectionTokenHandler","req","res","body","method","status","json","error","gate","String","staff","action","mintToken","terminalReadiness","registerLocation","console","hostName","hostId","host","app","firestore","collection","doc","get","trim","slice","available","merchant","locationId","Promise","all","org","testMode","merchantReady","Boolean","locationReady","code","merchantAccountId","token","secret","merchantDisplayName","readPosTerminalAddress","raw","undefined","address","text","value","max","line1","line2","city","state","postalCode","country","toUpperCase","location","orgId","displayName"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,aAAa,QAAQ,2BAA0B;AAExD,SAASC,iBAAiB,EAAEC,cAAc,QAAuB,gBAAY;AAC7E,SAASC,iBAAiB,EAAEC,oBAAoB,Q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WAAWW,UAAU,OAAOrD,IAAIG,MAAM,CAACkD,SAASlD,MAAM,EAAEC,IAAI,CAAC;QAAEC,OAAOgD,SAAShD,KAAK;IAAC;IACzF,OAAOL,IAAIG,MAAM,CAAC,KAAKC,IAAI,CAAC;QAAEsB,YAAY2B,SAAS3B,UAAU;IAAC;AAChE"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/server/pos-terminal-connection-token.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 { firebaseAdmin } from '@aglyn/tenant-data-admin'\nimport type { PluginApiHandler } from '@aglyn/aglyn/server'\nimport { authorizePosStaff, posRequestBody, type PosStaff } from './pos-auth'\nimport { posStripeTestMode, posTerminalAvailable } from './pos-stripe'\nimport {\n createPosTerminalConnectionToken,\n ensurePosTerminalLocation,\n posMerchantAccount,\n posTerminalLocationId,\n posTerminalRecordedLocationId,\n type PosTerminalAddress,\n} from './pos-terminal'\n\n/**\n * `POST /api/commerce/pos-terminal-connection-token` (AGL-3618): what the\n * native Aglyn POS app's Stripe Terminal SDK (iOS and Android) needs to drive\n * Tap to Pay and Bluetooth readers for ONE site.\n *\n * Gated exactly like a register sale (`authorizePosStaff`): a site role that\n * may sell, `managePos`, and the `pos` entitlement. The app holds no key and\n * no privileged path. Every token is scoped to the site's own Terminal\n * Location, so the SDK can connect only to readers in that Location, and the\n * PaymentIntents it collects are the server's own (`card-present-sdk`).\n *\n * Actions:\n * - `token` (the default): the secret, the Location id, the merchant's\n * account id and display name, and test mode; or a 409 whose `code` names\n * what is missing: `terminal-unavailable`, `merchant-not-ready`,\n * `location-required`.\n * - `status`: the same readiness as booleans, minting nothing.\n * - `location`: registers the site's Location from an address, once.\n */\nexport const posTerminalConnectionTokenHandler: PluginApiHandler = async (req, res) => {\n if (req.method !== 'POST') return res.status(405).json({ error: 'Method not allowed' })\n const body = posRequestBody(req)\n const gate = await authorizePosStaff(req, String(body['hostId'] ?? ''))\n if ('error' in gate) return res.status(gate.status).json({ error: gate.error })\n const staff = gate.staff\n const action = String(body['action'] ?? 'token')\n try {\n switch (action) {\n case 'token':\n return await mintToken(staff, res)\n case 'status':\n return res.status(200).json(await terminalReadiness(staff))\n case 'location':\n return await registerLocation(staff, body, res)\n default:\n return res.status(400).json({ error: 'Unknown action' })\n }\n } catch (error) {\n console.error('[pos-terminal-connection-token]', action, error)\n return res.status(500).json({ error: 'Card readers could not be reached. Try again.' })\n }\n}\n\nasync function hostName(hostId: string): Promise<string> {\n const host = await firebaseAdmin.app().firestore().collection('hosts').doc(hostId).get()\n return String(host.get('name') ?? host.get('title') ?? '').trim().slice(0, 100) || 'Store'\n}\n\n/** Readiness as the native POS app's readers panel draws it. */\nexport async function terminalReadiness(staff: PosStaff) {\n const available = posTerminalAvailable()\n // Any recorded Location counts: one made on the platform before the store\n // moved to its own Stripe account is made again there at the next token.\n const [merchant, locationId] = await Promise.all([\n posMerchantAccount(staff.hostId, staff.org),\n posTerminalRecordedLocationId(staff.hostId),\n ])\n return {\n available,\n testMode: posStripeTestMode(),\n merchantReady: Boolean(merchant),\n locationReady: Boolean(locationId),\n }\n}\n\ntype Res = Parameters<PluginApiHandler>[1]\n\nasync function mintToken(staff: PosStaff, res: Res) {\n if (!posTerminalAvailable()) {\n return res\n .status(409)\n .json({ error: 'Card readers are not available yet.', code: 'terminal-unavailable' })\n }\n // A reader that connects for a store that cannot take card payments would\n // only fail at the first sale, in front of a customer.\n const merchant = await posMerchantAccount(staff.hostId, staff.org)\n if (!merchant) {\n return res.status(409).json({\n error: 'Finish setting up payments in the console before taking cards.',\n code: 'merchant-not-ready',\n })\n }\n let token = await createPosTerminalConnectionToken(staff.hostId)\n if (!token && !(await posTerminalLocationId(staff.hostId))) {\n // A Location made on the platform before the store moved to its own\n // Stripe account is made again there, at the same address, so the app\n // keeps working without asking the store for it again.\n const moved = await ensurePosTerminalLocation({\n hostId: staff.hostId,\n orgId: staff.orgId,\n displayName: await hostName(staff.hostId),\n })\n if (moved.ok) token = await createPosTerminalConnectionToken(staff.hostId)\n }\n if (!token) {\n const locationId = await posTerminalLocationId(staff.hostId)\n return locationId\n ? res.status(502).json({ error: 'Stripe did not answer. Try again.' })\n : res.status(409).json({\n error: 'Add the store address card readers are used at.',\n code: 'location-required',\n })\n }\n return res.status(200).json({\n secret: token.secret,\n locationId: token.locationId,\n // Identifies the merchant only. It is never the SDK's `onBehalfOf`: a\n // destination store's card-present charges settle on Aglyn's platform\n // account (AGL-3607), and a direct store's token above was minted ON its\n // own account, so the SDK already works there.\n merchantAccountId: merchant.accountId,\n merchantDisplayName: await hostName(staff.hostId),\n testMode: posStripeTestMode(),\n })\n}\n\n/** An address from the native POS app, bounded the way `pos-readers` bounds it. */\nexport function readPosTerminalAddress(raw: unknown): PosTerminalAddress | undefined {\n if (!raw || typeof raw !== 'object') return undefined\n const address = raw as Record<string, unknown>\n const text = (value: unknown, max: number) => String(value ?? '').trim().slice(0, max)\n return {\n line1: text(address['line1'], 200),\n ...(text(address['line2'], 200) ? { line2: text(address['line2'], 200) } : {}),\n city: text(address['city'], 100),\n ...(text(address['state'], 100) ? { state: text(address['state'], 100) } : {}),\n postalCode: text(address['postalCode'], 20),\n country: text(address['country'], 2).toUpperCase(),\n }\n}\n\nasync function registerLocation(staff: PosStaff, body: Record<string, unknown>, res: Res) {\n if (!posTerminalAvailable()) {\n return res\n .status(409)\n .json({ error: 'Card readers are not available yet.', code: 'terminal-unavailable' })\n }\n const address = readPosTerminalAddress(body['address'])\n const location = await ensurePosTerminalLocation({\n hostId: staff.hostId,\n orgId: staff.orgId,\n displayName: await hostName(staff.hostId),\n ...(address ? { address } : {}),\n })\n if ('error' in location) return res.status(location.status).json({ error: location.error })\n return res.status(200).json({ locationId: location.locationId })\n}\n"],"names":["firebaseAdmin","authorizePosStaff","posRequestBody","posStripeTestMode","posTerminalAvailable","createPosTerminalConnectionToken","ensurePosTerminalLocation","posMerchantAccount","posTerminalLocationId","posTerminalRecordedLocationId","posTerminalConnectionTokenHandler","req","res","body","method","status","json","error","gate","String","staff","action","mintToken","terminalReadiness","registerLocation","console","hostName","hostId","host","app","firestore","collection","doc","get","trim","slice","available","merchant","locationId","Promise","all","org","testMode","merchantReady","Boolean","locationReady","code","token","moved","orgId","displayName","ok","secret","merchantAccountId","accountId","merchantDisplayName","readPosTerminalAddress","raw","undefined","address","text","value","max","line1","line2","city","state","postalCode","country","toUpperCase","location"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,aAAa,QAAQ,2BAA0B;AAExD,SAASC,iBAAiB,EAAEC,cAAc,QAAuB,gBAAY;AAC7E,SAASC,iBAAiB,EAAEC,oBAAoB,QAAQ,kBAAc;AACtE,SACEC,gCAAgC,EAChCC,yBAAyB,EACzBC,kBAAkB,EAClBC,qBAAqB,EACrBC,6BAA6B,QAExB,oBAAgB;AAEvB;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,MAAMC,oCAAsD,OAAOC,KAAKC;QAG5BC,cAG3BA;IALtB,IAAIF,IAAIG,MAAM,KAAK,QAAQ,OAAOF,IAAIG,MAAM,CAAC,KAAKC,IAAI,CAAC;QAAEC,OAAO;IAAqB;IACrF,MAAMJ,OAAOX,eAAeS;IAC5B,MAAMO,OAAO,MAAMjB,kBAAkBU,KAAKQ,QAAON,eAAAA,IAAI,CAAC,SAAS,YAAdA,eAAkB;IACnE,IAAI,WAAWK,MAAM,OAAON,IAAIG,MAAM,CAACG,KAAKH,MAAM,EAAEC,IAAI,CAAC;QAAEC,OAAOC,KAAKD,KAAK;IAAC;IAC7E,MAAMG,QAA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C,KAAKC,IAAI,CAAC;QAAEsB,YAAYgC,SAAShC,UAAU;IAAC;AAChE"}
@@ -14,6 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { type SaleChargeModel } from '@aglyn/tenant-data-admin/server/payment-provider';
17
18
  import * as CommerceModel from '../model';
18
19
  import type { PosRegisterSettings } from '../plugin-config';
19
20
  import { type PosLiftedOrder, type PosPaymentOutcome } from './pos-sale';
@@ -29,9 +30,36 @@ export interface PosTerminalReader {
29
30
  createdAtMs: number;
30
31
  createdBy?: string;
31
32
  lastSeenAtMs?: number;
33
+ /**
34
+ * The store's own Stripe account the reader is registered on, for a
35
+ * direct-charge store. Absent: registered on the platform.
36
+ */
37
+ stripeAccount?: string;
32
38
  }
33
- /** The merchant's connected account, when it can take card payments now. */
34
- export declare function posMerchantAccount(hostId: string, org: Record<string, any> | null): Promise<string | null>;
39
+ /** The store's selling account for an in-person card, and how it sells. */
40
+ export interface PosMerchant {
41
+ accountId: string;
42
+ chargeModel: SaleChargeModel;
43
+ }
44
+ /**
45
+ * The merchant's connected account and its charge model, when it can take
46
+ * card payments now. The ONE door every in-person card route reads the
47
+ * store's account through; where the account is recorded is
48
+ * `sellerPaymentAccount`'s business, not this file's.
49
+ */
50
+ export declare function posMerchantAccount(hostId: string, org: Record<string, any> | null): Promise<PosMerchant | null>;
51
+ /**
52
+ * The account the site's Terminal objects belong on NOW: the store's own for
53
+ * a direct-charge store, null (the platform) for every other. Not gated on
54
+ * readiness: a Location or a reader belongs where the store will sell.
55
+ */
56
+ export declare function posTerminalAccount(hostId: string, org?: Record<string, any> | null): Promise<string | null>;
57
+ /** The account a card payment's Stripe objects live on; null for the platform. */
58
+ export declare function posPaymentAccount(payment: Pick<CommerceModel.OrderPayment, 'chargeModel' | 'stripeAccountId'>): string | null;
59
+ /** The account a reader is registered on; null for the platform. */
60
+ export declare function posReaderAccount(reader: Pick<PosTerminalReader, 'stripeAccount'>): string | null;
61
+ /** What a cashier reads when a reader sits on another account than the store sells on. */
62
+ export declare const POS_READER_ON_OTHER_ACCOUNT = "This card reader was set up before the store started taking payments on its own Stripe account. Remove it in Registers and devices, then add it again with the new code it shows.";
35
63
  /** A reader id as Stripe mints them; anything else never reaches Stripe. */
36
64
  export declare function isTerminalReaderId(value: unknown): value is string;
37
65
  /** The reader, when it is THIS site's; null for anyone else's or none. */
@@ -56,15 +84,24 @@ export declare function posTerminalAddressProblem(address: Partial<PosTerminalAd
56
84
  */
57
85
  export declare function posTerminalLocationKey(hostId: string, displayName: string, address: PosTerminalAddress): string;
58
86
  /**
59
- * The site's Terminal Location, created on first use (on the PLATFORM, with
60
- * the merchant named in metadata). Its address is the store's, because Stripe
61
- * uses it to configure the reader for the right country.
87
+ * The site's Terminal Location, created on first use, on the account the
88
+ * store sells on ({@link posTerminalAccount}): the PLATFORM for a destination
89
+ * store, with the merchant named in metadata, or the store's OWN account for
90
+ * a direct-charge store. Its address is the store's, because Stripe uses it
91
+ * to configure the reader for the right country.
92
+ *
93
+ * A Location recorded on another account (a store that sold through the
94
+ * platform before it moved to its own account) is made again on the store's
95
+ * account, at the address given or else the old Location's own, and the
96
+ * configuration it carried is set up again there.
62
97
  */
63
98
  export declare function ensurePosTerminalLocation(options: {
64
99
  hostId: string;
65
100
  orgId: string;
66
101
  displayName: string;
67
102
  address?: PosTerminalAddress;
103
+ /** The account to make it on, when the caller already asked; else asked here. */
104
+ account?: string | null;
68
105
  }): Promise<{
69
106
  ok: true;
70
107
  locationId: string;
@@ -109,7 +146,9 @@ export declare function savePosReaderConfiguration(hostId: string, params: PosSt
109
146
  */
110
147
  export declare function syncPosReaderTipping(hostId: string, settings: PosRegisterSettings): Promise<void>;
111
148
  /** Reads a reader from Stripe and keeps its status on the site's document. */
112
- export declare function refreshPosReaderStatus(hostId: string, readerId: string): Promise<{
149
+ export declare function refreshPosReaderStatus(hostId: string, readerId: string,
150
+ /** The account the reader is registered on ({@link posReaderAccount}); null for the platform. */
151
+ account?: string | null): Promise<{
113
152
  status: string;
114
153
  action: any;
115
154
  } | null>;
@@ -126,9 +165,11 @@ interface CardStart {
126
165
  /**
127
166
  * Creates (or finds) the card-present PaymentIntent for one payment WITHOUT
128
167
  * choosing how the card is collected: reserves the amount in the ledger and
129
- * creates a manual-capture destination charge to the merchant (settled on
130
- * Aglyn's platform account, with no `on_behalf_of`, as ToS §10.7 states),
131
- * keyed by the payment so a retry returns the same intent.
168
+ * creates a manual-capture charge, keyed by the payment so a retry returns
169
+ * the same intent. For a destination store it is a destination charge to the
170
+ * merchant (settled on Aglyn's platform account, with no `on_behalf_of`, as
171
+ * ToS §10.7 states); for a direct-charge store it is made ON the store's own
172
+ * account (ToS v24 §10.2(a)) with Aglyn's take as the application fee.
132
173
  *
133
174
  * Two collectors use it. {@link startCardPresentPayment} pushes the intent
134
175
  * to a smart reader the site owns; a native companion app (AGL-3618)
@@ -139,6 +180,7 @@ interface CardStart {
139
180
  */
140
181
  export declare function createCardPresentIntent(start: CardStart & {
141
182
  readerId?: string;
183
+ readerAccount?: string | null;
142
184
  }): Promise<PosPaymentOutcome & {
143
185
  clientSecret?: string;
144
186
  paymentIntentId?: string;
@@ -153,14 +195,27 @@ export declare function startCardPresentPayment(start: CardStart & {
153
195
  readerId: string;
154
196
  settings: PosRegisterSettings;
155
197
  }): Promise<PosPaymentOutcome>;
156
- /** The site's Terminal Location id, or null before a reader was ever set up. */
157
- export declare function posTerminalLocationId(hostId: string): Promise<string | null>;
198
+ /** The site's recorded Location id on any account, or null before a reader was ever set up. */
199
+ export declare function posTerminalRecordedLocationId(hostId: string): Promise<string | null>;
200
+ /**
201
+ * The site's Terminal Location id on the account the store sells on now, or
202
+ * null before a reader was ever set up there. A Location made on another
203
+ * account (the platform, for a store now on its own) is not this store's
204
+ * Location any more: {@link ensurePosTerminalLocation} makes it again.
205
+ */
206
+ export declare function posTerminalLocationId(hostId: string, account?: string | null): Promise<string | null>;
158
207
  /**
159
208
  * A Terminal SDK connection token scoped to the site's own Location, for a
160
209
  * native companion app's SDK (AGL-3618). Scoping it to the Location is what
161
210
  * keeps one store's app from discovering another store's readers: Stripe
162
211
  * only lets a location-scoped token connect to readers in that Location.
163
212
  * Null when the site has no Location yet, never an unscoped token.
213
+ *
214
+ * A direct-charge store's token is minted ON its own account (the
215
+ * `Stripe-Account` header), as Stripe's Terminal-with-direct-charges guide
216
+ * asks: the SDK then sees that account's Location and readers, collects the
217
+ * intents this server made there, and creates any intent of its own (a card
218
+ * taken offline) on that account too.
164
219
  */
165
220
  export declare function createPosTerminalConnectionToken(hostId: string): Promise<{
166
221
  secret: string;
@@ -185,6 +240,7 @@ export declare function startCardKeyedPayment(start: CardStart & {
185
240
  paymentMethodId?: string;
186
241
  }): Promise<PosPaymentOutcome & {
187
242
  clientSecret?: string;
243
+ stripeAccount?: string;
188
244
  }>;
189
245
  /** What a typed card that needs the cardholder's bank to approve it says. */
190
246
  export declare const KEYED_CARD_NEEDS_AUTHENTICATION = "This card needs the cardholder to approve the payment with their bank, which a typed card cannot do. Use Card (QR) so they can approve it on their phone.";
@@ -245,10 +301,16 @@ export declare function simulatePosReaderTap(input: {
245
301
  * by trusting the event's own copy (whose API version predates the tip
246
302
  * fields). Returns the site when the event was the register's, so the
247
303
  * dispatcher can count it as claimed; null for every other event.
304
+ *
305
+ * `account` is the connected account a Connect-delivered event came from
306
+ * (`connectEventAccount`): a direct-charge store's reader and intents live
307
+ * there, so the reader event's intent is read there. The settlement itself
308
+ * reads the account the payment recorded, never the event's word.
248
309
  */
249
310
  export declare function handlePosStripeEvent(input: {
250
311
  type: string;
251
312
  object: any;
313
+ account?: string | null;
252
314
  }): Promise<{
253
315
  hostId: string;
254
316
  } | null>;
@@ -267,8 +329,12 @@ export interface PosOfflineCardIntent {
267
329
  last4?: string;
268
330
  failureMessage?: string;
269
331
  }
270
- /** Reads one offline card's PaymentIntent, with its charge's card details. */
271
- export declare function retrievePosOfflineCardIntent(paymentIntentId: string): Promise<{
332
+ /**
333
+ * Reads one offline card's PaymentIntent, with its charge's card details, on
334
+ * `account` (a direct-charge store's own, where its app's SDK made it) or
335
+ * the platform.
336
+ */
337
+ export declare function retrievePosOfflineCardIntent(paymentIntentId: string, account?: string | null): Promise<{
272
338
  ok: true;
273
339
  intent: PosOfflineCardIntent;
274
340
  } | {
@@ -276,7 +342,7 @@ export declare function retrievePosOfflineCardIntent(paymentIntentId: string): P
276
342
  error: string;
277
343
  }>;
278
344
  /** Captures one authorized offline card with the platform's fee; a repeat finds the first capture. */
279
- export declare function capturePosOfflineCardIntent(paymentIntentId: string, applicationFeeCents: number, idempotencyKey: string): Promise<{
345
+ export declare function capturePosOfflineCardIntent(paymentIntentId: string, applicationFeeCents: number, idempotencyKey: string, account?: string | null): Promise<{
280
346
  ok: true;
281
347
  intent: PosOfflineCardIntent;
282
348
  } | {