@shopfront/bridge 2.0.1 → 2.0.2
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/lib/Mocks/APIs/Sale/MockCurrentSale.d.ts +1 -1
- package/lib/Mocks/APIs/Sale/MockCurrentSale.js +10 -10
- package/lib/Mocks/MockApplication.d.ts +3 -3
- package/lib/Mocks/MockApplication.js +8 -9
- package/lib/Mocks/MockBridge.d.ts +1 -1
- package/lib/Mocks/MockBridge.js +1 -1
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ export declare class MockCurrentSale extends BaseCurrentSale {
|
|
|
7
7
|
/**
|
|
8
8
|
* Fires the event trigger
|
|
9
9
|
*/
|
|
10
|
-
protected triggerEvent(event: DirectShopfrontEvent): void
|
|
10
|
+
protected triggerEvent(event: DirectShopfrontEvent): Promise<void>;
|
|
11
11
|
/**
|
|
12
12
|
* Check if the sale has already been cancelled, if it has, throw a SaleCancelledError.
|
|
13
13
|
*/
|
|
@@ -31,9 +31,9 @@ export class MockCurrentSale extends BaseCurrentSale {
|
|
|
31
31
|
/**
|
|
32
32
|
* Fires the event trigger
|
|
33
33
|
*/
|
|
34
|
-
triggerEvent(event) {
|
|
34
|
+
async triggerEvent(event) {
|
|
35
35
|
if (this.application instanceof MockApplication) {
|
|
36
|
-
this.application.fireEvent(event);
|
|
36
|
+
await this.application.fireEvent(event);
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
throw new Error("Manually firing events is only supported in the `MockApplication`");
|
|
@@ -111,7 +111,7 @@ export class MockCurrentSale extends BaseCurrentSale {
|
|
|
111
111
|
this.products[index]["quantity"] += product.getQuantity();
|
|
112
112
|
const newPrice = this.roundNumber(currentRate * this.products[index].getQuantity());
|
|
113
113
|
this.handleSaleProductPriceChange(index, currentPrice, newPrice);
|
|
114
|
-
this.triggerEvent("SALE_UPDATE_PRODUCTS");
|
|
114
|
+
await this.triggerEvent("SALE_UPDATE_PRODUCTS");
|
|
115
115
|
return;
|
|
116
116
|
}
|
|
117
117
|
catch (e) {
|
|
@@ -124,8 +124,8 @@ export class MockCurrentSale extends BaseCurrentSale {
|
|
|
124
124
|
product["edited"] = false;
|
|
125
125
|
this.products.push(this.cloneProduct(product));
|
|
126
126
|
this.updateSaleTotal(product.getPrice() || 0);
|
|
127
|
-
this.triggerEvent("SALE_ADD_PRODUCT");
|
|
128
|
-
this.triggerEvent("SALE_UPDATE_PRODUCTS");
|
|
127
|
+
await this.triggerEvent("SALE_ADD_PRODUCT");
|
|
128
|
+
await this.triggerEvent("SALE_UPDATE_PRODUCTS");
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
131
|
* @inheritDoc
|
|
@@ -142,7 +142,7 @@ export class MockCurrentSale extends BaseCurrentSale {
|
|
|
142
142
|
for (let i = 0, l = this.products.length; i < l; i++) {
|
|
143
143
|
this.products[i]["indexAddress"] = [i];
|
|
144
144
|
}
|
|
145
|
-
this.triggerEvent("SALE_REMOVE_PRODUCT");
|
|
145
|
+
await this.triggerEvent("SALE_REMOVE_PRODUCT");
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* @inheritDoc
|
|
@@ -158,7 +158,7 @@ export class MockCurrentSale extends BaseCurrentSale {
|
|
|
158
158
|
const remaining = this.roundNumber(this.sale.totals.sale - this.sale.totals.paid);
|
|
159
159
|
if (remaining <= 0) {
|
|
160
160
|
this.clearSale();
|
|
161
|
-
this.triggerEvent("SALE_CLEAR");
|
|
161
|
+
await this.triggerEvent("SALE_CLEAR");
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
@@ -184,7 +184,7 @@ export class MockCurrentSale extends BaseCurrentSale {
|
|
|
184
184
|
async addCustomer(customer) {
|
|
185
185
|
this.checkIfCancelled();
|
|
186
186
|
this.customer = customer;
|
|
187
|
-
this.triggerEvent("SALE_ADD_CUSTOMER");
|
|
187
|
+
await this.triggerEvent("SALE_ADD_CUSTOMER");
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
190
190
|
* @inheritDoc
|
|
@@ -192,7 +192,7 @@ export class MockCurrentSale extends BaseCurrentSale {
|
|
|
192
192
|
async removeCustomer() {
|
|
193
193
|
this.checkIfCancelled();
|
|
194
194
|
this.customer = null;
|
|
195
|
-
this.triggerEvent("SALE_REMOVE_CUSTOMER");
|
|
195
|
+
await this.triggerEvent("SALE_REMOVE_CUSTOMER");
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
198
198
|
* @inheritDoc
|
|
@@ -258,7 +258,7 @@ export class MockCurrentSale extends BaseCurrentSale {
|
|
|
258
258
|
this.products[index]["metaData"] = product.getMetaData();
|
|
259
259
|
}
|
|
260
260
|
product.clearModificationFlags();
|
|
261
|
-
this.triggerEvent("SALE_UPDATE_PRODUCTS");
|
|
261
|
+
await this.triggerEvent("SALE_UPDATE_PRODUCTS");
|
|
262
262
|
}
|
|
263
263
|
/**
|
|
264
264
|
* Retrieves the index of a product in the sale
|
|
@@ -20,11 +20,11 @@ export declare class MockApplication extends BaseApplication {
|
|
|
20
20
|
/**
|
|
21
21
|
* Handles an application event
|
|
22
22
|
*/
|
|
23
|
-
protected handleEvent: (event: keyof FromShopfront | keyof FromShopfrontInternal, data: Record<string, unknown>, id: string) => void
|
|
23
|
+
protected handleEvent: (event: keyof FromShopfront | keyof FromShopfrontInternal, data: Record<string, unknown>, id: string) => Promise<void>;
|
|
24
24
|
/**
|
|
25
25
|
* Calls any registered listeners for the received event
|
|
26
26
|
*/
|
|
27
|
-
protected emit(event: ListenableFromShopfrontEvents | DirectShopfrontEvent, data: (Record<string, unknown> | string) | undefined, id: string):
|
|
27
|
+
protected emit(event: ListenableFromShopfrontEvents | DirectShopfrontEvent, data: (Record<string, unknown> | string) | undefined, id: string): Promise<void>;
|
|
28
28
|
/**
|
|
29
29
|
* @inheritDoc
|
|
30
30
|
*/
|
|
@@ -149,6 +149,6 @@ export declare class MockApplication extends BaseApplication {
|
|
|
149
149
|
/**
|
|
150
150
|
* Mocks an event being fired from Shopfront
|
|
151
151
|
*/
|
|
152
|
-
fireEvent<T extends ListenableFromShopfrontEvents, HasParams extends (Parameters<FromShopfront[T]["emit"]> extends [never] ? false : true)>(event: T | DirectShopfrontEvent, ...data: HasParams extends true ? Parameters<FromShopfront[T]["emit"]> : [undefined]): void
|
|
152
|
+
fireEvent<T extends ListenableFromShopfrontEvents, HasParams extends (Parameters<FromShopfront[T]["emit"]> extends [never] ? false : true)>(event: T | DirectShopfrontEvent, ...data: HasParams extends true ? Parameters<FromShopfront[T]["emit"]> : [undefined]): Promise<void>;
|
|
153
153
|
}
|
|
154
154
|
export {};
|
|
@@ -32,7 +32,7 @@ export class MockApplication extends BaseApplication {
|
|
|
32
32
|
/**
|
|
33
33
|
* Handles an application event
|
|
34
34
|
*/
|
|
35
|
-
this.handleEvent = (event, data, id) => {
|
|
35
|
+
this.handleEvent = async (event, data, id) => {
|
|
36
36
|
if (event === "READY") {
|
|
37
37
|
this.isReady = true;
|
|
38
38
|
this.key = data.key;
|
|
@@ -66,7 +66,7 @@ export class MockApplication extends BaseApplication {
|
|
|
66
66
|
// Handled elsewhere
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
|
-
this.emit(event, data, id);
|
|
69
|
+
await this.emit(event, data, id);
|
|
70
70
|
};
|
|
71
71
|
/**
|
|
72
72
|
* Updates the cached location data
|
|
@@ -95,7 +95,7 @@ export class MockApplication extends BaseApplication {
|
|
|
95
95
|
/**
|
|
96
96
|
* Calls any registered listeners for the received event
|
|
97
97
|
*/
|
|
98
|
-
emit(event, data = {}, id) {
|
|
98
|
+
async emit(event, data = {}, id) {
|
|
99
99
|
if (isDirectShopfrontEvent(event)) {
|
|
100
100
|
const listeners = this.directListeners[event];
|
|
101
101
|
if (typeof listeners === "undefined") {
|
|
@@ -106,10 +106,8 @@ export class MockApplication extends BaseApplication {
|
|
|
106
106
|
for (const e of listeners.values()) {
|
|
107
107
|
results.push(e());
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// Ensure void is returned
|
|
112
|
-
});
|
|
109
|
+
await Promise.all(results);
|
|
110
|
+
return;
|
|
113
111
|
}
|
|
114
112
|
const results = [];
|
|
115
113
|
if (typeof this.listeners[event] === "undefined") {
|
|
@@ -124,6 +122,7 @@ export class MockApplication extends BaseApplication {
|
|
|
124
122
|
for (const e of this.listeners[event].values()) {
|
|
125
123
|
results.push(e.emit(data, bridge));
|
|
126
124
|
}
|
|
125
|
+
await Promise.allSettled(results);
|
|
127
126
|
// The responses have been removed as we don't currently need them
|
|
128
127
|
}
|
|
129
128
|
/**
|
|
@@ -463,7 +462,7 @@ export class MockApplication extends BaseApplication {
|
|
|
463
462
|
/**
|
|
464
463
|
* Mocks an event being fired from Shopfront
|
|
465
464
|
*/
|
|
466
|
-
fireEvent(event, ...data) {
|
|
465
|
+
async fireEvent(event, ...data) {
|
|
467
466
|
let params;
|
|
468
467
|
if (data.length > 0) {
|
|
469
468
|
if (typeof data[0] === "object") {
|
|
@@ -476,7 +475,7 @@ export class MockApplication extends BaseApplication {
|
|
|
476
475
|
}
|
|
477
476
|
// We don't care about the Bridge parameter, as that is passed in by the `emit` method
|
|
478
477
|
}
|
|
479
|
-
this.emit(event, params, "");
|
|
478
|
+
await this.emit(event, params, "");
|
|
480
479
|
}
|
|
481
480
|
;
|
|
482
481
|
}
|
|
@@ -19,7 +19,7 @@ export declare class MockBridge extends BaseBridge {
|
|
|
19
19
|
/**
|
|
20
20
|
* @inheritDoc
|
|
21
21
|
*/
|
|
22
|
-
sendMessage(type: ApplicationEvents.ToShopfront, data?: unknown, id?: string): void
|
|
22
|
+
sendMessage(type: ApplicationEvents.ToShopfront, data?: unknown, id?: string): Promise<void>;
|
|
23
23
|
/**
|
|
24
24
|
* @inheritDoc
|
|
25
25
|
*/
|
package/lib/Mocks/MockBridge.js
CHANGED
|
@@ -26,7 +26,7 @@ export class MockBridge extends BaseBridge {
|
|
|
26
26
|
/**
|
|
27
27
|
* @inheritDoc
|
|
28
28
|
*/
|
|
29
|
-
sendMessage(type, data, id) {
|
|
29
|
+
async sendMessage(type, data, id) {
|
|
30
30
|
if (type === ApplicationEvents.ToShopfront.READY) {
|
|
31
31
|
if (typeof data !== "undefined") {
|
|
32
32
|
throw new TypeError("The `data` parameter must be undefined when requesting ready state");
|