@aglyn/plugins-commerce 1.26.6 → 1.28.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 (34) hide show
  1. package/package.json +13 -13
  2. package/src/lib/components/console/pos-hardware-card.component.js +70 -67
  3. package/src/lib/components/console/pos-hardware-card.component.js.map +1 -1
  4. package/src/lib/components/console/pos-hardware-waiting-card.component.js +19 -17
  5. package/src/lib/components/console/pos-hardware-waiting-card.component.js.map +1 -1
  6. package/src/lib/components/console/product-editor-dialog.component.js +4 -43
  7. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  8. package/src/lib/contracts.d.ts +7 -0
  9. package/src/lib/contracts.js.map +1 -1
  10. package/src/lib/model/pos-hardware-shop.d.ts +152 -0
  11. package/src/lib/model/pos-hardware-shop.js +152 -0
  12. package/src/lib/model/pos-hardware-shop.js.map +1 -0
  13. package/src/lib/model/product-write.d.ts +29 -8
  14. package/src/lib/model/product-write.js +64 -2
  15. package/src/lib/model/product-write.js.map +1 -1
  16. package/src/lib/native-nav.js +13 -1
  17. package/src/lib/native-nav.js.map +1 -1
  18. package/src/lib/server/api-v1/openapi.d.ts +6 -6
  19. package/src/lib/server/api-v1/openapi.js +203 -16
  20. package/src/lib/server/api-v1/openapi.js.map +1 -1
  21. package/src/lib/server/api-v1/order-view.d.ts +8 -0
  22. package/src/lib/server/api-v1/order-view.js +21 -4
  23. package/src/lib/server/api-v1/order-view.js.map +1 -1
  24. package/src/lib/server/api-v1/orders-and-products.js +46 -59
  25. package/src/lib/server/api-v1/orders-and-products.js.map +1 -1
  26. package/src/lib/server/api-v1/product-view.d.ts +76 -0
  27. package/src/lib/server/api-v1/product-view.js +86 -0
  28. package/src/lib/server/api-v1/product-view.js.map +1 -0
  29. package/src/lib/server/api-v1/product-writes.d.ts +149 -0
  30. package/src/lib/server/api-v1/product-writes.js +673 -0
  31. package/src/lib/server/api-v1/product-writes.js.map +1 -0
  32. package/src/lib/server/products-write.d.ts +94 -2
  33. package/src/lib/server/products-write.js +171 -112
  34. package/src/lib/server/products-write.js.map +1 -1
@@ -85,6 +85,13 @@ export interface OrderEventOrder {
85
85
  refundedCents: number;
86
86
  /** The tax regime: `stripe-automatic`, `manual`, `none`, or `null` when not recorded. */
87
87
  taxMode: string | null;
88
+ /**
89
+ * Where the sale was charged (AGL-3614). `direct`: on the seller's own
90
+ * Stripe account, so the money is the seller's, Stripe's fees are the
91
+ * seller's, and so is the tax when Stripe Tax calculated it. `null`: through
92
+ * the platform's account, or not recorded.
93
+ */
94
+ chargeModel?: 'direct' | null;
88
95
  /** Whether real money moved (AGL-3699): `false` for a Stripe test-mode order. */
89
96
  livemode?: boolean;
90
97
  /** The optional lines the buyer added at checkout and whose offer each was (AGL-3635). */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/plugins/commerce/src/lib/contracts.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 { definePluginDomainEvent } from '@aglyn/aglyn/plugin-manager/plugin-domain-events'\nimport { definePluginServiceContract } from '@aglyn/aglyn/plugin-manager/plugin-services'\n\n/**\n * What commerce publishes for other plugins (AGL-3980): the order and return\n * events it raises, the checkout it reports, and the order history service it\n * registers — each by its id and its shape, and nothing that runs commerce.\n *\n * Another plugin imports this module as `@aglyn/plugins-commerce/contracts`,\n * names `commerce` in its `uses` in plugins.config.json, and carries\n * `@aglyn/plugins-commerce` as an optional peer. Importing it never loads\n * commerce, so the subscriber still runs with commerce absent: an event it\n * listens for is simply never raised, and the history service resolves to\n * `null`. `check:lib-boundaries` refuses a runtime import here other than\n * `@aglyn/aglyn`, and any other import of commerce from another plugin.\n */\n\n// ── Events (AGL-3611) ────────────────────────────────────────────────────────\n//\n// Each payload carries `order` in the public API's shape (`GET\n// /v1/sites/{siteId}/orders/{orderId}`), as it stood once the fact was\n// written, so a subscriber reads one documented object rather than the\n// plugin's storage.\n\n/** A shipment as the order itself lists it. */\nexport interface OrderViewFulfillment {\n id: string | null\n lineItemIds: unknown[]\n /** Units per line; a fulfillment recorded before quantities shipped every unit of the lines it names. */\n lines: Array<{ lineItemId: number; quantity: number }>\n status: 'active' | 'cancelled'\n carrier: string | null\n trackingNumber: string | null\n trackingUrl: string | null\n labelUrl: string | null\n /** ISO 8601. */\n at: string | null\n}\n\n/** An order as the public API returns it. Money is integer cents. */\nexport interface OrderEventOrder {\n id: string\n object: 'order'\n number: number | null\n status: string | null\n channel: string\n currency: string\n customerEmail: string | null\n customerName: string | null\n /** The lines as stored, serialized; their fields are not a contract yet. */\n lineItems: unknown\n totals: {\n itemsCents: number\n shippingCents: number\n taxCents: number\n discountCents: number\n totalCents: number | null\n feeCents: number\n /** Optional lines the buyer added at checkout (AGL-3635), inside `totalCents` and outside `itemsCents`. */\n extrasCents?: number\n /** A register tip (AGL-3607), on top of `totalCents`; the merchant's, not revenue. */\n tipCents?: number\n }\n /**\n * How a register sale was paid (AGL-3614): each tender that succeeded, with\n * its tip and the application fee Stripe took from it. Only the card\n * tenders (`card_present`, `card_keyed`, `card_link`) went through Stripe.\n * Empty for a sale that is not the register's.\n */\n payments?: Array<{\n method: 'cash' | 'card_present' | 'card_keyed' | 'card_link' | 'gift_card' | 'folio' | 'credit'\n amountCents: number\n tipCents: number\n feeCents: number\n }>\n /** The part of `totals.discountCents` a gift card paid online (AGL-3614). */\n giftCardRedeemedCents?: number\n refundedCents: number\n /** The tax regime: `stripe-automatic`, `manual`, `none`, or `null` when not recorded. */\n taxMode: string | null\n /** Whether real money moved (AGL-3699): `false` for a Stripe test-mode order. */\n livemode?: boolean\n /** The optional lines the buyer added at checkout and whose offer each was (AGL-3635). */\n extras?: Array<{\n id: string\n pluginId: string\n key: string\n label: string\n amountCents: number\n quoteRef: string | null\n }>\n /** Store credit another plugin kept that paid part of the sale (AGL-3640). */\n credits?: Array<{\n providerId: string\n pluginId: string\n reference: string\n label: string\n last4: string\n amountCents: number\n appliedAs: 'discount' | 'tender'\n }>\n /** The merchant's own tax service that priced the sale (AGL-3631); `null` when none was asked. */\n taxEngine?: {\n provider: string\n providerLabel: string\n status: 'quoted' | 'fallback'\n reason: string | null\n sandbox: boolean\n } | null\n disputed?: boolean\n /** The address as stored, serialized; `null` for an order that ships nowhere. */\n shippingAddress?: Record<string, unknown> | null\n couponCode?: string | null\n fulfillments?: OrderViewFulfillment[]\n /** ISO 8601. */\n created?: string | null\n [key: string]: unknown\n}\n\n/** A shipment as an event carries it. */\nexport interface OrderEventFulfillment {\n id: string\n lines: Array<{ lineItemId: number; quantity: number }>\n carrier: string | null\n trackingNumber: string | null\n trackingUrl: string | null\n labelUrl: string | null\n /** What the shipment cost to send — its label's cost, or the merchant's hand-entered one (AGL-3705) — in integer cents of the order's currency; `null` when unknown (AGL-3693). */\n labelCostCents: number | null\n at: string\n}\n\n/** A refund as an event carries it: what THIS refund moved. */\nexport interface OrderEventRefund {\n /** Stripe's refund id, when there is one. */\n id: string | null\n amountCents: number\n /** The line indexes refunded by name; empty for an amount-only refund. */\n lineItemIds: number[]\n /** Whether this refund left nothing more to refund. */\n full: boolean\n}\n\n/** A return as an event carries it. */\nexport interface OrderEventReturn {\n id: string\n status: string\n lines: Array<{ lineItemId: number; quantity: number; reason: string }>\n refundCents: number | null\n /** What went back in stock when the parcel arrived; `null` before then. */\n restock?: Array<{ lineItemId: number; quantity: number }> | null\n}\n\nexport interface OrderEventPayload {\n order: OrderEventOrder\n}\nexport interface OrderFulfilledEventPayload extends OrderEventPayload {\n fulfillment: OrderEventFulfillment\n}\nexport interface OrderRefundedEventPayload extends OrderEventPayload {\n refund: OrderEventRefund\n}\nexport interface ReturnEventPayload extends OrderEventPayload {\n return: OrderEventReturn\n}\n\nexport const ORDER_PAID_EVENT = definePluginDomainEvent<OrderEventPayload>('order.paid')\nexport const ORDER_FULFILLED_EVENT = definePluginDomainEvent<OrderFulfilledEventPayload>('order.fulfilled')\nexport const ORDER_DELIVERED_EVENT = definePluginDomainEvent<OrderEventPayload>('order.delivered')\nexport const ORDER_REFUNDED_EVENT = definePluginDomainEvent<OrderRefundedEventPayload>('order.refunded')\nexport const ORDER_CANCELLED_EVENT = definePluginDomainEvent<OrderEventPayload>('order.cancelled')\nexport const RETURN_REQUESTED_EVENT = definePluginDomainEvent<ReturnEventPayload>('return.requested')\nexport const RETURN_APPROVED_EVENT = definePluginDomainEvent<ReturnEventPayload>('return.approved')\nexport const RETURN_DECLINED_EVENT = definePluginDomainEvent<ReturnEventPayload>('return.declined')\nexport const RETURN_RECEIVED_EVENT = definePluginDomainEvent<ReturnEventPayload>('return.received')\nexport const RETURN_REFUNDED_EVENT = definePluginDomainEvent<ReturnEventPayload>('return.refunded')\n\n/**\n * A checkout a shopper reached with an address (AGL-3639): the fact an\n * abandoned-cart flow in a merchant's own email platform starts from. Not an\n * order event — nothing was bought — so it is raised beside them rather than\n * among them: it is not a workflow trigger and not offered to the merchant's\n * outbound webhooks, whose events are about orders.\n */\nexport interface CheckoutStartedEventPayload {\n checkout: {\n /** The checkout session's id: one event per checkout. */\n id: string\n email: string\n /** Whether the shopper ticked the store's marketing box at checkout. */\n marketingOptIn: boolean\n currency: string\n /** The basket's list value, integer cents, before discounts and shipping. */\n itemsCents: number\n /** Where the shopper can pick the checkout up again. */\n resumeUrl: string | null\n items: Array<{\n productId: string\n variantId: string | null\n name: string\n sku: string | null\n quantity: number\n unitCents: number\n }>\n }\n}\n\nexport const CHECKOUT_STARTED_EVENT = definePluginDomainEvent<CheckoutStartedEventPayload>('checkout.started')\n\n/** Every order and return event commerce raises, by name. */\nexport type CommerceEventName =\n | 'order.paid'\n | 'order.fulfilled'\n | 'order.delivered'\n | 'order.refunded'\n | 'order.cancelled'\n | 'return.requested'\n | 'return.approved'\n | 'return.declined'\n | 'return.received'\n | 'return.refunded'\n\n/** The order lifecycle's five events, by name. */\nexport type CommerceOrderEventName = Extract<CommerceEventName, `order.${string}`>\n\n/** The event names, for a webhook's event picker. */\nexport const COMMERCE_EVENT_NAMES: readonly CommerceEventName[] = [\n 'order.paid',\n 'order.fulfilled',\n 'order.delivered',\n 'order.refunded',\n 'order.cancelled',\n 'return.requested',\n 'return.approved',\n 'return.declined',\n 'return.received',\n 'return.refunded',\n]\n\n// ── Order history (AGL-3614) ─────────────────────────────────────────────────\n//\n// The events bring every order from the moment a subscriber listens. A plugin\n// that must also read the orders BEFORE that — accounting, posting a\n// merchant's earlier sales from a start date — reads them through this\n// service, in the same public shape the events carry, and never through\n// commerce's storage. Commerce registers the one implementation from its\n// console server declarations; with commerce absent it resolves to `null`.\n\n/** One stored order, as the history hands it out. */\nexport interface OrderHistoryEntry {\n id: string\n createdAtMs: number\n /** When it was paid; `null` for one never paid. */\n paidAtMs: number | null\n /** The newest refund on its timeline, or `null`. */\n lastRefundAtMs: number | null\n /** Whether its prices include the tax. */\n taxInclusive: boolean\n /** The tax rate it was charged under, when one was named. */\n taxRateId: string | null\n /** The order in the public API's shape. */\n order: OrderEventOrder\n}\n\nexport interface OrderHistoryPageRequest {\n hostId: string\n /** Orders created at or after this… */\n fromMs: number\n /** …and before this. */\n untilMs: number\n /** At most this many, oldest first; capped at 200. */\n limit: number\n}\n\nexport interface OrderHistoryReader {\n listOrders(request: OrderHistoryPageRequest): Promise<OrderHistoryEntry[]>\n}\n\nexport const ORDER_HISTORY_CONTRACT_ID = 'commerce.orderHistory'\n\nexport const ORDER_HISTORY_CONTRACT = definePluginServiceContract<OrderHistoryReader>(ORDER_HISTORY_CONTRACT_ID, {\n multiple: false,\n})\n"],"names":["definePluginDomainEvent","definePluginServiceContract","ORDER_PAID_EVENT","ORDER_FULFILLED_EVENT","ORDER_DELIVERED_EVENT","ORDER_REFUNDED_EVENT","ORDER_CANCELLED_EVENT","RETURN_REQUESTED_EVENT","RETURN_APPROVED_EVENT","RETURN_DECLINED_EVENT","RETURN_RECEIVED_EVENT","RETURN_REFUNDED_EVENT","CHECKOUT_STARTED_EVENT","COMMERCE_EVENT_NAMES","ORDER_HISTORY_CONTRACT_ID","ORDER_HISTORY_CONTRACT","multiple"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,uBAAuB,QAAQ,mDAAkD;AAC1F,SAASC,2BAA2B,QAAQ,8CAA6C;AAqKzF,OAAO,MAAMC,mBAAmBF,wBAA2C,cAAa;AACxF,OAAO,MAAMG,wBAAwBH,wBAAoD,mBAAkB;AAC3G,OAAO,MAAMI,wBAAwBJ,wBAA2C,mBAAkB;AAClG,OAAO,MAAMK,uBAAuBL,wBAAmD,kBAAiB;AACxG,OAAO,MAAMM,wBAAwBN,wBAA2C,mBAAkB;AAClG,OAAO,MAAMO,yBAAyBP,wBAA4C,oBAAmB;AACrG,OAAO,MAAMQ,wBAAwBR,wBAA4C,mBAAkB;AACnG,OAAO,MAAMS,wBAAwBT,wBAA4C,mBAAkB;AACnG,OAAO,MAAMU,wBAAwBV,wBAA4C,mBAAkB;AACnG,OAAO,MAAMW,wBAAwBX,wBAA4C,mBAAkB;AAgCnG,OAAO,MAAMY,yBAAyBZ,wBAAqD,oBAAmB;AAkB9G,mDAAmD,GACnD,OAAO,MAAMa,uBAAqD;IAChE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAyCD,OAAO,MAAMC,4BAA4B,wBAAuB;AAEhE,OAAO,MAAMC,yBAAyBd,4BAAgDa,2BAA2B;IAC/GE,UAAU;AACZ,GAAE"}
1
+ {"version":3,"sources":["../../../../../../libs/plugins/commerce/src/lib/contracts.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 { definePluginDomainEvent } from '@aglyn/aglyn/plugin-manager/plugin-domain-events'\nimport { definePluginServiceContract } from '@aglyn/aglyn/plugin-manager/plugin-services'\n\n/**\n * What commerce publishes for other plugins (AGL-3980): the order and return\n * events it raises, the checkout it reports, and the order history service it\n * registers — each by its id and its shape, and nothing that runs commerce.\n *\n * Another plugin imports this module as `@aglyn/plugins-commerce/contracts`,\n * names `commerce` in its `uses` in plugins.config.json, and carries\n * `@aglyn/plugins-commerce` as an optional peer. Importing it never loads\n * commerce, so the subscriber still runs with commerce absent: an event it\n * listens for is simply never raised, and the history service resolves to\n * `null`. `check:lib-boundaries` refuses a runtime import here other than\n * `@aglyn/aglyn`, and any other import of commerce from another plugin.\n */\n\n// ── Events (AGL-3611) ────────────────────────────────────────────────────────\n//\n// Each payload carries `order` in the public API's shape (`GET\n// /v1/sites/{siteId}/orders/{orderId}`), as it stood once the fact was\n// written, so a subscriber reads one documented object rather than the\n// plugin's storage.\n\n/** A shipment as the order itself lists it. */\nexport interface OrderViewFulfillment {\n id: string | null\n lineItemIds: unknown[]\n /** Units per line; a fulfillment recorded before quantities shipped every unit of the lines it names. */\n lines: Array<{ lineItemId: number; quantity: number }>\n status: 'active' | 'cancelled'\n carrier: string | null\n trackingNumber: string | null\n trackingUrl: string | null\n labelUrl: string | null\n /** ISO 8601. */\n at: string | null\n}\n\n/** An order as the public API returns it. Money is integer cents. */\nexport interface OrderEventOrder {\n id: string\n object: 'order'\n number: number | null\n status: string | null\n channel: string\n currency: string\n customerEmail: string | null\n customerName: string | null\n /** The lines as stored, serialized; their fields are not a contract yet. */\n lineItems: unknown\n totals: {\n itemsCents: number\n shippingCents: number\n taxCents: number\n discountCents: number\n totalCents: number | null\n feeCents: number\n /** Optional lines the buyer added at checkout (AGL-3635), inside `totalCents` and outside `itemsCents`. */\n extrasCents?: number\n /** A register tip (AGL-3607), on top of `totalCents`; the merchant's, not revenue. */\n tipCents?: number\n }\n /**\n * How a register sale was paid (AGL-3614): each tender that succeeded, with\n * its tip and the application fee Stripe took from it. Only the card\n * tenders (`card_present`, `card_keyed`, `card_link`) went through Stripe.\n * Empty for a sale that is not the register's.\n */\n payments?: Array<{\n method: 'cash' | 'card_present' | 'card_keyed' | 'card_link' | 'gift_card' | 'folio' | 'credit'\n amountCents: number\n tipCents: number\n feeCents: number\n }>\n /** The part of `totals.discountCents` a gift card paid online (AGL-3614). */\n giftCardRedeemedCents?: number\n refundedCents: number\n /** The tax regime: `stripe-automatic`, `manual`, `none`, or `null` when not recorded. */\n taxMode: string | null\n /**\n * Where the sale was charged (AGL-3614). `direct`: on the seller's own\n * Stripe account, so the money is the seller's, Stripe's fees are the\n * seller's, and so is the tax when Stripe Tax calculated it. `null`: through\n * the platform's account, or not recorded.\n */\n chargeModel?: 'direct' | null\n /** Whether real money moved (AGL-3699): `false` for a Stripe test-mode order. */\n livemode?: boolean\n /** The optional lines the buyer added at checkout and whose offer each was (AGL-3635). */\n extras?: Array<{\n id: string\n pluginId: string\n key: string\n label: string\n amountCents: number\n quoteRef: string | null\n }>\n /** Store credit another plugin kept that paid part of the sale (AGL-3640). */\n credits?: Array<{\n providerId: string\n pluginId: string\n reference: string\n label: string\n last4: string\n amountCents: number\n appliedAs: 'discount' | 'tender'\n }>\n /** The merchant's own tax service that priced the sale (AGL-3631); `null` when none was asked. */\n taxEngine?: {\n provider: string\n providerLabel: string\n status: 'quoted' | 'fallback'\n reason: string | null\n sandbox: boolean\n } | null\n disputed?: boolean\n /** The address as stored, serialized; `null` for an order that ships nowhere. */\n shippingAddress?: Record<string, unknown> | null\n couponCode?: string | null\n fulfillments?: OrderViewFulfillment[]\n /** ISO 8601. */\n created?: string | null\n [key: string]: unknown\n}\n\n/** A shipment as an event carries it. */\nexport interface OrderEventFulfillment {\n id: string\n lines: Array<{ lineItemId: number; quantity: number }>\n carrier: string | null\n trackingNumber: string | null\n trackingUrl: string | null\n labelUrl: string | null\n /** What the shipment cost to send — its label's cost, or the merchant's hand-entered one (AGL-3705) — in integer cents of the order's currency; `null` when unknown (AGL-3693). */\n labelCostCents: number | null\n at: string\n}\n\n/** A refund as an event carries it: what THIS refund moved. */\nexport interface OrderEventRefund {\n /** Stripe's refund id, when there is one. */\n id: string | null\n amountCents: number\n /** The line indexes refunded by name; empty for an amount-only refund. */\n lineItemIds: number[]\n /** Whether this refund left nothing more to refund. */\n full: boolean\n}\n\n/** A return as an event carries it. */\nexport interface OrderEventReturn {\n id: string\n status: string\n lines: Array<{ lineItemId: number; quantity: number; reason: string }>\n refundCents: number | null\n /** What went back in stock when the parcel arrived; `null` before then. */\n restock?: Array<{ lineItemId: number; quantity: number }> | null\n}\n\nexport interface OrderEventPayload {\n order: OrderEventOrder\n}\nexport interface OrderFulfilledEventPayload extends OrderEventPayload {\n fulfillment: OrderEventFulfillment\n}\nexport interface OrderRefundedEventPayload extends OrderEventPayload {\n refund: OrderEventRefund\n}\nexport interface ReturnEventPayload extends OrderEventPayload {\n return: OrderEventReturn\n}\n\nexport const ORDER_PAID_EVENT = definePluginDomainEvent<OrderEventPayload>('order.paid')\nexport const ORDER_FULFILLED_EVENT = definePluginDomainEvent<OrderFulfilledEventPayload>('order.fulfilled')\nexport const ORDER_DELIVERED_EVENT = definePluginDomainEvent<OrderEventPayload>('order.delivered')\nexport const ORDER_REFUNDED_EVENT = definePluginDomainEvent<OrderRefundedEventPayload>('order.refunded')\nexport const ORDER_CANCELLED_EVENT = definePluginDomainEvent<OrderEventPayload>('order.cancelled')\nexport const RETURN_REQUESTED_EVENT = definePluginDomainEvent<ReturnEventPayload>('return.requested')\nexport const RETURN_APPROVED_EVENT = definePluginDomainEvent<ReturnEventPayload>('return.approved')\nexport const RETURN_DECLINED_EVENT = definePluginDomainEvent<ReturnEventPayload>('return.declined')\nexport const RETURN_RECEIVED_EVENT = definePluginDomainEvent<ReturnEventPayload>('return.received')\nexport const RETURN_REFUNDED_EVENT = definePluginDomainEvent<ReturnEventPayload>('return.refunded')\n\n/**\n * A checkout a shopper reached with an address (AGL-3639): the fact an\n * abandoned-cart flow in a merchant's own email platform starts from. Not an\n * order event — nothing was bought — so it is raised beside them rather than\n * among them: it is not a workflow trigger and not offered to the merchant's\n * outbound webhooks, whose events are about orders.\n */\nexport interface CheckoutStartedEventPayload {\n checkout: {\n /** The checkout session's id: one event per checkout. */\n id: string\n email: string\n /** Whether the shopper ticked the store's marketing box at checkout. */\n marketingOptIn: boolean\n currency: string\n /** The basket's list value, integer cents, before discounts and shipping. */\n itemsCents: number\n /** Where the shopper can pick the checkout up again. */\n resumeUrl: string | null\n items: Array<{\n productId: string\n variantId: string | null\n name: string\n sku: string | null\n quantity: number\n unitCents: number\n }>\n }\n}\n\nexport const CHECKOUT_STARTED_EVENT = definePluginDomainEvent<CheckoutStartedEventPayload>('checkout.started')\n\n/** Every order and return event commerce raises, by name. */\nexport type CommerceEventName =\n | 'order.paid'\n | 'order.fulfilled'\n | 'order.delivered'\n | 'order.refunded'\n | 'order.cancelled'\n | 'return.requested'\n | 'return.approved'\n | 'return.declined'\n | 'return.received'\n | 'return.refunded'\n\n/** The order lifecycle's five events, by name. */\nexport type CommerceOrderEventName = Extract<CommerceEventName, `order.${string}`>\n\n/** The event names, for a webhook's event picker. */\nexport const COMMERCE_EVENT_NAMES: readonly CommerceEventName[] = [\n 'order.paid',\n 'order.fulfilled',\n 'order.delivered',\n 'order.refunded',\n 'order.cancelled',\n 'return.requested',\n 'return.approved',\n 'return.declined',\n 'return.received',\n 'return.refunded',\n]\n\n// ── Order history (AGL-3614) ─────────────────────────────────────────────────\n//\n// The events bring every order from the moment a subscriber listens. A plugin\n// that must also read the orders BEFORE that — accounting, posting a\n// merchant's earlier sales from a start date — reads them through this\n// service, in the same public shape the events carry, and never through\n// commerce's storage. Commerce registers the one implementation from its\n// console server declarations; with commerce absent it resolves to `null`.\n\n/** One stored order, as the history hands it out. */\nexport interface OrderHistoryEntry {\n id: string\n createdAtMs: number\n /** When it was paid; `null` for one never paid. */\n paidAtMs: number | null\n /** The newest refund on its timeline, or `null`. */\n lastRefundAtMs: number | null\n /** Whether its prices include the tax. */\n taxInclusive: boolean\n /** The tax rate it was charged under, when one was named. */\n taxRateId: string | null\n /** The order in the public API's shape. */\n order: OrderEventOrder\n}\n\nexport interface OrderHistoryPageRequest {\n hostId: string\n /** Orders created at or after this… */\n fromMs: number\n /** …and before this. */\n untilMs: number\n /** At most this many, oldest first; capped at 200. */\n limit: number\n}\n\nexport interface OrderHistoryReader {\n listOrders(request: OrderHistoryPageRequest): Promise<OrderHistoryEntry[]>\n}\n\nexport const ORDER_HISTORY_CONTRACT_ID = 'commerce.orderHistory'\n\nexport const ORDER_HISTORY_CONTRACT = definePluginServiceContract<OrderHistoryReader>(ORDER_HISTORY_CONTRACT_ID, {\n multiple: false,\n})\n"],"names":["definePluginDomainEvent","definePluginServiceContract","ORDER_PAID_EVENT","ORDER_FULFILLED_EVENT","ORDER_DELIVERED_EVENT","ORDER_REFUNDED_EVENT","ORDER_CANCELLED_EVENT","RETURN_REQUESTED_EVENT","RETURN_APPROVED_EVENT","RETURN_DECLINED_EVENT","RETURN_RECEIVED_EVENT","RETURN_REFUNDED_EVENT","CHECKOUT_STARTED_EVENT","COMMERCE_EVENT_NAMES","ORDER_HISTORY_CONTRACT_ID","ORDER_HISTORY_CONTRACT","multiple"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,uBAAuB,QAAQ,mDAAkD;AAC1F,SAASC,2BAA2B,QAAQ,8CAA6C;AA4KzF,OAAO,MAAMC,mBAAmBF,wBAA2C,cAAa;AACxF,OAAO,MAAMG,wBAAwBH,wBAAoD,mBAAkB;AAC3G,OAAO,MAAMI,wBAAwBJ,wBAA2C,mBAAkB;AAClG,OAAO,MAAMK,uBAAuBL,wBAAmD,kBAAiB;AACxG,OAAO,MAAMM,wBAAwBN,wBAA2C,mBAAkB;AAClG,OAAO,MAAMO,yBAAyBP,wBAA4C,oBAAmB;AACrG,OAAO,MAAMQ,wBAAwBR,wBAA4C,mBAAkB;AACnG,OAAO,MAAMS,wBAAwBT,wBAA4C,mBAAkB;AACnG,OAAO,MAAMU,wBAAwBV,wBAA4C,mBAAkB;AACnG,OAAO,MAAMW,wBAAwBX,wBAA4C,mBAAkB;AAgCnG,OAAO,MAAMY,yBAAyBZ,wBAAqD,oBAAmB;AAkB9G,mDAAmD,GACnD,OAAO,MAAMa,uBAAqD;IAChE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAyCD,OAAO,MAAMC,4BAA4B,wBAAuB;AAEhE,OAAO,MAAMC,yBAAyBd,4BAAgDa,2BAA2B;IAC/GE,UAAU;AACZ,GAAE"}
@@ -0,0 +1,152 @@
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
+ /** What the buyer reads of their return request. */
18
+ export declare const POS_HARDWARE_RETURN_LABELS: Record<string, string>;
19
+ /** The Hardware card's words. */
20
+ export declare const POS_HARDWARE_SHOP_TEXT: {
21
+ readonly header: "Hardware";
22
+ readonly subheader: "Card readers and accessories, set up and shipped to you";
23
+ /** The card while the shop is closed: the purchase history alone. */
24
+ readonly historySubheader: "Your card reader orders";
25
+ readonly intro: "Choose the readers and accessories you need. We set each reader up and ship your order to the address you enter at checkout. The delivery email says how to start taking payments with it.";
26
+ readonly shipsTo: "Ships to street addresses in the United States. P.O. boxes and military addresses are not accepted.";
27
+ readonly placed: "Thanks, your order is in. It shows under Your orders within a minute, and we email you as it ships.";
28
+ readonly canceled: "Checkout was canceled. Nothing was charged.";
29
+ readonly ordersTitle: "Your orders";
30
+ readonly noOrders: "No hardware orders yet.";
31
+ readonly quantity: "Quantity";
32
+ readonly shipping: "Shipping";
33
+ readonly items: "Items";
34
+ readonly tax: "Tax";
35
+ readonly taxAtCheckout: "Calculated at checkout";
36
+ readonly total: "Total";
37
+ readonly totalBeforeTax: "Total before tax";
38
+ readonly termsBefore: "I accept the ";
39
+ readonly termsLink: "hardware terms of sale (Terms, Sections 4.26–4.32)";
40
+ readonly termsAfter: ".";
41
+ readonly businessUse: "I am buying this hardware for use in my business.";
42
+ readonly checkout: "Check out";
43
+ readonly checkoutFailed: "Checkout could not be started";
44
+ readonly buyKeyReason: "Only a member with the \"Buy point of sale hardware\" permission can place an order. Ask an organization admin.";
45
+ readonly termsReason: "Accept the hardware terms of sale and confirm the hardware is for your business first.";
46
+ readonly returnAction: "Request a return";
47
+ readonly returnBody: "Tell us why. Our team gets your request and arranges the return with you. Returns follow the hardware terms of sale: the return shipping is yours to pay, the original shipping is not refunded, and any restocking fee charged for the return comes off the refund.";
48
+ readonly returnField: "Why are you returning it?";
49
+ readonly returnCancel: "Cancel";
50
+ readonly returnSend: "Request return";
51
+ readonly returnSent: "Return requested. Our team arranges it with you.";
52
+ readonly returnFailed: "The request did not go through";
53
+ readonly columnOrder: "Order";
54
+ readonly columnPlaced: "Placed";
55
+ readonly columnItems: "Items";
56
+ readonly columnTotal: "Total";
57
+ readonly columnStatus: "Status";
58
+ readonly columnReturn: "Return";
59
+ readonly columnTracking: "Tracking";
60
+ };
61
+ /** The Card readers to set up card's words. */
62
+ export declare const POS_HARDWARE_WAITING_TEXT: {
63
+ readonly header: "Card readers to set up";
64
+ readonly subheader: "Bought in person, ready for your store";
65
+ readonly planPrompt: "A card reader takes payments at the register, which comes with the point of sale. Add it, then set the reader up here.";
66
+ readonly planReason: "Add a plan with the point of sale first.";
67
+ readonly openDevices: "Open POS devices";
68
+ readonly markSetUp: "Mark set up";
69
+ readonly marked: "Marked set up";
70
+ readonly whichStore: "Which store is it for?";
71
+ readonly choose: "Choose";
72
+ readonly chosen: "Store chosen";
73
+ readonly failed: "That did not work. Try again.";
74
+ };
75
+ /** The title of the return request: `Return HW-1A2B3C?`. */
76
+ export declare function posHardwareReturnTitle(number: string): string;
77
+ /** Whether a return reason is long enough to send (the route asks the same). */
78
+ export declare function posHardwareReturnReasonReady(reason: string): boolean;
79
+ /**
80
+ * Whether an order offers "Request a return": none asked yet, and a reader
81
+ * bought in person, or an order shipped to you once it has shipped.
82
+ */
83
+ export declare function posHardwareReturnOffered(order: {
84
+ status: string;
85
+ source?: string | null;
86
+ returnRequest?: {
87
+ state: string;
88
+ } | null;
89
+ }): boolean;
90
+ /**
91
+ * The orders shipped from the Hardware card that have arrived, by number, for
92
+ * the point of sale prompt. A reader bought from the platform's own store is
93
+ * prompted on the Card readers to set up card instead, so it is not named twice.
94
+ */
95
+ export declare function posHardwareArrivedNumbers(orders: ReadonlyArray<{
96
+ number: string;
97
+ status: string;
98
+ source?: string | null;
99
+ }>): string[];
100
+ /** An order's items as Your orders lists them: `Pocket reader (M2) × 2, …`. */
101
+ export declare function posHardwareOrderItems(lines: ReadonlyArray<{
102
+ name: string;
103
+ quantity: number;
104
+ }>): string;
105
+ /** A waiting reader's items as its card heads them: `2 × Pocket reader (M2), …`. */
106
+ export declare function posHardwareWaitingItems(lines: ReadonlyArray<{
107
+ name: string;
108
+ quantity: number;
109
+ }>): string;
110
+ /** What a reader waiting for its store still needs, once the store is chosen. */
111
+ export declare function posHardwareWaitingNote(input: {
112
+ storeName: string;
113
+ serialsTaken: number;
114
+ hasLocation: boolean;
115
+ }): string;
116
+ /**
117
+ * The basket's lines and summary, from the quantities chosen: the lines a
118
+ * checkout sends (quantity above 0, in the catalog's order), the items'
119
+ * subtotal, the shipping chosen and the total before any tax.
120
+ */
121
+ export declare function posHardwareBasket(input: {
122
+ offers: ReadonlyArray<{
123
+ sku: string;
124
+ unitCents: number;
125
+ }>;
126
+ quantities: Readonly<Record<string, number>>;
127
+ shippingCents: number | null;
128
+ automaticTax: boolean;
129
+ }): {
130
+ lines: Array<{
131
+ sku: string;
132
+ quantity: number;
133
+ }>;
134
+ itemsCents: number;
135
+ totalCents: number;
136
+ totalLabel: string;
137
+ };
138
+ /**
139
+ * Check out's state: `blocked` with the reason the button names when the
140
+ * member may not buy or has not ticked both boxes, and otherwise whether it
141
+ * is pressable (a basket and a shipping speed).
142
+ */
143
+ export declare function posHardwareCheckoutState(input: {
144
+ canBuy: boolean;
145
+ termsAccepted: boolean;
146
+ businessUse: boolean;
147
+ hasLines: boolean;
148
+ hasShipping: boolean;
149
+ }): {
150
+ blockedReason: string | null;
151
+ enabled: boolean;
152
+ };
@@ -0,0 +1,152 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ import { POS_HARDWARE_TERMS_SECTIONS } from "./pos-hardware-terms.js";
17
+ /*==========================================
18
+ * THE HARDWARE SHOP AS A MERCHANT READS IT (AGL-4038): the words and the
19
+ * small rules of the Hardware card and the Card readers to set up card, in
20
+ * one pure module so the console and the native apps (through the native
21
+ * contracts) say and decide the same things. The route
22
+ * (`/api/commerce/pos-hardware`) still decides every one of them again.
23
+ *=========================================*/ /** What the buyer reads of their return request. */ export const POS_HARDWARE_RETURN_LABELS = {
24
+ requested: 'Return requested',
25
+ declined: 'Return declined',
26
+ refunded: 'Returned'
27
+ };
28
+ /** The Hardware card's words. */ export const POS_HARDWARE_SHOP_TEXT = {
29
+ header: 'Hardware',
30
+ subheader: 'Card readers and accessories, set up and shipped to you',
31
+ /** The card while the shop is closed: the purchase history alone. */ historySubheader: 'Your card reader orders',
32
+ intro: 'Choose the readers and accessories you need. We set each reader up and ship your order to the address you enter at checkout. The delivery email says how to start taking payments with it.',
33
+ shipsTo: 'Ships to street addresses in the United States. P.O. boxes and military addresses are not accepted.',
34
+ placed: 'Thanks, your order is in. It shows under Your orders within a minute, and we email you as it ships.',
35
+ canceled: 'Checkout was canceled. Nothing was charged.',
36
+ ordersTitle: 'Your orders',
37
+ noOrders: 'No hardware orders yet.',
38
+ quantity: 'Quantity',
39
+ shipping: 'Shipping',
40
+ items: 'Items',
41
+ tax: 'Tax',
42
+ taxAtCheckout: 'Calculated at checkout',
43
+ total: 'Total',
44
+ totalBeforeTax: 'Total before tax',
45
+ termsBefore: 'I accept the ',
46
+ termsLink: `hardware terms of sale (Terms, Sections ${POS_HARDWARE_TERMS_SECTIONS})`,
47
+ termsAfter: '.',
48
+ businessUse: 'I am buying this hardware for use in my business.',
49
+ checkout: 'Check out',
50
+ checkoutFailed: 'Checkout could not be started',
51
+ buyKeyReason: 'Only a member with the "Buy point of sale hardware" permission can place an order. Ask an organization admin.',
52
+ termsReason: 'Accept the hardware terms of sale and confirm the hardware is for your business first.',
53
+ returnAction: 'Request a return',
54
+ returnBody: 'Tell us why. Our team gets your request and arranges the return with you. Returns follow the hardware terms of sale: the return shipping is yours to pay, the original shipping is not refunded, and any restocking fee charged for the return comes off the refund.',
55
+ returnField: 'Why are you returning it?',
56
+ returnCancel: 'Cancel',
57
+ returnSend: 'Request return',
58
+ returnSent: 'Return requested. Our team arranges it with you.',
59
+ returnFailed: 'The request did not go through',
60
+ columnOrder: 'Order',
61
+ columnPlaced: 'Placed',
62
+ columnItems: 'Items',
63
+ columnTotal: 'Total',
64
+ columnStatus: 'Status',
65
+ columnReturn: 'Return',
66
+ columnTracking: 'Tracking'
67
+ };
68
+ /** The Card readers to set up card's words. */ export const POS_HARDWARE_WAITING_TEXT = {
69
+ header: 'Card readers to set up',
70
+ subheader: 'Bought in person, ready for your store',
71
+ planPrompt: 'A card reader takes payments at the register, which comes with the point of sale. Add it, then set the reader up here.',
72
+ planReason: 'Add a plan with the point of sale first.',
73
+ openDevices: 'Open POS devices',
74
+ markSetUp: 'Mark set up',
75
+ marked: 'Marked set up',
76
+ whichStore: 'Which store is it for?',
77
+ choose: 'Choose',
78
+ chosen: 'Store chosen',
79
+ failed: 'That did not work. Try again.'
80
+ };
81
+ /** The title of the return request: `Return HW-1A2B3C?`. */ export function posHardwareReturnTitle(number) {
82
+ return `Return ${number}?`;
83
+ }
84
+ /** Whether a return reason is long enough to send (the route asks the same). */ export function posHardwareReturnReasonReady(reason) {
85
+ return String(reason != null ? reason : '').trim().length >= 3;
86
+ }
87
+ /**
88
+ * Whether an order offers "Request a return": none asked yet, and a reader
89
+ * bought in person, or an order shipped to you once it has shipped.
90
+ */ export function posHardwareReturnOffered(order) {
91
+ var _order_source;
92
+ if (order.returnRequest) return false;
93
+ return order.status === 'delivered' || order.status === 'registered' || ((_order_source = order.source) != null ? _order_source : 'online') !== 'in_person' && order.status === 'shipped';
94
+ }
95
+ /**
96
+ * The orders shipped from the Hardware card that have arrived, by number, for
97
+ * the point of sale prompt. A reader bought from the platform's own store is
98
+ * prompted on the Card readers to set up card instead, so it is not named twice.
99
+ */ export function posHardwareArrivedNumbers(orders) {
100
+ return orders.filter((order)=>{
101
+ var _order_source;
102
+ return ((_order_source = order.source) != null ? _order_source : 'online') === 'online' && (order.status === 'delivered' || order.status === 'registered');
103
+ }).map((order)=>order.number);
104
+ }
105
+ /** An order's items as Your orders lists them: `Pocket reader (M2) × 2, …`. */ export function posHardwareOrderItems(lines) {
106
+ return lines.map((line)=>`${line.name} × ${line.quantity}`).join(', ');
107
+ }
108
+ /** A waiting reader's items as its card heads them: `2 × Pocket reader (M2), …`. */ export function posHardwareWaitingItems(lines) {
109
+ return lines.map((line)=>`${line.quantity} × ${line.name}`).join(', ');
110
+ }
111
+ /** What a reader waiting for its store still needs, once the store is chosen. */ export function posHardwareWaitingNote(input) {
112
+ const base = input.serialsTaken ? `For ${input.storeName}. Add it on the POS devices card with the code it shows, and it is set up: we know its serial number.` : `For ${input.storeName}. Add it on the POS devices card with the code it shows, then mark it set up.`;
113
+ return input.hasLocation ? base : `${base} The first reader asks for the store’s address.`;
114
+ }
115
+ /**
116
+ * The basket's lines and summary, from the quantities chosen: the lines a
117
+ * checkout sends (quantity above 0, in the catalog's order), the items'
118
+ * subtotal, the shipping chosen and the total before any tax.
119
+ */ export function posHardwareBasket(input) {
120
+ var _input_shippingCents;
121
+ const lines = input.offers.map((offer)=>{
122
+ var _input_quantities_offer_sku;
123
+ return {
124
+ sku: offer.sku,
125
+ quantity: Math.max(0, Math.floor(Number((_input_quantities_offer_sku = input.quantities[offer.sku]) != null ? _input_quantities_offer_sku : 0)))
126
+ };
127
+ }).filter((line)=>line.quantity > 0);
128
+ const itemsCents = lines.reduce((sum, line)=>{
129
+ var _ref;
130
+ var _input_offers_find;
131
+ return sum + ((_ref = (_input_offers_find = input.offers.find((offer)=>offer.sku === line.sku)) == null ? void 0 : _input_offers_find.unitCents) != null ? _ref : 0) * line.quantity;
132
+ }, 0);
133
+ return {
134
+ lines,
135
+ itemsCents,
136
+ totalCents: itemsCents + ((_input_shippingCents = input.shippingCents) != null ? _input_shippingCents : 0),
137
+ totalLabel: input.automaticTax ? POS_HARDWARE_SHOP_TEXT.totalBeforeTax : POS_HARDWARE_SHOP_TEXT.total
138
+ };
139
+ }
140
+ /**
141
+ * Check out's state: `blocked` with the reason the button names when the
142
+ * member may not buy or has not ticked both boxes, and otherwise whether it
143
+ * is pressable (a basket and a shipping speed).
144
+ */ export function posHardwareCheckoutState(input) {
145
+ const blockedReason = !input.canBuy ? POS_HARDWARE_SHOP_TEXT.buyKeyReason : !input.termsAccepted || !input.businessUse ? POS_HARDWARE_SHOP_TEXT.termsReason : null;
146
+ return {
147
+ blockedReason,
148
+ enabled: blockedReason === null && input.hasLines && input.hasShipping
149
+ };
150
+ }
151
+
152
+ //# sourceMappingURL=pos-hardware-shop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/pos-hardware-shop.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 { POS_HARDWARE_TERMS_SECTIONS } from './pos-hardware-terms'\n\n/*==========================================\n * THE HARDWARE SHOP AS A MERCHANT READS IT (AGL-4038): the words and the\n * small rules of the Hardware card and the Card readers to set up card, in\n * one pure module so the console and the native apps (through the native\n * contracts) say and decide the same things. The route\n * (`/api/commerce/pos-hardware`) still decides every one of them again.\n *=========================================*/\n\n/** What the buyer reads of their return request. */\nexport const POS_HARDWARE_RETURN_LABELS: Record<string, string> = {\n requested: 'Return requested',\n declined: 'Return declined',\n refunded: 'Returned',\n}\n\n/** The Hardware card's words. */\nexport const POS_HARDWARE_SHOP_TEXT = {\n header: 'Hardware',\n subheader: 'Card readers and accessories, set up and shipped to you',\n /** The card while the shop is closed: the purchase history alone. */\n historySubheader: 'Your card reader orders',\n intro:\n 'Choose the readers and accessories you need. We set each reader up and ship your order to the address you enter at checkout. The delivery email says how to start taking payments with it.',\n shipsTo: 'Ships to street addresses in the United States. P.O. boxes and military addresses are not accepted.',\n placed: 'Thanks, your order is in. It shows under Your orders within a minute, and we email you as it ships.',\n canceled: 'Checkout was canceled. Nothing was charged.',\n ordersTitle: 'Your orders',\n noOrders: 'No hardware orders yet.',\n quantity: 'Quantity',\n shipping: 'Shipping',\n items: 'Items',\n tax: 'Tax',\n taxAtCheckout: 'Calculated at checkout',\n total: 'Total',\n totalBeforeTax: 'Total before tax',\n termsBefore: 'I accept the ',\n termsLink: `hardware terms of sale (Terms, Sections ${POS_HARDWARE_TERMS_SECTIONS})`,\n termsAfter: '.',\n businessUse: 'I am buying this hardware for use in my business.',\n checkout: 'Check out',\n checkoutFailed: 'Checkout could not be started',\n buyKeyReason:\n 'Only a member with the \"Buy point of sale hardware\" permission can place an order. Ask an organization admin.',\n termsReason: 'Accept the hardware terms of sale and confirm the hardware is for your business first.',\n returnAction: 'Request a return',\n returnBody:\n 'Tell us why. Our team gets your request and arranges the return with you. Returns follow the hardware terms of sale: the return shipping is yours to pay, the original shipping is not refunded, and any restocking fee charged for the return comes off the refund.',\n returnField: 'Why are you returning it?',\n returnCancel: 'Cancel',\n returnSend: 'Request return',\n returnSent: 'Return requested. Our team arranges it with you.',\n returnFailed: 'The request did not go through',\n columnOrder: 'Order',\n columnPlaced: 'Placed',\n columnItems: 'Items',\n columnTotal: 'Total',\n columnStatus: 'Status',\n columnReturn: 'Return',\n columnTracking: 'Tracking',\n} as const\n\n/** The Card readers to set up card's words. */\nexport const POS_HARDWARE_WAITING_TEXT = {\n header: 'Card readers to set up',\n subheader: 'Bought in person, ready for your store',\n planPrompt:\n 'A card reader takes payments at the register, which comes with the point of sale. Add it, then set the reader up here.',\n planReason: 'Add a plan with the point of sale first.',\n openDevices: 'Open POS devices',\n markSetUp: 'Mark set up',\n marked: 'Marked set up',\n whichStore: 'Which store is it for?',\n choose: 'Choose',\n chosen: 'Store chosen',\n failed: 'That did not work. Try again.',\n} as const\n\n/** The title of the return request: `Return HW-1A2B3C?`. */\nexport function posHardwareReturnTitle(number: string): string {\n return `Return ${number}?`\n}\n\n/** Whether a return reason is long enough to send (the route asks the same). */\nexport function posHardwareReturnReasonReady(reason: string): boolean {\n return String(reason ?? '').trim().length >= 3\n}\n\n/**\n * Whether an order offers \"Request a return\": none asked yet, and a reader\n * bought in person, or an order shipped to you once it has shipped.\n */\nexport function posHardwareReturnOffered(order: {\n status: string\n source?: string | null\n returnRequest?: { state: string } | null\n}): boolean {\n if (order.returnRequest) return false\n return (\n order.status === 'delivered' ||\n order.status === 'registered' ||\n ((order.source ?? 'online') !== 'in_person' && order.status === 'shipped')\n )\n}\n\n/**\n * The orders shipped from the Hardware card that have arrived, by number, for\n * the point of sale prompt. A reader bought from the platform's own store is\n * prompted on the Card readers to set up card instead, so it is not named twice.\n */\nexport function posHardwareArrivedNumbers(\n orders: ReadonlyArray<{ number: string; status: string; source?: string | null }>,\n): string[] {\n return orders\n .filter((order) => (order.source ?? 'online') === 'online' && (order.status === 'delivered' || order.status === 'registered'))\n .map((order) => order.number)\n}\n\n/** An order's items as Your orders lists them: `Pocket reader (M2) × 2, …`. */\nexport function posHardwareOrderItems(lines: ReadonlyArray<{ name: string; quantity: number }>): string {\n return lines.map((line) => `${line.name} × ${line.quantity}`).join(', ')\n}\n\n/** A waiting reader's items as its card heads them: `2 × Pocket reader (M2), …`. */\nexport function posHardwareWaitingItems(lines: ReadonlyArray<{ name: string; quantity: number }>): string {\n return lines.map((line) => `${line.quantity} × ${line.name}`).join(', ')\n}\n\n/** What a reader waiting for its store still needs, once the store is chosen. */\nexport function posHardwareWaitingNote(input: { storeName: string; serialsTaken: number; hasLocation: boolean }): string {\n const base = input.serialsTaken\n ? `For ${input.storeName}. Add it on the POS devices card with the code it shows, and it is set up: we know its serial number.`\n : `For ${input.storeName}. Add it on the POS devices card with the code it shows, then mark it set up.`\n return input.hasLocation ? base : `${base} The first reader asks for the store’s address.`\n}\n\n/**\n * The basket's lines and summary, from the quantities chosen: the lines a\n * checkout sends (quantity above 0, in the catalog's order), the items'\n * subtotal, the shipping chosen and the total before any tax.\n */\nexport function posHardwareBasket(input: {\n offers: ReadonlyArray<{ sku: string; unitCents: number }>\n quantities: Readonly<Record<string, number>>\n shippingCents: number | null\n automaticTax: boolean\n}): {\n lines: Array<{ sku: string; quantity: number }>\n itemsCents: number\n totalCents: number\n totalLabel: string\n} {\n const lines = input.offers\n .map((offer) => ({ sku: offer.sku, quantity: Math.max(0, Math.floor(Number(input.quantities[offer.sku] ?? 0))) }))\n .filter((line) => line.quantity > 0)\n const itemsCents = lines.reduce(\n (sum, line) => sum + (input.offers.find((offer) => offer.sku === line.sku)?.unitCents ?? 0) * line.quantity,\n 0,\n )\n return {\n lines,\n itemsCents,\n totalCents: itemsCents + (input.shippingCents ?? 0),\n totalLabel: input.automaticTax ? POS_HARDWARE_SHOP_TEXT.totalBeforeTax : POS_HARDWARE_SHOP_TEXT.total,\n }\n}\n\n/**\n * Check out's state: `blocked` with the reason the button names when the\n * member may not buy or has not ticked both boxes, and otherwise whether it\n * is pressable (a basket and a shipping speed).\n */\nexport function posHardwareCheckoutState(input: {\n canBuy: boolean\n termsAccepted: boolean\n businessUse: boolean\n hasLines: boolean\n hasShipping: boolean\n}): { blockedReason: string | null; enabled: boolean } {\n const blockedReason = !input.canBuy\n ? POS_HARDWARE_SHOP_TEXT.buyKeyReason\n : !input.termsAccepted || !input.businessUse\n ? POS_HARDWARE_SHOP_TEXT.termsReason\n : null\n return { blockedReason, enabled: blockedReason === null && input.hasLines && input.hasShipping }\n}\n"],"names":["POS_HARDWARE_TERMS_SECTIONS","POS_HARDWARE_RETURN_LABELS","requested","declined","refunded","POS_HARDWARE_SHOP_TEXT","header","subheader","historySubheader","intro","shipsTo","placed","canceled","ordersTitle","noOrders","quantity","shipping","items","tax","taxAtCheckout","total","totalBeforeTax","termsBefore","termsLink","termsAfter","businessUse","checkout","checkoutFailed","buyKeyReason","termsReason","returnAction","returnBody","returnField","returnCancel","returnSend","returnSent","returnFailed","columnOrder","columnPlaced","columnItems","columnTotal","columnStatus","columnReturn","columnTracking","POS_HARDWARE_WAITING_TEXT","planPrompt","planReason","openDevices","markSetUp","marked","whichStore","choose","chosen","failed","posHardwareReturnTitle","number","posHardwareReturnReasonReady","reason","String","trim","length","posHardwareReturnOffered","order","returnRequest","status","source","posHardwareArrivedNumbers","orders","filter","map","posHardwareOrderItems","lines","line","name","join","posHardwareWaitingItems","posHardwareWaitingNote","input","base","serialsTaken","storeName","hasLocation","posHardwareBasket","offers","offer","sku","Math","max","floor","Number","quantities","itemsCents","reduce","sum","find","unitCents","totalCents","shippingCents","totalLabel","automaticTax","posHardwareCheckoutState","blockedReason","canBuy","termsAccepted","enabled","hasLines","hasShipping"],"mappings":"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"}
@@ -14,7 +14,9 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { type HostProduct, type InventoryAdjustment, type InventoryAdjustmentReason, type SmartCollectionRules } from './commerce';
17
+ import { type HostProduct, type ProductOption, type ProductVariant, type InventoryAdjustment, type InventoryAdjustmentReason, type SmartCollectionRules } from './commerce';
18
+ /** The longest product name a save keeps: {@link productSaveFields} cuts a longer one here. */
19
+ export declare const PRODUCT_NAME_MAX_LENGTH = 120;
18
20
  /** A product as the editor holds it: the stored fields plus keys the listener or a seed may carry. */
19
21
  export type EditedProduct = HostProduct & {
20
22
  $id?: string;
@@ -56,8 +58,8 @@ export declare function productSaveFields(current: EditedProduct, nowMs: number)
56
58
  categoryIds?: string[];
57
59
  collectionIds?: string[];
58
60
  tags?: string[];
59
- options?: import("./commerce").ProductOption[];
60
- variants: import("./commerce").ProductVariant[];
61
+ options?: ProductOption[];
62
+ variants: ProductVariant[];
61
63
  seo?: {
62
64
  title?: string;
63
65
  description?: string;
@@ -99,6 +101,25 @@ export declare function productSaveFields(current: EditedProduct, nowMs: number)
99
101
  deletedAt?: number | null;
100
102
  stockHolds?: Record<string, unknown>;
101
103
  };
104
+ /**
105
+ * A product nobody has saved yet, as the editor starts one: a draft, at the
106
+ * default price (AGL-3676), for the owner to change or clear.
107
+ */
108
+ export declare function blankProductDraft(): HostProduct;
109
+ /** Stable key for matching variants across matrix regenerations. */
110
+ export declare function variantComboKey(options: Record<string, string> | undefined): string;
111
+ /**
112
+ * The variants a change of option VALUES makes, as the editor rebuilds them:
113
+ * one per combination of `options`, each an existing variant with the same
114
+ * selections where there is one (so its id, price, SKU and stock survive the
115
+ * change), and otherwise a new variant at the first variant's price (none
116
+ * where it has none, the default on a product with no variant yet) and stock.
117
+ *
118
+ * Ask {@link variantMatrixProblem} first: past the ceiling the editor keeps
119
+ * the variants as they are and refuses the save (AGL-4100). A rename is not
120
+ * a change of values; it goes through `renameProductOptions` (AGL-3066).
121
+ */
122
+ export declare function variantsForOptions(at: Pick<HostProduct, 'variants'>, options: ProductOption[], nowMs: number): ProductVariant[];
102
123
  /** What the smart-collection rules are matched against: the saved name with the product's own facts. */
103
124
  export declare function productMembershipInput(fields: {
104
125
  name: string;
@@ -107,7 +128,7 @@ export declare function productMembershipInput(fields: {
107
128
  type: import("./commerce").ProductType;
108
129
  tags: string[];
109
130
  categoryIds: string[];
110
- variants: import("./commerce").ProductVariant[];
131
+ variants: ProductVariant[];
111
132
  };
112
133
  /**
113
134
  * An EDIT's replacing write, without its membership and server timestamp:
@@ -138,8 +159,8 @@ export declare function productEditWrite(fields: ReturnType<typeof productSaveFi
138
159
  categoryIds?: string[];
139
160
  collectionIds?: string[];
140
161
  tags?: string[];
141
- options?: import("./commerce").ProductOption[];
142
- variants: import("./commerce").ProductVariant[];
162
+ options?: ProductOption[];
163
+ variants: ProductVariant[];
143
164
  seo?: {
144
165
  title?: string;
145
166
  description?: string;
@@ -215,8 +236,8 @@ export declare function productDuplicateFields(product: HostProduct & {
215
236
  categoryIds?: string[];
216
237
  collectionIds?: string[];
217
238
  tags?: string[];
218
- options?: import("./commerce").ProductOption[];
219
- variants: import("./commerce").ProductVariant[];
239
+ options?: ProductOption[];
240
+ variants: ProductVariant[];
220
241
  seo?: {
221
242
  title?: string;
222
243
  description?: string;
@@ -15,7 +15,17 @@ import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_wi
15
15
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
- */ import { adjustVariantInventory, commerceSlug, productSearchFields, productStockFields, variantHasPrice } from "./commerce.js";
18
+ */ import { adjustVariantInventory, COMMERCE_DEFAULT_PRICE_USD, commerceSlug, expandVariantMatrix, productSearchFields, productStockFields, variantHasPrice } from "./commerce.js";
19
+ /*
20
+ * WHAT A PRODUCT SAVE AND A STOCK ADJUSTMENT WRITE, worked out once.
21
+ *
22
+ * The console's product editor and its Adjust stock dialog compute these
23
+ * fields in the browser before their Firestore writes; the native apps save
24
+ * through `commerce/products/save` and `commerce/products/stock`, which run
25
+ * this same code on the server. One computation, so a product saved from a
26
+ * phone carries exactly the search keys, stock verdict, price, image and
27
+ * smart-collection membership the console would have written.
28
+ */ /** The longest product name a save keeps: {@link productSaveFields} cuts a longer one here. */ export const PRODUCT_NAME_MAX_LENGTH = 120;
19
29
  /**
20
30
  * The fields a product save writes, before its collection membership and its
21
31
  * timestamps: the product as edited, with
@@ -40,7 +50,7 @@ import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_wi
40
50
  ]);
41
51
  const primaryVariant = current.variants[0];
42
52
  return _extends({}, currentFields, productSearchFields({
43
- name: current.name.trim().slice(0, 120),
53
+ name: current.name.trim().slice(0, PRODUCT_NAME_MAX_LENGTH),
44
54
  variants: current.variants
45
55
  }), {
46
56
  slug: current.slug || commerceSlug(current.name),
@@ -57,6 +67,58 @@ import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_wi
57
67
  updatedAtMs: nowMs
58
68
  });
59
69
  }
70
+ /**
71
+ * A product nobody has saved yet, as the editor starts one: a draft, at the
72
+ * default price (AGL-3676), for the owner to change or clear.
73
+ */ export function blankProductDraft() {
74
+ return {
75
+ name: '',
76
+ slug: '',
77
+ type: 'physical',
78
+ status: 'draft',
79
+ variants: [
80
+ {
81
+ id: 'default',
82
+ priceUsd: COMMERCE_DEFAULT_PRICE_USD
83
+ }
84
+ ]
85
+ };
86
+ }
87
+ /** Stable key for matching variants across matrix regenerations. */ export function variantComboKey(options) {
88
+ return Object.entries(options != null ? options : {}).sort(([a], [b])=>a.localeCompare(b)).map(([name, value])=>`${name}:${value}`).join('|');
89
+ }
90
+ /**
91
+ * The variants a change of option VALUES makes, as the editor rebuilds them:
92
+ * one per combination of `options`, each an existing variant with the same
93
+ * selections where there is one (so its id, price, SKU and stock survive the
94
+ * change), and otherwise a new variant at the first variant's price (none
95
+ * where it has none, the default on a product with no variant yet) and stock.
96
+ *
97
+ * Ask {@link variantMatrixProblem} first: past the ceiling the editor keeps
98
+ * the variants as they are and refuses the save (AGL-4100). A rename is not
99
+ * a change of values; it goes through `renameProductOptions` (AGL-3066).
100
+ */ export function variantsForOptions(at, options, nowMs) {
101
+ const previous = new Map(at.variants.map((variant)=>[
102
+ variantComboKey(variant.options),
103
+ variant
104
+ ]));
105
+ const fallback = at.variants[0];
106
+ return expandVariantMatrix(options).map((combo, comboIndex)=>{
107
+ var _previous_get, _ref;
108
+ return (_previous_get = previous.get(variantComboKey(combo))) != null ? _previous_get : // An unpriced variant is stored with no `priceUsd` (AGL-3676), as a
109
+ // proposed product's are; the type names the priced shape.
110
+ _extends({
111
+ id: `v${nowMs.toString(36)}${comboIndex}`,
112
+ options: combo
113
+ }, fallback ? variantHasPrice(fallback) ? {
114
+ priceUsd: fallback.priceUsd
115
+ } : {} : {
116
+ priceUsd: COMMERCE_DEFAULT_PRICE_USD
117
+ }, {
118
+ inventory: (_ref = fallback == null ? void 0 : fallback.inventory) != null ? _ref : null
119
+ });
120
+ });
121
+ }
60
122
  /** What the smart-collection rules are matched against: the saved name with the product's own facts. */ export function productMembershipInput(fields, current) {
61
123
  return {
62
124
  name: fields.name,