@shopfront/bridge 2.0.0 → 2.0.1

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 (244) hide show
  1. package/.idea/codeStyles/Project.xml +10 -0
  2. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  3. package/.idea/git_toolbox_blame.xml +6 -0
  4. package/.idea/git_toolbox_prj.xml +15 -0
  5. package/.idea/inspectionProfiles/Project_Default.xml +5 -0
  6. package/.idea/jsLinters/eslint.xml +6 -0
  7. package/.idea/modules.xml +1 -1
  8. package/.idea/php.xml +15 -0
  9. package/lib/APIs/Database/BaseDatabase.d.ts +28 -0
  10. package/lib/APIs/Database/BaseDatabase.js +5 -0
  11. package/lib/APIs/Database/Database.d.ts +19 -7
  12. package/lib/APIs/Database/Database.js +22 -12
  13. package/lib/APIs/Database/types/BaseBarcodeTemplateRepository.d.ts +8 -0
  14. package/lib/APIs/Database/types/BaseBarcodeTemplateRepository.js +1 -0
  15. package/lib/APIs/Database/types/BaseClassificationRepository.d.ts +11 -0
  16. package/lib/APIs/Database/types/BaseClassificationRepository.js +1 -0
  17. package/lib/APIs/Database/types/BaseCustomerDisplayRepository.d.ts +10 -0
  18. package/lib/APIs/Database/types/BaseCustomerDisplayRepository.js +1 -0
  19. package/lib/APIs/Database/types/BaseCustomerGroupRepository.d.ts +24 -0
  20. package/lib/APIs/Database/types/BaseCustomerGroupRepository.js +1 -0
  21. package/lib/APIs/Database/types/BaseCustomerRepository.d.ts +76 -0
  22. package/lib/APIs/Database/types/BaseCustomerRepository.js +1 -0
  23. package/lib/APIs/Database/types/BaseEnterpriseRepository.d.ts +8 -0
  24. package/lib/APIs/Database/types/BaseEnterpriseRepository.js +1 -0
  25. package/lib/APIs/Database/types/BaseGiftCardRepository.d.ts +18 -0
  26. package/lib/APIs/Database/types/BaseGiftCardRepository.js +1 -0
  27. package/lib/APIs/Database/types/BaseKitchenOrderRepository.d.ts +41 -0
  28. package/lib/APIs/Database/types/BaseKitchenOrderRepository.js +1 -0
  29. package/lib/APIs/Database/types/BaseKitchenScreenRepository.d.ts +16 -0
  30. package/lib/APIs/Database/types/BaseKitchenScreenRepository.js +1 -0
  31. package/lib/APIs/Database/types/BaseLockedResourceRepository.d.ts +12 -0
  32. package/lib/APIs/Database/types/BaseLockedResourceRepository.js +1 -0
  33. package/lib/APIs/Database/types/BaseLoyaltyRepository.d.ts +16 -0
  34. package/lib/APIs/Database/types/BaseLoyaltyRepository.js +1 -0
  35. package/lib/APIs/Database/types/BaseMovementRepository.d.ts +16 -0
  36. package/lib/APIs/Database/types/BaseMovementRepository.js +1 -0
  37. package/lib/APIs/Database/types/BaseOutletRepository.d.ts +19 -0
  38. package/lib/APIs/Database/types/BaseOutletRepository.js +1 -0
  39. package/lib/APIs/Database/types/BasePaymentMethodRepository.d.ts +27 -0
  40. package/lib/APIs/Database/types/BasePaymentMethodRepository.js +1 -0
  41. package/lib/APIs/Database/types/BasePriceListRepository.d.ts +40 -0
  42. package/lib/APIs/Database/types/BasePriceListRepository.js +1 -0
  43. package/lib/APIs/Database/types/BasePriceSetRepository.d.ts +6 -0
  44. package/lib/APIs/Database/types/BasePriceSetRepository.js +1 -0
  45. package/lib/APIs/Database/types/BaseProductRepository.d.ts +160 -0
  46. package/lib/APIs/Database/types/BaseProductRepository.js +1 -0
  47. package/lib/APIs/Database/types/BasePromotionCategoryRepository.d.ts +10 -0
  48. package/lib/APIs/Database/types/BasePromotionCategoryRepository.js +1 -0
  49. package/lib/APIs/Database/types/BasePromotionRepository.d.ts +72 -0
  50. package/lib/APIs/Database/types/BasePromotionRepository.js +1 -0
  51. package/lib/APIs/Database/types/BaseReceiptRepository.d.ts +31 -0
  52. package/lib/APIs/Database/types/BaseReceiptRepository.js +1 -0
  53. package/lib/APIs/Database/types/BaseRegisterRepository.d.ts +56 -0
  54. package/lib/APIs/Database/types/BaseRegisterRepository.js +1 -0
  55. package/lib/APIs/Database/types/BaseRepository.d.ts +41 -0
  56. package/lib/APIs/Database/types/BaseRepository.js +1 -0
  57. package/lib/APIs/Database/types/BaseSalesKeyRepository.d.ts +37 -0
  58. package/lib/APIs/Database/types/BaseSalesKeyRepository.js +1 -0
  59. package/lib/APIs/Database/types/BaseSalesRepository.d.ts +123 -0
  60. package/lib/APIs/Database/types/BaseSalesRepository.js +1 -0
  61. package/lib/APIs/Database/types/BaseSearchableRepository.d.ts +8 -0
  62. package/lib/APIs/Database/types/BaseSearchableRepository.js +1 -0
  63. package/lib/APIs/Database/types/BaseStocktakeAccumulatedRepository.d.ts +16 -0
  64. package/lib/APIs/Database/types/BaseStocktakeAccumulatedRepository.js +1 -0
  65. package/lib/APIs/Database/types/BaseStocktakeRepository.d.ts +8 -0
  66. package/lib/APIs/Database/types/BaseStocktakeRepository.js +1 -0
  67. package/lib/APIs/Database/types/BaseStocktakeScannedRepository.d.ts +24 -0
  68. package/lib/APIs/Database/types/BaseStocktakeScannedRepository.js +1 -0
  69. package/lib/APIs/Database/types/BaseSupplierRepository.d.ts +35 -0
  70. package/lib/APIs/Database/types/BaseSupplierRepository.js +1 -0
  71. package/lib/APIs/Database/types/BaseTakingsRepository.d.ts +13 -0
  72. package/lib/APIs/Database/types/BaseTakingsRepository.js +1 -0
  73. package/lib/APIs/Database/types/BaseTaxRateRepository.d.ts +9 -0
  74. package/lib/APIs/Database/types/BaseTaxRateRepository.js +1 -0
  75. package/lib/APIs/Database/types/BaseTransfereeRepository.d.ts +12 -0
  76. package/lib/APIs/Database/types/BaseTransfereeRepository.js +1 -0
  77. package/lib/APIs/Database/types/BaseVendorConnectionRepository.d.ts +7 -0
  78. package/lib/APIs/Database/types/BaseVendorConnectionRepository.js +1 -0
  79. package/lib/APIs/Database/types/DataSourceTables.d.ts +61 -0
  80. package/lib/APIs/Database/types/DataSourceTables.js +1 -0
  81. package/lib/APIs/Fulfilment/FulfilmentTypes.d.ts +2 -2
  82. package/lib/APIs/Fulfilment/FulfilmentTypes.js +1 -2
  83. package/lib/APIs/InternalMessages/InternalMessageSource.d.ts +6 -3
  84. package/lib/APIs/InternalMessages/InternalMessageSource.js +6 -7
  85. package/lib/APIs/Sale/BaseCurrentSale.d.ts +83 -0
  86. package/lib/APIs/Sale/BaseCurrentSale.js +13 -0
  87. package/lib/APIs/Sale/BaseSale.d.ts +3 -38
  88. package/lib/APIs/Sale/BaseSale.js +1 -40
  89. package/lib/APIs/Sale/CurrentSale.d.ts +19 -84
  90. package/lib/APIs/Sale/CurrentSale.js +32 -102
  91. package/lib/APIs/Sale/Exceptions.d.ts +3 -0
  92. package/lib/APIs/Sale/Exceptions.js +7 -7
  93. package/lib/APIs/Sale/Sale.d.ts +39 -7
  94. package/lib/APIs/Sale/Sale.js +41 -13
  95. package/lib/APIs/Sale/SaleCustomer.d.ts +0 -2
  96. package/lib/APIs/Sale/SaleCustomer.js +1 -7
  97. package/lib/APIs/Sale/SalePayment.d.ts +3 -22
  98. package/lib/APIs/Sale/SalePayment.js +7 -33
  99. package/lib/APIs/Sale/SaleProduct.d.ts +6 -46
  100. package/lib/APIs/Sale/SaleProduct.js +6 -53
  101. package/lib/APIs/Sale/ShopfrontSaleState.d.ts +7 -9
  102. package/lib/APIs/Sale/ShopfrontSaleState.js +1 -2
  103. package/lib/APIs/Sale/index.d.ts +9 -9
  104. package/lib/APIs/Sale/index.js +7 -39
  105. package/lib/Actions/BaseAction.d.ts +21 -5
  106. package/lib/Actions/BaseAction.js +155 -97
  107. package/lib/Actions/Button.d.ts +2 -2
  108. package/lib/Actions/Button.js +3 -7
  109. package/lib/Actions/CustomerListOption.d.ts +2 -2
  110. package/lib/Actions/CustomerListOption.js +2 -6
  111. package/lib/Actions/Dialog.d.ts +4 -4
  112. package/lib/Actions/Dialog.js +2 -6
  113. package/lib/Actions/Redirect.d.ts +2 -2
  114. package/lib/Actions/Redirect.js +7 -9
  115. package/lib/Actions/SaleKey.d.ts +2 -2
  116. package/lib/Actions/SaleKey.js +3 -7
  117. package/lib/Actions/SaleUpdate.d.ts +3 -3
  118. package/lib/Actions/SaleUpdate.js +3 -7
  119. package/lib/Actions/Toast.d.ts +3 -3
  120. package/lib/Actions/Toast.js +2 -6
  121. package/lib/Application.d.ts +114 -78
  122. package/lib/Application.js +207 -160
  123. package/lib/ApplicationEvents.d.ts +66 -53
  124. package/lib/ApplicationEvents.js +10 -6
  125. package/lib/BaseApplication.d.ts +169 -0
  126. package/lib/BaseApplication.js +40 -0
  127. package/lib/BaseBridge.d.ts +33 -0
  128. package/lib/BaseBridge.js +16 -0
  129. package/lib/Bridge.d.ts +46 -9
  130. package/lib/Bridge.js +42 -54
  131. package/lib/Common/EventEmitter.d.ts +10 -1
  132. package/lib/Common/EventEmitter.js +10 -5
  133. package/lib/Common/Serializable.d.ts +8 -6
  134. package/lib/Common/Serializable.js +1 -2
  135. package/lib/EmitableEvents/BaseEmitableEvent.d.ts +7 -1
  136. package/lib/EmitableEvents/BaseEmitableEvent.js +7 -5
  137. package/lib/EmitableEvents/Fulfilment/Options.d.ts +1 -1
  138. package/lib/EmitableEvents/Fulfilment/Options.js +4 -8
  139. package/lib/EmitableEvents/Fulfilment/OrderCancel.d.ts +1 -1
  140. package/lib/EmitableEvents/Fulfilment/OrderCancel.js +4 -8
  141. package/lib/EmitableEvents/Fulfilment/OrderCreate.d.ts +2 -2
  142. package/lib/EmitableEvents/Fulfilment/OrderCreate.js +4 -8
  143. package/lib/EmitableEvents/Fulfilment/OrderUpdate.d.ts +2 -2
  144. package/lib/EmitableEvents/Fulfilment/OrderUpdate.js +4 -8
  145. package/lib/EmitableEvents/Fulfilment/OrdersSync.d.ts +2 -2
  146. package/lib/EmitableEvents/Fulfilment/OrdersSync.js +4 -8
  147. package/lib/EmitableEvents/Fulfilment/RegisterIntent.d.ts +2 -2
  148. package/lib/EmitableEvents/Fulfilment/RegisterIntent.js +4 -8
  149. package/lib/EmitableEvents/Fulfilment/index.d.ts +7 -7
  150. package/lib/EmitableEvents/Fulfilment/index.js +6 -15
  151. package/lib/EmitableEvents/InternalMessage.d.ts +2 -2
  152. package/lib/EmitableEvents/InternalMessage.js +4 -8
  153. package/lib/EmitableEvents/SellScreenOption.d.ts +2 -2
  154. package/lib/EmitableEvents/SellScreenOption.js +7 -11
  155. package/lib/EmitableEvents/SellScreenPromotionApplicable.d.ts +1 -1
  156. package/lib/EmitableEvents/SellScreenPromotionApplicable.js +4 -8
  157. package/lib/EmitableEvents/TableUpdate.d.ts +2 -2
  158. package/lib/EmitableEvents/TableUpdate.js +4 -8
  159. package/lib/Events/AudioPermissionChange.d.ts +5 -2
  160. package/lib/Events/AudioPermissionChange.js +6 -7
  161. package/lib/Events/AudioReady.d.ts +5 -2
  162. package/lib/Events/AudioReady.js +6 -7
  163. package/lib/Events/BaseEvent.d.ts +8 -3
  164. package/lib/Events/BaseEvent.js +1 -6
  165. package/lib/Events/Callback.d.ts +5 -2
  166. package/lib/Events/Callback.js +5 -6
  167. package/lib/Events/FormatIntegratedProduct.d.ts +27 -32
  168. package/lib/Events/FormatIntegratedProduct.js +12 -9
  169. package/lib/Events/FulfilmentCollectOrder.d.ts +5 -2
  170. package/lib/Events/FulfilmentCollectOrder.js +5 -6
  171. package/lib/Events/FulfilmentCompleteOrder.d.ts +5 -2
  172. package/lib/Events/FulfilmentCompleteOrder.js +5 -6
  173. package/lib/Events/FulfilmentGetOrder.d.ts +12 -6
  174. package/lib/Events/FulfilmentGetOrder.js +10 -8
  175. package/lib/Events/FulfilmentOrderApproval.d.ts +5 -2
  176. package/lib/Events/FulfilmentOrderApproval.js +5 -6
  177. package/lib/Events/FulfilmentProcessOrder.d.ts +12 -10
  178. package/lib/Events/FulfilmentProcessOrder.js +7 -8
  179. package/lib/Events/FulfilmentVoidOrder.d.ts +5 -2
  180. package/lib/Events/FulfilmentVoidOrder.js +5 -6
  181. package/lib/Events/GiftCardCodeCheck.d.ts +19 -0
  182. package/lib/Events/GiftCardCodeCheck.js +23 -0
  183. package/lib/Events/InternalPageMessage.d.ts +10 -4
  184. package/lib/Events/InternalPageMessage.js +12 -10
  185. package/lib/Events/PaymentMethodsEnabled.d.ts +16 -11
  186. package/lib/Events/PaymentMethodsEnabled.js +10 -8
  187. package/lib/Events/Ready.d.ts +12 -7
  188. package/lib/Events/Ready.js +5 -6
  189. package/lib/Events/RegisterChanged.d.ts +12 -6
  190. package/lib/Events/RegisterChanged.js +6 -7
  191. package/lib/Events/RequestButtons.d.ts +17 -12
  192. package/lib/Events/RequestButtons.js +13 -11
  193. package/lib/Events/RequestCustomerListOptions.d.ts +11 -5
  194. package/lib/Events/RequestCustomerListOptions.js +12 -11
  195. package/lib/Events/RequestSaleKeys.d.ts +12 -6
  196. package/lib/Events/RequestSaleKeys.js +13 -11
  197. package/lib/Events/RequestSellScreenOptions.d.ts +18 -5
  198. package/lib/Events/RequestSellScreenOptions.js +17 -9
  199. package/lib/Events/RequestSettings.d.ts +11 -5
  200. package/lib/Events/RequestSettings.js +12 -10
  201. package/lib/Events/RequestTableColumns.d.ts +16 -11
  202. package/lib/Events/RequestTableColumns.js +12 -9
  203. package/lib/Events/SaleComplete.d.ts +15 -18
  204. package/lib/Events/SaleComplete.js +6 -7
  205. package/lib/Events/UIPipeline.d.ts +17 -5
  206. package/lib/Events/UIPipeline.js +17 -10
  207. package/lib/Mocks/APIs/Sale/MockCurrentSale.d.ts +99 -0
  208. package/lib/Mocks/APIs/Sale/MockCurrentSale.js +326 -0
  209. package/lib/Mocks/Database/MockDatabase.d.ts +96 -0
  210. package/lib/Mocks/Database/MockDatabase.js +89 -0
  211. package/lib/Mocks/MockApplication.d.ts +154 -0
  212. package/lib/Mocks/MockApplication.js +482 -0
  213. package/lib/Mocks/MockBridge.d.ts +31 -0
  214. package/lib/Mocks/MockBridge.js +77 -0
  215. package/lib/Mocks/index.d.ts +7 -0
  216. package/lib/Mocks/index.js +15 -0
  217. package/lib/Utilities/ActionEventRegistrar.d.ts +19 -4
  218. package/lib/Utilities/ActionEventRegistrar.js +19 -3
  219. package/lib/Utilities/MiscTypes.d.ts +6 -4
  220. package/lib/Utilities/MiscTypes.js +1 -2
  221. package/lib/Utilities/SaleCreate.d.ts +6 -2
  222. package/lib/Utilities/SaleCreate.js +10 -6
  223. package/lib/Utilities/Static.d.ts +3 -0
  224. package/lib/Utilities/Static.js +5 -7
  225. package/lib/Utilities/UUID.d.ts +9 -3
  226. package/lib/Utilities/UUID.js +10 -7
  227. package/lib/index.d.ts +16 -14
  228. package/lib/index.js +14 -49
  229. package/package.json +3 -2
  230. package/lib/APIs/CurrentSale/Exceptions.d.ts +0 -6
  231. package/lib/APIs/CurrentSale/Exceptions.js +0 -15
  232. package/lib/APIs/CurrentSale/Sale.d.ts +0 -182
  233. package/lib/APIs/CurrentSale/Sale.js +0 -290
  234. package/lib/APIs/CurrentSale/SaleCustomer.d.ts +0 -10
  235. package/lib/APIs/CurrentSale/SaleCustomer.js +0 -17
  236. package/lib/APIs/CurrentSale/SalePayment.d.ts +0 -68
  237. package/lib/APIs/CurrentSale/SalePayment.js +0 -99
  238. package/lib/APIs/CurrentSale/SaleProduct.d.ts +0 -121
  239. package/lib/APIs/CurrentSale/SaleProduct.js +0 -167
  240. package/lib/APIs/CurrentSale/ShopfrontSaleState.d.ts +0 -53
  241. package/lib/APIs/CurrentSale/ShopfrontSaleState.js +0 -2
  242. package/lib/APIs/CurrentSale/index.d.ts +0 -6
  243. package/lib/APIs/CurrentSale/index.js +0 -37
  244. /package/.idea/{embedded-bridge.iml → shopfront-embedded-bridge.iml} +0 -0
@@ -0,0 +1,77 @@
1
+ import * as ApplicationEvents from "../ApplicationEvents.js";
2
+ import { BaseBridge } from "../BaseBridge.js";
3
+ export class MockBridge extends BaseBridge {
4
+ constructor(key, url) {
5
+ super(key, url);
6
+ this.isReady = false;
7
+ }
8
+ /**
9
+ * @inheritDoc
10
+ */
11
+ destroy() {
12
+ this.listeners = [];
13
+ }
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ registerListeners() {
18
+ /* Do nothing */
19
+ }
20
+ /**
21
+ * @inheritDoc
22
+ */
23
+ unregisterListeners() {
24
+ /* Do nothing */
25
+ }
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ sendMessage(type, data, id) {
30
+ if (type === ApplicationEvents.ToShopfront.READY) {
31
+ if (typeof data !== "undefined") {
32
+ throw new TypeError("The `data` parameter must be undefined when requesting ready state");
33
+ }
34
+ if (this.isReady) {
35
+ throw new Error("Shopfront is already ready");
36
+ }
37
+ const listeners = this.listeners;
38
+ // We can fire off a READY event straight away
39
+ for (let i = 0, l = listeners.length; i < l; i++) {
40
+ listeners[i](type, {
41
+ key: "signing-key-uuid",
42
+ outlet: "outlet-uuid",
43
+ register: "register-uuid",
44
+ }, id);
45
+ }
46
+ return;
47
+ }
48
+ // No need to do anything
49
+ }
50
+ /**
51
+ * @inheritDoc
52
+ */
53
+ addEventListener(listener) {
54
+ if (this.listeners.includes(listener)) {
55
+ throw new Error("The listener provided is already registered");
56
+ }
57
+ this.listeners.push(listener);
58
+ // If this is a READY event listener, we can fire off a Ready event immediately
59
+ if (!this.hasListener) {
60
+ this.sendMessage(ApplicationEvents.ToShopfront.READY);
61
+ this.hasListener = true;
62
+ }
63
+ }
64
+ /**
65
+ * @inheritDoc
66
+ */
67
+ removeEventListener(listener) {
68
+ const index = this.listeners.indexOf(listener);
69
+ if (index === -1) {
70
+ return;
71
+ }
72
+ this.listeners = [
73
+ ...this.listeners.slice(0, index),
74
+ ...this.listeners.slice(index + 1),
75
+ ];
76
+ }
77
+ }
@@ -0,0 +1,7 @@
1
+ import { MockApplication } from "./MockApplication.js";
2
+ import { MockBridge } from "./MockBridge.js";
3
+ /**
4
+ * Creates a mocked instance of the Embedded Application
5
+ */
6
+ declare function mockApplication(id: string, vendor: string): MockApplication;
7
+ export { MockApplication, mockApplication, MockBridge, };
@@ -0,0 +1,15 @@
1
+ import { MockApplication } from "./MockApplication.js";
2
+ import { MockBridge } from "./MockBridge.js";
3
+ /**
4
+ * Creates a mocked instance of the Embedded Application
5
+ */
6
+ function mockApplication(id, vendor) {
7
+ if (typeof id === "undefined") {
8
+ throw new TypeError("You must specify the ID for the application");
9
+ }
10
+ if (typeof vendor === "undefined") {
11
+ throw new TypeError("You must specify the Vendor for the application");
12
+ }
13
+ return new MockApplication(new MockBridge(id, vendor));
14
+ }
15
+ export { MockApplication, mockApplication, MockBridge, };
@@ -1,12 +1,27 @@
1
- import { BaseAction } from "../Actions/BaseAction";
1
+ import { BaseAction } from "../Actions/BaseAction.js";
2
2
  declare class ActionEventRegistrar {
3
- events: {
4
- [id: string]: BaseAction<undefined>;
5
- };
3
+ private events;
6
4
  constructor();
5
+ /**
6
+ * Registers an event action listener
7
+ * @param id
8
+ * @param action
9
+ */
7
10
  add(id: string, action: BaseAction<undefined>): void;
11
+ /**
12
+ * Removes an event action listener
13
+ * @param id
14
+ */
8
15
  remove(id: string): void;
16
+ /**
17
+ * Invokes the registered action event listener
18
+ * @param id
19
+ * @param data
20
+ */
9
21
  fire(id: string, data: unknown): void;
22
+ /**
23
+ * Clears all registered listeners
24
+ */
10
25
  clear(): void;
11
26
  }
12
27
  declare const _default: ActionEventRegistrar;
@@ -1,15 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  class ActionEventRegistrar {
4
2
  constructor() {
5
3
  this.events = {};
6
4
  }
5
+ /**
6
+ * Registers an event action listener
7
+ * @param id
8
+ * @param action
9
+ */
7
10
  add(id, action) {
8
11
  this.events[id] = action;
9
12
  }
13
+ /**
14
+ * Removes an event action listener
15
+ * @param id
16
+ */
10
17
  remove(id) {
18
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
11
19
  delete this.events[id];
12
20
  }
21
+ /**
22
+ * Invokes the registered action event listener
23
+ * @param id
24
+ * @param data
25
+ */
13
26
  fire(id, data) {
14
27
  if (typeof this.events[id] === "undefined") {
15
28
  // The event must have stopped listening
@@ -17,8 +30,11 @@ class ActionEventRegistrar {
17
30
  }
18
31
  this.events[id].handleRegistrarEvent(id, data);
19
32
  }
33
+ /**
34
+ * Clears all registered listeners
35
+ */
20
36
  clear() {
21
37
  this.events = {};
22
38
  }
23
39
  }
24
- exports.default = new ActionEventRegistrar();
40
+ export default new ActionEventRegistrar();
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * A property which might be a promise or the promise's wrapped type
3
3
  */
4
- export declare type MaybePromise<P> = P | Promise<P>;
5
- export interface ConstructorClass<T> {
6
- new (...args: Array<unknown>): T;
7
- }
4
+ export type MaybePromise<P> = P | Promise<P>;
5
+ export type ConstructorClass<T> = new (...args: Array<unknown>) => T;
6
+ /**
7
+ * A function that may or may not be asynchronous
8
+ */
9
+ export type AnyFunction = (...args: Array<any>) => any;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,5 +1,5 @@
1
- import { Sale, ShopfrontSalePaymentStatus } from "../APIs/Sale";
2
- import { BaseSaleData } from "../APIs/Sale/BaseSale";
1
+ import { BaseSaleData } from "../APIs/Sale/BaseSale.js";
2
+ import { Sale, ShopfrontSalePaymentStatus } from "../APIs/Sale/index.js";
3
3
  export interface SaleProductData {
4
4
  uuid: string;
5
5
  caseQuantity: number;
@@ -23,4 +23,8 @@ export interface SaleData extends BaseSaleData {
23
23
  payments: Array<SalePaymentData>;
24
24
  products: Array<SaleProductData>;
25
25
  }
26
+ /**
27
+ * Builds a Shopfront sale from the embedded sale data
28
+ * @param sale
29
+ */
26
30
  export declare function buildSaleData(sale: Sale): SaleData;
@@ -1,6 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildSaleData = void 0;
1
+ /**
2
+ * Builds a Shopfront sale product from the embedded product data
3
+ * @param product
4
+ */
4
5
  function buildSaleProductData(product) {
5
6
  const price = product.getPrice();
6
7
  if (typeof price !== "number") {
@@ -20,7 +21,11 @@ function buildSaleProductData(product) {
20
21
  price,
21
22
  };
22
23
  }
23
- function buildSaleData(sale) {
24
+ /**
25
+ * Builds a Shopfront sale from the embedded sale data
26
+ * @param sale
27
+ */
28
+ export function buildSaleData(sale) {
24
29
  const customer = sale.getCustomer();
25
30
  return {
26
31
  register: sale.getRegister(),
@@ -49,8 +54,7 @@ function buildSaleData(sale) {
49
54
  status: payment.getStatus(),
50
55
  rounding: payment.getRounding() || 0,
51
56
  cashout: payment.getCashout() || 0,
52
- metaData: payment.getMetaData()
57
+ metaData: payment.getMetaData(),
53
58
  })),
54
59
  };
55
60
  }
56
- exports.buildSaleData = buildSaleData;
@@ -1 +1,4 @@
1
+ /**
2
+ * A decorator function that enforces static interface implementation for a class at compile time.
3
+ */
1
4
  export declare function staticImplements<T>(): (constructor: T) => void;
@@ -1,9 +1,7 @@
1
- "use strict";
2
- // noinspection JSUnusedLocalSymbols
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.staticImplements = void 0;
5
- function staticImplements() {
6
- // eslint-disable-next-line @typescript-eslint/no-empty-function,@typescript-eslint/no-unused-vars
1
+ /**
2
+ * A decorator function that enforces static interface implementation for a class at compile time.
3
+ */
4
+ export function staticImplements() {
5
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
7
6
  return (constructor) => { };
8
7
  }
9
- exports.staticImplements = staticImplements;
@@ -1,12 +1,18 @@
1
1
  /**
2
2
  * Fast UUID generator, RFC4122 version 4 compliant.
3
3
  * @author Jeff Ward (jcward.com).
4
- * @license MIT license
5
- * @link http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
6
- **/
4
+ * @license MIT
5
+ * {@link http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136}
6
+ */
7
7
  export default class UUID {
8
8
  protected lut: Array<string>;
9
9
  constructor();
10
+ /**
11
+ * Generates a UUID
12
+ */
10
13
  generate(): string;
14
+ /**
15
+ * Static method for generating a UUID
16
+ */
11
17
  static generate(): string;
12
18
  }
@@ -1,12 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  /**
4
2
  * Fast UUID generator, RFC4122 version 4 compliant.
5
3
  * @author Jeff Ward (jcward.com).
6
- * @license MIT license
7
- * @link http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
8
- **/
9
- class UUID {
4
+ * @license MIT
5
+ * {@link http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136}
6
+ */
7
+ export default class UUID {
10
8
  constructor() {
11
9
  this.lut = [];
12
10
  for (let i = 0; i < 256; i++) {
@@ -14,6 +12,9 @@ class UUID {
14
12
  }
15
13
  this.generate = this.generate.bind(this);
16
14
  }
15
+ /**
16
+ * Generates a UUID
17
+ */
17
18
  generate() {
18
19
  const d0 = Math.random() * 0xffffffff | 0;
19
20
  const d1 = Math.random() * 0xffffffff | 0;
@@ -36,6 +37,9 @@ class UUID {
36
37
  this.lut[d3 >> 16 & 0xff] +
37
38
  this.lut[d3 >> 24 & 0xff];
38
39
  }
40
+ /**
41
+ * Static method for generating a UUID
42
+ */
39
43
  static generate() {
40
44
  if (typeof self?.crypto?.randomUUID === "function") {
41
45
  return self.crypto.randomUUID();
@@ -43,4 +47,3 @@ class UUID {
43
47
  return (new UUID()).generate();
44
48
  }
45
49
  }
46
- exports.default = UUID;
package/lib/index.d.ts CHANGED
@@ -1,14 +1,16 @@
1
- export { Bridge } from "./Bridge";
2
- export { Button } from "./Actions/Button";
3
- export { Redirect } from "./Actions/Redirect";
4
- export { Toast, ToastType } from "./Actions/Toast";
5
- export { Dialog } from "./Actions/Dialog";
6
- export { SaleKey } from "./Actions/SaleKey";
7
- export { SellScreenOption } from "./EmitableEvents/SellScreenOption";
8
- export { TableUpdate } from "./EmitableEvents/TableUpdate";
9
- export { SaleData as SaleCreateData, SalePaymentData as SaleCreatePaymentData, SaleProductData as SaleCreateProductData } from "./Utilities/SaleCreate";
10
- export { SellScreenPromotionApplicable } from "./EmitableEvents/SellScreenPromotionApplicable";
11
- export { CompletedSale } from "./Events/SaleComplete";
12
- export { Application, ShopfrontEmbeddedVerificationToken, ShopfrontTokenDecodingError } from "./Application";
13
- export * as Sales from "./APIs/Sale/index";
14
- export * as Fulfilment from "./EmitableEvents/Fulfilment/index";
1
+ export { Button } from "./Actions/Button.js";
2
+ export { Dialog } from "./Actions/Dialog.js";
3
+ export { Redirect } from "./Actions/Redirect.js";
4
+ export { SaleKey } from "./Actions/SaleKey.js";
5
+ export { Toast, type ToastType } from "./Actions/Toast.js";
6
+ export * as Sales from "./APIs/Sale/index.js";
7
+ export { Application } from "./Application.js";
8
+ export { type ShopfrontEmbeddedVerificationToken, ShopfrontTokenDecodingError } from "./BaseApplication.js";
9
+ export { Bridge } from "./Bridge.js";
10
+ export * as Fulfilment from "./EmitableEvents/Fulfilment/index.js";
11
+ export { SellScreenOption } from "./EmitableEvents/SellScreenOption.js";
12
+ export { SellScreenPromotionApplicable } from "./EmitableEvents/SellScreenPromotionApplicable.js";
13
+ export { TableUpdate } from "./EmitableEvents/TableUpdate.js";
14
+ export type { CompletedSale } from "./Events/SaleComplete.js";
15
+ export * from "./Mocks/index.js";
16
+ export type { SaleData as SaleCreateData, SalePaymentData as SaleCreatePaymentData, SaleProductData as SaleCreateProductData, } from "./Utilities/SaleCreate.js";
package/lib/index.js CHANGED
@@ -1,49 +1,14 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Fulfilment = exports.Sales = exports.ShopfrontTokenDecodingError = exports.Application = exports.SellScreenPromotionApplicable = exports.TableUpdate = exports.SellScreenOption = exports.SaleKey = exports.Dialog = exports.Toast = exports.Redirect = exports.Button = exports.Bridge = void 0;
27
- var Bridge_1 = require("./Bridge");
28
- Object.defineProperty(exports, "Bridge", { enumerable: true, get: function () { return Bridge_1.Bridge; } });
29
- var Button_1 = require("./Actions/Button");
30
- Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return Button_1.Button; } });
31
- var Redirect_1 = require("./Actions/Redirect");
32
- Object.defineProperty(exports, "Redirect", { enumerable: true, get: function () { return Redirect_1.Redirect; } });
33
- var Toast_1 = require("./Actions/Toast");
34
- Object.defineProperty(exports, "Toast", { enumerable: true, get: function () { return Toast_1.Toast; } });
35
- var Dialog_1 = require("./Actions/Dialog");
36
- Object.defineProperty(exports, "Dialog", { enumerable: true, get: function () { return Dialog_1.Dialog; } });
37
- var SaleKey_1 = require("./Actions/SaleKey");
38
- Object.defineProperty(exports, "SaleKey", { enumerable: true, get: function () { return SaleKey_1.SaleKey; } });
39
- var SellScreenOption_1 = require("./EmitableEvents/SellScreenOption");
40
- Object.defineProperty(exports, "SellScreenOption", { enumerable: true, get: function () { return SellScreenOption_1.SellScreenOption; } });
41
- var TableUpdate_1 = require("./EmitableEvents/TableUpdate");
42
- Object.defineProperty(exports, "TableUpdate", { enumerable: true, get: function () { return TableUpdate_1.TableUpdate; } });
43
- var SellScreenPromotionApplicable_1 = require("./EmitableEvents/SellScreenPromotionApplicable");
44
- Object.defineProperty(exports, "SellScreenPromotionApplicable", { enumerable: true, get: function () { return SellScreenPromotionApplicable_1.SellScreenPromotionApplicable; } });
45
- var Application_1 = require("./Application");
46
- Object.defineProperty(exports, "Application", { enumerable: true, get: function () { return Application_1.Application; } });
47
- Object.defineProperty(exports, "ShopfrontTokenDecodingError", { enumerable: true, get: function () { return Application_1.ShopfrontTokenDecodingError; } });
48
- exports.Sales = __importStar(require("./APIs/Sale/index"));
49
- exports.Fulfilment = __importStar(require("./EmitableEvents/Fulfilment/index"));
1
+ export { Button } from "./Actions/Button.js";
2
+ export { Dialog } from "./Actions/Dialog.js";
3
+ export { Redirect } from "./Actions/Redirect.js";
4
+ export { SaleKey } from "./Actions/SaleKey.js";
5
+ export { Toast } from "./Actions/Toast.js";
6
+ export * as Sales from "./APIs/Sale/index.js";
7
+ export { Application } from "./Application.js";
8
+ export { ShopfrontTokenDecodingError } from "./BaseApplication.js";
9
+ export { Bridge } from "./Bridge.js";
10
+ export * as Fulfilment from "./EmitableEvents/Fulfilment/index.js";
11
+ export { SellScreenOption } from "./EmitableEvents/SellScreenOption.js";
12
+ export { SellScreenPromotionApplicable } from "./EmitableEvents/SellScreenPromotionApplicable.js";
13
+ export { TableUpdate } from "./EmitableEvents/TableUpdate.js";
14
+ export * from "./Mocks/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopfront/bridge",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "main": "./lib/index.js",
5
5
  "license": "ISC",
6
6
  "description": "The bridge used to embed your application within Shopfront",
@@ -30,6 +30,7 @@
30
30
  "build": "tsc",
31
31
  "watch": "tsc -w",
32
32
  "lint": "eslint . --fix",
33
- "test": "npx @onshopfront/core test"
33
+ "test": "npx @onshopfront/core test",
34
+ "prepublishOnly": "npm run build"
34
35
  }
35
36
  }
@@ -1,6 +0,0 @@
1
- export declare class SaleCancelledError extends Error {
2
- constructor();
3
- }
4
- export declare class InvalidSaleDeviceError extends Error {
5
- constructor();
6
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InvalidSaleDeviceError = exports.SaleCancelledError = void 0;
4
- class SaleCancelledError extends Error {
5
- constructor() {
6
- super("The sale is no longer active.");
7
- }
8
- }
9
- exports.SaleCancelledError = SaleCancelledError;
10
- class InvalidSaleDeviceError extends Error {
11
- constructor() {
12
- super("This device is no longer a register able to perform a sale.");
13
- }
14
- }
15
- exports.InvalidSaleDeviceError = InvalidSaleDeviceError;
@@ -1,182 +0,0 @@
1
- import { Application } from "../../Application";
2
- import { ShopfrontSaleState } from "./ShopfrontSaleState";
3
- import { SaleUpdate, SaleUpdateChanges } from "../../Actions/SaleUpdate";
4
- import { SaleProduct } from "./SaleProduct";
5
- import { SalePayment } from "./SalePayment";
6
- import { SaleCustomer } from "./SaleCustomer";
7
- export declare class Sale {
8
- protected application: Application;
9
- protected sale: ShopfrontSaleState;
10
- protected cancelled: boolean;
11
- /**
12
- * Create a sale from a sale state.
13
- * It's highly recommend to not construct a sale manually, instead use application.getCurrentSale().
14
- *
15
- * @param {Application} application
16
- * @param {ShopfrontSaleState} sale
17
- */
18
- constructor(application: Application, sale: ShopfrontSaleState);
19
- /**
20
- * Get the raw state of the sale, it is highly recommend that you DO NOT use this method as the
21
- * returned data may be quite volatile.
22
- *
23
- * @internal
24
- * @returns {ShopfrontSaleState}
25
- */
26
- getRawState(): ShopfrontSaleState;
27
- /**
28
- * Update the sale to be the latest sale that exists on the sell screen.
29
- *
30
- * @returns {Promise<void>}
31
- */
32
- refreshSale(): Promise<void>;
33
- /**
34
- * Check if the sale has already been cancelled, if it has, throw a SaleCancelledError.
35
- *
36
- * @protected
37
- */
38
- protected checkIfCancelled(): void;
39
- /**
40
- * Send a sale update to Shopfront.
41
- *
42
- * @protected
43
- * @param {SaleUpdate} update
44
- * @returns {Promise<void>}
45
- */
46
- protected sendSaleUpdate(update: SaleUpdate<keyof SaleUpdateChanges>): Promise<void>;
47
- /**
48
- * Get the products that are currently on the sale.
49
- *
50
- * @returns {Array<SaleProduct>}
51
- */
52
- getProducts(): Array<SaleProduct>;
53
- /**
54
- * Get the payments that are currently on the sale.
55
- *
56
- * @returns {Array<SalePayment>}
57
- */
58
- getPayments(): Array<SalePayment>;
59
- /**
60
- * Get the current customer on the sale.
61
- *
62
- * @returns {SaleCustomer | null}
63
- */
64
- getCustomer(): null | SaleCustomer;
65
- /**
66
- * Get the external sale note (visible to the customer).
67
- *
68
- * @returns {string}
69
- */
70
- getExternalNote(): string;
71
- /**
72
- * Get the internal sale note.
73
- *
74
- * @returns {string}
75
- */
76
- getInternalNote(): string;
77
- /**
78
- * Get the order reference (visible to the customer).
79
- *
80
- * @returns {string}
81
- */
82
- getOrderReference(): string;
83
- /**
84
- * Get the current meta data for the sale
85
- *
86
- * @returns {Record<string, unknown>}
87
- */
88
- getMetaData(): Record<string, unknown>;
89
- /**
90
- * Cancel the current sale in progress.
91
- *
92
- * @returns {Promise<void>}
93
- */
94
- cancelSale(): Promise<void>;
95
- /**
96
- * Add a product to the sale.
97
- *
98
- * @param {SaleProduct} product
99
- * @returns {Promise<void>}
100
- */
101
- addProduct(product: SaleProduct): Promise<void>;
102
- /**
103
- * Remove a product from the sale.
104
- * It's highly recommended that you pass in a product that has been retrieved using sale.getProducts().
105
- *
106
- * @param {SaleProduct} product
107
- * @returns {Promise<void>}
108
- */
109
- removeProduct(product: SaleProduct): Promise<void>;
110
- /**
111
- * Add a payment to the sell screen.
112
- *
113
- * If you specify a payment with a status, it will bypass the payment gateway (i.e. it won't request that the
114
- * user takes money from the customer).
115
- *
116
- * If you don't specify a cashout amount, it will automatically determine if the payment method normally requests
117
- * cashout (from the payment method settings).
118
- *
119
- * @param {SalePayment} payment
120
- * @returns {Promise<void>}
121
- */
122
- addPayment(payment: SalePayment): Promise<void>;
123
- /**
124
- * Reverse a payment on the sell screen.
125
- *
126
- * This is used to issue a refund to the customer. The sale payment amount should be positive.
127
- *
128
- * @param {SalePayment} payment
129
- * @returns {Promise<void>}
130
- */
131
- reversePayment(payment: SalePayment): Promise<void>;
132
- /**
133
- * Add a customer to the sale.
134
- * If there is already a customer on the sale this will override that customer.
135
- *
136
- * @param {SaleCustomer} customer
137
- * @returns {Promise<void>}
138
- */
139
- addCustomer(customer: SaleCustomer): Promise<void>;
140
- /**
141
- * Remove the customer from the current sale.
142
- * If there is no customer currently on the sale this will be ignored.
143
- * If there are "on account" or loyalty payments still on the sale, this will be ignored.
144
- *
145
- * @returns {Promise<void>}
146
- */
147
- removeCustomer(): Promise<void>;
148
- /**
149
- * Set the external note for the sale.
150
- *
151
- * @param {string} note The note to set.
152
- * @param {boolean} append Whether to append the note to the current sale note.
153
- * @returns {Promise<void>}
154
- */
155
- setExternalNote(note: string, append?: boolean): Promise<void>;
156
- /**
157
- * Set the internal note for the sale.
158
- *
159
- * @param {string} note The note to set.
160
- * @param {boolean} append Whether to append the note to the current sale note.
161
- * @returns {Promise<void>}
162
- */
163
- setInternalNote(note: string, append?: boolean): Promise<void>;
164
- /**
165
- * Set the order reference to the provided string.
166
- *
167
- * @param {string} reference
168
- * @returns {Promise<void>}
169
- */
170
- setOrderReference(reference: string): Promise<void>;
171
- /**
172
- * Set the meta data of the sale, this will override the previous meta data.
173
- *
174
- * @param metaData
175
- */
176
- setMetaData(metaData: Record<string, unknown>): Promise<void>;
177
- /**
178
- * Update a product's details, currently this only updates the top-level meta data
179
- * @param product
180
- */
181
- updateProduct(product: SaleProduct): Promise<void>;
182
- }