@peabody-soft/mbs-model-ts 1.11.0 → 1.13.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/Constants.d.ts +1 -0
- package/dist/Constants.js +3 -0
- package/dist/Exceptions.d.ts +5 -0
- package/dist/Exceptions.js +16 -2
- package/dist/Ids.d.ts +1 -0
- package/dist/Ids.js +5 -3
- package/dist/InMemoryLock.d.ts +5 -0
- package/dist/InMemoryLock.js +20 -0
- package/dist/Lock.d.ts +3 -0
- package/dist/Lock.js +1 -0
- package/dist/Message.d.ts +1 -5
- package/dist/Message.js +2 -12
- package/dist/Model.d.ts +17 -4
- package/dist/Model.js +304 -113
- package/dist/Order.d.ts +2 -2
- package/dist/Order.js +4 -4
- package/dist/ProtoMap.d.ts +13 -4
- package/dist/ProtoMap.js +139 -71
- package/dist/Service.d.ts +3 -4
- package/dist/ServiceProxy.d.ts +3 -4
- package/dist/ServiceProxy.js +4 -6
- package/dist/SyncCache.d.ts +6 -2
- package/dist/SyncCache.js +83 -44
- package/dist/SyncKeys.js +3 -2
- package/dist/generated/BusinessSyncInRequest.d.ts +30 -16
- package/dist/generated/BusinessSyncInRequest.js +9 -1
- package/dist/generated/BusinessSyncInResponse.d.ts +9 -6
- package/dist/generated/Constants.d.ts +2 -12
- package/dist/generated/Constants.js +2 -12
- package/dist/generated/Message.d.ts +5 -16
- package/dist/generated/Message.js +8 -22
- package/dist/generated/Party.d.ts +52 -0
- package/dist/generated/Party.js +68 -0
- package/dist/generated/PartyPreferencesPayload.d.ts +2 -1
- package/dist/generated/ProfileSyncOutRequest.d.ts +2 -0
- package/dist/generated/ProfileSyncOutResponse.d.ts +2 -2
- package/dist/generated/SalesOrderPayload.d.ts +9 -8
- package/dist/generated/User.d.ts +3 -1
- package/dist/generated/UserRequest.d.ts +52 -0
- package/dist/generated/{CreateUserRequest.js → UserRequest.js} +11 -11
- package/dist/index.d.ts +4 -2
- package/dist/index.js +7 -5
- package/package.json +2 -2
- package/dist/generated/CreateUserRequest.d.ts +0 -43
package/dist/Constants.d.ts
CHANGED
|
@@ -9,3 +9,4 @@ export declare function quantityFromScaledValue(scaledQuantity: number): number;
|
|
|
9
9
|
export declare function quantityToScaledValue(quantity: number): number;
|
|
10
10
|
export declare function taxRateFromScaledValue(scaledTaxRate: number): number;
|
|
11
11
|
export declare function taxRateToScaledValue(taxRate: number): number;
|
|
12
|
+
export declare const MAX_PROFILE_STALENESS_MS: number;
|
package/dist/Constants.js
CHANGED
|
@@ -44,3 +44,6 @@ export function taxRateFromScaledValue(scaledTaxRate) {
|
|
|
44
44
|
export function taxRateToScaledValue(taxRate) {
|
|
45
45
|
return Math.round(taxRate * (proto_Constants.TAX_RATE_FACTOR / 100));
|
|
46
46
|
}
|
|
47
|
+
// How long a signed-in customer's profile may go without a read before Model.refreshProfileIfStale
|
|
48
|
+
// reads it again. A profile changes only when the customer edits it, on this or another device.
|
|
49
|
+
export const MAX_PROFILE_STALENESS_MS = 60 * 60 * 1000;
|
package/dist/Exceptions.d.ts
CHANGED
|
@@ -2,3 +2,8 @@ export declare class InvalidArgumentException extends Error {
|
|
|
2
2
|
}
|
|
3
3
|
export declare class IllegalOperationException extends Error {
|
|
4
4
|
}
|
|
5
|
+
export declare class StoreCorruptException extends Error {
|
|
6
|
+
readonly containerName: string;
|
|
7
|
+
readonly reason: unknown;
|
|
8
|
+
constructor(containerName: string, reason: unknown);
|
|
9
|
+
}
|
package/dist/Exceptions.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
// The two programming errors this library throws
|
|
2
|
-
// failure is a rejected promise (see
|
|
1
|
+
// The two programming errors this library throws, and the exception for a store it cannot read. A
|
|
2
|
+
// UI does not recover from a programming error. A sync failure is a rejected promise (see
|
|
3
|
+
// ServiceExceptions.ts).
|
|
3
4
|
// A caller passed something this library cannot work with
|
|
4
5
|
export class InvalidArgumentException extends Error {
|
|
5
6
|
}
|
|
6
7
|
// A caller did something in an order this library does not allow
|
|
7
8
|
export class IllegalOperationException extends Error {
|
|
8
9
|
}
|
|
10
|
+
// The store holds data that cannot be decoded, for example a blob cut short or one written by an
|
|
11
|
+
// incompatible version. Everything in a store came from a server, except a cart that was not sent
|
|
12
|
+
// and the id of a sign up that is under way. So deleting the containers and calling
|
|
13
|
+
// Model.initialize again recovers: SyncCache keeps the containers it has opened, so a new
|
|
14
|
+
// Model.initialize is needed after a delete.
|
|
15
|
+
// containerName is the container that failed, and reason is what the decoder threw.
|
|
16
|
+
export class StoreCorruptException extends Error {
|
|
17
|
+
constructor(containerName, reason) {
|
|
18
|
+
super(`The store holds data in container ${containerName} that cannot be read`);
|
|
19
|
+
this.containerName = containerName;
|
|
20
|
+
this.reason = reason;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/dist/Ids.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export default class Ids {
|
|
|
13
13
|
static readonly GENERAL_SETTINGS_CONFIGURATION_ID: bigint;
|
|
14
14
|
static readonly ATTACHMENT_BASE_URL_BLOB_ID: bigint;
|
|
15
15
|
static readonly AUTH_TOKENS_BLOB_ID: bigint;
|
|
16
|
+
static readonly USER_ID_BLOB_ID: bigint;
|
|
16
17
|
private static readonly SYNC_CURSOR_BLOB_ID_BASE;
|
|
17
18
|
private static readonly UNSIGNED_64_BIT_MASK;
|
|
18
19
|
private static readonly UNSIGNED_32_BIT_MASK;
|
package/dist/Ids.js
CHANGED
|
@@ -15,8 +15,8 @@ class Ids {
|
|
|
15
15
|
return (BigInt(entityTypeId) << Ids.ENTITY_TYPE_BIT_SHIFT) | (lowPart & Ids.ID_MASK);
|
|
16
16
|
}
|
|
17
17
|
// The cart's message id: the business link id with the entity type swapped for the message one
|
|
18
|
-
// (Java Message.getPartyPreferencesMessageId).
|
|
19
|
-
//
|
|
18
|
+
// (Java Message.getPartyPreferencesMessageId). One link has one cart. The server stores a cart
|
|
19
|
+
// only under this id, and refuses an order that has it.
|
|
20
20
|
static getPartyPreferencesMessageId(businessLinkId) {
|
|
21
21
|
return Ids.buildId(proto_Constants.MESSAGE_ENTITY_TYPE_ID, Ids.getLowPart(businessLinkId));
|
|
22
22
|
}
|
|
@@ -74,7 +74,9 @@ Ids.GENERAL_SETTINGS_CONFIGURATION_ID = 0x0d10000000000000n;
|
|
|
74
74
|
Ids.ATTACHMENT_BASE_URL_BLOB_ID = -1n;
|
|
75
75
|
// Where a container keeps the credentials that sign its calls (see AuthTokens). Written with a null eTag, since a reissued token is not a later version of the earlier one. The latest wins.
|
|
76
76
|
Ids.AUTH_TOKENS_BLOB_ID = -2n;
|
|
77
|
-
//
|
|
77
|
+
// Where a profile container keeps the id that the next sign up creates the user under (see Model.createUser). Written with a null eTag, since a new id replaces the old one. It is the one blob a container holds that no response carried.
|
|
78
|
+
Ids.USER_ID_BLOB_ID = -3n;
|
|
79
|
+
// The first of a block of fixed blob ids, one per key (see getSyncCursorBlobId). A key is an entity type id, below 0x80, so the block runs from -0x100 down to -0x17F and cannot meet the fixed blobs at -1, -2 and -3.
|
|
78
80
|
Ids.SYNC_CURSOR_BLOB_ID_BASE = -0x100n;
|
|
79
81
|
Ids.UNSIGNED_64_BIT_MASK = (1n << 64n) - 1n;
|
|
80
82
|
Ids.UNSIGNED_32_BIT_MASK = (1n << 32n) - 1n;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// A Lock that excludes only callers of this object, in order. For a test, or for a caller whose
|
|
2
|
+
// store is used by one tab.
|
|
3
|
+
export default class InMemoryLock {
|
|
4
|
+
constructor() {
|
|
5
|
+
this._tails = new Map();
|
|
6
|
+
}
|
|
7
|
+
runExclusive(key, action) {
|
|
8
|
+
const previous = this._tails.get(key) ?? Promise.resolve();
|
|
9
|
+
const result = previous.then(action);
|
|
10
|
+
// The next caller starts when this one settles, whether or not it failed
|
|
11
|
+
const tail = result.then(() => undefined, () => undefined);
|
|
12
|
+
this._tails.set(key, tail);
|
|
13
|
+
// Forget the key when nobody is waiting, so the map does not grow with every key used
|
|
14
|
+
void tail.then(() => {
|
|
15
|
+
if (this._tails.get(key) === tail)
|
|
16
|
+
this._tails.delete(key);
|
|
17
|
+
});
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/dist/Lock.d.ts
ADDED
package/dist/Lock.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/Message.d.ts
CHANGED
|
@@ -5,12 +5,8 @@ export default abstract class Message extends Entity {
|
|
|
5
5
|
private readonly _senderId;
|
|
6
6
|
private readonly _messageType;
|
|
7
7
|
private readonly _taskStatus;
|
|
8
|
-
|
|
9
|
-
private readonly _senderPhone;
|
|
10
|
-
protected constructor(header: EntityHeader, _senderId: bigint, _messageType: proto_MessageType, _taskStatus: proto_TaskStatus, _senderName: string | null, _senderPhone: string | null);
|
|
8
|
+
protected constructor(header: EntityHeader, _senderId: bigint, _messageType: proto_MessageType, _taskStatus: proto_TaskStatus);
|
|
11
9
|
get senderId(): bigint;
|
|
12
10
|
get messageType(): proto_MessageType;
|
|
13
11
|
get taskStatus(): proto_TaskStatus;
|
|
14
|
-
get senderName(): string | null;
|
|
15
|
-
get senderPhone(): string | null;
|
|
16
12
|
}
|
package/dist/Message.js
CHANGED
|
@@ -2,17 +2,14 @@ import Entity from "./Entity";
|
|
|
2
2
|
// Something a customer sent to a business: an order (sales order) or a shopping cart (party preferences), the two payloads this library understands.
|
|
3
3
|
// A business entity despite being customer-authored, since Java authorizes the message table through Right.MESSAGES_MODIFY against the business.
|
|
4
4
|
export default class Message extends Entity {
|
|
5
|
-
constructor(header, _senderId, _messageType, _taskStatus
|
|
5
|
+
constructor(header, _senderId, _messageType, _taskStatus) {
|
|
6
6
|
super(header);
|
|
7
7
|
this._senderId = _senderId;
|
|
8
8
|
this._messageType = _messageType;
|
|
9
9
|
this._taskStatus = _taskStatus;
|
|
10
|
-
this._senderName = _senderName;
|
|
11
|
-
this._senderPhone = _senderPhone;
|
|
12
10
|
}
|
|
13
11
|
// The customer's party id at the business (BusinessLink.partyId), not the id of their User. A
|
|
14
|
-
// business sync out sends a customer only messages from their own party.
|
|
15
|
-
// senderPhone identify the sender without resolving the party.
|
|
12
|
+
// business sync out sends a customer only messages from their own party.
|
|
16
13
|
get senderId() {
|
|
17
14
|
return this._senderId;
|
|
18
15
|
}
|
|
@@ -23,11 +20,4 @@ export default class Message extends Entity {
|
|
|
23
20
|
get taskStatus() {
|
|
24
21
|
return this._taskStatus;
|
|
25
22
|
}
|
|
26
|
-
get senderName() {
|
|
27
|
-
return this._senderName;
|
|
28
|
-
}
|
|
29
|
-
// E.164 formatted
|
|
30
|
-
get senderPhone() {
|
|
31
|
-
return this._senderPhone;
|
|
32
|
-
}
|
|
33
23
|
}
|
package/dist/Model.d.ts
CHANGED
|
@@ -4,26 +4,29 @@ import Address from "./Address";
|
|
|
4
4
|
import Business from "./Business";
|
|
5
5
|
import Database from "./Database";
|
|
6
6
|
import LiveData from "./LiveData";
|
|
7
|
+
import Lock from "./Lock";
|
|
7
8
|
import Profile from "./Profile";
|
|
8
9
|
import Service from "./Service";
|
|
9
10
|
import ShoppingList from "./ShoppingList";
|
|
10
11
|
import UserProfile from "./UserProfile";
|
|
11
12
|
export default class Model {
|
|
12
13
|
private constructor();
|
|
13
|
-
static initialize(service: Service, database: Database): void;
|
|
14
|
+
static initialize(service: Service, database: Database, lock?: Lock): void;
|
|
14
15
|
static getInstance(): Model;
|
|
15
16
|
get business(): LiveData<Business | null>;
|
|
16
17
|
get profile(): LiveData<Profile | null>;
|
|
17
18
|
signIn(authenticationMethod: proto_AuthenticationMethod, subjectId: string, authenticationToken: string): Promise<void>;
|
|
18
19
|
createUser(authenticationMethod: proto_AuthenticationMethod, subjectId: string, authenticationToken: string, userToCreate: UserProfile): Promise<void>;
|
|
19
20
|
updateUser(userProfile: UserProfile): Promise<void>;
|
|
21
|
+
changeUser(change: (current: UserProfile) => UserProfile): Promise<void>;
|
|
22
|
+
refreshProfileIfStale(): Promise<boolean>;
|
|
20
23
|
signOut(): Promise<void>;
|
|
21
24
|
setBusinessId(businessId: string): Promise<void>;
|
|
22
25
|
updateCart(shoppingList: ShoppingList): Promise<void>;
|
|
23
26
|
updateCartLocalOnly(shoppingList: ShoppingList): Promise<void>;
|
|
24
27
|
createOrder(orderId: bigint, fulfillmentMode: proto_FulfillmentMode, deliveryAddressId: bigint, deliveryAddress: Address | null, note: string | null): Promise<void>;
|
|
25
28
|
private beginSignIn;
|
|
26
|
-
private
|
|
29
|
+
private sendBusinessMessages;
|
|
27
30
|
private storeCartInCache;
|
|
28
31
|
private requireBusinessBeingBrowsed;
|
|
29
32
|
private requireCustomerOfBusiness;
|
|
@@ -35,34 +38,44 @@ export default class Model {
|
|
|
35
38
|
private static isBusinessNamed;
|
|
36
39
|
private requireBusinessLink;
|
|
37
40
|
private readJoinBusinessId;
|
|
41
|
+
private getVettedBusiness;
|
|
38
42
|
private static findBusinessEntity;
|
|
39
43
|
private static findBusinessLink;
|
|
40
44
|
private static getBusinessContainerName;
|
|
41
45
|
private requireBusinessAuthTokens;
|
|
42
46
|
private profileSyncIn;
|
|
47
|
+
private syncProfile;
|
|
48
|
+
private readStoredUser;
|
|
49
|
+
private sendUserUpdate;
|
|
43
50
|
private createProfileOnServer;
|
|
51
|
+
private readProfilePages;
|
|
44
52
|
private static requireJoinedBusiness;
|
|
45
|
-
private cacheProfileResponse;
|
|
46
|
-
private writeProfileResponse;
|
|
47
53
|
private storeIssuedTokens;
|
|
48
54
|
private getProfileContainerName;
|
|
49
55
|
private requireProfileContainerName;
|
|
50
56
|
private buildProfileAuthTokens;
|
|
51
57
|
private requireProfileAuthTokens;
|
|
58
|
+
private static getProfileCursorsKey;
|
|
52
59
|
private publishBusiness;
|
|
53
60
|
private publish;
|
|
54
61
|
private static buildPublishable;
|
|
55
62
|
private publishProfile;
|
|
63
|
+
private publishProfileFromStore;
|
|
64
|
+
private refreshProfile;
|
|
56
65
|
private static getService;
|
|
57
66
|
private static getCache;
|
|
58
67
|
private static _service;
|
|
59
68
|
private static _cache;
|
|
69
|
+
private static _lock;
|
|
60
70
|
private static _instance;
|
|
61
71
|
private _authenticationMethod;
|
|
62
72
|
private _subjectId;
|
|
63
73
|
private _authenticationToken;
|
|
64
74
|
private _businessId;
|
|
65
75
|
private _isPublishedBusinessVetted;
|
|
76
|
+
private _profileReadAt;
|
|
77
|
+
private _publishedProfileCursors;
|
|
78
|
+
private _profileRefresh;
|
|
66
79
|
private readonly _business;
|
|
67
80
|
private readonly _profile;
|
|
68
81
|
}
|