@aglyn/plugins-commerce 1.26.5 → 1.27.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.
- package/package.json +13 -13
- package/src/lib/components/console/product-editor-dialog.component.js +4 -43
- package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
- package/src/lib/contracts.d.ts +7 -0
- package/src/lib/contracts.js.map +1 -1
- package/src/lib/model/product-write.d.ts +29 -8
- package/src/lib/model/product-write.js +64 -2
- package/src/lib/model/product-write.js.map +1 -1
- package/src/lib/native-nav.js +12 -1
- package/src/lib/native-nav.js.map +1 -1
- package/src/lib/server/api-v1/openapi.d.ts +6 -6
- package/src/lib/server/api-v1/openapi.js +203 -16
- package/src/lib/server/api-v1/openapi.js.map +1 -1
- package/src/lib/server/api-v1/order-view.d.ts +8 -0
- package/src/lib/server/api-v1/order-view.js +21 -4
- package/src/lib/server/api-v1/order-view.js.map +1 -1
- package/src/lib/server/api-v1/orders-and-products.js +46 -59
- package/src/lib/server/api-v1/orders-and-products.js.map +1 -1
- package/src/lib/server/api-v1/product-view.d.ts +76 -0
- package/src/lib/server/api-v1/product-view.js +86 -0
- package/src/lib/server/api-v1/product-view.js.map +1 -0
- package/src/lib/server/api-v1/product-writes.d.ts +149 -0
- package/src/lib/server/api-v1/product-writes.js +673 -0
- package/src/lib/server/api-v1/product-writes.js.map +1 -0
- package/src/lib/server/products-write.d.ts +94 -2
- package/src/lib/server/products-write.js +171 -112
- package/src/lib/server/products-write.js.map +1 -1
package/src/lib/contracts.d.ts
CHANGED
|
@@ -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). */
|
package/src/lib/contracts.js.map
CHANGED
|
@@ -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"}
|
|
@@ -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?:
|
|
60
|
-
variants:
|
|
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:
|
|
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?:
|
|
142
|
-
variants:
|
|
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?:
|
|
219
|
-
variants:
|
|
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,
|
|
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,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/product-write.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 {\n adjustVariantInventory,\n commerceSlug,\n type HostProduct,\n type InventoryAdjustment,\n type InventoryAdjustmentReason,\n productSearchFields,\n productStockFields,\n type SmartCollectionRules,\n variantHasPrice,\n} from './commerce'\n\n/*\n * WHAT A PRODUCT SAVE AND A STOCK ADJUSTMENT WRITE, worked out once.\n *\n * The console's product editor and its Adjust stock dialog compute these\n * fields in the browser before their Firestore writes; the native apps save\n * through `commerce/products/save` and `commerce/products/stock`, which run\n * this same code on the server. One computation, so a product saved from a\n * phone carries exactly the search keys, stock verdict, price, image and\n * smart-collection membership the console would have written.\n */\n\n/** A product as the editor holds it: the stored fields plus keys the listener or a seed may carry. */\nexport type EditedProduct = HostProduct & {\n $id?: string\n skus?: string[]\n barcodes?: string[]\n stockHolds?: Record<string, unknown>\n}\n\n/**\n * The fields a product save writes, before its collection membership and its\n * timestamps: the product as edited, with\n *\n * - `$id` dropped (AGL-1374): the listener's synthetic key, never a field;\n * - the seed's `skus` / `barcodes` dropped (AGL-3321): `productSearchFields`\n * omits each when no variant has one, so a seeded copy would outlive the\n * last SKU;\n * - the trimmed name with the search keys derived from it, together, so the\n * two cannot drift (AGL-2501);\n * - a slug, the primary variant's price, the stock fields, the first image\n * and `updatedAtMs`.\n */\nexport function productSaveFields(current: EditedProduct, nowMs: number) {\n const {\n $id: _syntheticId,\n skus: _seededSkus,\n barcodes: _seededBarcodes,\n // A sample the merchant saves is theirs now (AGL-4065).\n sample: _sample,\n ...currentFields\n } = current\n const primaryVariant = current.variants[0]\n return {\n ...currentFields,\n ...productSearchFields({\n name: current.name.trim().slice(0, 120),\n variants: current.variants,\n }),\n slug: current.slug || commerceSlug(current.name),\n // The legacy flat price, only where there is one (AGL-3676): an owner\n // may save a product before pricing it, and an unpriced product is not\n // a free one. `null` rather than absent, so an edit's full replace and\n // the native save write the same field.\n priceUsd: variantHasPrice(primaryVariant) ? primaryVariant.priceUsd : null,\n ...productStockFields({\n variants: current.variants,\n oversellPolicy: current.oversellPolicy,\n }),\n imageUrl: current.mediaUrls?.[0] ?? current.imageUrl ?? null,\n updatedAtMs: nowMs,\n }\n}\n\n/** What the smart-collection rules are matched against: the saved name with the product's own facts. */\nexport function productMembershipInput(\n fields: { name: string },\n current: Pick<HostProduct, 'type' | 'tags' | 'categoryIds' | 'variants'>,\n) {\n return {\n name: fields.name,\n type: current.type,\n tags: current.tags,\n categoryIds: current.categoryIds,\n variants: current.variants,\n }\n}\n\n/**\n * An EDIT's replacing write, without its membership and server timestamp:\n * live stock holds are not the editor's to write (AGL-2356), so the seed's\n * are dropped and the stored ones carried; the product stays live\n * (`deletedAt: null`, AGL-3321).\n */\nexport function productEditWrite(\n fields: ReturnType<typeof productSaveFields>,\n liveHolds: Record<string, unknown> | null | undefined,\n) {\n const { stockHolds: _seededHolds, ...withoutHolds } = fields as typeof fields & {\n stockHolds?: Record<string, unknown>\n }\n return {\n ...withoutHolds,\n ...(liveHolds ? { stockHolds: liveHolds } : {}),\n deletedAt: null,\n }\n}\n\n/** A duplicate's name: the source's, marked as a copy. */\nexport function productDuplicateName(name: string): string {\n return `${name} (copy)`\n}\n\n/** The slug a duplicate starts from, before the store is asked which are taken. */\nexport function productDuplicateSlugBase(slug: string | undefined, name: string): string {\n return commerceSlug(`${slug || commerceSlug(name)}-copy`)\n}\n\n/**\n * What Duplicate writes (the products list's Duplicate, AGL-3321): the source\n * as a draft under the copy's name, with the COPY's search keys (spreading the\n * source's would sort and find it by the source's name) and stock fields, and\n * not the source's SKU and barcode keys, which are derived again from its\n * variants. The caller adds the claimed `slug`'s smart-collection membership.\n */\nexport function productDuplicateFields(\n product: HostProduct & { $id?: string; skus?: string[]; barcodes?: string[] },\n slug: string,\n nowMs: number,\n) {\n const { $id: _sourceId, skus: _skus, barcodes: _barcodes, ...copy } = product\n return {\n ...copy,\n ...productSearchFields({ name: productDuplicateName(product.name), variants: product.variants }),\n ...productStockFields(product),\n slug,\n status: 'draft' as const,\n createdAtMs: nowMs,\n updatedAtMs: nowMs,\n }\n}\n\n/** A smart collection as `hosts/{hostId}/collections` stores it, as the membership rules read it. */\nexport function smartCollectionRulesOf(id: string, data: Record<string, unknown>): SmartCollectionRules {\n return {\n id,\n rules: (data['rules'] as SmartCollectionRules['rules']) ?? [],\n matchAll: data['matchAll'] as boolean | undefined,\n }\n}\n\n/** One stock adjustment, as the Adjust stock dialog asks for it. */\nexport interface StockAdjustment {\n variantId: string\n delta: number\n reason: InventoryAdjustmentReason\n locationId?: string\n}\n\n/**\n * The product update and the ledger row one stock adjustment writes: the\n * variants with the count moved, the stock fields that move with it\n * (AGL-3321), and the same `inventoryAdjustments` row the sale webhook writes\n * (AGL-281). A zero or non-numeric delta writes nothing.\n */\nexport function stockAdjustmentWrite(\n product: HostProduct,\n productId: string,\n adjustment: StockAdjustment,\n nowMs: number,\n): { update: Record<string, unknown>; ledger: InventoryAdjustment } | null {\n const delta = Math.round(Number(adjustment.delta))\n if (!delta) return null\n const variants = adjustVariantInventory(product, adjustment.variantId, delta, adjustment.locationId || undefined)\n return {\n update: {\n variants,\n ...productStockFields({ ...product, variants }),\n updatedAtMs: nowMs,\n },\n ledger: {\n productId,\n variantId: adjustment.variantId,\n delta,\n reason: adjustment.reason,\n ...(adjustment.locationId ? { locationId: adjustment.locationId } : {}),\n atMs: nowMs,\n },\n }\n}\n"],"names":["adjustVariantInventory","commerceSlug","productSearchFields","productStockFields","variantHasPrice","productSaveFields","current","nowMs","$id","_syntheticId","skus","_seededSkus","barcodes","_seededBarcodes","sample","_sample","currentFields","primaryVariant","variants","name","trim","slice","slug","priceUsd","oversellPolicy","imageUrl","mediaUrls","updatedAtMs","productMembershipInput","fields","type","tags","categoryIds","productEditWrite","liveHolds","stockHolds","_seededHolds","withoutHolds","deletedAt","productDuplicateName","productDuplicateSlugBase","productDuplicateFields","product","_sourceId","_skus","_barcodes","copy","status","createdAtMs","smartCollectionRulesOf","id","data","rules","matchAll","stockAdjustmentWrite","productId","adjustment","delta","Math","round","Number","variantId","locationId","undefined","update","ledger","reason","atMs"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,sBAAsB,EACtBC,YAAY,EAIZC,mBAAmB,EACnBC,kBAAkB,EAElBC,eAAe,QACV,gBAAY;AAqBnB;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,kBAAkBC,OAAsB,EAAEC,KAAa;QA0BzDD;QAAAA;IAzBZ,MAAM,EACJE,KAAKC,YAAY,EACjBC,MAAMC,WAAW,EACjBC,UAAUC,eAAe,EACzB,wDAAwD;IACxDC,QAAQC,OAAO,EAEhB,GAAGT,SADCU,iDACDV;;;;;;IACJ,MAAMW,iBAAiBX,QAAQY,QAAQ,CAAC,EAAE;IAC1C,OAAO,aACFF,eACAd,oBAAoB;QACrBiB,MAAMb,QAAQa,IAAI,CAACC,IAAI,GAAGC,KAAK,CAAC,GAAG;QACnCH,UAAUZ,QAAQY,QAAQ;IAC5B;QACAI,MAAMhB,QAAQgB,IAAI,IAAIrB,aAAaK,QAAQa,IAAI;QAC/C,sEAAsE;QACtE,uEAAuE;QACvE,uEAAuE;QACvE,wCAAwC;QACxCI,UAAUnB,gBAAgBa,kBAAkBA,eAAeM,QAAQ,GAAG;OACnEpB,mBAAmB;QACpBe,UAAUZ,QAAQY,QAAQ;QAC1BM,gBAAgBlB,QAAQkB,cAAc;IACxC;QACAC,QAAQ,GAAEnB,iBAAAA,qBAAAA,QAAQoB,SAAS,qBAAjBpB,kBAAmB,CAAC,EAAE,oBAAIA,QAAQmB,QAAQ,YAA1CnB,OAA8C;QACxDqB,aAAapB;;AAEjB;AAEA,sGAAsG,GACtG,OAAO,SAASqB,uBACdC,MAAwB,EACxBvB,OAAwE;IAExE,OAAO;QACLa,MAAMU,OAAOV,IAAI;QACjBW,MAAMxB,QAAQwB,IAAI;QAClBC,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AMkD,QAAQC,KAAKC,KAAK,CAACC,OAAOJ,WAAWC,KAAK;IAChD,IAAI,CAACA,OAAO,OAAO;IACnB,MAAMvC,WAAWlB,uBAAuB0C,SAASc,WAAWK,SAAS,EAAEJ,OAAOD,WAAWM,UAAU,IAAIC;IACvG,OAAO;QACLC,QAAQ;YACN9C;WACGf,mBAAmB,aAAKuC;YAASxB;;YACpCS,aAAapB;;QAEf0D,QAAQ;YACNV;YACAM,WAAWL,WAAWK,SAAS;YAC/BJ;YACAS,QAAQV,WAAWU,MAAM;WACrBV,WAAWM,UAAU,GAAG;YAAEA,YAAYN,WAAWM,UAAU;QAAC,IAAI,CAAC;YACrEK,MAAM5D;;IAEV;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/commerce/src/lib/model/product-write.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 {\n adjustVariantInventory,\n COMMERCE_DEFAULT_PRICE_USD,\n commerceSlug,\n expandVariantMatrix,\n type HostProduct,\n type ProductOption,\n type ProductVariant,\n type InventoryAdjustment,\n type InventoryAdjustmentReason,\n productSearchFields,\n productStockFields,\n type SmartCollectionRules,\n variantHasPrice,\n} from './commerce'\n\n/*\n * WHAT A PRODUCT SAVE AND A STOCK ADJUSTMENT WRITE, worked out once.\n *\n * The console's product editor and its Adjust stock dialog compute these\n * fields in the browser before their Firestore writes; the native apps save\n * through `commerce/products/save` and `commerce/products/stock`, which run\n * this same code on the server. One computation, so a product saved from a\n * phone carries exactly the search keys, stock verdict, price, image and\n * smart-collection membership the console would have written.\n */\n\n/** The longest product name a save keeps: {@link productSaveFields} cuts a longer one here. */\nexport const PRODUCT_NAME_MAX_LENGTH = 120\n\n/** A product as the editor holds it: the stored fields plus keys the listener or a seed may carry. */\nexport type EditedProduct = HostProduct & {\n $id?: string\n skus?: string[]\n barcodes?: string[]\n stockHolds?: Record<string, unknown>\n}\n\n/**\n * The fields a product save writes, before its collection membership and its\n * timestamps: the product as edited, with\n *\n * - `$id` dropped (AGL-1374): the listener's synthetic key, never a field;\n * - the seed's `skus` / `barcodes` dropped (AGL-3321): `productSearchFields`\n * omits each when no variant has one, so a seeded copy would outlive the\n * last SKU;\n * - the trimmed name with the search keys derived from it, together, so the\n * two cannot drift (AGL-2501);\n * - a slug, the primary variant's price, the stock fields, the first image\n * and `updatedAtMs`.\n */\nexport function productSaveFields(current: EditedProduct, nowMs: number) {\n const {\n $id: _syntheticId,\n skus: _seededSkus,\n barcodes: _seededBarcodes,\n // A sample the merchant saves is theirs now (AGL-4065).\n sample: _sample,\n ...currentFields\n } = current\n const primaryVariant = current.variants[0]\n return {\n ...currentFields,\n ...productSearchFields({\n name: current.name.trim().slice(0, PRODUCT_NAME_MAX_LENGTH),\n variants: current.variants,\n }),\n slug: current.slug || commerceSlug(current.name),\n // The legacy flat price, only where there is one (AGL-3676): an owner\n // may save a product before pricing it, and an unpriced product is not\n // a free one. `null` rather than absent, so an edit's full replace and\n // the native save write the same field.\n priceUsd: variantHasPrice(primaryVariant) ? primaryVariant.priceUsd : null,\n ...productStockFields({\n variants: current.variants,\n oversellPolicy: current.oversellPolicy,\n }),\n imageUrl: current.mediaUrls?.[0] ?? current.imageUrl ?? null,\n updatedAtMs: nowMs,\n }\n}\n\n/**\n * A product nobody has saved yet, as the editor starts one: a draft, at the\n * default price (AGL-3676), for the owner to change or clear.\n */\nexport function blankProductDraft(): HostProduct {\n return {\n name: '',\n slug: '',\n type: 'physical',\n status: 'draft',\n variants: [{ id: 'default', priceUsd: COMMERCE_DEFAULT_PRICE_USD }],\n }\n}\n\n/** Stable key for matching variants across matrix regenerations. */\nexport function variantComboKey(options: Record<string, string> | undefined): string {\n return Object.entries(options ?? {})\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([name, value]) => `${name}:${value}`)\n .join('|')\n}\n\n/**\n * The variants a change of option VALUES makes, as the editor rebuilds them:\n * one per combination of `options`, each an existing variant with the same\n * selections where there is one (so its id, price, SKU and stock survive the\n * change), and otherwise a new variant at the first variant's price (none\n * where it has none, the default on a product with no variant yet) and stock.\n *\n * Ask {@link variantMatrixProblem} first: past the ceiling the editor keeps\n * the variants as they are and refuses the save (AGL-4100). A rename is not\n * a change of values; it goes through `renameProductOptions` (AGL-3066).\n */\nexport function variantsForOptions(\n at: Pick<HostProduct, 'variants'>,\n options: ProductOption[],\n nowMs: number,\n): ProductVariant[] {\n const previous = new Map(at.variants.map((variant) => [variantComboKey(variant.options), variant]))\n const fallback = at.variants[0]\n return expandVariantMatrix(options).map(\n (combo, comboIndex) =>\n previous.get(variantComboKey(combo)) ??\n // An unpriced variant is stored with no `priceUsd` (AGL-3676), as a\n // proposed product's are; the type names the priced shape.\n ({\n id: `v${nowMs.toString(36)}${comboIndex}`,\n options: combo,\n ...(fallback\n ? variantHasPrice(fallback)\n ? { priceUsd: fallback.priceUsd }\n : {}\n : { priceUsd: COMMERCE_DEFAULT_PRICE_USD }),\n inventory: fallback?.inventory ?? null,\n } as ProductVariant),\n )\n}\n\n/** What the smart-collection rules are matched against: the saved name with the product's own facts. */\nexport function productMembershipInput(\n fields: { name: string },\n current: Pick<HostProduct, 'type' | 'tags' | 'categoryIds' | 'variants'>,\n) {\n return {\n name: fields.name,\n type: current.type,\n tags: current.tags,\n categoryIds: current.categoryIds,\n variants: current.variants,\n }\n}\n\n/**\n * An EDIT's replacing write, without its membership and server timestamp:\n * live stock holds are not the editor's to write (AGL-2356), so the seed's\n * are dropped and the stored ones carried; the product stays live\n * (`deletedAt: null`, AGL-3321).\n */\nexport function productEditWrite(\n fields: ReturnType<typeof productSaveFields>,\n liveHolds: Record<string, unknown> | null | undefined,\n) {\n const { stockHolds: _seededHolds, ...withoutHolds } = fields as typeof fields & {\n stockHolds?: Record<string, unknown>\n }\n return {\n ...withoutHolds,\n ...(liveHolds ? { stockHolds: liveHolds } : {}),\n deletedAt: null,\n }\n}\n\n/** A duplicate's name: the source's, marked as a copy. */\nexport function productDuplicateName(name: string): string {\n return `${name} (copy)`\n}\n\n/** The slug a duplicate starts from, before the store is asked which are taken. */\nexport function productDuplicateSlugBase(slug: string | undefined, name: string): string {\n return commerceSlug(`${slug || commerceSlug(name)}-copy`)\n}\n\n/**\n * What Duplicate writes (the products list's Duplicate, AGL-3321): the source\n * as a draft under the copy's name, with the COPY's search keys (spreading the\n * source's would sort and find it by the source's name) and stock fields, and\n * not the source's SKU and barcode keys, which are derived again from its\n * variants. The caller adds the claimed `slug`'s smart-collection membership.\n */\nexport function productDuplicateFields(\n product: HostProduct & { $id?: string; skus?: string[]; barcodes?: string[] },\n slug: string,\n nowMs: number,\n) {\n const { $id: _sourceId, skus: _skus, barcodes: _barcodes, ...copy } = product\n return {\n ...copy,\n ...productSearchFields({ name: productDuplicateName(product.name), variants: product.variants }),\n ...productStockFields(product),\n slug,\n status: 'draft' as const,\n createdAtMs: nowMs,\n updatedAtMs: nowMs,\n }\n}\n\n/** A smart collection as `hosts/{hostId}/collections` stores it, as the membership rules read it. */\nexport function smartCollectionRulesOf(id: string, data: Record<string, unknown>): SmartCollectionRules {\n return {\n id,\n rules: (data['rules'] as SmartCollectionRules['rules']) ?? [],\n matchAll: data['matchAll'] as boolean | undefined,\n }\n}\n\n/** One stock adjustment, as the Adjust stock dialog asks for it. */\nexport interface StockAdjustment {\n variantId: string\n delta: number\n reason: InventoryAdjustmentReason\n locationId?: string\n}\n\n/**\n * The product update and the ledger row one stock adjustment writes: the\n * variants with the count moved, the stock fields that move with it\n * (AGL-3321), and the same `inventoryAdjustments` row the sale webhook writes\n * (AGL-281). A zero or non-numeric delta writes nothing.\n */\nexport function stockAdjustmentWrite(\n product: HostProduct,\n productId: string,\n adjustment: StockAdjustment,\n nowMs: number,\n): { update: Record<string, unknown>; ledger: InventoryAdjustment } | null {\n const delta = Math.round(Number(adjustment.delta))\n if (!delta) return null\n const variants = adjustVariantInventory(product, adjustment.variantId, delta, adjustment.locationId || undefined)\n return {\n update: {\n variants,\n ...productStockFields({ ...product, variants }),\n updatedAtMs: nowMs,\n },\n ledger: {\n productId,\n variantId: adjustment.variantId,\n delta,\n reason: adjustment.reason,\n ...(adjustment.locationId ? { locationId: adjustment.locationId } : {}),\n atMs: nowMs,\n },\n }\n}\n"],"names":["adjustVariantInventory","COMMERCE_DEFAULT_PRICE_USD","commerceSlug","expandVariantMatrix","productSearchFields","productStockFields","variantHasPrice","PRODUCT_NAME_MAX_LENGTH","productSaveFields","current","nowMs","$id","_syntheticId","skus","_seededSkus","barcodes","_seededBarcodes","sample","_sample","currentFields","primaryVariant","variants","name","trim","slice","slug","priceUsd","oversellPolicy","imageUrl","mediaUrls","updatedAtMs","blankProductDraft","type","status","id","variantComboKey","options","Object","entries","sort","a","b","localeCompare","map","value","join","variantsForOptions","at","previous","Map","variant","fallback","combo","comboIndex","get","toString","inventory","productMembershipInput","fields","tags","categoryIds","productEditWrite","liveHolds","stockHolds","_seededHolds","withoutHolds","deletedAt","productDuplicateName","productDuplicateSlugBase","productDuplicateFields","product","_sourceId","_skus","_barcodes","copy","createdAtMs","smartCollectionRulesOf","data","rules","matchAll","stockAdjustmentWrite","productId","adjustment","delta","Math","round","Number","variantId","locationId","undefined","update","ledger","reason","atMs"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,SACEA,sBAAsB,EACtBC,0BAA0B,EAC1BC,YAAY,EACZC,mBAAmB,EAMnBC,mBAAmB,EACnBC,kBAAkB,EAElBC,eAAe,QACV,gBAAY;AAEnB;;;;;;;;;CASC,GAED,6FAA6F,GAC7F,OAAO,MAAMC,0BAA0B,IAAG;AAU1C;;;;;;;;;;;;CAYC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WM,UAAU;QAAC,IAAI,CAAC;YACrEK,MAAMnF;;IAEV;AACF"}
|
package/src/lib/native-nav.js
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
order: 10,
|
|
35
35
|
sections: [
|
|
36
36
|
nativeNavHubSection('host', '/products', 'orders', 'Orders', 'commerce.orders'),
|
|
37
|
+
nativeNavHubSection('host', '/products', 'subscriptions', 'Subscriptions', 'commerce.subscriptions'),
|
|
37
38
|
nativeNavHubSection('host', '/products', 'returns', 'Returns', 'commerce.returns'),
|
|
38
39
|
nativeNavHubSection('host', '/products', 'reservations', 'Reservations', 'commerce.reservations')
|
|
39
40
|
],
|
|
@@ -59,7 +60,17 @@
|
|
|
59
60
|
sections: [
|
|
60
61
|
nativeNavHubSection('host', '/products', 'catalog', 'Catalog', 'commerce.products'),
|
|
61
62
|
nativeNavHubSection('host', '/products', 'promotions', 'Promotions', 'commerce.promotions'),
|
|
62
|
-
nativeNavHubSection('host', '/products', 'analytics', 'Analytics', 'commerce.sales')
|
|
63
|
+
nativeNavHubSection('host', '/products', 'analytics', 'Analytics', 'commerce.sales'),
|
|
64
|
+
// The console's Settings group (`COMMERCE_CONSOLE_SECTIONS`): each page's own
|
|
65
|
+
// settings, then the zone where other plugins' cards for that page land.
|
|
66
|
+
// Point of sale waits for its registers and hardware screens.
|
|
67
|
+
nativeNavHubSection('host', '/products', 'payments', 'Payments', 'commerce.settingsPayments'),
|
|
68
|
+
nativeNavHubSection('host', '/products', 'checkout', 'Checkout', 'commerce.settingsCheckout'),
|
|
69
|
+
nativeNavHubSection('host', '/products', 'taxes', 'Taxes', 'commerce.settingsTaxes'),
|
|
70
|
+
nativeNavHubSection('host', '/products', 'shipping', 'Shipping & delivery', 'commerce.settingsShipping'),
|
|
71
|
+
nativeNavHubSection('host', '/products', 'notifications', 'Notifications', 'commerce.settingsNotifications'),
|
|
72
|
+
nativeNavHubSection('host', '/products', 'channels', 'Sales channels', 'commerce.settingsChannels'),
|
|
73
|
+
nativeNavHubSection('host', '/products', 'integrations', 'Integrations', 'commerce.settings')
|
|
63
74
|
],
|
|
64
75
|
actions: [
|
|
65
76
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/plugins/commerce/src/lib/native-nav.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 {\n type NativeNavContribution,\n type NativeNavCreateContribution,\n type NativeNavElsewhere,\n nativeNavHubSection,\n nativeNavIcon,\n nativeNavRef,\n} from '@aglyn/aglyn/app-utils/native-nav'\n\n/**\n * Orders and Products in the native apps' navigation (AGL-3943): the rows this plugin\n * adds to the manifest the shells draw, placed into the core's lists by\n * `order` (`assembleNativeNav`, `generate:native-contracts`). Labels are the\n * console's words, held by `apps/console/specs/native-nav-manifest.spec.ts`.\n *\n * Imports only the core's plain nav module, so the native contracts read it.\n */\n\nexport const NATIVE_NAV_ROWS: readonly NativeNavContribution[] = [\n {\n list: 'site',\n group: 'sell',\n row: {\n id: 'orders',\n label: 'Orders',\n icon: nativeNavIcon('bag', 'shopping_bag'),\n screen: 'commerce.orders',\n pluginId: 'commerce',\n order: 10,\n sections: [\n nativeNavHubSection('host', '/products', 'orders', 'Orders', 'commerce.orders'),\n nativeNavHubSection('host', '/products', 'returns', 'Returns', 'commerce.returns'),\n nativeNavHubSection('host', '/products', 'reservations', 'Reservations', 'commerce.reservations'),\n ],\n docs: '/commerce-and-bookings/commerce/overview',\n console: nativeNavRef('hostPluginSection', '/products/orders'),\n },\n },\n {\n list: 'site',\n group: 'sell',\n row: {\n id: 'products',\n label: 'Products',\n icon: nativeNavIcon('tag', 'sell'),\n screen: 'commerce.products',\n pluginId: 'commerce',\n order: 20,\n keywords: ['catalog', 'stock', 'inventory'],\n sections: [\n nativeNavHubSection('host', '/products', 'catalog', 'Catalog', 'commerce.products'),\n nativeNavHubSection('host', '/products', 'promotions', 'Promotions', 'commerce.promotions'),\n nativeNavHubSection('host', '/products', 'analytics', 'Analytics', 'commerce.sales'),\n ],\n actions: [\n {\n id: 'scan',\n label: 'Scan stock',\n icon: nativeNavIcon('barcode.viewfinder', 'qr_code_scanner'),\n screen: 'commerce.scan',\n },\n {\n id: 'newProduct',\n label: 'New product',\n icon: nativeNavIcon('plus', 'add'),\n screen: 'commerce.product',\n params: { new: '1' },\n },\n ],\n docs: '/commerce-and-bookings/commerce/overview',\n console: nativeNavRef('hostPluginTab', '/products'),\n },\n },\n]\n\n/** The console's POS tab is the register app's, not a row of this one. */\nexport const NATIVE_NAV_ELSEWHERE: readonly NativeNavElsewhere[] = [\n { console: nativeNavRef('hostPluginTab', '/pos'), where: 'The POS app' },\n]\n\n/** A product (\"Add product\" on Catalog) and a draft order (\"Draft order\" on Orders). */\nexport const NATIVE_NAV_CREATE: readonly NativeNavCreateContribution[] = [\n {\n scope: 'site',\n item: {\n id: 'product',\n label: 'Product',\n icon: nativeNavIcon('tag', 'sell'),\n screen: 'commerce.product',\n params: { new: '1' },\n pluginId: 'commerce',\n planFeature: 'commerce',\n order: 20,\n console: nativeNavRef('hostPluginSection', '/products/catalog'),\n },\n },\n {\n scope: 'site',\n item: {\n id: 'draftOrder',\n label: 'Draft order',\n icon: nativeNavIcon('link.badge.plus', 'link'),\n screen: 'commerce.orders',\n params: { new: '1' },\n pluginId: 'commerce',\n planFeature: 'commerce',\n order: 30,\n console: nativeNavRef('hostPluginSection', '/products/orders'),\n },\n },\n]\n"],"names":["nativeNavHubSection","nativeNavIcon","nativeNavRef","NATIVE_NAV_ROWS","list","group","row","id","label","icon","screen","pluginId","order","sections","docs","console","keywords","actions","params","new","NATIVE_NAV_ELSEWHERE","where","NATIVE_NAV_CREATE","scope","item","planFeature"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAIEA,mBAAmB,EACnBC,aAAa,EACbC,YAAY,QACP,oCAAmC;AAE1C;;;;;;;CAOC,GAED,OAAO,MAAMC,kBAAoD;IAC/D;QACEC,MAAM;QACNC,OAAO;QACPC,KAAK;YACHC,IAAI;YACJC,OAAO;YACPC,MAAMR,cAAc,OAAO;YAC3BS,QAAQ;YACRC,UAAU;YACVC,OAAO;YACPC,UAAU;gBACRb,oBAAoB,QAAQ,aAAa,UAAU,UAAU;gBAC7DA,oBAAoB,QAAQ,aAAa,WAAW,WAAW;gBAC/DA,oBAAoB,QAAQ,aAAa,gBAAgB,gBAAgB;aAC1E;YACDc,MAAM;YACNC,SAASb,aAAa,qBAAqB;QAC7C;IACF;IACA;QACEE,MAAM;QACNC,OAAO;QACPC,KAAK;YACHC,IAAI;YACJC,OAAO;YACPC,MAAMR,cAAc,OAAO;YAC3BS,QAAQ;YACRC,UAAU;YACVC,OAAO;YACPI,UAAU;gBAAC;gBAAW;gBAAS;aAAY;YAC3CH,UAAU;gBACRb,oBAAoB,QAAQ,aAAa,WAAW,WAAW;gBAC/DA,oBAAoB,QAAQ,aAAa,cAAc,cAAc;gBACrEA,oBAAoB,QAAQ,aAAa,aAAa,aAAa;
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/plugins/commerce/src/lib/native-nav.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 {\n type NativeNavContribution,\n type NativeNavCreateContribution,\n type NativeNavElsewhere,\n nativeNavHubSection,\n nativeNavIcon,\n nativeNavRef,\n} from '@aglyn/aglyn/app-utils/native-nav'\n\n/**\n * Orders and Products in the native apps' navigation (AGL-3943): the rows this plugin\n * adds to the manifest the shells draw, placed into the core's lists by\n * `order` (`assembleNativeNav`, `generate:native-contracts`). Labels are the\n * console's words, held by `apps/console/specs/native-nav-manifest.spec.ts`.\n *\n * Imports only the core's plain nav module, so the native contracts read it.\n */\n\nexport const NATIVE_NAV_ROWS: readonly NativeNavContribution[] = [\n {\n list: 'site',\n group: 'sell',\n row: {\n id: 'orders',\n label: 'Orders',\n icon: nativeNavIcon('bag', 'shopping_bag'),\n screen: 'commerce.orders',\n pluginId: 'commerce',\n order: 10,\n sections: [\n nativeNavHubSection('host', '/products', 'orders', 'Orders', 'commerce.orders'),\n nativeNavHubSection('host', '/products', 'subscriptions', 'Subscriptions', 'commerce.subscriptions'),\n nativeNavHubSection('host', '/products', 'returns', 'Returns', 'commerce.returns'),\n nativeNavHubSection('host', '/products', 'reservations', 'Reservations', 'commerce.reservations'),\n ],\n docs: '/commerce-and-bookings/commerce/overview',\n console: nativeNavRef('hostPluginSection', '/products/orders'),\n },\n },\n {\n list: 'site',\n group: 'sell',\n row: {\n id: 'products',\n label: 'Products',\n icon: nativeNavIcon('tag', 'sell'),\n screen: 'commerce.products',\n pluginId: 'commerce',\n order: 20,\n keywords: ['catalog', 'stock', 'inventory'],\n sections: [\n nativeNavHubSection('host', '/products', 'catalog', 'Catalog', 'commerce.products'),\n nativeNavHubSection('host', '/products', 'promotions', 'Promotions', 'commerce.promotions'),\n nativeNavHubSection('host', '/products', 'analytics', 'Analytics', 'commerce.sales'),\n // The console's Settings group (`COMMERCE_CONSOLE_SECTIONS`): each page's own\n // settings, then the zone where other plugins' cards for that page land.\n // Point of sale waits for its registers and hardware screens.\n nativeNavHubSection('host', '/products', 'payments', 'Payments', 'commerce.settingsPayments'),\n nativeNavHubSection('host', '/products', 'checkout', 'Checkout', 'commerce.settingsCheckout'),\n nativeNavHubSection('host', '/products', 'taxes', 'Taxes', 'commerce.settingsTaxes'),\n nativeNavHubSection('host', '/products', 'shipping', 'Shipping & delivery', 'commerce.settingsShipping'),\n nativeNavHubSection('host', '/products', 'notifications', 'Notifications', 'commerce.settingsNotifications'),\n nativeNavHubSection('host', '/products', 'channels', 'Sales channels', 'commerce.settingsChannels'),\n nativeNavHubSection('host', '/products', 'integrations', 'Integrations', 'commerce.settings'),\n ],\n actions: [\n {\n id: 'scan',\n label: 'Scan stock',\n icon: nativeNavIcon('barcode.viewfinder', 'qr_code_scanner'),\n screen: 'commerce.scan',\n },\n {\n id: 'newProduct',\n label: 'New product',\n icon: nativeNavIcon('plus', 'add'),\n screen: 'commerce.product',\n params: { new: '1' },\n },\n ],\n docs: '/commerce-and-bookings/commerce/overview',\n console: nativeNavRef('hostPluginTab', '/products'),\n },\n },\n]\n\n/** The console's POS tab is the register app's, not a row of this one. */\nexport const NATIVE_NAV_ELSEWHERE: readonly NativeNavElsewhere[] = [\n { console: nativeNavRef('hostPluginTab', '/pos'), where: 'The POS app' },\n]\n\n/** A product (\"Add product\" on Catalog) and a draft order (\"Draft order\" on Orders). */\nexport const NATIVE_NAV_CREATE: readonly NativeNavCreateContribution[] = [\n {\n scope: 'site',\n item: {\n id: 'product',\n label: 'Product',\n icon: nativeNavIcon('tag', 'sell'),\n screen: 'commerce.product',\n params: { new: '1' },\n pluginId: 'commerce',\n planFeature: 'commerce',\n order: 20,\n console: nativeNavRef('hostPluginSection', '/products/catalog'),\n },\n },\n {\n scope: 'site',\n item: {\n id: 'draftOrder',\n label: 'Draft order',\n icon: nativeNavIcon('link.badge.plus', 'link'),\n screen: 'commerce.orders',\n params: { new: '1' },\n pluginId: 'commerce',\n planFeature: 'commerce',\n order: 30,\n console: nativeNavRef('hostPluginSection', '/products/orders'),\n },\n },\n]\n"],"names":["nativeNavHubSection","nativeNavIcon","nativeNavRef","NATIVE_NAV_ROWS","list","group","row","id","label","icon","screen","pluginId","order","sections","docs","console","keywords","actions","params","new","NATIVE_NAV_ELSEWHERE","where","NATIVE_NAV_CREATE","scope","item","planFeature"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAIEA,mBAAmB,EACnBC,aAAa,EACbC,YAAY,QACP,oCAAmC;AAE1C;;;;;;;CAOC,GAED,OAAO,MAAMC,kBAAoD;IAC/D;QACEC,MAAM;QACNC,OAAO;QACPC,KAAK;YACHC,IAAI;YACJC,OAAO;YACPC,MAAMR,cAAc,OAAO;YAC3BS,QAAQ;YACRC,UAAU;YACVC,OAAO;YACPC,UAAU;gBACRb,oBAAoB,QAAQ,aAAa,UAAU,UAAU;gBAC7DA,oBAAoB,QAAQ,aAAa,iBAAiB,iBAAiB;gBAC3EA,oBAAoB,QAAQ,aAAa,WAAW,WAAW;gBAC/DA,oBAAoB,QAAQ,aAAa,gBAAgB,gBAAgB;aAC1E;YACDc,MAAM;YACNC,SAASb,aAAa,qBAAqB;QAC7C;IACF;IACA;QACEE,MAAM;QACNC,OAAO;QACPC,KAAK;YACHC,IAAI;YACJC,OAAO;YACPC,MAAMR,cAAc,OAAO;YAC3BS,QAAQ;YACRC,UAAU;YACVC,OAAO;YACPI,UAAU;gBAAC;gBAAW;gBAAS;aAAY;YAC3CH,UAAU;gBACRb,oBAAoB,QAAQ,aAAa,WAAW,WAAW;gBAC/DA,oBAAoB,QAAQ,aAAa,cAAc,cAAc;gBACrEA,oBAAoB,QAAQ,aAAa,aAAa,aAAa;gBACnE,8EAA8E;gBAC9E,yEAAyE;gBACzE,8DAA8D;gBAC9DA,oBAAoB,QAAQ,aAAa,YAAY,YAAY;gBACjEA,oBAAoB,QAAQ,aAAa,YAAY,YAAY;gBACjEA,oBAAoB,QAAQ,aAAa,SAAS,SAAS;gBAC3DA,oBAAoB,QAAQ,aAAa,YAAY,uBAAuB;gBAC5EA,oBAAoB,QAAQ,aAAa,iBAAiB,iBAAiB;gBAC3EA,oBAAoB,QAAQ,aAAa,YAAY,kBAAkB;gBACvEA,oBAAoB,QAAQ,aAAa,gBAAgB,gBAAgB;aAC1E;YACDiB,SAAS;gBACP;oBACEV,IAAI;oBACJC,OAAO;oBACPC,MAAMR,cAAc,sBAAsB;oBAC1CS,QAAQ;gBACV;gBACA;oBACEH,IAAI;oBACJC,OAAO;oBACPC,MAAMR,cAAc,QAAQ;oBAC5BS,QAAQ;oBACRQ,QAAQ;wBAAEC,KAAK;oBAAI;gBACrB;aACD;YACDL,MAAM;YACNC,SAASb,aAAa,iBAAiB;QACzC;IACF;CACD,CAAA;AAED,wEAAwE,GACxE,OAAO,MAAMkB,uBAAsD;IACjE;QAAEL,SAASb,aAAa,iBAAiB;QAASmB,OAAO;IAAc;CACxE,CAAA;AAED,sFAAsF,GACtF,OAAO,MAAMC,oBAA4D;IACvE;QACEC,OAAO;QACPC,MAAM;YACJjB,IAAI;YACJC,OAAO;YACPC,MAAMR,cAAc,OAAO;YAC3BS,QAAQ;YACRQ,QAAQ;gBAAEC,KAAK;YAAI;YACnBR,UAAU;YACVc,aAAa;YACbb,OAAO;YACPG,SAASb,aAAa,qBAAqB;QAC7C;IACF;IACA;QACEqB,OAAO;QACPC,MAAM;YACJjB,IAAI;YACJC,OAAO;YACPC,MAAMR,cAAc,mBAAmB;YACvCS,QAAQ;YACRQ,QAAQ;gBAAEC,KAAK;YAAI;YACnBR,UAAU;YACVc,aAAa;YACbb,OAAO;YACPG,SAASb,aAAa,qBAAqB;QAC7C;IACF;CACD,CAAA"}
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { type ApiV1ResourceDescription } from '@aglyn/tenant-data-admin/server/api-v1-description';
|
|
18
18
|
/**
|
|
19
|
-
* A site's products
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* `api-v1-openapi.spec.ts` holds the
|
|
24
|
-
* documentation promises.
|
|
19
|
+
* A site's products, as the customer API's OpenAPI document describes them —
|
|
20
|
+
* what the console's builder turns into paths, tags and schemas, and the MCP
|
|
21
|
+
* tools derive from. The writes (AGL-4235) are the console editor's: the
|
|
22
|
+
* members `handleProducts` accepts are exactly `writable` and the
|
|
23
|
+
* `ProductVariantWrite` schema, and `api-v1-openapi.spec.ts` holds the
|
|
24
|
+
* document to every endpoint the documentation promises.
|
|
25
25
|
*/
|
|
26
26
|
export declare const PRODUCTS_API_V1_DESCRIPTION: ApiV1ResourceDescription;
|
|
27
27
|
export declare const ORDERS_API_V1_DESCRIPTION: ApiV1ResourceDescription;
|