@peabody-soft/mbs-model-ts 1.7.0 → 1.7.1

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/Order.js CHANGED
@@ -3,11 +3,9 @@ import { amountFromScaledValue } from "./Constants";
3
3
  import Message from "./Message";
4
4
  // An order a customer has placed: a message carrying a sales order payload.
5
5
  // The business completes an order (fulfilling or cancelling it) by deleting its message, so
6
- // isDeleted is true of a completed order. That message is still the whole order: status and what
7
- // the customer ordered are there to show, as for an open one. status says how far the business
8
- // got with it.
9
- // deliveryAddressId is an id into the customer's address list. deliveryAddress is a full address
10
- // sent directly, and takes precedence over deliveryAddressId when both are present.
6
+ // isDeleted is true of a completed order. The deleted message still holds the whole order, with
7
+ // its status and what the customer ordered, as an open order does. status records how far the
8
+ // business got with it.
11
9
  export default class Order extends Message {
12
10
  // For ProtoMap, which sees a total still multiplied by Constants.AMOUNT_FACTOR.
13
11
  static fromScaledValues(header, senderId, taskStatus, senderName, senderPhone, status, fulfillmentMode, shoppingList, scaledShoppingListTotal, shoppingListCount, deliveryAddressId, deliveryAddress, creationDate, note, scaledPaymentReceived) {
@@ -34,22 +32,22 @@ export default class Order extends Message {
34
32
  get fulfillmentMode() {
35
33
  return this._fulfillmentMode;
36
34
  }
37
- // What was ordered. An order completed before the business kept the list with it (an older
38
- // merchant app moved the list into a record of the sale, which a customer never sees) holds
39
- // ShoppingList.EMPTY, which has no lines. The totals below are then all that is left.
35
+ // What was ordered. An older merchant app moved the list of a completed order into a record of
36
+ // the sale, which a customer never sees. Such an order holds ShoppingList.EMPTY, which has no
37
+ // lines, and only the totals below remain.
40
38
  get shoppingList() {
41
39
  return this._shoppingList;
42
40
  }
43
- // The authoritative total to display. Unlike a total read off the list, it survives the order
44
- // having no list.
41
+ // The authoritative total to display. Unlike a total computed from the list, it is still
42
+ // available when the order has no list.
45
43
  get shoppingListTotal() {
46
44
  return this._shoppingListTotal;
47
45
  }
48
46
  get shoppingListCount() {
49
47
  return this._shoppingListCount;
50
48
  }
51
- // Names an address in the customer's address list. Constants.ENTITY_ID_NULL when the order has no
52
- // delivery address, as is normal for a pickup.
49
+ // The id of an address in the customer's address list, or Constants.ENTITY_ID_NULL when the order
50
+ // names none, as is normal for a pickup.
53
51
  get deliveryAddressId() {
54
52
  return this._deliveryAddressId;
55
53
  }
@@ -1,5 +1,5 @@
1
- // An identifier of a package, such as a GTIN, and its kind. Java keys kinds by string id, so map
2
- // through the comments in PackageIdentifierType.proto, never the enum ordinal.
1
+ // An identifier of a package, such as a GTIN, and its kind. Java keys kinds by string id. Map a
2
+ // kind using the comments in PackageIdentifierType.proto, not the enum ordinal.
3
3
  export default class PackageIdentifier {
4
4
  constructor(_type, _value) {
5
5
  this._type = _type;
package/dist/Price.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import { amountFromScaledValue } from "./Constants";
2
2
  import Item from "./Item";
3
- // What one package costs: the regular price and the offer price. Exposed unscaled as numbers; they
4
- // travel multiplied by Constants.AMOUNT_FACTOR and stay well below 2^53, so nothing is lost.
3
+ // What one package costs: the regular price and the offer price. Both are exposed as unscaled
4
+ // numbers. On the wire they are multiplied by Constants.AMOUNT_FACTOR and stay well below 2^53,
5
+ // so unscaling loses nothing.
5
6
  //
6
- // BOTH INCLUDE TAXES: the taxes of the package's product (Product.taxes) are in the price, not
7
- // added to it, so this is what a customer pays and what a catalog shows. A shopping list stores a
8
- // price without them, so a cart takes the taxes out (CartEditor).
7
+ // BOTH INCLUDE TAXES: the taxes of the package's product (Product.taxes) are part of each price,
8
+ // not added to it, so a price is what a customer pays and what a catalog shows. A shopping list
9
+ // stores a price without taxes, so a cart takes them out (CartEditor).
9
10
  export default class Price extends Item {
10
11
  // For ProtoMap, which sees prices still multiplied by Constants.AMOUNT_FACTOR.
11
12
  static fromScaledValues(header, name, description, priceListId, isDisabled, packageId, scaledRegularPrice, scaledOfferPrice) {
package/dist/PriceList.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import Item from "./Item";
2
2
  // A named list of prices. A storefront sells from one, so no package has two prices to choose
3
- // between. Carried as an object, not a bare id, because a client naming a cart needs it.
3
+ // between. Catalog.priceList holds it, and CartEditor names its id on the carts it builds.
4
4
  export default class PriceList extends Item {
5
5
  }
package/dist/Product.js CHANGED
@@ -13,7 +13,7 @@ export default class Product extends Item {
13
13
  this._features = _features;
14
14
  this._isForOfflineSaleOnly = _isForOfflineSaleOnly;
15
15
  this._photos = _photos;
16
- // A package that cannot be bought is not kept, whoever builds the product and whatever they pass in
16
+ // A package that cannot be bought is dropped, whatever the caller passes in
17
17
  this._packages = Object.freeze(packages.filter((pkg) => pkg.isBuyable));
18
18
  }
19
19
  // The category this product is in, or Constants.ENTITY_ID_NULL when it is in none
@@ -38,11 +38,12 @@ export default class Product extends Item {
38
38
  return this._manufacturerAddress;
39
39
  }
40
40
  // The taxes included in the price of every package of this product (see Price), not added to it.
41
- // A UI shows a price as is, and shows these only as part of what a bill's total includes.
41
+ // A UI shows a price as is, and shows these taxes only as the portion of a bill's total that
42
+ // they make up.
42
43
  get taxes() {
43
44
  return this._taxes;
44
45
  }
45
- // One line bullet points about this product
46
+ // Bullet points about this product, one line each
46
47
  get features() {
47
48
  return this._features;
48
49
  }
@@ -62,19 +63,20 @@ export default class Product extends Item {
62
63
  }
63
64
  // The cheapest final price across variants (what a listing shows as "from"), or null if there
64
65
  // are no variants. Compares final price, since that is what a customer pays. Every variant is
65
- // taxed at this product's rates, so prices with taxes order the variants as prices without would.
66
+ // taxed at this product's rates, so comparing prices with taxes gives the same order as
67
+ // comparing them without.
66
68
  get lowestPrice() {
67
69
  let result = null;
68
70
  for (const pkg of this._packages) {
69
71
  const price = pkg.price;
70
72
  if (price === null)
71
- continue; // Not so of a buyable variant, though the type does not say
73
+ continue; // A buyable variant always has a price, but the type allows null
72
74
  if (result === null || price.finalPrice < result.finalPrice)
73
75
  result = price;
74
76
  }
75
77
  return result;
76
78
  }
77
- // True when any variant of this product is on offer, which is what a listing puts a badge on
79
+ // True when any variant of this product is on offer. A listing shows a badge for this.
78
80
  get isOnOffer() {
79
81
  for (const pkg of this._packages)
80
82
  if (pkg.price?.isOnOffer === true)
package/dist/Profile.js CHANGED
@@ -26,7 +26,7 @@ export default class Profile {
26
26
  this._businessLinkMap.set(businessLink.businessId, businessLink);
27
27
  }
28
28
  }
29
- // The id of the profile container this was built from, and what Model.signIn was given
29
+ // The subject id that Model.signIn was given, which the profile container's name is built from
30
30
  get profileId() {
31
31
  return this._profileId;
32
32
  }
@@ -51,8 +51,8 @@ export default class Profile {
51
51
  return this._businessLinkMap.get(businessEntityId) ?? null;
52
52
  }
53
53
  // The same, by the url friendly business id a storefront is reached by, however it is written in
54
- // the url. The server finds a business whatever the case, so this must too, or a customer who
55
- // has joined would be asked to join again.
54
+ // the url. The server finds a business whatever the case, so this must too. Otherwise a customer
55
+ // who has joined would be treated as not a member and asked to join again.
56
56
  getBusinessLinkFor(businessId) {
57
57
  const wanted = canonicalizeBusinessId(businessId);
58
58
  for (const business of this._businesses)
@@ -68,15 +68,16 @@ export default class Profile {
68
68
  // spaces normalized as Java StringHelper.normalizeSpace does, then lower case. So a url typed in any
69
69
  // case or spacing names one business. Inner spaces count, as an id can hold some (Java builds one
70
70
  // from the display name, "Warm Loaf_1a2b3c4d", or takes what is typed).
71
- // normalizeSpace is followed step for step, quirks included: a string with no whitespace at either
72
- // end and none twice in a row is left alone, and a non-breaking space is not whitespace to it, so
73
- // one between words stays unless something else in the string is normalized.
74
- // Java refuses an id not four to sixty-four characters long. This is only a comparison and does
75
- // not. The server answers a read of such an id with NotFoundException, as for a missing business.
71
+ // This follows normalizeSpace step for step, quirks included. A string with no whitespace at either
72
+ // end and none twice in a row is returned unchanged. A non-breaking space does not count as
73
+ // whitespace, but it becomes a plain space if the string is normalized for another reason.
74
+ // Java rejects an id that is not four to sixty-four characters long. This function only normalizes
75
+ // for comparison and does not check the length. The server answers a read of such an id with
76
+ // NotFoundException, as for a missing business.
76
77
  export function canonicalizeBusinessId(businessId) {
77
78
  return normalizeSpace(businessId).toLowerCase();
78
79
  }
79
- // Java StringHelper.normalizeSpace. Where Java answers null (a string of only whitespace), this answers an empty string.
80
+ // Java StringHelper.normalizeSpace. Where Java returns null (a string of only whitespace), this returns an empty string.
80
81
  function normalizeSpace(input) {
81
82
  if (!needsNormalization(input))
82
83
  return input;
@@ -98,8 +99,8 @@ function normalizeSpace(input) {
98
99
  }
99
100
  if (isAtStart)
100
101
  return "";
101
- // Java String.trim removes every character up to a space from either end, unlike a script's trim, which removes
102
- // Unicode spaces. The space standing for trailing whitespace goes with it (Java drops that one first, same result)
102
+ // Java String.trim removes every character up to a space from either end, unlike JavaScript's trim, which removes
103
+ // Unicode whitespace. The trailing space added for trailing whitespace is trimmed too (Java drops it first, with the same result)
103
104
  let first = 0;
104
105
  let last = result.length;
105
106
  while (first < last && result.charCodeAt(first) <= SPACE)
@@ -108,7 +109,7 @@ function normalizeSpace(input) {
108
109
  --last;
109
110
  return result.slice(first, last);
110
111
  }
111
- // Java StringHelper.needsNormalization: whitespace at either end, or two together between
112
+ // Java StringHelper.needsNormalization: whitespace at either end, or two whitespace characters in a row inside
112
113
  function needsNormalization(input) {
113
114
  if (input.length === 0)
114
115
  return false;
@@ -123,8 +124,8 @@ function needsNormalization(input) {
123
124
  }
124
125
  return false;
125
126
  }
126
- // Java Character.isWhitespace: the Unicode spaces that do not hold a place (not the no-break ones U+00A0, U+2007 and
127
- // U+202F) and the control characters that are spaces. A regular expression's \s differs: it includes the no-break
127
+ // Java Character.isWhitespace: the Unicode separators except the no-break ones (U+00A0, U+2007 and U+202F),
128
+ // and the control characters that are whitespace. A regular expression's \s differs: it includes the no-break
128
129
  // spaces and the byte order mark, and excludes U+001C to U+001F
129
130
  function isWhitespace(unit) {
130
131
  if (unit === SPACE)