@peabody-soft/mbs-model-ts 1.4.0 → 1.6.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/Address.js +8 -11
- package/dist/Attachment.js +7 -8
- package/dist/AttachmentBaseUrl.js +10 -10
- package/dist/AuthTokens.js +12 -7
- package/dist/Business.js +19 -19
- package/dist/BusinessIdentifier.js +2 -2
- package/dist/BusinessLink.js +16 -16
- package/dist/BusinessProfile.js +4 -4
- package/dist/CartEditor.d.ts +10 -5
- package/dist/CartEditor.js +258 -180
- package/dist/Catalog.js +31 -29
- package/dist/Constants.js +10 -10
- package/dist/ContainerNames.js +10 -11
- package/dist/Entity.js +11 -9
- package/dist/Enums.d.ts +1 -1
- package/dist/Enums.js +4 -3
- package/dist/Exceptions.js +2 -2
- package/dist/GeneralSettings.d.ts +4 -2
- package/dist/GeneralSettings.js +30 -18
- package/dist/HttpStatusCodes.js +10 -11
- package/dist/Ids.d.ts +2 -0
- package/dist/Ids.js +28 -24
- package/dist/Item.js +6 -7
- package/dist/LatLong.js +3 -3
- package/dist/LiveData.js +6 -6
- package/dist/Measures.js +2 -2
- package/dist/Message.js +6 -5
- package/dist/MockDatabase.js +2 -2
- package/dist/Model.d.ts +5 -0
- package/dist/Model.js +400 -254
- package/dist/Order.js +20 -17
- package/dist/Package.js +7 -8
- package/dist/PackageIdentifier.js +2 -2
- package/dist/PaymentMethodDetail.js +4 -4
- package/dist/Photo.js +6 -7
- package/dist/Price.js +9 -6
- package/dist/PriceList.js +2 -2
- package/dist/Product.d.ts +5 -3
- package/dist/Product.js +26 -19
- package/dist/ProductCategory.js +3 -4
- package/dist/Profile.d.ts +1 -0
- package/dist/Profile.js +94 -8
- package/dist/ProtoMap.d.ts +18 -8
- package/dist/ProtoMap.js +451 -331
- package/dist/Routes.js +3 -3
- package/dist/ServiceExceptions.js +11 -12
- package/dist/ServiceProxy.js +19 -23
- package/dist/ShoppingList.d.ts +30 -1
- package/dist/ShoppingList.js +339 -47
- package/dist/SyncCache.d.ts +12 -0
- package/dist/SyncCache.js +136 -56
- package/dist/SyncKeys.js +8 -8
- package/dist/SyncState.js +5 -5
- package/dist/Tax.d.ts +12 -4
- package/dist/Tax.js +37 -13
- package/dist/TaxHelper.d.ts +12 -0
- package/dist/TaxHelper.js +85 -0
- package/dist/TaxType.d.ts +7 -0
- package/dist/TaxType.js +31 -0
- package/dist/UserProfile.js +4 -4
- package/dist/WorkingDays.js +15 -15
- package/dist/generated/AttachmentType.d.ts +19 -1
- package/dist/generated/AttachmentType.js +18 -0
- package/dist/generated/AuthTokens.d.ts +3 -1
- package/dist/generated/BusinessLink.d.ts +4 -1
- package/dist/generated/BusinessSyncInRequest.d.ts +11 -3
- package/dist/generated/BusinessSyncInResponse.d.ts +5 -4
- package/dist/generated/BusinessSyncOutRequest.d.ts +37 -10
- package/dist/generated/BusinessSyncOutRequest.js +42 -29
- package/dist/generated/BusinessSyncOutResponse.d.ts +14 -1
- package/dist/generated/Configuration.d.ts +2 -1
- package/dist/generated/CreateUserRequest.d.ts +8 -2
- package/dist/generated/Entity.d.ts +7 -3
- package/dist/generated/GeneralSettings.d.ts +14 -4
- package/dist/generated/GeneralSettings.js +9 -1
- package/dist/generated/Message.d.ts +4 -2
- package/dist/generated/Product.d.ts +10 -1
- package/dist/generated/Product.js +9 -1
- package/dist/generated/ProfileSyncOutRequest.d.ts +17 -1
- package/dist/generated/ProfileSyncOutResponse.d.ts +8 -3
- package/dist/generated/SalesOrderPayload.d.ts +7 -2
- package/dist/generated/ShoppingList.d.ts +6 -3
- package/dist/generated/ShoppingListItem.d.ts +21 -6
- package/dist/generated/Tax.d.ts +4 -4
- package/dist/generated/Tax.js +7 -8
- package/dist/generated/WorkingHoursRange.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -10
- package/package.json +55 -55
- package/dist/generated/TaxType.d.ts +0 -25
- package/dist/generated/TaxType.js +0 -30
package/dist/Routes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The last path segment of each call this library makes, appended to the base url a ServiceProxy is
|
|
2
|
-
// built with. Named after the server method
|
|
3
|
-
//
|
|
4
|
-
// No route takes an id:
|
|
2
|
+
// built with. Named after the server method, in the kebab case Java Routes.java uses, with a prefix
|
|
3
|
+
// that keeps storefront methods apart from the merchant ones on the same host.
|
|
4
|
+
// No route takes an id: the request message carries everything.
|
|
5
5
|
class Routes {
|
|
6
6
|
}
|
|
7
7
|
Routes.BUSINESS_SYNC_OUT = "shop-business-sync-out";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// What a Service call fails with. Unlike the two in Exceptions.ts these are not programming errors
|
|
2
|
-
//
|
|
3
|
-
// it
|
|
4
|
-
//
|
|
5
|
-
// Each carries the status code
|
|
6
|
-
//
|
|
1
|
+
// What a Service call fails with. Unlike the two in Exceptions.ts these are not programming errors.
|
|
2
|
+
// A caller is expected to catch them and decide what to do: sign in again, retry, or show the shop
|
|
3
|
+
// it has cached. They mirror Java com.merabills.repository.client.exception, so both clients of
|
|
4
|
+
// this server describe a failure the same way.
|
|
5
|
+
// Each carries the status code. The derived classes let a caller catch the one case it can handle
|
|
6
|
+
// without testing a number.
|
|
7
7
|
// A call reached the server and the server refused it. Thrown directly for a status code none of the
|
|
8
|
-
// classes below names, so an unrecognised failure is still a ServiceException
|
|
8
|
+
// classes below names, so an unrecognised failure is still a ServiceException.
|
|
9
9
|
export class ServiceException extends Error {
|
|
10
10
|
constructor(httpStatusCode, message) {
|
|
11
11
|
super(message);
|
|
@@ -70,9 +70,9 @@ export class ServiceUnavailableException extends ServiceException {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
ServiceUnavailableException.STATUS_CODE = 503;
|
|
73
|
-
// The call never got an answer
|
|
74
|
-
// Not a ServiceException,
|
|
75
|
-
// request
|
|
73
|
+
// The call never got an answer: offline, DNS, TLS, a refused connection or one cut short.
|
|
74
|
+
// Not a ServiceException, since there is no status code and the server may have acted on the
|
|
75
|
+
// request. A caller that retries must be prepared for the first attempt to have succeeded.
|
|
76
76
|
export class NetworkConnectionException extends Error {
|
|
77
77
|
constructor(message, reason) {
|
|
78
78
|
super(message);
|
|
@@ -80,5 +80,4 @@ export class NetworkConnectionException extends Error {
|
|
|
80
80
|
this.name = new.target.name;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
//
|
|
84
|
-
// in its exception package and the mapping in HttpStatusCodes.
|
|
83
|
+
// The status code each of these stands for is mapped in HttpStatusCodes.ts.
|
package/dist/ServiceProxy.js
CHANGED
|
@@ -12,14 +12,13 @@ import { buildAuthTokensBytes } from "./ProtoMap";
|
|
|
12
12
|
import Routes from "./Routes";
|
|
13
13
|
import { NetworkConnectionException } from "./ServiceExceptions";
|
|
14
14
|
// A Service that reaches a real MeraBills server. Every call is one POST to the route named after
|
|
15
|
-
// it,
|
|
16
|
-
//
|
|
17
|
-
// One call is one page:
|
|
18
|
-
//
|
|
15
|
+
// it, with the encoded request message as the body and the encoded response message as the answer.
|
|
16
|
+
// This class translates nothing and reads no field of either.
|
|
17
|
+
// One call is one page: the loop over a paged sync out belongs to whoever caches what comes back,
|
|
18
|
+
// so each page is written as it arrives (see Model.businessSyncIn).
|
|
19
19
|
export default class ServiceProxy {
|
|
20
|
-
// The base url is everything before the route, with or without a trailing slash
|
|
21
|
-
//
|
|
22
|
-
// under a prefix works without the caller having to know how a route is built.
|
|
20
|
+
// The base url is everything before the route, with or without a trailing slash or a path of its
|
|
21
|
+
// own. The route is joined onto it, so a server reached under a prefix works.
|
|
23
22
|
constructor(serviceBaseUrl, fetchFunction = null) {
|
|
24
23
|
this._serviceBaseUrl = serviceBaseUrl.replace(TRAILING_SLASHES, "");
|
|
25
24
|
this._fetchFunction = fetchFunction;
|
|
@@ -40,8 +39,8 @@ export default class ServiceProxy {
|
|
|
40
39
|
async updateUser(user, authTokens) {
|
|
41
40
|
return this.post(Routes.UPDATE_USER, proto_User, user, proto_ProfileSyncOutResponse, authTokens);
|
|
42
41
|
}
|
|
43
|
-
// One call: encode, send, turn a refusal into
|
|
44
|
-
//
|
|
42
|
+
// One call: encode, send, turn a refusal into its exception, decode. The message types are
|
|
43
|
+
// passed in so every route is sent and read the same way.
|
|
45
44
|
async post(route, requestType, request, responseType, authTokens) {
|
|
46
45
|
const response = await this.send(route, requestType.toBinary(request), authTokens);
|
|
47
46
|
// The body of a failure is not a response message, so it has to be dealt with before decoding
|
|
@@ -51,8 +50,8 @@ export default class ServiceProxy {
|
|
|
51
50
|
}
|
|
52
51
|
async send(route, body, authTokens) {
|
|
53
52
|
const headers = { [CONTENT_TYPE_HEADER]: CONTENT_TYPE_PROTOBUF };
|
|
54
|
-
// An anonymous visitor
|
|
55
|
-
//
|
|
53
|
+
// An anonymous visitor gets no header, not an empty one. The protocol has no anonymous form of
|
|
54
|
+
// the message, so the absence says nobody claims to be calling.
|
|
56
55
|
if (authTokens !== null)
|
|
57
56
|
headers[AUTHORIZATION_HEADER] = toBase64(buildAuthTokensBytes(authTokens));
|
|
58
57
|
try {
|
|
@@ -63,14 +62,13 @@ export default class ServiceProxy {
|
|
|
63
62
|
});
|
|
64
63
|
}
|
|
65
64
|
catch (reason) {
|
|
66
|
-
// fetch rejects only when no answer arrived
|
|
67
|
-
//
|
|
68
|
-
// that retries has to be prepared for the first attempt to have succeeded.
|
|
65
|
+
// fetch rejects only when no answer arrived. A refusal resolves with a status code. See
|
|
66
|
+
// NetworkConnectionException for what a caller must expect.
|
|
69
67
|
throw new NetworkConnectionException(`The call to ${route} could not be completed`, reason);
|
|
70
68
|
}
|
|
71
69
|
}
|
|
72
|
-
// Resolved per call
|
|
73
|
-
//
|
|
70
|
+
// Resolved per call, not at construction, so a platform that installs fetch after this object is
|
|
71
|
+
// built still works and an absent fetch fails where it is needed.
|
|
74
72
|
getFetchFunction() {
|
|
75
73
|
const supplied = this._fetchFunction;
|
|
76
74
|
if (supplied !== null)
|
|
@@ -82,9 +80,8 @@ export default class ServiceProxy {
|
|
|
82
80
|
return platform.bind(globalThis);
|
|
83
81
|
}
|
|
84
82
|
// What the response says went wrong, if anything. This protocol has no error message of its own
|
|
85
|
-
// yet, so
|
|
86
|
-
//
|
|
87
|
-
// does not already.
|
|
83
|
+
// yet, so a failure body can be anything (a stack trace, an HTML page) and only its start is
|
|
84
|
+
// worth carrying. A body that cannot be read adds nothing to the status code.
|
|
88
85
|
static async readErrorMessage(route, response) {
|
|
89
86
|
let body;
|
|
90
87
|
try {
|
|
@@ -99,11 +96,10 @@ export default class ServiceProxy {
|
|
|
99
96
|
}
|
|
100
97
|
}
|
|
101
98
|
// A header carries text, so the encoded credentials travel as base64. No scheme prefix: the server
|
|
102
|
-
// reads the whole value as one encoded AuthTokens,
|
|
103
|
-
// as one serialized AuthTokens.
|
|
99
|
+
// reads the whole value as one encoded AuthTokens, as the Java client sends it.
|
|
104
100
|
function toBase64(bytes) {
|
|
105
|
-
// Built a character at a time
|
|
106
|
-
//
|
|
101
|
+
// Built a character at a time, since spreading the array into String.fromCharCode passes it as an
|
|
102
|
+
// argument list and overflows the stack when long enough
|
|
107
103
|
let binary = "";
|
|
108
104
|
for (const byte of bytes)
|
|
109
105
|
binary += String.fromCharCode(byte);
|
package/dist/ShoppingList.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ReservedPackage as proto_ReservedPackage } from "./generated/ReservedPackage";
|
|
2
|
+
import Tax, { TaxAmount } from "./Tax";
|
|
2
3
|
export default class ShoppingList {
|
|
3
4
|
private readonly _isFinal;
|
|
4
5
|
private readonly _autoAddDeliveryCharge;
|
|
@@ -12,6 +13,7 @@ export default class ShoppingList {
|
|
|
12
13
|
private readonly _existingItems;
|
|
13
14
|
private readonly _deletedItems;
|
|
14
15
|
static fromScaledValues(isFinal: boolean, autoAddDeliveryCharge: boolean, autoAddServiceCharge: boolean, inventoryLocationId: number, priceListId: bigint, scaledTotalAmountBeforeDiscount: bigint, scaledDiscount: bigint, existingItemCount: number, deletedItemCount: number, existingItems: ReadonlyArray<ShoppingListItem>, deletedItems: ReadonlyArray<ShoppingListItem>): ShoppingList;
|
|
16
|
+
static sumOfFinalPrices(items: ReadonlyArray<ShoppingListItem>): number;
|
|
15
17
|
constructor(_isFinal: boolean, _autoAddDeliveryCharge: boolean, _autoAddServiceCharge: boolean, _inventoryLocationId: number, _priceListId: bigint, _totalAmountBeforeDiscount: number, _discount: number, _existingItemCount: number, _deletedItemCount: number, _existingItems: ReadonlyArray<ShoppingListItem>, _deletedItems: ReadonlyArray<ShoppingListItem>);
|
|
16
18
|
get isFinal(): boolean;
|
|
17
19
|
get autoAddDeliveryCharge(): boolean;
|
|
@@ -26,8 +28,19 @@ export default class ShoppingList {
|
|
|
26
28
|
get itemCount(): number;
|
|
27
29
|
get existingItems(): ReadonlyArray<ShoppingListItem>;
|
|
28
30
|
get deletedItems(): ReadonlyArray<ShoppingListItem>;
|
|
31
|
+
get goodsItems(): ReadonlyArray<ShoppingListItem>;
|
|
32
|
+
get chargeItems(): ReadonlyArray<ShoppingListItem>;
|
|
33
|
+
get deliveryCharge(): ShoppingListItem | null;
|
|
34
|
+
get serviceCharge(): ShoppingListItem | null;
|
|
35
|
+
get removedItems(): ReadonlyArray<ShoppingListItem>;
|
|
36
|
+
changeOf(item: ShoppingListItem): ItemChange;
|
|
29
37
|
get computedTotal(): number;
|
|
38
|
+
get computedGoodsTotal(): number;
|
|
30
39
|
get computedTotalTax(): number;
|
|
40
|
+
get computedTaxes(): ReadonlyArray<TaxAmount>;
|
|
41
|
+
get computedTotalWithoutDiscounts(): number;
|
|
42
|
+
get savings(): number;
|
|
43
|
+
private get derived();
|
|
31
44
|
static readonly EMPTY: ShoppingList;
|
|
32
45
|
}
|
|
33
46
|
export declare class ShoppingListItem {
|
|
@@ -47,18 +60,34 @@ export declare class ShoppingListItem {
|
|
|
47
60
|
constructor(_packageId: bigint, _quantity: number, _unitPrice: number, _shoppingListOrder: number, _isOriginal: boolean, _isModified: boolean, _isStockKeepingRequired: boolean, _priceDiscount: number, _discount: number, _taxes: ReadonlyArray<Tax>, _expiryMinutes: number, _description: string | null);
|
|
48
61
|
get packageId(): bigint;
|
|
49
62
|
get isReservedPackage(): boolean;
|
|
63
|
+
get reservedPackage(): proto_ReservedPackage | null;
|
|
50
64
|
get quantity(): number;
|
|
51
65
|
get unitPrice(): number;
|
|
52
66
|
get shoppingListOrder(): number;
|
|
53
67
|
get isOriginal(): boolean;
|
|
54
68
|
get isModified(): boolean;
|
|
69
|
+
get change(): ItemChange;
|
|
55
70
|
get isStockKeepingRequired(): boolean;
|
|
56
71
|
get priceDiscount(): number;
|
|
57
72
|
get discount(): number;
|
|
58
73
|
get taxes(): ReadonlyArray<Tax>;
|
|
59
74
|
get expiryMinutes(): number;
|
|
60
75
|
get description(): string | null;
|
|
76
|
+
get regularUnitPrice(): number;
|
|
77
|
+
get unitPriceWithTaxes(): number;
|
|
78
|
+
get regularUnitPriceWithTaxes(): number;
|
|
61
79
|
get amount(): number;
|
|
80
|
+
get taxAmounts(): ReadonlyArray<number>;
|
|
62
81
|
get totalTax(): number;
|
|
63
82
|
get finalPrice(): number;
|
|
83
|
+
get finalPriceWithoutDiscounts(): number;
|
|
84
|
+
get isDiscounted(): boolean;
|
|
85
|
+
get isFree(): boolean;
|
|
64
86
|
}
|
|
87
|
+
export declare enum ItemChange {
|
|
88
|
+
NONE = 0,
|
|
89
|
+
ADDED = 1,
|
|
90
|
+
MODIFIED = 2,
|
|
91
|
+
REMOVED = 3
|
|
92
|
+
}
|
|
93
|
+
export declare function validatePricing(item: ShoppingListItem): void;
|