@asstio-dev/storefront 0.17.0 → 0.18.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/README.md CHANGED
@@ -251,10 +251,13 @@ Cards and cart lines carry the product facts the product page has: `brand`, `cat
251
251
  shape without `shortDescription` (`productFacts(orderLine).shortDescription` is `null`): its facts are the ones the
252
252
  charged checkout snapshot captured, never re-resolved — `url`, `facet` and attribute `facetKey`/`valueKeys` are `null`
253
253
  there, the blocks are empty on orders placed before they existed, and `null` on fee, shipping and adjustment lines.
254
- `productFacts()` reads them from any source:
254
+ A checkout cart line (`checkout.cart.lines[]`) has the order-line shape too, but is resolved **live while the attempt is
255
+ `open`**, like a cart line, with `url`, `facet` and attribute keys filled in. In every other status, and for a line the
256
+ catalogue can no longer describe, it carries the snapshot's frozen facts (links `null`). What it shows may therefore
257
+ differ from what the order later freezes. `productFacts()` reads them from any source:
255
258
 
256
259
  ```ts
257
- const facts = productFacts(line); // card, product, { product, variant }, cart line or product order line
260
+ const facts = productFacts(line); // card, product, { product, variant }, cart line, checkout cart line or product order line
258
261
  render(facts.brand?.label); // the item's brand: the variant's own, never a fallback to the family's
259
262
  render(facts.productBrand?.label); // the family brand
260
263
  ```
@@ -263,7 +266,8 @@ render(facts.productBrand?.label); // the family brand
263
266
  fall back to `productBrand`. **Categories carry no primary meaning**: `categories[0]` may be a gender, a brand or a
264
267
  product-type node. Pick the one you want by its root.
265
268
 
266
- `toGa4Item()` and `toGa4Ecommerce()` map the same sources to GA4 ecommerce data. They are pure: they send nothing and
269
+ `toGa4Item()` and `toGa4Ecommerce()` map the same sources to GA4 ecommerce data; `toGa4Ecommerce(checkout.cart)` is the
270
+ `begin_checkout` payload. They are pure: they send nothing and
267
271
  know nothing about consent or a data layer.
268
272
 
269
273
  | Source | `item_id` | `item_brand` | `price` | `quantity` | `item_variant` |
@@ -271,6 +275,7 @@ know nothing about consent or a data layer.
271
275
  | card (impression) | the family `sku` | `brand.label` | from-price | 1 | — |
272
276
  | `{ product, variant }` | the variant `sku` | the variant's brand | the variant's price | 1 | selected options |
273
277
  | cart line | the line `sku` | the variant's brand | the line's unit price | the line's | selected options |
278
+ | checkout cart line | the line `sku` | the variant's brand | the unit price | the line's | options |
274
279
  | order line (product) | the line `sku` | the variant's brand | the unit price | the line's | options |
275
280
 
276
281
  - A card is a family impression; later events carry the purchased sku. Pass `itemId` to report at family level.
@@ -1,6 +1,6 @@
1
- import { type CartLineDto, type OrderLineDto, type ProductCardDto, type ProductDto, type ProductFacts, type SelectedVariant } from "./types.js";
1
+ import { type CartLineDto, type CheckoutCartLineDto, type OrderLineDto, type ProductCardDto, type ProductDto, type ProductFacts, type SelectedVariant } from "./types.js";
2
2
  /**
3
- * The product facts of a card, a product page (with or without a selected variant), a cart line or an order line, so a
3
+ * The product facts of a card, a product page (with or without a selected variant), a cart line, a checkout cart line or an order line, so a
4
4
  * frontend never needs to know where a surface keeps them. Returns the DTO's own arrays and objects — never copies,
5
5
  * filters or mutates them. `brand` is the item's brand: a selected or purchased variant's own, with no fallback to the
6
6
  * family brand (null can mean an explicit "none"). An order line that is not a product line throws.
@@ -9,4 +9,5 @@ export declare function productFacts(source: ProductCardDto): ProductFacts;
9
9
  export declare function productFacts(source: ProductDto): ProductFacts;
10
10
  export declare function productFacts(source: SelectedVariant): ProductFacts;
11
11
  export declare function productFacts(source: CartLineDto): ProductFacts;
12
+ export declare function productFacts(source: CheckoutCartLineDto): ProductFacts;
12
13
  export declare function productFacts(source: OrderLineDto): ProductFacts;
@@ -12,11 +12,13 @@ export function productFacts(source) {
12
12
  };
13
13
  }
14
14
  if (isObject(s.product) && isObject(s.variant)) {
15
- // A cart line or a selected-variant wrapper: the same fact paths.
15
+ // A cart line, a checkout cart line or a selected-variant wrapper: the same fact paths. A checkout line's product has no
16
+ // `shortDescription` (it is the order-line shape), so it reads null there.
16
17
  const { product, variant } = source;
18
+ const short = product.shortDescription;
17
19
  return {
18
20
  brand: variant.brand, productBrand: product.brand, categories: product.categories,
19
- attributes: product.attributes, shortDescription: product.shortDescription ?? null,
21
+ attributes: product.attributes, shortDescription: short ?? null,
20
22
  };
21
23
  }
22
24
  const flat = source;
@@ -1,4 +1,4 @@
1
- import { type CartDto, type Ga4Ecommerce, type Ga4Item, type Ga4ItemOptions, type Ga4ItemSource, type Ga4Purchase, type Ga4SharedOptions, type OrderDto } from "./types.js";
1
+ import { type CartDto, type CheckoutCartDto, type Ga4Ecommerce, type Ga4Item, type Ga4ItemOptions, type Ga4ItemSource, type Ga4Purchase, type Ga4SharedOptions, type OrderDto } from "./types.js";
2
2
  /** An item and its unit price in cents, so a payload's `value` sums exact cents rather than re-reading floats. */
3
3
  export type MappedItem = {
4
4
  item: Ga4Item;
@@ -6,7 +6,7 @@ export type MappedItem = {
6
6
  };
7
7
  /**
8
8
  * One GA4 item from a card (an impression: the family sku and from-price), a product with its selected variant, a cart
9
- * line or a product order line. `item_brand` and the categories come from `productFacts`, so they never disagree with it.
9
+ * line, a checkout cart line or a product order line. `item_brand` and the categories come from `productFacts`, so they never disagree with it.
10
10
  * A source without a price throws — never `price: 0`.
11
11
  */
12
12
  export declare function toGa4Item(source: Ga4ItemSource, opts?: Ga4ItemOptions): Ga4Item;
@@ -18,4 +18,5 @@ export declare function mapItem(source: Ga4ItemSource, opts?: Ga4ItemOptions): M
18
18
  * recorded VAT and its `shipping` comes from its shipping lines, each netted at its own rate and rounded once.
19
19
  */
20
20
  export declare function toGa4Ecommerce(source: CartDto, opts?: Ga4SharedOptions): Ga4Ecommerce;
21
+ export declare function toGa4Ecommerce(source: CheckoutCartDto, opts?: Ga4SharedOptions): Ga4Ecommerce;
21
22
  export declare function toGa4Ecommerce(source: OrderDto, opts?: Ga4SharedOptions): Ga4Purchase;
@@ -3,7 +3,7 @@ import { productFacts } from "./facts.js";
3
3
  import { AnalyticsError, } from "./types.js";
4
4
  /**
5
5
  * One GA4 item from a card (an impression: the family sku and from-price), a product with its selected variant, a cart
6
- * line or a product order line. `item_brand` and the categories come from `productFacts`, so they never disagree with it.
6
+ * line, a checkout cart line or a product order line. `item_brand` and the categories come from `productFacts`, so they never disagree with it.
7
7
  * A source without a price throws — never `price: 0`.
8
8
  */
9
9
  export function toGa4Item(source, opts = {}) {
@@ -65,6 +65,11 @@ function lineOf(source) {
65
65
  throw new AnalyticsError(`an order line of type "${l.type}" is not an item`);
66
66
  return { id: l.sku, name: l.name, gross: parseDecimal(l.unitPriceInc), vatRate: parseDecimal(l.vatRate), quantity: sourceQuantity(l.quantity), options: l.options };
67
67
  }
68
+ if (typeof s.unitPriceInc === "string" && typeof s.productId === "string" && typeof s.type !== "string") {
69
+ // A checkout cart line: the snapshot's own amounts (`unitPriceInc`, `vatRate`), not a PriceDto, and the options on the line.
70
+ const l = source;
71
+ return { id: l.sku, name: l.name, gross: parseDecimal(l.unitPriceInc), vatRate: parseDecimal(l.vatRate), quantity: sourceQuantity(l.quantity), options: l.options };
72
+ }
68
73
  if (typeof s.variant === "object" && s.variant !== null && "selectedOptions" in s.variant) {
69
74
  if ("quantity" in s) {
70
75
  const l = source;
@@ -7,6 +7,8 @@ export type CartDto = Schemas["CartDto"];
7
7
  export type CartLineDto = Schemas["CartLineDto"];
8
8
  export type OrderDto = Schemas["OrderDto"];
9
9
  export type OrderLineDto = Schemas["OrderLineDto"];
10
+ export type CheckoutCartDto = Schemas["CheckoutCartDto"];
11
+ export type CheckoutCartLineDto = Schemas["CheckoutCartLineDto"];
10
12
  export type BrandDto = Schemas["BrandDto"];
11
13
  export type CategoryRefDto = Schemas["CategoryRefDto"];
12
14
  export type AttributeDto = Schemas["AttributeDto"];
@@ -26,7 +28,7 @@ export type ProductFacts = {
26
28
  categories: CategoryRefDto[];
27
29
  /** As the source carries them: a `ProductDto` may include `html` attributes; cards, cart and order lines do not. */
28
30
  attributes: AttributeDto[];
29
- /** Null on order lines. */
31
+ /** Null on order lines and checkout cart lines. */
30
32
  shortDescription: string | null;
31
33
  };
32
34
  /** A source the analytics helpers cannot map: a non-product order line, an unpriced variant, an invalid quantity. */
@@ -70,7 +72,7 @@ export type Ga4ItemOptions = Ga4SharedOptions & {
70
72
  itemId?: string;
71
73
  index?: number;
72
74
  };
73
- export type Ga4ItemSource = ProductCardDto | SelectedVariant | CartLineDto | OrderLineDto;
75
+ export type Ga4ItemSource = ProductCardDto | SelectedVariant | CartLineDto | CheckoutCartLineDto | OrderLineDto;
74
76
  /** `view_cart`, `begin_checkout` and the like. */
75
77
  export type Ga4Ecommerce = {
76
78
  currency: string;
package/dist/schema.d.ts CHANGED
@@ -541,11 +541,13 @@ export interface components {
541
541
  options: {
542
542
  [key: string]: string;
543
543
  };
544
+ product: components["schemas"]["OrderLineProductDto"];
544
545
  productId: string;
545
546
  /** Format: int32 */
546
547
  quantity: number | string;
547
548
  sku: string;
548
549
  unitPriceInc: string;
550
+ variant: components["schemas"]["OrderLineVariantDto"];
549
551
  variantId: string;
550
552
  vatRate: string;
551
553
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asstio-dev/storefront",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Typed client for the Asstio Storefront API (generated from OpenAPI).",
5
5
  "repository": {
6
6
  "type": "git",
package/src/schema.d.ts CHANGED
@@ -541,11 +541,13 @@ export interface components {
541
541
  options: {
542
542
  [key: string]: string;
543
543
  };
544
+ product: components["schemas"]["OrderLineProductDto"];
544
545
  productId: string;
545
546
  /** Format: int32 */
546
547
  quantity: number | string;
547
548
  sku: string;
548
549
  unitPriceInc: string;
550
+ variant: components["schemas"]["OrderLineVariantDto"];
549
551
  variantId: string;
550
552
  vatRate: string;
551
553
  };