@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/Attachment.js +2 -2
- package/dist/AttachmentBaseUrl.js +4 -4
- package/dist/AuthTokens.js +7 -7
- package/dist/Business.js +11 -10
- package/dist/BusinessIdentifier.js +3 -2
- package/dist/BusinessLink.js +3 -2
- package/dist/CartEditor.js +89 -81
- package/dist/Catalog.js +4 -4
- package/dist/Constants.js +2 -2
- package/dist/ContainerNames.js +6 -6
- package/dist/Entity.js +4 -3
- package/dist/Enums.js +2 -2
- package/dist/Exceptions.js +2 -2
- package/dist/GeneralSettings.js +9 -8
- package/dist/HttpStatusCodes.js +7 -7
- package/dist/Ids.js +4 -5
- package/dist/Item.js +6 -4
- package/dist/LiveData.js +2 -2
- package/dist/Measures.js +3 -2
- package/dist/Message.js +1 -1
- package/dist/MockDatabase.js +6 -5
- package/dist/Model.js +166 -162
- package/dist/Order.js +10 -12
- package/dist/PackageIdentifier.js +2 -2
- package/dist/Price.js +6 -5
- package/dist/PriceList.js +1 -1
- package/dist/Product.js +8 -6
- package/dist/Profile.js +15 -14
- package/dist/ProtoMap.js +159 -155
- package/dist/ServiceExceptions.js +6 -6
- package/dist/ServiceProxy.js +15 -14
- package/dist/ShoppingList.js +101 -100
- package/dist/SyncCache.js +76 -68
- package/dist/SyncKeys.js +5 -5
- package/dist/SyncState.js +14 -6
- package/dist/Tax.js +11 -10
- package/dist/TaxHelper.js +9 -8
- package/dist/TaxType.js +7 -6
- package/dist/UserProfile.js +7 -7
- package/dist/WorkingDays.js +21 -18
- package/dist/index.js +11 -8
- package/package.json +1 -1
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.
|
|
7
|
-
//
|
|
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
|
|
38
|
-
//
|
|
39
|
-
//
|
|
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
|
|
44
|
-
//
|
|
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
|
-
//
|
|
52
|
-
//
|
|
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
|
|
2
|
-
//
|
|
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.
|
|
4
|
-
//
|
|
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
|
|
7
|
-
// added to it, so
|
|
8
|
-
// price without
|
|
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.
|
|
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
|
|
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
|
|
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
|
-
//
|
|
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
|
|
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; //
|
|
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
|
|
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
|
|
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
|
|
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
|
-
//
|
|
72
|
-
// end and none twice in a row is
|
|
73
|
-
//
|
|
74
|
-
// Java
|
|
75
|
-
// not. The server answers a read of such an id with
|
|
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
|
|
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
|
|
102
|
-
// Unicode
|
|
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
|
|
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
|
|
127
|
-
//
|
|
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)
|