Component evidence

Spree Multi-Seller Order Group Type Guard (src/order-group.ts)

spree · packages/admin-sdk/src/order-group.ts · typescript · BSD-3-Clause
paymentsintegrationlang:typescripttag:spree

Type guard function to distinguish between a single multi-seller order group and a regular order payload in Spree.

Source preview public preview
// Source: https://github.com/spree/spree | License: BSD-3-Clause | Copyright 2024-present, Vendo Sp. z o.o., Vendo Connect Inc
// Provided via justclaw.it.com; keep this notice with the code.
import type Order from './types/generated/Order'
import type OrderGroup from './types/generated/OrderGroup'

/**
 * Whether a completion answered with the group a multi-seller order divided
 * into, rather than with one order.
 *
 * Keyed on `seller_count`, which only the group carries — the payload has no
 * type discriminator of its own.
 */
export function isOrderGroup(result: Order | OrderGroup): result is OrderGroup {
  return 'seller_count' in result
}