@shopfront/bridge 2.0.1 → 2.0.4

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.
Files changed (46) hide show
  1. package/.github/workflows/npm-publish.yml +13 -2
  2. package/lib/Application.d.ts +2 -18
  3. package/lib/Application.js +1 -141
  4. package/lib/ApplicationEvents.d.ts +54 -5
  5. package/lib/BaseApplication.d.ts +11 -17
  6. package/lib/BaseApplication.js +197 -1
  7. package/lib/BaseBridge.d.ts +1 -0
  8. package/lib/BaseBridge.js +1 -3
  9. package/lib/Bridge.d.ts +0 -19
  10. package/lib/Bridge.js +2 -1
  11. package/lib/Events/DirectEvents/BaseDirectEvent.d.ts +13 -0
  12. package/lib/Events/DirectEvents/BaseDirectEvent.js +5 -0
  13. package/lib/Events/DirectEvents/SaleAddCustomer.d.ts +13 -0
  14. package/lib/Events/DirectEvents/SaleAddCustomer.js +24 -0
  15. package/lib/Events/DirectEvents/SaleAddProduct.d.ts +13 -0
  16. package/lib/Events/DirectEvents/SaleAddProduct.js +24 -0
  17. package/lib/Events/DirectEvents/SaleChangeQuantity.d.ts +13 -0
  18. package/lib/Events/DirectEvents/SaleChangeQuantity.js +24 -0
  19. package/lib/Events/DirectEvents/SaleClear.d.ts +13 -0
  20. package/lib/Events/DirectEvents/SaleClear.js +21 -0
  21. package/lib/Events/DirectEvents/SaleRemoveCustomer.d.ts +13 -0
  22. package/lib/Events/DirectEvents/SaleRemoveCustomer.js +21 -0
  23. package/lib/Events/DirectEvents/SaleRemoveProduct.d.ts +13 -0
  24. package/lib/Events/DirectEvents/SaleRemoveProduct.js +24 -0
  25. package/lib/Events/DirectEvents/SaleUpdateProducts.d.ts +13 -0
  26. package/lib/Events/DirectEvents/SaleUpdateProducts.js +24 -0
  27. package/lib/Events/DirectEvents/types/SaleEventData.d.ts +70 -0
  28. package/lib/Events/DirectEvents/types/SaleEventData.js +1 -0
  29. package/lib/Mocks/APIs/Sale/MockCurrentSale.d.ts +7 -2
  30. package/lib/Mocks/APIs/Sale/MockCurrentSale.js +94 -10
  31. package/lib/Mocks/MockApplication.d.ts +8 -21
  32. package/lib/Mocks/MockApplication.js +12 -165
  33. package/lib/Mocks/MockBridge.d.ts +1 -1
  34. package/lib/Mocks/MockBridge.js +3 -1
  35. package/package.json +1 -1
  36. package/.idea/codeStyles/Project.xml +0 -10
  37. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  38. package/.idea/git_toolbox_blame.xml +0 -6
  39. package/.idea/git_toolbox_prj.xml +0 -15
  40. package/.idea/inspectionProfiles/Project_Default.xml +0 -11
  41. package/.idea/jsLinters/eslint.xml +0 -6
  42. package/.idea/misc.xml +0 -6
  43. package/.idea/modules.xml +0 -8
  44. package/.idea/php.xml +0 -33
  45. package/.idea/shopfront-embedded-bridge.iml +0 -10
  46. package/.idea/vcs.xml +0 -6
package/lib/Bridge.js CHANGED
@@ -19,7 +19,6 @@ export class Bridge extends BaseBridge {
19
19
  throw new Error("The bridge has not been initialised within a frame");
20
20
  }
21
21
  super(key, url);
22
- this.target = null;
23
22
  /**
24
23
  * @inheritDoc
25
24
  */
@@ -64,6 +63,8 @@ export class Bridge extends BaseBridge {
64
63
  listeners[i](event.data.type, event.data.data, event.data.id);
65
64
  }
66
65
  };
66
+ this.registerListeners();
67
+ this.sendMessage(ApplicationEvents.ToShopfront.READY);
67
68
  }
68
69
  /**
69
70
  * @inheritDoc
@@ -0,0 +1,13 @@
1
+ import { DirectShopfrontCallbacks, DirectShopfrontEvent, DirectShopfrontEventData } from "../../ApplicationEvents.js";
2
+ export declare abstract class BaseDirectEvent<TEvent extends DirectShopfrontEvent, TData = DirectShopfrontEventData[TEvent], TCallback = DirectShopfrontCallbacks[TEvent]> {
3
+ protected callback: TCallback;
4
+ protected constructor(callback: TCallback);
5
+ /**
6
+ * Ensures the event data is formatted correctly
7
+ */
8
+ protected abstract isEventData(event: unknown): event is TData;
9
+ /**
10
+ * Invokes the registered callback
11
+ */
12
+ abstract emit(event: unknown): Promise<void>;
13
+ }
@@ -0,0 +1,5 @@
1
+ export class BaseDirectEvent {
2
+ constructor(callback) {
3
+ this.callback = callback;
4
+ }
5
+ }
@@ -0,0 +1,13 @@
1
+ import { DirectShopfrontCallbacks, DirectShopfrontEventData } from "../../ApplicationEvents.js";
2
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
3
+ export declare class SaleAddCustomer extends BaseDirectEvent<"SALE_ADD_CUSTOMER"> {
4
+ constructor(callback: DirectShopfrontCallbacks["SALE_ADD_CUSTOMER"]);
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ protected isEventData(event: unknown): event is DirectShopfrontEventData["SALE_ADD_CUSTOMER"];
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ emit(event: unknown): Promise<void>;
13
+ }
@@ -0,0 +1,24 @@
1
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
2
+ export class SaleAddCustomer extends BaseDirectEvent {
3
+ constructor(callback) {
4
+ super(callback);
5
+ }
6
+ /**
7
+ * @inheritDoc
8
+ */
9
+ isEventData(event) {
10
+ if (!event || typeof event !== "object") {
11
+ return false;
12
+ }
13
+ return "customer" in event;
14
+ }
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ async emit(event) {
19
+ if (!this.isEventData(event)) {
20
+ return;
21
+ }
22
+ return this.callback(event);
23
+ }
24
+ }
@@ -0,0 +1,13 @@
1
+ import { DirectShopfrontCallbacks, DirectShopfrontEventData } from "../../ApplicationEvents.js";
2
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
3
+ export declare class SaleAddProduct extends BaseDirectEvent<"SALE_ADD_PRODUCT"> {
4
+ constructor(callback: DirectShopfrontCallbacks["SALE_ADD_PRODUCT"]);
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ protected isEventData(event: unknown): event is DirectShopfrontEventData["SALE_ADD_PRODUCT"];
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ emit(event: unknown): Promise<void>;
13
+ }
@@ -0,0 +1,24 @@
1
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
2
+ export class SaleAddProduct extends BaseDirectEvent {
3
+ constructor(callback) {
4
+ super(callback);
5
+ }
6
+ /**
7
+ * @inheritDoc
8
+ */
9
+ isEventData(event) {
10
+ if (!event || typeof event !== "object") {
11
+ return false;
12
+ }
13
+ return "product" in event && "indexAddress" in event;
14
+ }
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ async emit(event) {
19
+ if (!this.isEventData(event)) {
20
+ return;
21
+ }
22
+ return this.callback(event);
23
+ }
24
+ }
@@ -0,0 +1,13 @@
1
+ import { DirectShopfrontCallbacks, DirectShopfrontEventData } from "../../ApplicationEvents.js";
2
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
3
+ export declare class SaleChangeQuantity extends BaseDirectEvent<"SALE_CHANGE_QUANTITY"> {
4
+ constructor(callback: DirectShopfrontCallbacks["SALE_CHANGE_QUANTITY"]);
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ protected isEventData(event: unknown): event is DirectShopfrontEventData["SALE_CHANGE_QUANTITY"];
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ emit(event: unknown): Promise<void>;
13
+ }
@@ -0,0 +1,24 @@
1
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
2
+ export class SaleChangeQuantity extends BaseDirectEvent {
3
+ constructor(callback) {
4
+ super(callback);
5
+ }
6
+ /**
7
+ * @inheritDoc
8
+ */
9
+ isEventData(event) {
10
+ if (!event || typeof event !== "object") {
11
+ return false;
12
+ }
13
+ return "indexAddress" in event && "amount" in event && "absolute" in event;
14
+ }
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ async emit(event) {
19
+ if (!this.isEventData(event)) {
20
+ return;
21
+ }
22
+ return this.callback(event);
23
+ }
24
+ }
@@ -0,0 +1,13 @@
1
+ import { DirectShopfrontCallbacks, DirectShopfrontEventData } from "../../ApplicationEvents.js";
2
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
3
+ export declare class SaleClear extends BaseDirectEvent<"SALE_CLEAR"> {
4
+ constructor(callback: DirectShopfrontCallbacks["SALE_CLEAR"]);
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ protected isEventData(event: unknown): event is DirectShopfrontEventData["SALE_CLEAR"];
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ emit(event: unknown): Promise<void>;
13
+ }
@@ -0,0 +1,21 @@
1
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
2
+ export class SaleClear extends BaseDirectEvent {
3
+ constructor(callback) {
4
+ super(callback);
5
+ }
6
+ /**
7
+ * @inheritDoc
8
+ */
9
+ isEventData(event) {
10
+ return true;
11
+ }
12
+ /**
13
+ * @inheritDoc
14
+ */
15
+ async emit(event) {
16
+ if (!this.isEventData(event)) {
17
+ return;
18
+ }
19
+ return this.callback();
20
+ }
21
+ }
@@ -0,0 +1,13 @@
1
+ import { DirectShopfrontCallbacks, DirectShopfrontEventData } from "../../ApplicationEvents.js";
2
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
3
+ export declare class SaleRemoveCustomer extends BaseDirectEvent<"SALE_REMOVE_CUSTOMER"> {
4
+ constructor(callback: DirectShopfrontCallbacks["SALE_REMOVE_CUSTOMER"]);
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ protected isEventData(event: unknown): event is DirectShopfrontEventData["SALE_REMOVE_CUSTOMER"];
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ emit(event: unknown): Promise<void>;
13
+ }
@@ -0,0 +1,21 @@
1
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
2
+ export class SaleRemoveCustomer extends BaseDirectEvent {
3
+ constructor(callback) {
4
+ super(callback);
5
+ }
6
+ /**
7
+ * @inheritDoc
8
+ */
9
+ isEventData(event) {
10
+ return true;
11
+ }
12
+ /**
13
+ * @inheritDoc
14
+ */
15
+ async emit(event) {
16
+ if (!this.isEventData(event)) {
17
+ return;
18
+ }
19
+ return this.callback();
20
+ }
21
+ }
@@ -0,0 +1,13 @@
1
+ import { DirectShopfrontCallbacks, DirectShopfrontEventData } from "../../ApplicationEvents.js";
2
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
3
+ export declare class SaleRemoveProduct extends BaseDirectEvent<"SALE_REMOVE_PRODUCT"> {
4
+ constructor(callback: DirectShopfrontCallbacks["SALE_REMOVE_PRODUCT"]);
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ protected isEventData(event: unknown): event is DirectShopfrontEventData["SALE_REMOVE_PRODUCT"];
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ emit(event: unknown): Promise<void>;
13
+ }
@@ -0,0 +1,24 @@
1
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
2
+ export class SaleRemoveProduct extends BaseDirectEvent {
3
+ constructor(callback) {
4
+ super(callback);
5
+ }
6
+ /**
7
+ * @inheritDoc
8
+ */
9
+ isEventData(event) {
10
+ if (!event || typeof event !== "object") {
11
+ return false;
12
+ }
13
+ return "indexAddress" in event;
14
+ }
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ async emit(event) {
19
+ if (!this.isEventData(event)) {
20
+ return;
21
+ }
22
+ return this.callback(event);
23
+ }
24
+ }
@@ -0,0 +1,13 @@
1
+ import { DirectShopfrontCallbacks, DirectShopfrontEventData } from "../../ApplicationEvents.js";
2
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
3
+ export declare class SaleUpdateProducts extends BaseDirectEvent<"SALE_UPDATE_PRODUCTS"> {
4
+ constructor(callback: DirectShopfrontCallbacks["SALE_UPDATE_PRODUCTS"]);
5
+ /**
6
+ * @inheritDoc
7
+ */
8
+ protected isEventData(event: unknown): event is DirectShopfrontEventData["SALE_UPDATE_PRODUCTS"];
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ emit(event: unknown): Promise<void>;
13
+ }
@@ -0,0 +1,24 @@
1
+ import { BaseDirectEvent } from "./BaseDirectEvent.js";
2
+ export class SaleUpdateProducts extends BaseDirectEvent {
3
+ constructor(callback) {
4
+ super(callback);
5
+ }
6
+ /**
7
+ * @inheritDoc
8
+ */
9
+ isEventData(event) {
10
+ if (!event || typeof event !== "object") {
11
+ return false;
12
+ }
13
+ return "products" in event;
14
+ }
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ async emit(event) {
19
+ if (!this.isEventData(event)) {
20
+ return;
21
+ }
22
+ return this.callback(event);
23
+ }
24
+ }
@@ -0,0 +1,70 @@
1
+ type SaleProductType = "Normal" | "Product" | "GiftCard" | "Voucher" | "Basket" | "Package" | "Component" | "Integrated" | "Surcharge";
2
+ interface SaleGiftCard {
3
+ code: string;
4
+ amount: number;
5
+ expiry: string;
6
+ source: string;
7
+ }
8
+ interface SaleActiveSurcharge {
9
+ id: number;
10
+ amount: number;
11
+ }
12
+ export interface SaleEventProduct {
13
+ uuid: string;
14
+ type: SaleProductType;
15
+ name: string;
16
+ caseQuantity: number;
17
+ isCase: boolean;
18
+ quantity: number;
19
+ loyalty: {
20
+ earn: number;
21
+ redeem: number;
22
+ };
23
+ prices: {
24
+ price: number;
25
+ unlockedPrice: number;
26
+ normal: number;
27
+ base: number;
28
+ addPrice: number;
29
+ removePrice: number;
30
+ additionalPrice: number;
31
+ discountRate?: number;
32
+ };
33
+ tax: {
34
+ id: false | string;
35
+ amount: number;
36
+ };
37
+ surcharge: null | SaleActiveSurcharge;
38
+ products: Array<SaleEventProduct>;
39
+ defaultProducts: Array<SaleEventProduct>;
40
+ preventManualDiscount: boolean;
41
+ special: boolean;
42
+ edited: boolean;
43
+ promotions: Record<string, {
44
+ name: string;
45
+ active: boolean;
46
+ quantity: number;
47
+ }>;
48
+ rebates: Record<string, {
49
+ amount: number;
50
+ quantity: number;
51
+ }>;
52
+ giftCard: SaleGiftCard | null;
53
+ note: string;
54
+ userId: null | string;
55
+ priceSet?: string;
56
+ deleted?: boolean;
57
+ initiallyDeleted?: boolean;
58
+ familyId: string | null;
59
+ categoryId: string | null;
60
+ tags: Array<string>;
61
+ canUnlock: boolean;
62
+ discountReason?: string;
63
+ requestPrice?: boolean;
64
+ lockQuantity: boolean;
65
+ metaData: Record<string, unknown>;
66
+ barcodeQuantity?: number;
67
+ lineId: string;
68
+ priceList: boolean;
69
+ }
70
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,13 +1,14 @@
1
1
  import { BaseCurrentSale } from "../../../APIs/Sale/BaseCurrentSale.js";
2
2
  import { SaleCustomer, SalePayment, SaleProduct, ShopfrontSaleState } from "../../../APIs/Sale/index.js";
3
- import { DirectShopfrontEvent } from "../../../ApplicationEvents.js";
3
+ import { DirectShopfrontEvent, DirectShopfrontEventData } from "../../../ApplicationEvents.js";
4
+ import { SaleEventProduct } from "../../../Events/DirectEvents/types/SaleEventData.js";
4
5
  import { MockApplication } from "../../MockApplication.js";
5
6
  export declare class MockCurrentSale extends BaseCurrentSale {
6
7
  constructor(application: MockApplication, saleState?: ShopfrontSaleState);
7
8
  /**
8
9
  * Fires the event trigger
9
10
  */
10
- protected triggerEvent(event: DirectShopfrontEvent): void;
11
+ protected triggerEvent<Event extends DirectShopfrontEvent>(event: Event, data: DirectShopfrontEventData[Event]): Promise<void>;
11
12
  /**
12
13
  * Check if the sale has already been cancelled, if it has, throw a SaleCancelledError.
13
14
  */
@@ -92,6 +93,10 @@ export declare class MockCurrentSale extends BaseCurrentSale {
92
93
  * Clones a sale payment so it can be added to the sale
93
94
  */
94
95
  protected clonePayment(payment: SalePayment, reverse?: boolean): SalePayment;
96
+ /**
97
+ * Generates a SaleEventProduct from a SaleProduct
98
+ */
99
+ protected generateSaleEventProduct(product: SaleProduct): SaleEventProduct;
95
100
  /**
96
101
  * Clear the sale data
97
102
  */
@@ -31,9 +31,31 @@ export class MockCurrentSale extends BaseCurrentSale {
31
31
  /**
32
32
  * Fires the event trigger
33
33
  */
34
- triggerEvent(event) {
34
+ async triggerEvent(event, data) {
35
35
  if (this.application instanceof MockApplication) {
36
- this.application.fireEvent(event);
36
+ switch (event) {
37
+ case "SALE_ADD_PRODUCT":
38
+ await this.application.fireEvent("SALE_ADD_PRODUCT", data);
39
+ break;
40
+ case "SALE_REMOVE_PRODUCT":
41
+ await this.application.fireEvent("SALE_REMOVE_PRODUCT", data);
42
+ break;
43
+ case "SALE_CHANGE_QUANTITY":
44
+ await this.application.fireEvent("SALE_CHANGE_QUANTITY", data);
45
+ break;
46
+ case "SALE_UPDATE_PRODUCTS":
47
+ await this.application.fireEvent("SALE_UPDATE_PRODUCTS", data);
48
+ break;
49
+ case "SALE_ADD_CUSTOMER":
50
+ await this.application.fireEvent("SALE_ADD_CUSTOMER", data);
51
+ break;
52
+ case "SALE_REMOVE_CUSTOMER":
53
+ await this.application.fireEvent("SALE_REMOVE_CUSTOMER");
54
+ break;
55
+ case "SALE_CLEAR":
56
+ await this.application.fireEvent("SALE_CLEAR");
57
+ break;
58
+ }
37
59
  }
38
60
  else {
39
61
  throw new Error("Manually firing events is only supported in the `MockApplication`");
@@ -111,7 +133,7 @@ export class MockCurrentSale extends BaseCurrentSale {
111
133
  this.products[index]["quantity"] += product.getQuantity();
112
134
  const newPrice = this.roundNumber(currentRate * this.products[index].getQuantity());
113
135
  this.handleSaleProductPriceChange(index, currentPrice, newPrice);
114
- this.triggerEvent("SALE_UPDATE_PRODUCTS");
136
+ await this.triggerEvent("SALE_UPDATE_PRODUCTS", { products: [] });
115
137
  return;
116
138
  }
117
139
  catch (e) {
@@ -124,8 +146,13 @@ export class MockCurrentSale extends BaseCurrentSale {
124
146
  product["edited"] = false;
125
147
  this.products.push(this.cloneProduct(product));
126
148
  this.updateSaleTotal(product.getPrice() || 0);
127
- this.triggerEvent("SALE_ADD_PRODUCT");
128
- this.triggerEvent("SALE_UPDATE_PRODUCTS");
149
+ await this.triggerEvent("SALE_ADD_PRODUCT", {
150
+ product: this.generateSaleEventProduct(product),
151
+ indexAddress: product.getIndexAddress(),
152
+ });
153
+ await this.triggerEvent("SALE_UPDATE_PRODUCTS", {
154
+ products: [this.generateSaleEventProduct(product)],
155
+ });
129
156
  }
130
157
  /**
131
158
  * @inheritDoc
@@ -142,7 +169,9 @@ export class MockCurrentSale extends BaseCurrentSale {
142
169
  for (let i = 0, l = this.products.length; i < l; i++) {
143
170
  this.products[i]["indexAddress"] = [i];
144
171
  }
145
- this.triggerEvent("SALE_REMOVE_PRODUCT");
172
+ await this.triggerEvent("SALE_REMOVE_PRODUCT", {
173
+ indexAddress: product.getIndexAddress(),
174
+ });
146
175
  }
147
176
  /**
148
177
  * @inheritDoc
@@ -158,7 +187,7 @@ export class MockCurrentSale extends BaseCurrentSale {
158
187
  const remaining = this.roundNumber(this.sale.totals.sale - this.sale.totals.paid);
159
188
  if (remaining <= 0) {
160
189
  this.clearSale();
161
- this.triggerEvent("SALE_CLEAR");
190
+ await this.triggerEvent("SALE_CLEAR", undefined);
162
191
  }
163
192
  }
164
193
  /**
@@ -184,7 +213,11 @@ export class MockCurrentSale extends BaseCurrentSale {
184
213
  async addCustomer(customer) {
185
214
  this.checkIfCancelled();
186
215
  this.customer = customer;
187
- this.triggerEvent("SALE_ADD_CUSTOMER");
216
+ await this.triggerEvent("SALE_ADD_CUSTOMER", {
217
+ customer: {
218
+ uuid: customer.getId(),
219
+ },
220
+ });
188
221
  }
189
222
  /**
190
223
  * @inheritDoc
@@ -192,7 +225,7 @@ export class MockCurrentSale extends BaseCurrentSale {
192
225
  async removeCustomer() {
193
226
  this.checkIfCancelled();
194
227
  this.customer = null;
195
- this.triggerEvent("SALE_REMOVE_CUSTOMER");
228
+ await this.triggerEvent("SALE_REMOVE_CUSTOMER", undefined);
196
229
  }
197
230
  /**
198
231
  * @inheritDoc
@@ -258,7 +291,9 @@ export class MockCurrentSale extends BaseCurrentSale {
258
291
  this.products[index]["metaData"] = product.getMetaData();
259
292
  }
260
293
  product.clearModificationFlags();
261
- this.triggerEvent("SALE_UPDATE_PRODUCTS");
294
+ await this.triggerEvent("SALE_UPDATE_PRODUCTS", {
295
+ products: [this.generateSaleEventProduct(product)],
296
+ });
262
297
  }
263
298
  /**
264
299
  * Retrieves the index of a product in the sale
@@ -294,6 +329,55 @@ export class MockCurrentSale extends BaseCurrentSale {
294
329
  clone["metaData"] = payment["metaData"];
295
330
  return clone;
296
331
  }
332
+ /**
333
+ * Generates a SaleEventProduct from a SaleProduct
334
+ */
335
+ generateSaleEventProduct(product) {
336
+ return {
337
+ uuid: product.getId(),
338
+ type: product.getType() ?? "Product",
339
+ name: product.getName() ?? "Unknown Product",
340
+ caseQuantity: product.getCaseQuantity() ?? 1,
341
+ isCase: (product.getCaseQuantity() ?? 1) / product.getQuantity() === 0,
342
+ quantity: product.getQuantity(),
343
+ loyalty: {
344
+ earn: 0,
345
+ redeem: 0,
346
+ },
347
+ prices: {
348
+ price: 0,
349
+ unlockedPrice: 0,
350
+ normal: 0,
351
+ base: 0,
352
+ addPrice: 0,
353
+ removePrice: 0,
354
+ additionalPrice: 0,
355
+ },
356
+ tax: {
357
+ id: "tax-rate-id",
358
+ amount: 0,
359
+ },
360
+ surcharge: null,
361
+ products: [],
362
+ defaultProducts: [],
363
+ preventManualDiscount: false,
364
+ special: false,
365
+ edited: false,
366
+ promotions: {},
367
+ rebates: {},
368
+ giftCard: null,
369
+ note: "",
370
+ userId: null,
371
+ familyId: null,
372
+ categoryId: null,
373
+ tags: [],
374
+ canUnlock: false,
375
+ lockQuantity: false,
376
+ metaData: product.getMetaData(),
377
+ lineId: "",
378
+ priceList: false,
379
+ };
380
+ }
297
381
  /**
298
382
  * Clear the sale data
299
383
  */
@@ -1,9 +1,8 @@
1
1
  import { Sale } from "../APIs/Sale/index.js";
2
- import { DirectShopfrontEvent, DirectShopfrontEventCallback, FromShopfront, FromShopfrontCallbacks, FromShopfrontInternal, ListenableFromShopfrontEvents, RegisterChangedEvent, SellScreenActionMode, SellScreenSummaryMode, SoundEvents } from "../ApplicationEvents.js";
2
+ import { DirectShopfrontCallbacks, DirectShopfrontEvent, FromShopfront, FromShopfrontInternal, ListenableFromShopfrontEvent, RegisterChangedEvent, SellScreenActionMode, SellScreenSummaryMode, SoundEvents } from "../ApplicationEvents.js";
3
3
  import { BaseApplication, ShopfrontEmbeddedVerificationToken } from "../BaseApplication.js";
4
4
  import { Serializable } from "../Common/Serializable.js";
5
5
  import { BaseEmitableEvent } from "../EmitableEvents/BaseEmitableEvent.js";
6
- import { MaybePromise } from "../Utilities/MiscTypes.js";
7
6
  import { MockCurrentSale } from "./APIs/Sale/MockCurrentSale.js";
8
7
  import { MockBridge } from "./MockBridge.js";
9
8
  interface AudioRequestOptions {
@@ -20,27 +19,11 @@ export declare class MockApplication extends BaseApplication {
20
19
  /**
21
20
  * Handles an application event
22
21
  */
23
- protected handleEvent: (event: keyof FromShopfront | keyof FromShopfrontInternal, data: Record<string, unknown>, id: string) => void;
22
+ protected handleEvent: (event: keyof FromShopfront | keyof FromShopfrontInternal, data: Record<string, unknown>, id: string) => Promise<void>;
24
23
  /**
25
24
  * Calls any registered listeners for the received event
26
25
  */
27
- protected emit(event: ListenableFromShopfrontEvents | DirectShopfrontEvent, data: (Record<string, unknown> | string) | undefined, id: string): MaybePromise<void>;
28
- /**
29
- * @inheritDoc
30
- */
31
- addEventListener<E extends ListenableFromShopfrontEvents>(event: E, callback: FromShopfrontCallbacks[E]): void;
32
- /**
33
- * @inheritDoc
34
- */
35
- addEventListener(event: DirectShopfrontEvent, callback: DirectShopfrontEventCallback): void;
36
- /**
37
- * @inheritDoc
38
- */
39
- removeEventListener<E extends keyof FromShopfrontCallbacks>(event: E, callback: FromShopfrontCallbacks[E]): void;
40
- /**
41
- * @inheritDoc
42
- */
43
- removeEventListener<D>(event: DirectShopfrontEvent, callback: (event: D) => MaybePromise<void>): void;
26
+ protected emit(event: ListenableFromShopfrontEvent | DirectShopfrontEvent, data: (Record<string, unknown> | string) | undefined, id: string): Promise<void>;
44
27
  /**
45
28
  * @inheritDoc
46
29
  */
@@ -149,6 +132,10 @@ export declare class MockApplication extends BaseApplication {
149
132
  /**
150
133
  * Mocks an event being fired from Shopfront
151
134
  */
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;
135
+ fireEvent<T extends ListenableFromShopfrontEvent, HasParams extends (Parameters<FromShopfront[T]["emit"]> extends [never] ? false : true)>(event: T, ...data: HasParams extends true ? Parameters<FromShopfront[T]["emit"]> : [undefined]): Promise<void>;
136
+ /**
137
+ * Mocks an event being fired from Shopfront
138
+ */
139
+ fireEvent<D extends DirectShopfrontEvent, HasParams extends (Parameters<DirectShopfrontCallbacks[D]> extends [never] ? false : true)>(event: D, ...data: HasParams extends true ? Parameters<DirectShopfrontCallbacks[D]> : [undefined]): Promise<void>;
153
140
  }
154
141
  export {};