@peabody-soft/mbs-model-ts 1.0.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/LICENCE +661 -0
- package/dist/Address.d.ts +33 -0
- package/dist/Address.js +97 -0
- package/dist/Attachment.d.ts +16 -0
- package/dist/Attachment.js +49 -0
- package/dist/AttachmentBaseUrl.d.ts +11 -0
- package/dist/AttachmentBaseUrl.js +41 -0
- package/dist/AuthTokens.d.ts +13 -0
- package/dist/AuthTokens.js +30 -0
- package/dist/Business.d.ts +44 -0
- package/dist/Business.js +87 -0
- package/dist/BusinessIdentifier.d.ts +8 -0
- package/dist/BusinessIdentifier.js +14 -0
- package/dist/BusinessLink.d.ts +21 -0
- package/dist/BusinessLink.js +61 -0
- package/dist/BusinessProfile.d.ts +11 -0
- package/dist/BusinessProfile.js +27 -0
- package/dist/CartEditor.d.ts +59 -0
- package/dist/CartEditor.js +324 -0
- package/dist/Catalog.d.ts +28 -0
- package/dist/Catalog.js +115 -0
- package/dist/Constants.d.ts +10 -0
- package/dist/Constants.js +43 -0
- package/dist/ContainerNames.d.ts +2 -0
- package/dist/ContainerNames.js +21 -0
- package/dist/Database.d.ts +15 -0
- package/dist/Database.js +1 -0
- package/dist/Entity.d.ts +27 -0
- package/dist/Entity.js +69 -0
- package/dist/Enums.d.ts +16 -0
- package/dist/Enums.js +18 -0
- package/dist/Exceptions.d.ts +4 -0
- package/dist/Exceptions.js +8 -0
- package/dist/GeneralSettings.d.ts +46 -0
- package/dist/GeneralSettings.js +99 -0
- package/dist/HttpStatusCodes.d.ts +2 -0
- package/dist/HttpStatusCodes.js +34 -0
- package/dist/Ids.d.ts +17 -0
- package/dist/Ids.js +78 -0
- package/dist/Item.d.ts +12 -0
- package/dist/Item.js +30 -0
- package/dist/LatLong.d.ts +7 -0
- package/dist/LatLong.js +17 -0
- package/dist/LiveData.d.ts +30 -0
- package/dist/LiveData.js +76 -0
- package/dist/Measures.d.ts +20 -0
- package/dist/Measures.js +34 -0
- package/dist/Message.d.ts +16 -0
- package/dist/Message.js +32 -0
- package/dist/MockDatabase.d.ts +19 -0
- package/dist/MockDatabase.js +73 -0
- package/dist/Model.d.ts +63 -0
- package/dist/Model.js +629 -0
- package/dist/Order.d.ts +31 -0
- package/dist/Order.js +70 -0
- package/dist/Package.d.ts +25 -0
- package/dist/Package.js +52 -0
- package/dist/PackageIdentifier.d.ts +8 -0
- package/dist/PackageIdentifier.js +14 -0
- package/dist/PaymentMethodDetail.d.ts +8 -0
- package/dist/PaymentMethodDetail.js +17 -0
- package/dist/Photo.d.ts +11 -0
- package/dist/Photo.js +29 -0
- package/dist/Price.d.ts +17 -0
- package/dist/Price.js +52 -0
- package/dist/PriceList.d.ts +3 -0
- package/dist/PriceList.js +5 -0
- package/dist/Product.d.ts +33 -0
- package/dist/Product.js +84 -0
- package/dist/ProductCategory.d.ts +10 -0
- package/dist/ProductCategory.js +18 -0
- package/dist/Profile.d.ts +20 -0
- package/dist/Profile.js +55 -0
- package/dist/ProtoMap.d.ts +71 -0
- package/dist/ProtoMap.js +1126 -0
- package/dist/Routes.d.ts +7 -0
- package/dist/Routes.js +12 -0
- package/dist/Service.d.ts +16 -0
- package/dist/Service.js +1 -0
- package/dist/ServiceExceptions.d.ts +40 -0
- package/dist/ServiceExceptions.js +84 -0
- package/dist/ServiceProxy.d.ts +25 -0
- package/dist/ServiceProxy.js +117 -0
- package/dist/ShoppingList.d.ts +64 -0
- package/dist/ShoppingList.js +188 -0
- package/dist/SyncCache.d.ts +28 -0
- package/dist/SyncCache.js +137 -0
- package/dist/SyncKeys.d.ts +5 -0
- package/dist/SyncKeys.js +41 -0
- package/dist/SyncState.d.ts +8 -0
- package/dist/SyncState.js +30 -0
- package/dist/Tax.d.ts +10 -0
- package/dist/Tax.js +30 -0
- package/dist/UserProfile.d.ts +16 -0
- package/dist/UserProfile.js +40 -0
- package/dist/WorkingDays.d.ts +33 -0
- package/dist/WorkingDays.js +121 -0
- package/dist/generated/Address.d.ts +77 -0
- package/dist/generated/Address.js +110 -0
- package/dist/generated/AddressList.d.ts +39 -0
- package/dist/generated/AddressList.js +60 -0
- package/dist/generated/AddressType.d.ts +15 -0
- package/dist/generated/AddressType.js +20 -0
- package/dist/generated/Attachment.d.ts +66 -0
- package/dist/generated/Attachment.js +89 -0
- package/dist/generated/AttachmentType.d.ts +154 -0
- package/dist/generated/AttachmentType.js +159 -0
- package/dist/generated/AuthTokens.d.ts +56 -0
- package/dist/generated/AuthTokens.js +74 -0
- package/dist/generated/AuthenticationMethod.d.ts +24 -0
- package/dist/generated/AuthenticationMethod.js +29 -0
- package/dist/generated/Business.d.ts +54 -0
- package/dist/generated/Business.js +75 -0
- package/dist/generated/BusinessIdentifier.d.ts +36 -0
- package/dist/generated/BusinessIdentifier.js +60 -0
- package/dist/generated/BusinessIdentifierType.d.ts +49 -0
- package/dist/generated/BusinessIdentifierType.js +54 -0
- package/dist/generated/BusinessLink.d.ts +76 -0
- package/dist/generated/BusinessLink.js +99 -0
- package/dist/generated/BusinessSyncInRequest.d.ts +42 -0
- package/dist/generated/BusinessSyncInRequest.js +60 -0
- package/dist/generated/BusinessSyncInResponse.d.ts +42 -0
- package/dist/generated/BusinessSyncInResponse.js +60 -0
- package/dist/generated/BusinessSyncOutRequest.d.ts +82 -0
- package/dist/generated/BusinessSyncOutRequest.js +107 -0
- package/dist/generated/BusinessSyncOutResponse.d.ts +106 -0
- package/dist/generated/BusinessSyncOutResponse.js +139 -0
- package/dist/generated/Configuration.d.ts +48 -0
- package/dist/generated/Configuration.js +63 -0
- package/dist/generated/Constants.d.ts +474 -0
- package/dist/generated/Constants.js +479 -0
- package/dist/generated/CreateUserRequest.d.ts +37 -0
- package/dist/generated/CreateUserRequest.js +59 -0
- package/dist/generated/DimensionUnit.d.ts +28 -0
- package/dist/generated/DimensionUnit.js +33 -0
- package/dist/generated/Dimensions.d.ts +41 -0
- package/dist/generated/Dimensions.js +76 -0
- package/dist/generated/Entity.d.ts +62 -0
- package/dist/generated/Entity.js +83 -0
- package/dist/generated/FulfillmentMode.d.ts +32 -0
- package/dist/generated/FulfillmentMode.js +37 -0
- package/dist/generated/GeneralSettings.d.ts +141 -0
- package/dist/generated/GeneralSettings.js +186 -0
- package/dist/generated/Item.d.ts +54 -0
- package/dist/generated/Item.js +82 -0
- package/dist/generated/LatLong.d.ts +36 -0
- package/dist/generated/LatLong.js +59 -0
- package/dist/generated/Message.d.ts +80 -0
- package/dist/generated/Message.js +114 -0
- package/dist/generated/MessageType.d.ts +34 -0
- package/dist/generated/MessageType.js +39 -0
- package/dist/generated/OrderStatus.d.ts +50 -0
- package/dist/generated/OrderStatus.js +55 -0
- package/dist/generated/Package.d.ts +63 -0
- package/dist/generated/Package.js +92 -0
- package/dist/generated/PackageIdentifier.d.ts +36 -0
- package/dist/generated/PackageIdentifier.js +60 -0
- package/dist/generated/PackageIdentifierType.d.ts +49 -0
- package/dist/generated/PackageIdentifierType.js +54 -0
- package/dist/generated/PartyPreferencesPayload.d.ts +41 -0
- package/dist/generated/PartyPreferencesPayload.js +60 -0
- package/dist/generated/PaymentMethod.d.ts +20 -0
- package/dist/generated/PaymentMethod.js +25 -0
- package/dist/generated/PaymentMethodDetail.d.ts +37 -0
- package/dist/generated/PaymentMethodDetail.js +59 -0
- package/dist/generated/Price.d.ts +52 -0
- package/dist/generated/Price.js +75 -0
- package/dist/generated/PriceList.d.ts +34 -0
- package/dist/generated/PriceList.js +51 -0
- package/dist/generated/Product.d.ts +77 -0
- package/dist/generated/Product.js +106 -0
- package/dist/generated/ProductCategory.d.ts +32 -0
- package/dist/generated/ProductCategory.js +51 -0
- package/dist/generated/ProductType.d.ts +42 -0
- package/dist/generated/ProductType.js +47 -0
- package/dist/generated/ProfileSyncOutRequest.d.ts +51 -0
- package/dist/generated/ProfileSyncOutRequest.js +75 -0
- package/dist/generated/ProfileSyncOutResponse.d.ts +56 -0
- package/dist/generated/ProfileSyncOutResponse.js +77 -0
- package/dist/generated/ReservedPackage.d.ts +34 -0
- package/dist/generated/ReservedPackage.js +39 -0
- package/dist/generated/Role.d.ts +71 -0
- package/dist/generated/Role.js +76 -0
- package/dist/generated/SalesOrderPayload.d.ts +85 -0
- package/dist/generated/SalesOrderPayload.js +123 -0
- package/dist/generated/ShoppingList.d.ts +99 -0
- package/dist/generated/ShoppingList.js +132 -0
- package/dist/generated/ShoppingListItem.d.ts +102 -0
- package/dist/generated/ShoppingListItem.js +139 -0
- package/dist/generated/TaskStatus.d.ts +20 -0
- package/dist/generated/TaskStatus.js +25 -0
- package/dist/generated/Tax.d.ts +37 -0
- package/dist/generated/Tax.js +60 -0
- package/dist/generated/TaxType.d.ts +25 -0
- package/dist/generated/TaxType.js +30 -0
- package/dist/generated/UrlAndToken.d.ts +54 -0
- package/dist/generated/UrlAndToken.js +67 -0
- package/dist/generated/User.d.ts +63 -0
- package/dist/generated/User.js +89 -0
- package/dist/generated/Weight.d.ts +33 -0
- package/dist/generated/Weight.js +60 -0
- package/dist/generated/WeightUnit.d.ts +28 -0
- package/dist/generated/WeightUnit.js +33 -0
- package/dist/generated/WorkingDays.d.ts +42 -0
- package/dist/generated/WorkingDays.js +68 -0
- package/dist/generated/WorkingHours.d.ts +33 -0
- package/dist/generated/WorkingHours.js +52 -0
- package/dist/generated/WorkingHoursRange.d.ts +42 -0
- package/dist/generated/WorkingHoursRange.js +59 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +60 -0
- package/package.json +55 -0
package/dist/Order.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FulfillmentMode as proto_FulfillmentMode } from "./generated/FulfillmentMode";
|
|
2
|
+
import { OrderStatus as proto_OrderStatus } from "./generated/OrderStatus";
|
|
3
|
+
import { TaskStatus as proto_TaskStatus } from "./generated/TaskStatus";
|
|
4
|
+
import Address from "./Address";
|
|
5
|
+
import { EntityHeader } from "./Entity";
|
|
6
|
+
import Message from "./Message";
|
|
7
|
+
import ShoppingList from "./ShoppingList";
|
|
8
|
+
export default class Order extends Message {
|
|
9
|
+
private readonly _status;
|
|
10
|
+
private readonly _fulfillmentMode;
|
|
11
|
+
private readonly _shoppingList;
|
|
12
|
+
private readonly _shoppingListTotal;
|
|
13
|
+
private readonly _shoppingListCount;
|
|
14
|
+
private readonly _deliveryAddressId;
|
|
15
|
+
private readonly _deliveryAddress;
|
|
16
|
+
private readonly _note;
|
|
17
|
+
private readonly _paymentReceived;
|
|
18
|
+
static fromScaledValues(header: EntityHeader, senderId: bigint, taskStatus: proto_TaskStatus, senderName: string | null, senderPhone: string | null, status: proto_OrderStatus, fulfillmentMode: proto_FulfillmentMode, shoppingList: ShoppingList, scaledShoppingListTotal: bigint, shoppingListCount: number, deliveryAddressId: bigint, deliveryAddress: Address | null, creationDate: bigint, note: string | null, scaledPaymentReceived: bigint | undefined): Order;
|
|
19
|
+
constructor(header: EntityHeader, senderId: bigint, taskStatus: proto_TaskStatus, senderName: string | null, senderPhone: string | null, _status: proto_OrderStatus, _fulfillmentMode: proto_FulfillmentMode, _shoppingList: ShoppingList, _shoppingListTotal: number, _shoppingListCount: number, _deliveryAddressId: bigint, _deliveryAddress: Address | null, creationDate: bigint, _note: string | null, _paymentReceived: number | null);
|
|
20
|
+
get status(): proto_OrderStatus;
|
|
21
|
+
get fulfillmentMode(): proto_FulfillmentMode;
|
|
22
|
+
get shoppingList(): ShoppingList;
|
|
23
|
+
get shoppingListTotal(): number;
|
|
24
|
+
get shoppingListCount(): number;
|
|
25
|
+
get deliveryAddressId(): bigint;
|
|
26
|
+
get deliveryAddress(): Address | null;
|
|
27
|
+
get creationDate(): Date;
|
|
28
|
+
get note(): string | null;
|
|
29
|
+
get paymentReceived(): number | null;
|
|
30
|
+
private readonly _creationDate;
|
|
31
|
+
}
|
package/dist/Order.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { MessageType as proto_MessageType } from "./generated/MessageType";
|
|
2
|
+
import { amountFromScaledValue } from "./Constants";
|
|
3
|
+
import Message from "./Message";
|
|
4
|
+
// An order a customer has placed: a message carrying a sales order payload.
|
|
5
|
+
// deliveryAddressId is an id into the customer's address list, not an address; deliveryAddress is
|
|
6
|
+
// a full address sent directly instead, and takes precedence over deliveryAddressId when both are
|
|
7
|
+
// present. paymentReceived is set only by an operator of the business, never by this library.
|
|
8
|
+
export default class Order extends Message {
|
|
9
|
+
// Only ProtoMap calls this: it is the one place that sees a total still multiplied by
|
|
10
|
+
// Constants.AMOUNT_FACTOR.
|
|
11
|
+
static fromScaledValues(header, senderId, taskStatus, senderName, senderPhone, status, fulfillmentMode, shoppingList, scaledShoppingListTotal, shoppingListCount, deliveryAddressId, deliveryAddress, creationDate, note, scaledPaymentReceived) {
|
|
12
|
+
return new Order(header, senderId, taskStatus, senderName, senderPhone, status, fulfillmentMode, shoppingList, amountFromScaledValue(scaledShoppingListTotal), shoppingListCount, deliveryAddressId, deliveryAddress, creationDate, note, scaledPaymentReceived === undefined ? null : amountFromScaledValue(scaledPaymentReceived));
|
|
13
|
+
}
|
|
14
|
+
constructor(header, senderId, taskStatus, senderName, senderPhone, _status, _fulfillmentMode, _shoppingList, _shoppingListTotal, _shoppingListCount, _deliveryAddressId, _deliveryAddress, creationDate, _note, _paymentReceived) {
|
|
15
|
+
super(header, senderId, proto_MessageType.SALES_ORDER, taskStatus, senderName, senderPhone);
|
|
16
|
+
this._status = _status;
|
|
17
|
+
this._fulfillmentMode = _fulfillmentMode;
|
|
18
|
+
this._shoppingList = _shoppingList;
|
|
19
|
+
this._shoppingListTotal = _shoppingListTotal;
|
|
20
|
+
this._shoppingListCount = _shoppingListCount;
|
|
21
|
+
this._deliveryAddressId = _deliveryAddressId;
|
|
22
|
+
this._deliveryAddress = _deliveryAddress;
|
|
23
|
+
this._note = _note;
|
|
24
|
+
this._paymentReceived = _paymentReceived;
|
|
25
|
+
this._creationDate = Number(creationDate);
|
|
26
|
+
}
|
|
27
|
+
// How far the business has got with fulfilling this order, as opposed to taskStatus, which is
|
|
28
|
+
// how far it has got with reading the message
|
|
29
|
+
get status() {
|
|
30
|
+
return this._status;
|
|
31
|
+
}
|
|
32
|
+
get fulfillmentMode() {
|
|
33
|
+
return this._fulfillmentMode;
|
|
34
|
+
}
|
|
35
|
+
// What was ordered. A fulfilled order can have had its list cleared, in which case the totals
|
|
36
|
+
// below are all that is left of it.
|
|
37
|
+
get shoppingList() {
|
|
38
|
+
return this._shoppingList;
|
|
39
|
+
}
|
|
40
|
+
// The authoritative total to display; survives the shopping list being cleared, unlike a total
|
|
41
|
+
// read off the list itself.
|
|
42
|
+
get shoppingListTotal() {
|
|
43
|
+
return this._shoppingListTotal;
|
|
44
|
+
}
|
|
45
|
+
get shoppingListCount() {
|
|
46
|
+
return this._shoppingListCount;
|
|
47
|
+
}
|
|
48
|
+
// Names an address in the address list of the customer, and Constants.ENTITY_ID_NULL when the
|
|
49
|
+
// order has no delivery address - which is normal for one to be picked up
|
|
50
|
+
get deliveryAddressId() {
|
|
51
|
+
return this._deliveryAddressId;
|
|
52
|
+
}
|
|
53
|
+
// A full address sent directly rather than by id, and null when none was. Takes precedence over
|
|
54
|
+
// deliveryAddressId for display when it is not null - see the comment on this class.
|
|
55
|
+
get deliveryAddress() {
|
|
56
|
+
return this._deliveryAddress;
|
|
57
|
+
}
|
|
58
|
+
// When the customer placed this order, which is not the same as when the entity was created
|
|
59
|
+
get creationDate() {
|
|
60
|
+
return new Date(this._creationDate);
|
|
61
|
+
}
|
|
62
|
+
get note() {
|
|
63
|
+
return this._note;
|
|
64
|
+
}
|
|
65
|
+
// What the business has recorded as received against this order so far, and null when it has
|
|
66
|
+
// recorded nothing - only a business operator sets this, never this library.
|
|
67
|
+
get paymentReceived() {
|
|
68
|
+
return this._paymentReceived;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { EntityHeader } from "./Entity";
|
|
2
|
+
import Item from "./Item";
|
|
3
|
+
import { Dimensions, Weight } from "./Measures";
|
|
4
|
+
import PackageIdentifier from "./PackageIdentifier";
|
|
5
|
+
import Photo from "./Photo";
|
|
6
|
+
import Price from "./Price";
|
|
7
|
+
export default class Package extends Item {
|
|
8
|
+
private readonly _isSoldLoose;
|
|
9
|
+
private readonly _itemCode;
|
|
10
|
+
private readonly _identifiers;
|
|
11
|
+
private readonly _dimensions;
|
|
12
|
+
private readonly _weight;
|
|
13
|
+
private readonly _photos;
|
|
14
|
+
private readonly _price;
|
|
15
|
+
constructor(header: EntityHeader, name: string, description: string | null, productId: bigint, isDisabled: boolean, _isSoldLoose: boolean, _itemCode: bigint, _identifiers: ReadonlyArray<PackageIdentifier>, _dimensions: Dimensions | null, _weight: Weight | null, _photos: ReadonlyArray<Photo>, _price: Price | null);
|
|
16
|
+
get productId(): bigint;
|
|
17
|
+
get isSoldLoose(): boolean;
|
|
18
|
+
get itemCode(): bigint;
|
|
19
|
+
get identifiers(): ReadonlyArray<PackageIdentifier>;
|
|
20
|
+
get dimensions(): Dimensions | null;
|
|
21
|
+
get weight(): Weight | null;
|
|
22
|
+
get photos(): ReadonlyArray<Photo>;
|
|
23
|
+
get price(): Price | null;
|
|
24
|
+
get isBuyable(): boolean;
|
|
25
|
+
}
|
package/dist/Package.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Item from "./Item";
|
|
2
|
+
// A package, or variant, of a product - a 500 gram bottle of mango pickle, for example - and the
|
|
3
|
+
// thing a customer actually buys. Built complete, with photos and price already resolved, so everything here is readonly.
|
|
4
|
+
export default class Package extends Item {
|
|
5
|
+
constructor(header, name, description, productId, isDisabled, _isSoldLoose, _itemCode, _identifiers, _dimensions, _weight, _photos, _price) {
|
|
6
|
+
super(header, name, description, productId, isDisabled);
|
|
7
|
+
this._isSoldLoose = _isSoldLoose;
|
|
8
|
+
this._itemCode = _itemCode;
|
|
9
|
+
this._identifiers = _identifiers;
|
|
10
|
+
this._dimensions = _dimensions;
|
|
11
|
+
this._weight = _weight;
|
|
12
|
+
this._photos = _photos;
|
|
13
|
+
this._price = _price;
|
|
14
|
+
}
|
|
15
|
+
// The product this package is a variant of, which is the parent id every item has
|
|
16
|
+
get productId() {
|
|
17
|
+
return this.parentItemId;
|
|
18
|
+
}
|
|
19
|
+
// True when this package can be bought in a quantity a customer chooses, such as 4.2 litres of
|
|
20
|
+
// oil, rather than in whole units
|
|
21
|
+
get isSoldLoose() {
|
|
22
|
+
return this._isSoldLoose;
|
|
23
|
+
}
|
|
24
|
+
// GTIN, barcode and the like. Zero when the package has none.
|
|
25
|
+
get itemCode() {
|
|
26
|
+
return this._itemCode;
|
|
27
|
+
}
|
|
28
|
+
get identifiers() {
|
|
29
|
+
return this._identifiers;
|
|
30
|
+
}
|
|
31
|
+
get dimensions() {
|
|
32
|
+
return this._dimensions;
|
|
33
|
+
}
|
|
34
|
+
get weight() {
|
|
35
|
+
return this._weight;
|
|
36
|
+
}
|
|
37
|
+
get photos() {
|
|
38
|
+
return this._photos;
|
|
39
|
+
}
|
|
40
|
+
// What this package costs; null when the business has not priced it, in which case it cannot be
|
|
41
|
+
// bought.
|
|
42
|
+
get price() {
|
|
43
|
+
return this._price;
|
|
44
|
+
}
|
|
45
|
+
// True when this package is enabled and has a price that is itself enabled. isDisabled is
|
|
46
|
+
// checked directly rather than trusted to have been filtered out: a product-level filter does
|
|
47
|
+
// not, by itself, guarantee that every package - or every price - of an otherwise visible
|
|
48
|
+
// product is itself enabled.
|
|
49
|
+
get isBuyable() {
|
|
50
|
+
return !this.isDisabled && this._price !== null && !this._price.isDisabled;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PackageIdentifierType as proto_PackageIdentifierType } from "./generated/PackageIdentifierType";
|
|
2
|
+
export default class PackageIdentifier {
|
|
3
|
+
private readonly _type;
|
|
4
|
+
private readonly _value;
|
|
5
|
+
constructor(_type: proto_PackageIdentifierType, _value: string);
|
|
6
|
+
get type(): proto_PackageIdentifierType;
|
|
7
|
+
get value(): string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// An identifier of a package - a GTIN, for example - and the kind of identifier it is. Java keys
|
|
2
|
+
// these by string id, not ordinal, so map through PackageIdentifierType.proto's comments, never the enum ordinal.
|
|
3
|
+
export default class PackageIdentifier {
|
|
4
|
+
constructor(_type, _value) {
|
|
5
|
+
this._type = _type;
|
|
6
|
+
this._value = _value;
|
|
7
|
+
}
|
|
8
|
+
get type() {
|
|
9
|
+
return this._type;
|
|
10
|
+
}
|
|
11
|
+
get value() {
|
|
12
|
+
return this._value;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PaymentMethod as proto_PaymentMethod } from "./generated/PaymentMethod";
|
|
2
|
+
export default class PaymentMethodDetail {
|
|
3
|
+
private readonly _method;
|
|
4
|
+
private readonly _data;
|
|
5
|
+
constructor(_method: proto_PaymentMethod, _data: string | null);
|
|
6
|
+
get method(): proto_PaymentMethod;
|
|
7
|
+
get data(): string | null;
|
|
8
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// A payment method a business accepts, and what a customer needs in order to use it - the UPI id
|
|
2
|
+
// of the business, for example.
|
|
3
|
+
//
|
|
4
|
+
// The data is null rather than empty when the business has given none, which is normal for a
|
|
5
|
+
// method that needs nothing, such as cash.
|
|
6
|
+
export default class PaymentMethodDetail {
|
|
7
|
+
constructor(_method, _data) {
|
|
8
|
+
this._method = _method;
|
|
9
|
+
this._data = _data;
|
|
10
|
+
}
|
|
11
|
+
get method() {
|
|
12
|
+
return this._method;
|
|
13
|
+
}
|
|
14
|
+
get data() {
|
|
15
|
+
return this._data;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/dist/Photo.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AttachmentType as proto_AttachmentType } from "./generated/AttachmentType";
|
|
2
|
+
import Attachment from "./Attachment";
|
|
3
|
+
import AttachmentBaseUrl from "./AttachmentBaseUrl";
|
|
4
|
+
export default class Photo {
|
|
5
|
+
private readonly _attachment;
|
|
6
|
+
private readonly _attachmentBaseUrl;
|
|
7
|
+
constructor(_attachment: Attachment, _attachmentBaseUrl: AttachmentBaseUrl | null);
|
|
8
|
+
get attachmentType(): proto_AttachmentType;
|
|
9
|
+
get url(): URL | null;
|
|
10
|
+
private _url;
|
|
11
|
+
}
|
package/dist/Photo.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// A photo of a business, product or package: which one it belongs to, and where to fetch it from.
|
|
2
|
+
// All that's exposed of an Attachment - nothing else on it is useful to a UI.
|
|
3
|
+
export default class Photo {
|
|
4
|
+
// The base url is the one in effect when this photo was built, not looked up at read time - a
|
|
5
|
+
// photo is rebuilt by the next sync rather than edited in place, so there is nothing to keep in
|
|
6
|
+
// sync with a later renewal.
|
|
7
|
+
constructor(_attachment, _attachmentBaseUrl) {
|
|
8
|
+
this._attachment = _attachment;
|
|
9
|
+
this._attachmentBaseUrl = _attachmentBaseUrl;
|
|
10
|
+
this._url = null;
|
|
11
|
+
}
|
|
12
|
+
get attachmentType() {
|
|
13
|
+
return this._attachment.attachmentType;
|
|
14
|
+
}
|
|
15
|
+
// Where to fetch this photo from, or null if there's nothing to fetch (deleted attachment, or the
|
|
16
|
+
// owning business's base url hadn't arrived when this photo was built). May be expired; cached
|
|
17
|
+
// once built.
|
|
18
|
+
get url() {
|
|
19
|
+
if (this._url !== null)
|
|
20
|
+
return this._url;
|
|
21
|
+
const storageFileName = this._attachment.storageFileName;
|
|
22
|
+
if (storageFileName === null)
|
|
23
|
+
return null; // Deleted, so there is no file
|
|
24
|
+
if (this._attachmentBaseUrl === null)
|
|
25
|
+
return null; // No base url had arrived when this was built
|
|
26
|
+
this._url = this._attachmentBaseUrl.createFileUrl(storageFileName);
|
|
27
|
+
return this._url;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/dist/Price.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EntityHeader } from "./Entity";
|
|
2
|
+
import Item from "./Item";
|
|
3
|
+
export default class Price extends Item {
|
|
4
|
+
private readonly _packageId;
|
|
5
|
+
private readonly _regularPrice;
|
|
6
|
+
private readonly _offerPrice;
|
|
7
|
+
static fromScaledValues(header: EntityHeader, name: string, description: string | null, priceListId: bigint, isDisabled: boolean, packageId: bigint, scaledRegularPrice: bigint, scaledOfferPrice: bigint): Price;
|
|
8
|
+
constructor(header: EntityHeader, name: string, description: string | null, priceListId: bigint, isDisabled: boolean, _packageId: bigint, _regularPrice: number, _offerPrice: number);
|
|
9
|
+
get packageId(): bigint;
|
|
10
|
+
get priceListId(): bigint;
|
|
11
|
+
get regularPrice(): number;
|
|
12
|
+
get offerPrice(): number;
|
|
13
|
+
get finalPrice(): number;
|
|
14
|
+
get isOnOffer(): boolean;
|
|
15
|
+
get discount(): number;
|
|
16
|
+
get discountPercent(): number;
|
|
17
|
+
}
|
package/dist/Price.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { amountFromScaledValue } from "./Constants";
|
|
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.
|
|
5
|
+
export default class Price extends Item {
|
|
6
|
+
// Only ProtoMap calls this: it is the one place that sees prices still multiplied by
|
|
7
|
+
// Constants.AMOUNT_FACTOR.
|
|
8
|
+
static fromScaledValues(header, name, description, priceListId, isDisabled, packageId, scaledRegularPrice, scaledOfferPrice) {
|
|
9
|
+
return new Price(header, name, description, priceListId, isDisabled, packageId, amountFromScaledValue(scaledRegularPrice), amountFromScaledValue(scaledOfferPrice));
|
|
10
|
+
}
|
|
11
|
+
constructor(header, name, description, priceListId, isDisabled, _packageId, _regularPrice, _offerPrice) {
|
|
12
|
+
super(header, name, description, priceListId, isDisabled);
|
|
13
|
+
this._packageId = _packageId;
|
|
14
|
+
this._regularPrice = _regularPrice;
|
|
15
|
+
this._offerPrice = _offerPrice;
|
|
16
|
+
}
|
|
17
|
+
// The package this price applies to. Nothing nests on the wire, so this is how the catalog finds
|
|
18
|
+
// the price of a package.
|
|
19
|
+
get packageId() {
|
|
20
|
+
return this._packageId;
|
|
21
|
+
}
|
|
22
|
+
// The list this price belongs to, which is the parent id every item has
|
|
23
|
+
get priceListId() {
|
|
24
|
+
return this.parentItemId;
|
|
25
|
+
}
|
|
26
|
+
get regularPrice() {
|
|
27
|
+
return this._regularPrice;
|
|
28
|
+
}
|
|
29
|
+
// Zero when this package is not on offer. Never greater than the regular price.
|
|
30
|
+
get offerPrice() {
|
|
31
|
+
return this._offerPrice;
|
|
32
|
+
}
|
|
33
|
+
// What a customer actually pays: the offer price when there is one, else the regular price.
|
|
34
|
+
// Computed here (not sent), matching the "on offer" definition from Price.proto.
|
|
35
|
+
get finalPrice() {
|
|
36
|
+
return this.isOnOffer ? this._offerPrice : this._regularPrice;
|
|
37
|
+
}
|
|
38
|
+
get isOnOffer() {
|
|
39
|
+
return this._offerPrice > 0 && this._offerPrice < this._regularPrice;
|
|
40
|
+
}
|
|
41
|
+
// What the offer takes off the regular price, and zero when there is no offer
|
|
42
|
+
get discount() {
|
|
43
|
+
return this._regularPrice - this.finalPrice;
|
|
44
|
+
}
|
|
45
|
+
// Discount as an exact, unrounded percentage of the regular price - rounding is left to the UI.
|
|
46
|
+
// Zero when the regular price is zero.
|
|
47
|
+
get discountPercent() {
|
|
48
|
+
if (this._regularPrice <= 0)
|
|
49
|
+
return 0;
|
|
50
|
+
return (this.discount / this._regularPrice) * 100;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import Item from "./Item";
|
|
2
|
+
// A named list of prices. A storefront sells from exactly one, so no package ever has two prices
|
|
3
|
+
// to choose between; it's carried (not just a bare id) because a client naming a cart needs it.
|
|
4
|
+
export default class PriceList extends Item {
|
|
5
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ProductType as proto_ProductType } from "./generated/ProductType";
|
|
2
|
+
import Address from "./Address";
|
|
3
|
+
import { EntityHeader } from "./Entity";
|
|
4
|
+
import Item from "./Item";
|
|
5
|
+
import Package from "./Package";
|
|
6
|
+
import Photo from "./Photo";
|
|
7
|
+
import Price from "./Price";
|
|
8
|
+
import Tax from "./Tax";
|
|
9
|
+
export default class Product extends Item {
|
|
10
|
+
private readonly _productType;
|
|
11
|
+
private readonly _brand;
|
|
12
|
+
private readonly _isManufacturedByBusiness;
|
|
13
|
+
private readonly _manufacturer;
|
|
14
|
+
private readonly _manufacturerAddress;
|
|
15
|
+
private readonly _taxes;
|
|
16
|
+
private readonly _features;
|
|
17
|
+
private readonly _photos;
|
|
18
|
+
private readonly _packages;
|
|
19
|
+
constructor(header: EntityHeader, name: string, description: string | null, productCategoryId: bigint, isDisabled: boolean, _productType: proto_ProductType, _brand: string | null, _isManufacturedByBusiness: boolean | null, _manufacturer: string | null, _manufacturerAddress: Address | null, _taxes: ReadonlyArray<Tax>, _features: ReadonlyArray<string>, _photos: ReadonlyArray<Photo>, _packages: ReadonlyArray<Package>);
|
|
20
|
+
get productCategoryId(): bigint;
|
|
21
|
+
get productType(): proto_ProductType;
|
|
22
|
+
get brand(): string | null;
|
|
23
|
+
get isManufacturedByBusiness(): boolean | null;
|
|
24
|
+
get manufacturer(): string | null;
|
|
25
|
+
get manufacturerAddress(): Address | null;
|
|
26
|
+
get taxes(): ReadonlyArray<Tax>;
|
|
27
|
+
get features(): ReadonlyArray<string>;
|
|
28
|
+
get photos(): ReadonlyArray<Photo>;
|
|
29
|
+
get packages(): ReadonlyArray<Package>;
|
|
30
|
+
get lowestPrice(): Price | null;
|
|
31
|
+
get isOnOffer(): boolean;
|
|
32
|
+
get isBuyable(): boolean;
|
|
33
|
+
}
|
package/dist/Product.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import Item from "./Item";
|
|
2
|
+
// A product in the catalog: goods, a service, a raw material or a fixed asset. Built complete
|
|
3
|
+
// (photos/packages resolved first) so everything here is readonly except category (via parentItemId).
|
|
4
|
+
export default class Product extends Item {
|
|
5
|
+
constructor(header, name, description, productCategoryId, isDisabled, _productType, _brand, _isManufacturedByBusiness, _manufacturer, _manufacturerAddress, _taxes, _features, _photos, _packages) {
|
|
6
|
+
super(header, name, description, productCategoryId, isDisabled);
|
|
7
|
+
this._productType = _productType;
|
|
8
|
+
this._brand = _brand;
|
|
9
|
+
this._isManufacturedByBusiness = _isManufacturedByBusiness;
|
|
10
|
+
this._manufacturer = _manufacturer;
|
|
11
|
+
this._manufacturerAddress = _manufacturerAddress;
|
|
12
|
+
this._taxes = _taxes;
|
|
13
|
+
this._features = _features;
|
|
14
|
+
this._photos = _photos;
|
|
15
|
+
this._packages = _packages;
|
|
16
|
+
}
|
|
17
|
+
// The category this product is in, or Constants.ENTITY_ID_NULL when it is in none
|
|
18
|
+
get productCategoryId() {
|
|
19
|
+
return this.parentItemId;
|
|
20
|
+
}
|
|
21
|
+
get productType() {
|
|
22
|
+
return this._productType;
|
|
23
|
+
}
|
|
24
|
+
get brand() {
|
|
25
|
+
return this._brand;
|
|
26
|
+
}
|
|
27
|
+
// Null when the business hasn't said either way - the three states are why this isn't a plain
|
|
28
|
+
// boolean.
|
|
29
|
+
get isManufacturedByBusiness() {
|
|
30
|
+
return this._isManufacturedByBusiness;
|
|
31
|
+
}
|
|
32
|
+
get manufacturer() {
|
|
33
|
+
return this._manufacturer;
|
|
34
|
+
}
|
|
35
|
+
get manufacturerAddress() {
|
|
36
|
+
return this._manufacturerAddress;
|
|
37
|
+
}
|
|
38
|
+
get taxes() {
|
|
39
|
+
return this._taxes;
|
|
40
|
+
}
|
|
41
|
+
// One line bullet points about this product
|
|
42
|
+
get features() {
|
|
43
|
+
return this._features;
|
|
44
|
+
}
|
|
45
|
+
get photos() {
|
|
46
|
+
return this._photos;
|
|
47
|
+
}
|
|
48
|
+
// Every variant of this product, in the order they arrived - ordering them for display is a UI
|
|
49
|
+
// decision, see Catalog.comparePackages. A product with no packages cannot be bought.
|
|
50
|
+
get packages() {
|
|
51
|
+
return this._packages;
|
|
52
|
+
}
|
|
53
|
+
// The cheapest final price across variants (what a listing shows as "from"), or null if none has
|
|
54
|
+
// a price. Compares final price, not regular, since that's what a customer would actually pay.
|
|
55
|
+
get lowestPrice() {
|
|
56
|
+
let result = null;
|
|
57
|
+
for (const pkg of this._packages) {
|
|
58
|
+
const price = pkg.price;
|
|
59
|
+
if (price === null)
|
|
60
|
+
continue; // This variant cannot be bought
|
|
61
|
+
if (result === null || price.finalPrice < result.finalPrice)
|
|
62
|
+
result = price;
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
// True when any variant of this product is on offer, which is what a listing puts a badge on
|
|
67
|
+
get isOnOffer() {
|
|
68
|
+
for (const pkg of this._packages)
|
|
69
|
+
if (pkg.price?.isOnOffer === true)
|
|
70
|
+
return true;
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
// True when this product itself is enabled and at least one variant is buyable. The server
|
|
74
|
+
// still filters out draft and non-public products before they ever arrive, but isDisabled can
|
|
75
|
+
// change after an item exists, so it is checked here rather than trusted to have been filtered.
|
|
76
|
+
get isBuyable() {
|
|
77
|
+
if (this.isDisabled)
|
|
78
|
+
return false;
|
|
79
|
+
for (const pkg of this._packages)
|
|
80
|
+
if (pkg.isBuyable)
|
|
81
|
+
return true;
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Item from "./Item";
|
|
2
|
+
import Product from "./Product";
|
|
3
|
+
export default class ProductCategory extends Item {
|
|
4
|
+
get products(): ReadonlyArray<Product>;
|
|
5
|
+
private set products(value);
|
|
6
|
+
private _products;
|
|
7
|
+
}
|
|
8
|
+
export interface UpdatableProductCategory {
|
|
9
|
+
set products(value: ReadonlyArray<Product>);
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Item from "./Item";
|
|
2
|
+
// A category that groups products, real or the dummy one a Catalog builds to stand in for a
|
|
3
|
+
// product with no category of its own. Products are set once by the Catalog that builds this, not
|
|
4
|
+
// passed to the constructor - the full set isn't known until every product has been read. A
|
|
5
|
+
// Catalog never builds one of these with an empty products array - see Catalog for why.
|
|
6
|
+
export default class ProductCategory extends Item {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this._products = Object.freeze([]);
|
|
10
|
+
}
|
|
11
|
+
// Every buyable product whose productCategoryId names this category, in the order they arrived
|
|
12
|
+
get products() {
|
|
13
|
+
return this._products;
|
|
14
|
+
}
|
|
15
|
+
set products(value) {
|
|
16
|
+
this._products = value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import BusinessLink from "./BusinessLink";
|
|
2
|
+
import BusinessProfile from "./BusinessProfile";
|
|
3
|
+
import UserProfile from "./UserProfile";
|
|
4
|
+
export default class Profile {
|
|
5
|
+
private readonly _profileId;
|
|
6
|
+
private readonly _user;
|
|
7
|
+
constructor(_profileId: string, _user: UserProfile | null, businessLinks: ReadonlyArray<BusinessLink>, businesses: ReadonlyArray<BusinessProfile>);
|
|
8
|
+
get profileId(): string;
|
|
9
|
+
get user(): UserProfile | null;
|
|
10
|
+
get businessLinks(): ReadonlyArray<BusinessLink>;
|
|
11
|
+
get businesses(): ReadonlyArray<BusinessProfile>;
|
|
12
|
+
getBusiness(businessEntityId: bigint): BusinessProfile | null;
|
|
13
|
+
getBusinessLink(businessEntityId: bigint): BusinessLink | null;
|
|
14
|
+
getBusinessLinkFor(businessId: string): BusinessLink | null;
|
|
15
|
+
toString(): string;
|
|
16
|
+
private readonly _businessLinks;
|
|
17
|
+
private readonly _businesses;
|
|
18
|
+
private readonly _businessMap;
|
|
19
|
+
private readonly _businessLinkMap;
|
|
20
|
+
}
|
package/dist/Profile.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Everything one profile container holds: the customer, the businesses they may reach, and the
|
|
2
|
+
// link to each. Rebuilt by the sync layer from a profile container; not itself on the wire.
|
|
3
|
+
export default class Profile {
|
|
4
|
+
constructor(_profileId, _user, businessLinks, businesses) {
|
|
5
|
+
this._profileId = _profileId;
|
|
6
|
+
this._user = _user;
|
|
7
|
+
this._businessMap = new Map();
|
|
8
|
+
this._businessLinkMap = new Map();
|
|
9
|
+
// A business is listed only when its link is still held; a revoked link is removed by the
|
|
10
|
+
// sync but the business it named is not, so filtering here hides it without discarding it.
|
|
11
|
+
const linkedBusinessIds = new Set();
|
|
12
|
+
for (const businessLink of businessLinks)
|
|
13
|
+
linkedBusinessIds.add(businessLink.businessId);
|
|
14
|
+
this._businessLinks = Object.freeze([...businessLinks]);
|
|
15
|
+
this._businesses = Object.freeze(businesses.filter((business) => linkedBusinessIds.has(business.id)));
|
|
16
|
+
for (const business of this._businesses)
|
|
17
|
+
this._businessMap.set(business.id, business);
|
|
18
|
+
for (const businessLink of this._businessLinks)
|
|
19
|
+
this._businessLinkMap.set(businessLink.businessId, businessLink);
|
|
20
|
+
}
|
|
21
|
+
// The id of the profile container this was built from, and what Model.signIn was given
|
|
22
|
+
get profileId() {
|
|
23
|
+
return this._profileId;
|
|
24
|
+
}
|
|
25
|
+
// Null until a profile sync in has brought one, and after a tombstone for it
|
|
26
|
+
get user() {
|
|
27
|
+
return this._user;
|
|
28
|
+
}
|
|
29
|
+
// One per business this customer may reach, each carrying the token for it
|
|
30
|
+
get businessLinks() {
|
|
31
|
+
return this._businessLinks;
|
|
32
|
+
}
|
|
33
|
+
// The businesses those links name, in no particular order - a UI orders these for display
|
|
34
|
+
get businesses() {
|
|
35
|
+
return this._businesses;
|
|
36
|
+
}
|
|
37
|
+
getBusiness(businessEntityId) {
|
|
38
|
+
return this._businessMap.get(businessEntityId) ?? null;
|
|
39
|
+
}
|
|
40
|
+
// BusinessLink.businessId is an entity id, matching Business.entity.id and not the url friendly
|
|
41
|
+
// businessId - this join spares a caller from having to remember which one it is holding
|
|
42
|
+
getBusinessLink(businessEntityId) {
|
|
43
|
+
return this._businessLinkMap.get(businessEntityId) ?? null;
|
|
44
|
+
}
|
|
45
|
+
// The same, by the url friendly business id a storefront is reached by
|
|
46
|
+
getBusinessLinkFor(businessId) {
|
|
47
|
+
for (const business of this._businesses)
|
|
48
|
+
if (business.businessId === businessId)
|
|
49
|
+
return this.getBusinessLink(business.id);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
toString() {
|
|
53
|
+
return `Profile(profileId=${this._profileId}, user=${this._user?.formattedName ?? "none"}, businesses=${this._businesses.length})`;
|
|
54
|
+
}
|
|
55
|
+
}
|