@shopfront/bridge 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +481 -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
@@ -1,290 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Sale = void 0;
4
- const SaleUpdate_1 = require("../../Actions/SaleUpdate");
5
- const SaleProduct_1 = require("./SaleProduct");
6
- const SalePayment_1 = require("./SalePayment");
7
- const SaleCustomer_1 = require("./SaleCustomer");
8
- const Exceptions_1 = require("./Exceptions");
9
- class Sale {
10
- /**
11
- * Create a sale from a sale state.
12
- * It's highly recommend to not construct a sale manually, instead use application.getCurrentSale().
13
- *
14
- * @param {Application} application
15
- * @param {ShopfrontSaleState} sale
16
- */
17
- constructor(application, sale) {
18
- this.application = application;
19
- this.sale = sale;
20
- this.cancelled = false;
21
- }
22
- /**
23
- * Get the raw state of the sale, it is highly recommend that you DO NOT use this method as the
24
- * returned data may be quite volatile.
25
- *
26
- * @internal
27
- * @returns {ShopfrontSaleState}
28
- */
29
- getRawState() {
30
- return this.sale;
31
- }
32
- /**
33
- * Update the sale to be the latest sale that exists on the sell screen.
34
- *
35
- * @returns {Promise<void>}
36
- */
37
- async refreshSale() {
38
- this.checkIfCancelled();
39
- const newSale = await this.application.getCurrentSale();
40
- if (newSale === false) {
41
- throw new Exceptions_1.InvalidSaleDeviceError();
42
- }
43
- this.sale = newSale.getRawState();
44
- }
45
- /**
46
- * Check if the sale has already been cancelled, if it has, throw a SaleCancelledError.
47
- *
48
- * @protected
49
- */
50
- checkIfCancelled() {
51
- if (this.cancelled) {
52
- throw new Exceptions_1.SaleCancelledError();
53
- }
54
- }
55
- /**
56
- * Send a sale update to Shopfront.
57
- *
58
- * @protected
59
- * @param {SaleUpdate} update
60
- * @returns {Promise<void>}
61
- */
62
- sendSaleUpdate(update) {
63
- this.checkIfCancelled();
64
- this.application.send(update);
65
- return this.refreshSale();
66
- }
67
- /**
68
- * Get the products that are currently on the sale.
69
- *
70
- * @returns {Array<SaleProduct>}
71
- */
72
- getProducts() {
73
- const products = [];
74
- for (let i = 0, l = this.sale.products.length; i < l; i++) {
75
- // The hydration method loops through child products so we don't have to
76
- // worry about that here.
77
- products.push(SaleProduct_1.SaleProduct.HydrateFromState(this.sale.products[i], [i]));
78
- }
79
- return products;
80
- }
81
- /**
82
- * Get the payments that are currently on the sale.
83
- *
84
- * @returns {Array<SalePayment>}
85
- */
86
- getPayments() {
87
- const payments = [];
88
- for (let i = 0, l = this.sale.payments.length; i < l; i++) {
89
- payments.push(SalePayment_1.SalePayment.HydrateFromState(this.sale.payments[i]));
90
- }
91
- return payments;
92
- }
93
- /**
94
- * Get the current customer on the sale.
95
- *
96
- * @returns {SaleCustomer | null}
97
- */
98
- getCustomer() {
99
- if (this.sale.customer === false) {
100
- return null;
101
- }
102
- return new SaleCustomer_1.SaleCustomer(this.sale.customer.uuid);
103
- }
104
- /**
105
- * Get the external sale note (visible to the customer).
106
- *
107
- * @returns {string}
108
- */
109
- getExternalNote() {
110
- return this.sale.notes.sale;
111
- }
112
- /**
113
- * Get the internal sale note.
114
- *
115
- * @returns {string}
116
- */
117
- getInternalNote() {
118
- return this.sale.notes.internal;
119
- }
120
- /**
121
- * Get the order reference (visible to the customer).
122
- *
123
- * @returns {string}
124
- */
125
- getOrderReference() {
126
- return this.sale.orderReference;
127
- }
128
- /**
129
- * Get the current meta data for the sale
130
- *
131
- * @returns {Record<string, unknown>}
132
- */
133
- getMetaData() {
134
- return this.sale.metaData;
135
- }
136
- /**
137
- * Cancel the current sale in progress.
138
- *
139
- * @returns {Promise<void>}
140
- */
141
- async cancelSale() {
142
- await this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_CANCEL", {}));
143
- this.cancelled = true;
144
- }
145
- /**
146
- * Add a product to the sale.
147
- *
148
- * @param {SaleProduct} product
149
- * @returns {Promise<void>}
150
- */
151
- addProduct(product) {
152
- return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PRODUCT_ADD", {
153
- id: product.getId(),
154
- quantity: product.getQuantity(),
155
- price: product.getPrice(),
156
- indexAddress: product.getIndexAddress(),
157
- metaData: product.getMetaData(),
158
- }));
159
- }
160
- /**
161
- * Remove a product from the sale.
162
- * It's highly recommended that you pass in a product that has been retrieved using sale.getProducts().
163
- *
164
- * @param {SaleProduct} product
165
- * @returns {Promise<void>}
166
- */
167
- removeProduct(product) {
168
- return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PRODUCT_REMOVE", {
169
- id: product.getId(),
170
- indexAddress: product.getIndexAddress(),
171
- }));
172
- }
173
- /**
174
- * Add a payment to the sell screen.
175
- *
176
- * If you specify a payment with a status, it will bypass the payment gateway (i.e. it won't request that the
177
- * user takes money from the customer).
178
- *
179
- * If you don't specify a cashout amount, it will automatically determine if the payment method normally requests
180
- * cashout (from the payment method settings).
181
- *
182
- * @param {SalePayment} payment
183
- * @returns {Promise<void>}
184
- */
185
- addPayment(payment) {
186
- return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PAYMENT_ADD", {
187
- id: payment.getId(),
188
- amount: payment.getAmount(),
189
- cashout: payment.getCashout(),
190
- status: payment.getStatus(),
191
- }));
192
- }
193
- /**
194
- * Reverse a payment on the sell screen.
195
- *
196
- * This is used to issue a refund to the customer. The sale payment amount should be positive.
197
- *
198
- * @param {SalePayment} payment
199
- * @returns {Promise<void>}
200
- */
201
- reversePayment(payment) {
202
- return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PAYMENT_REVERSE", {
203
- id: payment.getId(),
204
- amount: payment.getAmount(),
205
- cashout: payment.getCashout(),
206
- status: payment.getStatus(),
207
- }));
208
- }
209
- /**
210
- * Add a customer to the sale.
211
- * If there is already a customer on the sale this will override that customer.
212
- *
213
- * @param {SaleCustomer} customer
214
- * @returns {Promise<void>}
215
- */
216
- addCustomer(customer) {
217
- return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("CUSTOMER_ADD", {
218
- id: customer.getId(),
219
- }));
220
- }
221
- /**
222
- * Remove the customer from the current sale.
223
- * If there is no customer currently on the sale this will be ignored.
224
- * If there are "on account" or loyalty payments still on the sale, this will be ignored.
225
- *
226
- * @returns {Promise<void>}
227
- */
228
- removeCustomer() {
229
- return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("CUSTOMER_REMOVE", {}));
230
- }
231
- /**
232
- * Set the external note for the sale.
233
- *
234
- * @param {string} note The note to set.
235
- * @param {boolean} append Whether to append the note to the current sale note.
236
- * @returns {Promise<void>}
237
- */
238
- setExternalNote(note, append = false) {
239
- return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_EXTERNAL_NOTE", {
240
- note,
241
- append,
242
- }));
243
- }
244
- /**
245
- * Set the internal note for the sale.
246
- *
247
- * @param {string} note The note to set.
248
- * @param {boolean} append Whether to append the note to the current sale note.
249
- * @returns {Promise<void>}
250
- */
251
- setInternalNote(note, append = false) {
252
- return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_INTERNAL_NOTE", {
253
- note,
254
- append,
255
- }));
256
- }
257
- /**
258
- * Set the order reference to the provided string.
259
- *
260
- * @param {string} reference
261
- * @returns {Promise<void>}
262
- */
263
- setOrderReference(reference) {
264
- return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_ORDER_REFERENCE", {
265
- reference,
266
- }));
267
- }
268
- /**
269
- * Set the meta data of the sale, this will override the previous meta data.
270
- *
271
- * @param metaData
272
- */
273
- setMetaData(metaData) {
274
- return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("SALE_META_DATA", {
275
- metaData,
276
- }));
277
- }
278
- /**
279
- * Update a product's details, currently this only updates the top-level meta data
280
- * @param product
281
- */
282
- updateProduct(product) {
283
- return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PRODUCT_UPDATE", {
284
- id: product.getId(),
285
- indexAddress: product.getIndexAddress(),
286
- metaData: product.getMetaData(),
287
- }));
288
- }
289
- }
290
- exports.Sale = Sale;
@@ -1,10 +0,0 @@
1
- export declare class SaleCustomer {
2
- protected id: string;
3
- constructor(id: string);
4
- /**
5
- * Get the ID of the customer.
6
- *
7
- * @returns {string}
8
- */
9
- getId(): string;
10
- }
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SaleCustomer = void 0;
4
- class SaleCustomer {
5
- constructor(id) {
6
- this.id = id;
7
- }
8
- /**
9
- * Get the ID of the customer.
10
- *
11
- * @returns {string}
12
- */
13
- getId() {
14
- return this.id;
15
- }
16
- }
17
- exports.SaleCustomer = SaleCustomer;
@@ -1,68 +0,0 @@
1
- import { ShopfrontSalePayment } from "./ShopfrontSaleState";
2
- export declare enum SalePaymentStatus {
3
- APPROVED = "completed",
4
- DECLINED = "failed",
5
- CANCELLED = "cancelled"
6
- }
7
- export declare class SalePayment {
8
- protected id: string;
9
- protected type?: string;
10
- protected status?: SalePaymentStatus;
11
- protected amount: number;
12
- protected cashout?: number;
13
- protected rounding?: number;
14
- constructor(id: string, amount: number, cashout?: number, status?: SalePaymentStatus);
15
- /**
16
- * Hydrate a sale payment from the SaleState.
17
- *
18
- * @internal
19
- * @param {ShopfrontSalePayment} payment
20
- * @returns {SalePayment}
21
- * @constructor
22
- */
23
- static HydrateFromState(payment: ShopfrontSalePayment): SalePayment;
24
- /**
25
- * Set the internal data for the payment.
26
- * This method is for hydration of the payment from Shopfront, it's highly recommend that you DO NOT use this method.
27
- *
28
- * @internal
29
- * @param {ShopfrontSalePayment} data
30
- */
31
- setInternal(data: ShopfrontSalePayment): void;
32
- /**
33
- * Get the ID of the sale payment method.
34
- *
35
- * @returns {string}
36
- */
37
- getId(): string;
38
- /**
39
- * Get the type of payment method this is.
40
- *
41
- * @returns {string | undefined}
42
- */
43
- getType(): string | undefined;
44
- /**
45
- * Get the status of this payment method.
46
- *
47
- * @returns {SalePaymentStatus | undefined}
48
- */
49
- getStatus(): SalePaymentStatus | undefined;
50
- /**
51
- * Get the value of this payment method.
52
- *
53
- * @returns {number}
54
- */
55
- getAmount(): number;
56
- /**
57
- * Get the cashout amount paid for on this payment method.
58
- *
59
- * @returns {number | undefined}
60
- */
61
- getCashout(): number | undefined;
62
- /**
63
- * Get the amount of rounding applied to this payment method.
64
- *
65
- * @returns {number | undefined}
66
- */
67
- getRounding(): number | undefined;
68
- }
@@ -1,99 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SalePayment = exports.SalePaymentStatus = void 0;
4
- var SalePaymentStatus;
5
- (function (SalePaymentStatus) {
6
- SalePaymentStatus["APPROVED"] = "completed";
7
- SalePaymentStatus["DECLINED"] = "failed";
8
- SalePaymentStatus["CANCELLED"] = "cancelled";
9
- })(SalePaymentStatus = exports.SalePaymentStatus || (exports.SalePaymentStatus = {}));
10
- class SalePayment {
11
- constructor(id, amount, cashout, status) {
12
- this.id = id;
13
- this.amount = amount;
14
- this.cashout = cashout;
15
- this.status = status;
16
- }
17
- /**
18
- * Hydrate a sale payment from the SaleState.
19
- *
20
- * @internal
21
- * @param {ShopfrontSalePayment} payment
22
- * @returns {SalePayment}
23
- * @constructor
24
- */
25
- static HydrateFromState(payment) {
26
- let status = SalePaymentStatus.APPROVED;
27
- switch (payment.status) {
28
- case "failed":
29
- status = SalePaymentStatus.DECLINED;
30
- break;
31
- case "cancelled":
32
- status = SalePaymentStatus.CANCELLED;
33
- break;
34
- }
35
- const hydrated = new SalePayment(payment.method, payment.amount, payment.cashout, status);
36
- hydrated.setInternal(payment);
37
- return hydrated;
38
- }
39
- /**
40
- * Set the internal data for the payment.
41
- * This method is for hydration of the payment from Shopfront, it's highly recommend that you DO NOT use this method.
42
- *
43
- * @internal
44
- * @param {ShopfrontSalePayment} data
45
- */
46
- setInternal(data) {
47
- this.type = data.type;
48
- this.rounding = data.rounding;
49
- }
50
- /**
51
- * Get the ID of the sale payment method.
52
- *
53
- * @returns {string}
54
- */
55
- getId() {
56
- return this.id;
57
- }
58
- /**
59
- * Get the type of payment method this is.
60
- *
61
- * @returns {string | undefined}
62
- */
63
- getType() {
64
- return this.type;
65
- }
66
- /**
67
- * Get the status of this payment method.
68
- *
69
- * @returns {SalePaymentStatus | undefined}
70
- */
71
- getStatus() {
72
- return this.status;
73
- }
74
- /**
75
- * Get the value of this payment method.
76
- *
77
- * @returns {number}
78
- */
79
- getAmount() {
80
- return this.amount;
81
- }
82
- /**
83
- * Get the cashout amount paid for on this payment method.
84
- *
85
- * @returns {number | undefined}
86
- */
87
- getCashout() {
88
- return this.cashout;
89
- }
90
- /**
91
- * Get the amount of rounding applied to this payment method.
92
- *
93
- * @returns {number | undefined}
94
- */
95
- getRounding() {
96
- return this.rounding;
97
- }
98
- }
99
- exports.SalePayment = SalePayment;
@@ -1,121 +0,0 @@
1
- import { ShopfrontSaleProduct, ShopfrontSaleProductType } from "./ShopfrontSaleState";
2
- export declare class SaleProduct {
3
- protected id: string;
4
- protected quantity: number;
5
- protected price?: number;
6
- protected indexAddress: Array<number>;
7
- protected name?: string;
8
- protected type?: ShopfrontSaleProductType;
9
- protected taxRateAmount?: number;
10
- protected note: string;
11
- protected contains: Array<SaleProduct>;
12
- protected edited: boolean;
13
- protected caseQuantity?: number;
14
- protected metaData: Record<string, unknown>;
15
- constructor(id: string, quantity: number, price?: number, indexAddress?: Array<number>);
16
- /**
17
- * Hydrate a sale product from the SaleState.
18
- *
19
- * @internal
20
- * @param {ShopfrontSaleProduct} product
21
- * @param {Array<number>} indexAddress
22
- * @returns {SaleProduct}
23
- * @constructor
24
- */
25
- static HydrateFromState(product: ShopfrontSaleProduct, indexAddress: Array<number>): SaleProduct;
26
- /**
27
- * Append a product to this product's list of contained products.
28
- *
29
- * @protected
30
- * @param {SaleProduct} product
31
- */
32
- protected appendProduct(product: SaleProduct): void;
33
- /**
34
- * Set the internal data for the product.
35
- * This method is for hydration of the product from Shopfront, it's highly recommend that you DO NOT use this method.
36
- *
37
- * @internal
38
- * @param {ShopfrontSaleProduct} data
39
- * @param {Array<number>} indexAddress
40
- */
41
- setInternal(data: ShopfrontSaleProduct, indexAddress: Array<number>): void;
42
- /**
43
- * Get the ID of the product.
44
- * @returns {string}
45
- */
46
- getId(): string;
47
- /**
48
- * Get the current sale quantity of the product.
49
- * @returns {number}
50
- */
51
- getQuantity(): number;
52
- /**
53
- * Get the current price of the product.
54
- * @returns {number | undefined}
55
- */
56
- getPrice(): number | undefined;
57
- /**
58
- * Get the index address of the product.
59
- * This is the internal address of where the product is in the sale.
60
- * (e.g. if the address is [1, 3] it's the fourth contained product in the second sale line).
61
- *
62
- * @returns {Array<number>}
63
- */
64
- getIndexAddress(): number[];
65
- /**
66
- * Get the name of the product.
67
- *
68
- * @returns {string | undefined}
69
- */
70
- getName(): string | undefined;
71
- /**
72
- * Get the type of product this product is.
73
- *
74
- * @returns {ShopfrontSaleProductType | undefined}
75
- */
76
- getType(): ShopfrontSaleProductType | undefined;
77
- /**
78
- * Get the tax rate amount.
79
- * This is the rate of the tax rate (e.g. 10 is a tax rate of 10%).
80
- *
81
- * @returns {number | undefined}
82
- */
83
- getTaxRateAmount(): number | undefined;
84
- /**
85
- * Get the sale note attached to this product.
86
- *
87
- * @returns {string}
88
- */
89
- getNote(): string;
90
- /**
91
- * Get the products this product contains.
92
- *
93
- * @returns {Array<SaleProduct>}
94
- */
95
- getContains(): SaleProduct[];
96
- /**
97
- * Get whether this product has been "edited".
98
- * Typically, being edited just means that this product has been discounted.
99
- *
100
- * @returns {boolean}
101
- */
102
- getEdited(): boolean;
103
- /**
104
- * Get the case quantity for this product.
105
- *
106
- * @returns {number | undefined}
107
- */
108
- getCaseQuantity(): number | undefined;
109
- /**
110
- * Get the meta data for the product.
111
- *
112
- * @returns {Record<string, unknown>}
113
- */
114
- getMetaData(): Record<string, unknown>;
115
- /**
116
- * Set the metaData for a product
117
- * @param key
118
- * @param value
119
- */
120
- setMetaData(key: string, value: unknown): void;
121
- }