@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,154 @@
1
+ import { Sale } from "../APIs/Sale/index.js";
2
+ import { DirectShopfrontEvent, DirectShopfrontEventCallback, FromShopfront, FromShopfrontCallbacks, FromShopfrontInternal, ListenableFromShopfrontEvents, RegisterChangedEvent, SellScreenActionMode, SellScreenSummaryMode, SoundEvents } from "../ApplicationEvents.js";
3
+ import { BaseApplication, ShopfrontEmbeddedVerificationToken } from "../BaseApplication.js";
4
+ import { Serializable } from "../Common/Serializable.js";
5
+ import { BaseEmitableEvent } from "../EmitableEvents/BaseEmitableEvent.js";
6
+ import { MaybePromise } from "../Utilities/MiscTypes.js";
7
+ import { MockCurrentSale } from "./APIs/Sale/MockCurrentSale.js";
8
+ import { MockBridge } from "./MockBridge.js";
9
+ interface AudioRequestOptions {
10
+ hasPermission: boolean;
11
+ forceError: boolean;
12
+ }
13
+ export declare class MockApplication extends BaseApplication {
14
+ protected currentSale: MockCurrentSale | false;
15
+ constructor(bridge: MockBridge);
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ destroy(): void;
20
+ /**
21
+ * Handles an application event
22
+ */
23
+ protected handleEvent: (event: keyof FromShopfront | keyof FromShopfrontInternal, data: Record<string, unknown>, id: string) => void;
24
+ /**
25
+ * Calls any registered listeners for the received event
26
+ */
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;
44
+ /**
45
+ * @inheritDoc
46
+ */
47
+ send(item: BaseEmitableEvent<unknown> | Serializable<unknown>): void;
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ download(file: string): void;
52
+ /**
53
+ * @inheritDoc
54
+ */
55
+ redirect(toLocation: string, externalRedirect?: boolean): void;
56
+ /**
57
+ * @inheritDoc
58
+ */
59
+ load(): () => void;
60
+ /**
61
+ * @inheritDoc
62
+ */
63
+ protected handleEventCallback(data: {
64
+ id?: string;
65
+ data: unknown;
66
+ }): void;
67
+ /**
68
+ * Updates the cached location data
69
+ */
70
+ protected handleLocationChanged: (data: RegisterChangedEvent) => undefined;
71
+ /**
72
+ * @inheritDoc
73
+ */
74
+ getAuthenticationKey(): string;
75
+ /**
76
+ * @inheritDoc
77
+ */
78
+ getCurrentSale(): Promise<MockCurrentSale | false>;
79
+ /**
80
+ * @inheritDoc
81
+ */
82
+ createSale(sale: Sale): Promise<{
83
+ success: boolean;
84
+ message?: string;
85
+ }>;
86
+ /**
87
+ * @inheritDoc
88
+ */
89
+ getLocation(options?: {
90
+ globalMode: boolean;
91
+ useRegister: boolean;
92
+ }): Promise<{
93
+ register: string | null;
94
+ outlet: string | null;
95
+ user: string | null;
96
+ }>;
97
+ /**
98
+ * @inheritDoc
99
+ */
100
+ printReceipt(content: string): void;
101
+ /**
102
+ * @inheritDoc
103
+ */
104
+ changeSellScreenActionMode(mode: SellScreenActionMode): void;
105
+ /**
106
+ * @inheritDoc
107
+ */
108
+ changeSellScreenSummaryMode(mode: SellScreenSummaryMode): void;
109
+ /**
110
+ * @inheritDoc
111
+ */
112
+ protected sendAudioRequest(type: SoundEvents, data?: unknown, options?: AudioRequestOptions): Promise<{
113
+ success: boolean;
114
+ message?: string;
115
+ }>;
116
+ /**
117
+ * @inheritDoc
118
+ */
119
+ requestAudioPermission(options?: AudioRequestOptions): Promise<{
120
+ success: boolean;
121
+ message?: string;
122
+ }>;
123
+ /**
124
+ * @inheritDoc
125
+ */
126
+ audioPreload(url: string, options?: AudioRequestOptions): Promise<{
127
+ success: boolean;
128
+ message?: string;
129
+ }>;
130
+ /**
131
+ * @inheritDoc
132
+ */
133
+ audioPlay(url: string, options?: AudioRequestOptions): Promise<{
134
+ success: boolean;
135
+ message?: string;
136
+ }>;
137
+ /**
138
+ * @inheritDoc
139
+ */
140
+ getOption<TValueType>(option: string, defaultValue: TValueType): Promise<TValueType>;
141
+ /**
142
+ * @inheritDoc
143
+ */
144
+ getToken(returnTokenObject: true): Promise<ShopfrontEmbeddedVerificationToken>;
145
+ /**
146
+ * @inheritDoc
147
+ */
148
+ getToken(returnTokenObject?: false): Promise<string>;
149
+ /**
150
+ * Mocks an event being fired from Shopfront
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;
153
+ }
154
+ export {};
@@ -0,0 +1,482 @@
1
+ import { isDirectShopfrontEvent, ToShopfront, } from "../ApplicationEvents.js";
2
+ import { BaseApplication } from "../BaseApplication.js";
3
+ import { AudioPermissionChange } from "../Events/AudioPermissionChange.js";
4
+ import { AudioReady } from "../Events/AudioReady.js";
5
+ import { FormatIntegratedProduct } from "../Events/FormatIntegratedProduct.js";
6
+ import { FulfilmentCollectOrder } from "../Events/FulfilmentCollectOrder.js";
7
+ import { FulfilmentCompleteOrder } from "../Events/FulfilmentCompleteOrder.js";
8
+ import { FulfilmentGetOrder } from "../Events/FulfilmentGetOrder.js";
9
+ import { FulfilmentOrderApproval } from "../Events/FulfilmentOrderApproval.js";
10
+ import { FulfilmentProcessOrder } from "../Events/FulfilmentProcessOrder.js";
11
+ import { FulfilmentVoidOrder } from "../Events/FulfilmentVoidOrder.js";
12
+ import { GiftCardCodeCheck } from "../Events/GiftCardCodeCheck.js";
13
+ import { InternalPageMessage } from "../Events/InternalPageMessage.js";
14
+ import { PaymentMethodsEnabled } from "../Events/PaymentMethodsEnabled.js";
15
+ import { Ready } from "../Events/Ready.js";
16
+ import { RegisterChanged } from "../Events/RegisterChanged.js";
17
+ import { RequestButtons } from "../Events/RequestButtons.js";
18
+ import { RequestCustomerListOptions } from "../Events/RequestCustomerListOptions.js";
19
+ import { RequestSaleKeys } from "../Events/RequestSaleKeys.js";
20
+ import { RequestSellScreenOptions } from "../Events/RequestSellScreenOptions.js";
21
+ import { RequestSettings } from "../Events/RequestSettings.js";
22
+ import { RequestTableColumns } from "../Events/RequestTableColumns.js";
23
+ import { SaleComplete } from "../Events/SaleComplete.js";
24
+ import { UIPipeline } from "../Events/UIPipeline.js";
25
+ import ActionEventRegistrar from "../Utilities/ActionEventRegistrar.js";
26
+ import { MockCurrentSale } from "./APIs/Sale/MockCurrentSale.js";
27
+ import { MockDatabase } from "./Database/MockDatabase.js";
28
+ export class MockApplication extends BaseApplication {
29
+ constructor(bridge) {
30
+ super(bridge, new MockDatabase(bridge));
31
+ this.currentSale = false;
32
+ /**
33
+ * Handles an application event
34
+ */
35
+ this.handleEvent = (event, data, id) => {
36
+ if (event === "READY") {
37
+ this.isReady = true;
38
+ this.key = data.key;
39
+ this.outlet = data.outlet;
40
+ this.register = data.register;
41
+ data = {
42
+ outlet: data.outlet,
43
+ register: data.register,
44
+ };
45
+ }
46
+ if (event === "CALLBACK") {
47
+ // Actions aren't implemented
48
+ return;
49
+ }
50
+ if (event === "CYCLE_KEY") {
51
+ // Not needed
52
+ return;
53
+ }
54
+ else if (event === "LOCATION_CHANGED") {
55
+ // Unregister all serialized listeners as they're no longer displayed
56
+ ActionEventRegistrar.clear();
57
+ return;
58
+ }
59
+ else if (event === "RESPONSE_CURRENT_SALE" ||
60
+ event === "RESPONSE_DATABASE_REQUEST" ||
61
+ event === "RESPONSE_LOCATION" ||
62
+ event === "RESPONSE_OPTION" ||
63
+ event === "RESPONSE_AUDIO_REQUEST" ||
64
+ event === "RESPONSE_SECURE_KEY" ||
65
+ event === "RESPONSE_CREATE_SALE") {
66
+ // Handled elsewhere
67
+ return;
68
+ }
69
+ this.emit(event, data, id);
70
+ };
71
+ /**
72
+ * Updates the cached location data
73
+ */
74
+ this.handleLocationChanged = (data) => {
75
+ this.register = data.register;
76
+ this.outlet = data.outlet;
77
+ this.user = data.user;
78
+ };
79
+ this.bridge.addEventListener(this.handleEvent);
80
+ this.addEventListener("REGISTER_CHANGED", this.handleLocationChanged);
81
+ this.fireEvent.bind(this);
82
+ // Fire a ready event immediately
83
+ this.handleEvent("READY", {
84
+ key: "embedded-key",
85
+ outlet: "outlet-id",
86
+ register: "register-id",
87
+ }, "");
88
+ }
89
+ /**
90
+ * @inheritDoc
91
+ */
92
+ destroy() {
93
+ this.bridge.destroy();
94
+ }
95
+ /**
96
+ * Calls any registered listeners for the received event
97
+ */
98
+ emit(event, data = {}, id) {
99
+ if (isDirectShopfrontEvent(event)) {
100
+ const listeners = this.directListeners[event];
101
+ if (typeof listeners === "undefined") {
102
+ // Don't need to do anything here
103
+ return;
104
+ }
105
+ const results = [];
106
+ for (const e of listeners.values()) {
107
+ results.push(e());
108
+ }
109
+ return Promise.all(results)
110
+ .then(() => {
111
+ // Ensure void is returned
112
+ });
113
+ }
114
+ const results = [];
115
+ if (typeof this.listeners[event] === "undefined") {
116
+ // Don't need to do anything here
117
+ return;
118
+ }
119
+ if (this.listeners[event].size === 0) {
120
+ // Don't need to do anything here
121
+ return;
122
+ }
123
+ const bridge = this.bridge;
124
+ for (const e of this.listeners[event].values()) {
125
+ results.push(e.emit(data, bridge));
126
+ }
127
+ // The responses have been removed as we don't currently need them
128
+ }
129
+ /**
130
+ * @inheritDoc
131
+ */
132
+ addEventListener(event, callback) {
133
+ if (isDirectShopfrontEvent(event)) {
134
+ if (typeof this.directListeners[event] === "undefined") {
135
+ this.directListeners[event] = new Set();
136
+ }
137
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
138
+ this.directListeners[event].add(callback);
139
+ return;
140
+ }
141
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
+ let c;
143
+ switch (event) {
144
+ case "READY":
145
+ c = new Ready(callback);
146
+ this.listeners[event].set(callback, c);
147
+ break;
148
+ case "REQUEST_SETTINGS":
149
+ c = new RequestSettings(callback);
150
+ this.listeners[event].set(callback, c);
151
+ break;
152
+ case "REQUEST_BUTTONS":
153
+ c = new RequestButtons(callback);
154
+ this.listeners[event].set(callback, c);
155
+ break;
156
+ case "REQUEST_TABLE_COLUMNS":
157
+ c = new RequestTableColumns(callback);
158
+ this.listeners[event].set(callback, c);
159
+ break;
160
+ case "REQUEST_SELL_SCREEN_OPTIONS":
161
+ c = new RequestSellScreenOptions(callback);
162
+ this.listeners[event].set(callback, c);
163
+ break;
164
+ case "INTERNAL_PAGE_MESSAGE":
165
+ c = new InternalPageMessage(callback, this);
166
+ this.listeners[event].set(callback, c);
167
+ break;
168
+ case "REGISTER_CHANGED":
169
+ c = new RegisterChanged(callback);
170
+ this.listeners[event].set(callback, c);
171
+ break;
172
+ case "REQUEST_CUSTOMER_LIST_OPTIONS":
173
+ c = new RequestCustomerListOptions(callback);
174
+ this.listeners[event].set(callback, c);
175
+ break;
176
+ case "FORMAT_INTEGRATED_PRODUCT":
177
+ c = new FormatIntegratedProduct(callback);
178
+ this.listeners[event].set(callback, c);
179
+ break;
180
+ case "REQUEST_SALE_KEYS":
181
+ c = new RequestSaleKeys(callback);
182
+ this.listeners[event].set(callback, c);
183
+ break;
184
+ case "SALE_COMPLETE":
185
+ c = new SaleComplete(callback);
186
+ this.listeners[event].set(callback, c);
187
+ break;
188
+ case "UI_PIPELINE":
189
+ c = new UIPipeline(callback);
190
+ this.listeners[event].set(callback, c);
191
+ break;
192
+ case "PAYMENT_METHODS_ENABLED":
193
+ c = new PaymentMethodsEnabled(callback);
194
+ this.listeners[event].set(callback, c);
195
+ break;
196
+ case "AUDIO_READY":
197
+ c = new AudioReady(callback);
198
+ this.listeners[event].set(callback, c);
199
+ break;
200
+ case "AUDIO_PERMISSION_CHANGE":
201
+ c = new AudioPermissionChange(callback);
202
+ this.listeners[event].set(callback, c);
203
+ break;
204
+ case "FULFILMENT_GET_ORDER":
205
+ if (this.listeners[event].size !== 0) {
206
+ throw new TypeError("Application already has 'FULFILMENT_GET_ORDER' event listener registered.");
207
+ }
208
+ c = new FulfilmentGetOrder(callback);
209
+ this.listeners[event].set(callback, c);
210
+ break;
211
+ case "FULFILMENT_VOID_ORDER":
212
+ c = new FulfilmentVoidOrder(callback);
213
+ this.listeners[event].set(callback, c);
214
+ break;
215
+ case "FULFILMENT_PROCESS_ORDER":
216
+ c = new FulfilmentProcessOrder(callback);
217
+ this.listeners[event].set(callback, c);
218
+ break;
219
+ case "FULFILMENT_ORDER_APPROVAL":
220
+ c = new FulfilmentOrderApproval(callback);
221
+ this.listeners[event].set(callback, c);
222
+ break;
223
+ case "FULFILMENT_ORDER_COLLECTED":
224
+ c = new FulfilmentCollectOrder(callback);
225
+ this.listeners[event].set(callback, c);
226
+ break;
227
+ case "FULFILMENT_ORDER_COMPLETED":
228
+ c = new FulfilmentCompleteOrder(callback);
229
+ this.listeners[event].set(callback, c);
230
+ break;
231
+ case "GIFT_CARD_CODE_CHECK":
232
+ c = new GiftCardCodeCheck(callback);
233
+ this.listeners[event].set(callback, c);
234
+ break;
235
+ }
236
+ if (typeof c === "undefined") {
237
+ throw new TypeError(`${event} has not been defined`);
238
+ }
239
+ if (event === "READY" && this.isReady) {
240
+ c = c;
241
+ c.emit({
242
+ outlet: this.outlet,
243
+ register: this.register,
244
+ user: this.user,
245
+ });
246
+ }
247
+ }
248
+ /**
249
+ * @inheritDoc
250
+ */
251
+ removeEventListener(event, callback) {
252
+ if (isDirectShopfrontEvent(event)) {
253
+ this.directListeners[event]?.delete(callback);
254
+ return;
255
+ }
256
+ this.listeners[event].delete(callback);
257
+ }
258
+ /**
259
+ * @inheritDoc
260
+ */
261
+ send(item) {
262
+ /* empty */
263
+ }
264
+ /**
265
+ * @inheritDoc
266
+ */
267
+ download(file) {
268
+ /* empty */
269
+ }
270
+ /**
271
+ * @inheritDoc
272
+ */
273
+ redirect(toLocation, externalRedirect = true) {
274
+ /* empty */
275
+ }
276
+ /**
277
+ * @inheritDoc
278
+ */
279
+ load() {
280
+ return () => undefined;
281
+ }
282
+ /**
283
+ * @inheritDoc
284
+ */
285
+ handleEventCallback(data) {
286
+ /* empty */
287
+ }
288
+ /**
289
+ * @inheritDoc
290
+ */
291
+ getAuthenticationKey() {
292
+ return this.key;
293
+ }
294
+ /**
295
+ * @inheritDoc
296
+ */
297
+ async getCurrentSale() {
298
+ if (!this.currentSale) {
299
+ this.currentSale = new MockCurrentSale(this);
300
+ }
301
+ return this.currentSale;
302
+ }
303
+ /**
304
+ * @inheritDoc
305
+ */
306
+ async createSale(sale) {
307
+ if (!sale.getRegister() && !this.register) {
308
+ return {
309
+ success: false,
310
+ message: "Sale has not provided a register and Shopfront currently doesn't have a register selected.",
311
+ };
312
+ }
313
+ if (!this.user) {
314
+ return {
315
+ success: false,
316
+ message: "A sale cannot be created when there is no user logged in to Shopfront.",
317
+ };
318
+ }
319
+ const payments = sale.getPayments();
320
+ let totalPaid = 0;
321
+ for (const payment of payments) {
322
+ // TODO: Double check this is still the case
323
+ if (payment.getCashout()) {
324
+ return {
325
+ success: false,
326
+ message: "Sale payment with cash out is currently unsupported " +
327
+ "through the Embedded Fulfilment API.",
328
+ };
329
+ }
330
+ if (payment.getRounding()) {
331
+ return {
332
+ success: false,
333
+ message: "Sale payment with rounding is currently unsupported " +
334
+ "through the Embedded Fulfilment API.",
335
+ };
336
+ }
337
+ totalPaid += payment.getAmount();
338
+ }
339
+ // Round to 4 decimal places to keep consistent with POS
340
+ const remaining = Math.round((sale.getSaleTotal() - totalPaid) * 1000) / 1000;
341
+ if (remaining < 0) {
342
+ return {
343
+ success: false,
344
+ message: "Total paid is greater than sale total.",
345
+ };
346
+ }
347
+ return {
348
+ success: true,
349
+ };
350
+ }
351
+ /**
352
+ * @inheritDoc
353
+ */
354
+ async getLocation(options) {
355
+ if (options) {
356
+ if (options.globalMode) {
357
+ return {
358
+ register: null,
359
+ outlet: null,
360
+ user: "shopfront-user-id",
361
+ };
362
+ }
363
+ else if (!options.useRegister) {
364
+ return {
365
+ register: null,
366
+ outlet: "shopfront-outlet-id",
367
+ user: "shopfront-user-id",
368
+ };
369
+ }
370
+ }
371
+ return {
372
+ register: "shopfront-register-id",
373
+ outlet: "shopfront-outlet-id",
374
+ user: "shopfront-user-id",
375
+ };
376
+ }
377
+ /**
378
+ * @inheritDoc
379
+ */
380
+ printReceipt(content) {
381
+ /* empty */
382
+ }
383
+ /**
384
+ * @inheritDoc
385
+ */
386
+ changeSellScreenActionMode(mode) {
387
+ /* empty */
388
+ }
389
+ /**
390
+ * @inheritDoc
391
+ */
392
+ changeSellScreenSummaryMode(mode) {
393
+ /* empty */
394
+ }
395
+ /**
396
+ * @inheritDoc
397
+ */
398
+ async sendAudioRequest(type, data, options) {
399
+ if (options) {
400
+ if (!options.hasPermission) {
401
+ return {
402
+ success: false,
403
+ message: "You do not have permission to play audio",
404
+ };
405
+ }
406
+ if (options.forceError) {
407
+ return {
408
+ success: false,
409
+ message: "An error occurred whilst trying to play the audio",
410
+ };
411
+ }
412
+ }
413
+ return {
414
+ success: true,
415
+ };
416
+ }
417
+ /**
418
+ * @inheritDoc
419
+ */
420
+ requestAudioPermission(options) {
421
+ return this.sendAudioRequest(ToShopfront.AUDIO_REQUEST_PERMISSION, undefined, options);
422
+ }
423
+ /**
424
+ * @inheritDoc
425
+ */
426
+ audioPreload(url, options) {
427
+ return this.sendAudioRequest(ToShopfront.AUDIO_PRELOAD, {
428
+ url,
429
+ }, options);
430
+ }
431
+ /**
432
+ * @inheritDoc
433
+ */
434
+ audioPlay(url, options) {
435
+ return this.sendAudioRequest(ToShopfront.AUDIO_PLAY, {
436
+ url,
437
+ }, options);
438
+ }
439
+ /**
440
+ * @inheritDoc
441
+ */
442
+ async getOption(option, defaultValue) {
443
+ return defaultValue;
444
+ }
445
+ /**
446
+ * @inheritDoc
447
+ */
448
+ async getToken(returnTokenObject) {
449
+ if (returnTokenObject) {
450
+ return {
451
+ id: "token-id",
452
+ app: "app-id",
453
+ auth: "embedded-token",
454
+ user: "user-id",
455
+ url: {
456
+ raw: "https://testing.test",
457
+ loaded: "https://frame.url",
458
+ },
459
+ };
460
+ }
461
+ return "embedded-token";
462
+ }
463
+ /**
464
+ * Mocks an event being fired from Shopfront
465
+ */
466
+ fireEvent(event, ...data) {
467
+ let params;
468
+ if (data.length > 0) {
469
+ if (typeof data[0] === "object") {
470
+ params = {
471
+ ...data[0],
472
+ };
473
+ }
474
+ else {
475
+ params = data[0];
476
+ }
477
+ // We don't care about the Bridge parameter, as that is passed in by the `emit` method
478
+ }
479
+ this.emit(event, params, "");
480
+ }
481
+ ;
482
+ }
@@ -0,0 +1,31 @@
1
+ import * as ApplicationEvents from "../ApplicationEvents.js";
2
+ import { BaseBridge } from "../BaseBridge.js";
3
+ import { ApplicationEventListener } from "../Bridge.js";
4
+ export declare class MockBridge extends BaseBridge {
5
+ protected isReady: boolean;
6
+ constructor(key: string, url: string);
7
+ /**
8
+ * @inheritDoc
9
+ */
10
+ destroy(): void;
11
+ /**
12
+ * @inheritDoc
13
+ */
14
+ protected registerListeners(): void;
15
+ /**
16
+ * @inheritDoc
17
+ */
18
+ protected unregisterListeners(): void;
19
+ /**
20
+ * @inheritDoc
21
+ */
22
+ sendMessage(type: ApplicationEvents.ToShopfront, data?: unknown, id?: string): void;
23
+ /**
24
+ * @inheritDoc
25
+ */
26
+ addEventListener(listener: ApplicationEventListener): void;
27
+ /**
28
+ * @inheritDoc
29
+ */
30
+ removeEventListener(listener: ApplicationEventListener): void;
31
+ }