@peabody-soft/mbs-model-ts 1.10.0 → 1.11.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/dist/Catalog.d.ts CHANGED
@@ -16,6 +16,8 @@ export default class Catalog {
16
16
  getCategory(productCategoryId: bigint): ProductCategory | null;
17
17
  getProduct(productId: bigint): Product | null;
18
18
  getPackage(packageId: bigint): Package | null;
19
+ getProductForDisplay(productId: bigint): Product | null;
20
+ getPackageForDisplay(packageId: bigint): Package | null;
19
21
  static comparePackages(left: Package, right: Package): number;
20
22
  static compareByName(left: Item, right: Item): number;
21
23
  private static compareNames;
@@ -27,6 +29,8 @@ export default class Catalog {
27
29
  private readonly _allProducts;
28
30
  private readonly _uncategorized;
29
31
  private readonly _candidatePackages;
32
+ private readonly _displayProductMap;
33
+ private readonly _displayPackageMap;
30
34
  private readonly _priceListMap;
31
35
  private _currentSalePriceListId;
32
36
  private _categories;
package/dist/Catalog.js CHANGED
@@ -13,6 +13,7 @@ class Catalog {
13
13
  constructor(categories, products, packages, priceLists, prices) {
14
14
  // Every package that has a product, by that product's id, whether it can be bought or not
15
15
  this._candidatePackages = new Map();
16
+ this._displayPackageMap = new Map();
16
17
  this._priceListMap = new Map();
17
18
  this._currentSalePriceListId = DEFAULT_SALE_PRICE_LIST_ID;
18
19
  // What a customer can reach, rebuilt by applySalePriceList
@@ -31,11 +32,13 @@ class Catalog {
31
32
  const productsById = new Map();
32
33
  for (const product of products)
33
34
  productsById.set(product.id, product);
35
+ this._displayProductMap = productsById;
34
36
  for (const pkg of packages) {
35
37
  const product = productsById.get(pkg.productId);
36
38
  if (product === undefined)
37
39
  continue;
38
40
  UpdatableEntity.setParent(pkg, product);
41
+ this._displayPackageMap.set(pkg.id, pkg);
39
42
  const productPackages = this._candidatePackages.get(product.id);
40
43
  if (productPackages === undefined)
41
44
  this._candidatePackages.set(product.id, [pkg]);
@@ -110,6 +113,25 @@ class Catalog {
110
113
  getPackage(packageId) {
111
114
  return this._packageMap.get(packageId) ?? null;
112
115
  }
116
+ // Like getProduct, but for any product that the server sent, whether it can be bought or not: it
117
+ // is disabled, or it has nothing left to buy. It is for drawing a shopping list that already
118
+ // exists, such as an order that was placed, whose line can name a product that is no longer
119
+ // sold. Do not use it to offer anything for sale. Its packages are not on offer either:
120
+ // Product.packages keeps only the buyable ones, so it is empty for a product that cannot be
121
+ // bought. Null for an unknown id.
122
+ getProductForDisplay(productId) {
123
+ return this._displayProductMap.get(productId) ?? null;
124
+ }
125
+ // Like getPackage, but for any package of a product that the server sent, whether it can be
126
+ // bought or not: it is disabled, it has no enabled price, or its product is disabled. For
127
+ // drawing a shopping list that already exists (see getProductForDisplay), not for offering
128
+ // anything for sale. Package.price is the price in the current sale price list, null when there
129
+ // is none, and disabled when the package is not in that list. Null for an unknown id, and for
130
+ // the four reserved package ids a shopping list uses for its charge and summary lines (see
131
+ // Ids.isReservedPackageId).
132
+ getPackageForDisplay(packageId) {
133
+ return this._displayPackageMap.get(packageId) ?? null;
134
+ }
113
135
  // Display comparator for packages, matching the merchant app's PackageComparator minus the
114
136
  // clauses a storefront cannot exercise (disabled packages and the purchase price list, neither sent)
115
137
  static comparePackages(left, right) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peabody-soft/mbs-model-ts",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "MeraBills storefront client-side model (TypeScript)",
5
5
  "author": "Peabody Soft",
6
6
  "license": "AGPL-3.0-or-later",