@shopfront/bridge 1.16.0 → 1.18.0

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 (67) hide show
  1. package/.idea/codeStyles/Project.xml +121 -0
  2. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  3. package/.idea/modules.xml +1 -1
  4. package/.idea/{embedded-bridge.iml → shopfront-embedded-bridge.iml} +0 -0
  5. package/lib/APIs/Fulfilment/FulfilmentTypes.d.ts +43 -0
  6. package/lib/APIs/Fulfilment/FulfilmentTypes.js +2 -0
  7. package/lib/APIs/Sale/BaseSale.d.ts +147 -0
  8. package/lib/APIs/Sale/BaseSale.js +152 -0
  9. package/lib/APIs/Sale/CurrentSale.d.ts +132 -0
  10. package/lib/APIs/Sale/CurrentSale.js +210 -0
  11. package/lib/APIs/Sale/Exceptions.d.ts +6 -0
  12. package/lib/APIs/Sale/Exceptions.js +15 -0
  13. package/lib/APIs/Sale/Sale.d.ts +34 -0
  14. package/lib/APIs/Sale/Sale.js +116 -0
  15. package/lib/APIs/Sale/SaleCustomer.d.ts +10 -0
  16. package/lib/APIs/Sale/SaleCustomer.js +17 -0
  17. package/lib/APIs/Sale/SalePayment.d.ts +69 -0
  18. package/lib/APIs/Sale/SalePayment.js +104 -0
  19. package/lib/APIs/Sale/SaleProduct.d.ts +129 -0
  20. package/lib/APIs/Sale/SaleProduct.js +181 -0
  21. package/lib/APIs/Sale/ShopfrontSaleState.d.ts +56 -0
  22. package/lib/APIs/Sale/ShopfrontSaleState.js +2 -0
  23. package/lib/APIs/Sale/index.d.ts +9 -0
  24. package/lib/APIs/Sale/index.js +39 -0
  25. package/lib/Actions/SaleUpdate.d.ts +1 -1
  26. package/lib/Application.d.ts +19 -4
  27. package/lib/Application.js +88 -4
  28. package/lib/ApplicationEvents.d.ts +50 -2
  29. package/lib/ApplicationEvents.js +11 -0
  30. package/lib/EmitableEvents/Fulfilment/Options.d.ts +7 -0
  31. package/lib/EmitableEvents/Fulfilment/Options.js +11 -0
  32. package/lib/EmitableEvents/Fulfilment/OrderCancel.d.ts +6 -0
  33. package/lib/EmitableEvents/Fulfilment/OrderCancel.js +13 -0
  34. package/lib/EmitableEvents/Fulfilment/OrderCreate.d.ts +7 -0
  35. package/lib/EmitableEvents/Fulfilment/OrderCreate.js +13 -0
  36. package/lib/EmitableEvents/Fulfilment/OrderSaleCreate.d.ts +8 -0
  37. package/lib/EmitableEvents/Fulfilment/OrderSaleCreate.js +14 -0
  38. package/lib/EmitableEvents/Fulfilment/OrderUpdate.d.ts +7 -0
  39. package/lib/EmitableEvents/Fulfilment/OrderUpdate.js +13 -0
  40. package/lib/EmitableEvents/Fulfilment/OrdersSync.d.ts +8 -0
  41. package/lib/EmitableEvents/Fulfilment/OrdersSync.js +14 -0
  42. package/lib/EmitableEvents/Fulfilment/RegisterIntent.d.ts +11 -0
  43. package/lib/EmitableEvents/Fulfilment/RegisterIntent.js +17 -0
  44. package/lib/EmitableEvents/Fulfilment/index.d.ts +7 -0
  45. package/lib/EmitableEvents/Fulfilment/index.js +15 -0
  46. package/lib/EmitableEvents/SaleCreate.d.ts +31 -0
  47. package/lib/EmitableEvents/SaleCreate.js +63 -0
  48. package/lib/Events/FulfilmentCollectOrder.d.ts +6 -0
  49. package/lib/Events/FulfilmentCollectOrder.js +13 -0
  50. package/lib/Events/FulfilmentCompleteOrder.d.ts +6 -0
  51. package/lib/Events/FulfilmentCompleteOrder.js +13 -0
  52. package/lib/Events/FulfilmentGetOrder.d.ts +10 -0
  53. package/lib/Events/FulfilmentGetOrder.js +17 -0
  54. package/lib/Events/FulfilmentOrderApproval.d.ts +6 -0
  55. package/lib/Events/FulfilmentOrderApproval.js +13 -0
  56. package/lib/Events/FulfilmentProcessOrder.d.ts +14 -0
  57. package/lib/Events/FulfilmentProcessOrder.js +17 -0
  58. package/lib/Events/FulfilmentVoidOrder.d.ts +6 -0
  59. package/lib/Events/FulfilmentVoidOrder.js +13 -0
  60. package/lib/Utilities/SaleCreate.d.ts +25 -0
  61. package/lib/Utilities/SaleCreate.js +55 -0
  62. package/lib/Utilities/UUID.d.ts +12 -0
  63. package/lib/Utilities/UUID.js +46 -0
  64. package/lib/index.d.ts +3 -1
  65. package/lib/index.js +3 -2
  66. package/package.json +1 -1
  67. package/.idea/misc.xml +0 -6
@@ -0,0 +1,129 @@
1
+ import { ShopfrontSaleProduct, ShopfrontSaleProductType } from "./ShopfrontSaleState";
2
+ export declare class SaleProduct {
3
+ readonly internalId: string;
4
+ protected id: string;
5
+ protected quantity: number;
6
+ protected price?: number;
7
+ protected indexAddress: Array<number>;
8
+ protected name?: string;
9
+ protected type?: ShopfrontSaleProductType;
10
+ protected taxRateAmount?: number;
11
+ protected note: string;
12
+ protected contains: Array<SaleProduct>;
13
+ protected edited: boolean;
14
+ protected caseQuantity?: number;
15
+ protected metaData: Record<string, unknown>;
16
+ protected mapped?: string;
17
+ constructor(id: string, quantity: number, price?: number, indexAddress?: Array<number>);
18
+ /**
19
+ * Hydrate a sale product from the SaleState.
20
+ *
21
+ * @internal
22
+ * @param {ShopfrontSaleProduct} product
23
+ * @param {Array<number>} indexAddress
24
+ * @returns {SaleProduct}
25
+ * @constructor
26
+ */
27
+ static HydrateFromState(product: ShopfrontSaleProduct, indexAddress: Array<number>): SaleProduct;
28
+ /**
29
+ * Append a product to this product's list of contained products.
30
+ *
31
+ * @protected
32
+ * @param {SaleProduct} product
33
+ */
34
+ protected appendProduct(product: SaleProduct): void;
35
+ /**
36
+ * Set the internal data for the product.
37
+ * This method is for hydration of the product from Shopfront, it's highly recommend that you DO NOT use this method.
38
+ *
39
+ * @internal
40
+ * @param {ShopfrontSaleProduct} data
41
+ * @param {Array<number>} indexAddress
42
+ */
43
+ setInternal(data: ShopfrontSaleProduct, indexAddress: Array<number>): void;
44
+ /**
45
+ * Get the ID of the product.
46
+ * @returns {string}
47
+ */
48
+ getId(): string;
49
+ /**
50
+ * Gets the mapped id for the product.
51
+ * Used when the product goes through the fulfilment process mapping
52
+ * @returns {string | undefined}
53
+ */
54
+ getMapped(): string | undefined;
55
+ /**
56
+ * Get the current sale quantity of the product.
57
+ * @returns {number}
58
+ */
59
+ getQuantity(): number;
60
+ /**
61
+ * Get the current price of the product.
62
+ * @returns {number | undefined}
63
+ */
64
+ getPrice(): number | undefined;
65
+ /**
66
+ * Get the index address of the product.
67
+ * This is the internal address of where the product is in the sale.
68
+ * (e.g. if the address is [1, 3] it's the fourth contained product in the second sale line).
69
+ *
70
+ * @returns {Array<number>}
71
+ */
72
+ getIndexAddress(): number[];
73
+ /**
74
+ * Get the name of the product.
75
+ *
76
+ * @returns {string | undefined}
77
+ */
78
+ getName(): string | undefined;
79
+ /**
80
+ * Get the type of product this product is.
81
+ *
82
+ * @returns {ShopfrontSaleProductType | undefined}
83
+ */
84
+ getType(): ShopfrontSaleProductType | undefined;
85
+ /**
86
+ * Get the tax rate amount.
87
+ * This is the rate of the tax rate (e.g. 10 is a tax rate of 10%).
88
+ *
89
+ * @returns {number | undefined}
90
+ */
91
+ getTaxRateAmount(): number | undefined;
92
+ /**
93
+ * Get the sale note attached to this product.
94
+ *
95
+ * @returns {string}
96
+ */
97
+ getNote(): string;
98
+ /**
99
+ * Get the products this product contains.
100
+ *
101
+ * @returns {Array<SaleProduct>}
102
+ */
103
+ getContains(): SaleProduct[];
104
+ /**
105
+ * Get whether this product has been "edited".
106
+ * Typically, being edited just means that this product has been discounted.
107
+ *
108
+ * @returns {boolean}
109
+ */
110
+ getEdited(): boolean;
111
+ /**
112
+ * Get the case quantity for this product.
113
+ *
114
+ * @returns {number | undefined}
115
+ */
116
+ getCaseQuantity(): number | undefined;
117
+ /**
118
+ * Get the meta data for the product.
119
+ *
120
+ * @returns {Record<string, unknown>}
121
+ */
122
+ getMetaData(): Record<string, unknown>;
123
+ /**
124
+ * Set the metaData for a product
125
+ * @param key
126
+ * @param value
127
+ */
128
+ setMetaData(key: string, value: unknown): void;
129
+ }
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SaleProduct = void 0;
7
+ const UUID_1 = __importDefault(require("../../Utilities/UUID"));
8
+ class SaleProduct {
9
+ constructor(id, quantity, price, indexAddress) {
10
+ this.metaData = {};
11
+ this.internalId = UUID_1.default.generate();
12
+ this.id = id;
13
+ this.quantity = quantity;
14
+ this.price = price;
15
+ this.indexAddress = indexAddress || [];
16
+ this.contains = [];
17
+ this.edited = typeof price !== "undefined";
18
+ this.note = "";
19
+ }
20
+ /**
21
+ * Hydrate a sale product from the SaleState.
22
+ *
23
+ * @internal
24
+ * @param {ShopfrontSaleProduct} product
25
+ * @param {Array<number>} indexAddress
26
+ * @returns {SaleProduct}
27
+ * @constructor
28
+ */
29
+ static HydrateFromState(product, indexAddress) {
30
+ const hydrated = new SaleProduct(product.uuid, product.quantity, product.prices.price, indexAddress);
31
+ hydrated.setInternal(product, indexAddress);
32
+ return hydrated;
33
+ }
34
+ /**
35
+ * Append a product to this product's list of contained products.
36
+ *
37
+ * @protected
38
+ * @param {SaleProduct} product
39
+ */
40
+ appendProduct(product) {
41
+ this.contains.push(product);
42
+ }
43
+ /**
44
+ * Set the internal data for the product.
45
+ * This method is for hydration of the product from Shopfront, it's highly recommend that you DO NOT use this method.
46
+ *
47
+ * @internal
48
+ * @param {ShopfrontSaleProduct} data
49
+ * @param {Array<number>} indexAddress
50
+ */
51
+ setInternal(data, indexAddress) {
52
+ this.name = data.name;
53
+ this.type = data.type;
54
+ this.taxRateAmount = data.tax?.amount || 0;
55
+ this.note = data.note;
56
+ this.edited = data.edited;
57
+ this.caseQuantity = data.caseQuantity;
58
+ this.metaData = data.metaData;
59
+ this.mapped = data.mapped;
60
+ for (let i = 0, l = data.products.length; i < l; i++) {
61
+ this.appendProduct(SaleProduct.HydrateFromState(data.products[i], [
62
+ ...indexAddress,
63
+ i,
64
+ ]));
65
+ }
66
+ }
67
+ /**
68
+ * Get the ID of the product.
69
+ * @returns {string}
70
+ */
71
+ getId() {
72
+ return this.id;
73
+ }
74
+ /**
75
+ * Gets the mapped id for the product.
76
+ * Used when the product goes through the fulfilment process mapping
77
+ * @returns {string | undefined}
78
+ */
79
+ getMapped() {
80
+ return this.mapped;
81
+ }
82
+ /**
83
+ * Get the current sale quantity of the product.
84
+ * @returns {number}
85
+ */
86
+ getQuantity() {
87
+ return this.quantity;
88
+ }
89
+ /**
90
+ * Get the current price of the product.
91
+ * @returns {number | undefined}
92
+ */
93
+ getPrice() {
94
+ return this.price;
95
+ }
96
+ /**
97
+ * Get the index address of the product.
98
+ * This is the internal address of where the product is in the sale.
99
+ * (e.g. if the address is [1, 3] it's the fourth contained product in the second sale line).
100
+ *
101
+ * @returns {Array<number>}
102
+ */
103
+ getIndexAddress() {
104
+ return this.indexAddress;
105
+ }
106
+ /**
107
+ * Get the name of the product.
108
+ *
109
+ * @returns {string | undefined}
110
+ */
111
+ getName() {
112
+ return this.name;
113
+ }
114
+ /**
115
+ * Get the type of product this product is.
116
+ *
117
+ * @returns {ShopfrontSaleProductType | undefined}
118
+ */
119
+ getType() {
120
+ return this.type;
121
+ }
122
+ /**
123
+ * Get the tax rate amount.
124
+ * This is the rate of the tax rate (e.g. 10 is a tax rate of 10%).
125
+ *
126
+ * @returns {number | undefined}
127
+ */
128
+ getTaxRateAmount() {
129
+ return this.taxRateAmount;
130
+ }
131
+ /**
132
+ * Get the sale note attached to this product.
133
+ *
134
+ * @returns {string}
135
+ */
136
+ getNote() {
137
+ return this.note;
138
+ }
139
+ /**
140
+ * Get the products this product contains.
141
+ *
142
+ * @returns {Array<SaleProduct>}
143
+ */
144
+ getContains() {
145
+ return this.contains;
146
+ }
147
+ /**
148
+ * Get whether this product has been "edited".
149
+ * Typically, being edited just means that this product has been discounted.
150
+ *
151
+ * @returns {boolean}
152
+ */
153
+ getEdited() {
154
+ return this.edited;
155
+ }
156
+ /**
157
+ * Get the case quantity for this product.
158
+ *
159
+ * @returns {number | undefined}
160
+ */
161
+ getCaseQuantity() {
162
+ return this.caseQuantity;
163
+ }
164
+ /**
165
+ * Get the meta data for the product.
166
+ *
167
+ * @returns {Record<string, unknown>}
168
+ */
169
+ getMetaData() {
170
+ return this.metaData;
171
+ }
172
+ /**
173
+ * Set the metaData for a product
174
+ * @param key
175
+ * @param value
176
+ */
177
+ setMetaData(key, value) {
178
+ this.metaData[key] = value;
179
+ }
180
+ }
181
+ exports.SaleProduct = SaleProduct;
@@ -0,0 +1,56 @@
1
+ export declare type ShopfrontSalePaymentStatus = "completed" | "cancelled" | "failed";
2
+ export declare type ShopfrontSaleProductType = "Normal" | "Basket" | "Package" | "Component" | "Voucher";
3
+ export interface ShopfrontSaleProduct {
4
+ uuid: string;
5
+ type: ShopfrontSaleProductType;
6
+ name: string;
7
+ quantity: number;
8
+ prices: {
9
+ price: number;
10
+ normal: number;
11
+ };
12
+ tax: null | {
13
+ id: string;
14
+ amount: number;
15
+ };
16
+ note: string;
17
+ products: Array<ShopfrontSaleProduct>;
18
+ edited: boolean;
19
+ caseQuantity: number;
20
+ metaData: Record<string, unknown>;
21
+ mapped?: string;
22
+ }
23
+ interface ShopfrontSaleCustomer {
24
+ uuid: string;
25
+ }
26
+ export interface ShopfrontSalePayment {
27
+ method: string;
28
+ type: string;
29
+ status: ShopfrontSalePaymentStatus;
30
+ amount: number;
31
+ cashout: number;
32
+ rounding: number;
33
+ }
34
+ export interface ShopfrontSaleState {
35
+ clientId?: string;
36
+ register?: string;
37
+ products: Array<ShopfrontSaleProduct>;
38
+ customer: false | ShopfrontSaleCustomer;
39
+ payments: Array<ShopfrontSalePayment>;
40
+ notes: {
41
+ internal: string;
42
+ sale: string;
43
+ };
44
+ totals: {
45
+ sale: number;
46
+ paid: number;
47
+ savings: number;
48
+ discount: number;
49
+ };
50
+ linkedTo: string;
51
+ orderReference: string;
52
+ refundReason: string;
53
+ priceSet: string | null;
54
+ metaData: Record<string, unknown>;
55
+ }
56
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ export { SaleData, SalePaymentData, SaleProductData } from "../../Utilities/SaleCreate";
2
+ export { ShopfrontSalePayment, ShopfrontSalePaymentStatus, ShopfrontSaleProduct, ShopfrontSaleProductType, ShopfrontSaleState } from "./ShopfrontSaleState";
3
+ export { BaseSale } from "./BaseSale";
4
+ export { SaleProduct } from "./SaleProduct";
5
+ export { SalePayment } from "./SalePayment";
6
+ export { SalePaymentStatus } from "./SalePayment";
7
+ export { SaleCustomer } from "./SaleCustomer";
8
+ export { Sale } from "./Sale";
9
+ export * as Exceptions from "./Exceptions";
@@ -0,0 +1,39 @@
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.Exceptions = exports.Sale = exports.SaleCustomer = exports.SalePaymentStatus = exports.SalePayment = exports.SaleProduct = exports.BaseSale = void 0;
27
+ var BaseSale_1 = require("./BaseSale");
28
+ Object.defineProperty(exports, "BaseSale", { enumerable: true, get: function () { return BaseSale_1.BaseSale; } });
29
+ var SaleProduct_1 = require("./SaleProduct");
30
+ Object.defineProperty(exports, "SaleProduct", { enumerable: true, get: function () { return SaleProduct_1.SaleProduct; } });
31
+ var SalePayment_1 = require("./SalePayment");
32
+ Object.defineProperty(exports, "SalePayment", { enumerable: true, get: function () { return SalePayment_1.SalePayment; } });
33
+ var SalePayment_2 = require("./SalePayment");
34
+ Object.defineProperty(exports, "SalePaymentStatus", { enumerable: true, get: function () { return SalePayment_2.SalePaymentStatus; } });
35
+ var SaleCustomer_1 = require("./SaleCustomer");
36
+ Object.defineProperty(exports, "SaleCustomer", { enumerable: true, get: function () { return SaleCustomer_1.SaleCustomer; } });
37
+ var Sale_1 = require("./Sale");
38
+ Object.defineProperty(exports, "Sale", { enumerable: true, get: function () { return Sale_1.Sale; } });
39
+ exports.Exceptions = __importStar(require("./Exceptions"));
@@ -1,6 +1,6 @@
1
1
  import { BaseAction } from "./BaseAction";
2
2
  import { Serialized } from "../Common/Serializable";
3
- import { ShopfrontSalePaymentStatus } from "../APIs/CurrentSale/ShopfrontSaleState";
3
+ import { ShopfrontSalePaymentStatus } from "../APIs/Sale";
4
4
  export interface SaleUpdateChanges {
5
5
  PRODUCT_ADD: {
6
6
  id: string;
@@ -2,11 +2,12 @@ import { Bridge } from "./Bridge";
2
2
  import { DirectShopfrontEvent, FromShopfront, FromShopfrontCallbacks, FromShopfrontInternal, RegisterChangedEvent, SoundEvents } from "./ApplicationEvents";
3
3
  import { Serializable } from "./Common/Serializable";
4
4
  import { BaseEmitableEvent } from "./EmitableEvents/BaseEmitableEvent";
5
- import { Sale } from "./APIs/CurrentSale";
6
- import { ShopfrontSaleState } from "./APIs/CurrentSale/ShopfrontSaleState";
5
+ import { ShopfrontSaleState } from "./APIs/Sale";
7
6
  import { Database } from "./APIs/Database/Database";
8
7
  import { MaybePromise } from "./Utilities/MiscTypes";
9
8
  import { BaseEvent } from "./Events/BaseEvent";
9
+ import { CurrentSale } from "./APIs/Sale/CurrentSale";
10
+ import { Sale } from "./APIs/Sale";
10
11
  export interface ShopfrontEmbeddedVerificationToken {
11
12
  auth: string;
12
13
  id: string;
@@ -60,9 +61,23 @@ export declare class Application {
60
61
  * Get the current sale on the sell screen, if the current device is not a register
61
62
  * then this will return false.
62
63
  *
63
- * @returns {Promise<Sale | boolean>}
64
+ * @returns {Promise<CurrentSale | boolean>}
64
65
  */
65
- getCurrentSale(): Promise<Sale | false>;
66
+ getCurrentSale(): Promise<CurrentSale | false>;
67
+ protected dataIsCreateEvent(data: Record<string, unknown>): data is {
68
+ requestId: string;
69
+ success: boolean;
70
+ message?: string;
71
+ };
72
+ /**
73
+ * Send the sale to be created on shopfront.
74
+ *
75
+ * @param sale
76
+ */
77
+ createSale(sale: Sale): Promise<{
78
+ success: boolean;
79
+ message?: string;
80
+ }>;
66
81
  protected dataIsLocation(data: Record<string, unknown>): data is {
67
82
  requestId: string;
68
83
  register: string | null;
@@ -13,7 +13,6 @@ const ActionEventRegistrar_1 = __importDefault(require("./Utilities/ActionEventR
13
13
  const RequestTableColumns_1 = require("./Events/RequestTableColumns");
14
14
  const RequestSellScreenOptions_1 = require("./Events/RequestSellScreenOptions");
15
15
  const BaseEmitableEvent_1 = require("./EmitableEvents/BaseEmitableEvent");
16
- const CurrentSale_1 = require("./APIs/CurrentSale");
17
16
  const InternalPageMessage_1 = require("./Events/InternalPageMessage");
18
17
  const RegisterChanged_1 = require("./Events/RegisterChanged");
19
18
  const Database_1 = require("./APIs/Database/Database");
@@ -24,6 +23,14 @@ const SaleComplete_1 = require("./Events/SaleComplete");
24
23
  const UIPipeline_1 = require("./Events/UIPipeline");
25
24
  const PaymentMethodsEnabled_1 = require("./Events/PaymentMethodsEnabled");
26
25
  const AudioPermissionChange_1 = require("./Events/AudioPermissionChange");
26
+ const FulfilmentGetOrder_1 = require("./Events/FulfilmentGetOrder");
27
+ const FulfilmentVoidOrder_1 = require("./Events/FulfilmentVoidOrder");
28
+ const FulfilmentProcessOrder_1 = require("./Events/FulfilmentProcessOrder");
29
+ const FulfilmentOrderApproval_1 = require("./Events/FulfilmentOrderApproval");
30
+ const FulfilmentCollectOrder_1 = require("./Events/FulfilmentCollectOrder");
31
+ const FulfilmentCompleteOrder_1 = require("./Events/FulfilmentCompleteOrder");
32
+ const CurrentSale_1 = require("./APIs/Sale/CurrentSale");
33
+ const SaleCreate_1 = require("./Utilities/SaleCreate");
27
34
  class ShopfrontTokenDecodingError extends Error {
28
35
  }
29
36
  exports.ShopfrontTokenDecodingError = ShopfrontTokenDecodingError;
@@ -45,6 +52,12 @@ class Application {
45
52
  UI_PIPELINE: new Map(),
46
53
  PAYMENT_METHODS_ENABLED: new Map(),
47
54
  AUDIO_PERMISSION_CHANGE: new Map(),
55
+ FULFILMENT_GET_ORDER: new Map(),
56
+ FULFILMENT_PROCESS_ORDER: new Map(),
57
+ FULFILMENT_VOID_ORDER: new Map(),
58
+ FULFILMENT_ORDER_APPROVAL: new Map(),
59
+ FULFILMENT_ORDER_COLLECTED: new Map(),
60
+ FULFILMENT_ORDER_COMPLETED: new Map(),
48
61
  };
49
62
  this.directListeners = {};
50
63
  this.handleEvent = (event, data, id) => {
@@ -77,7 +90,8 @@ class Application {
77
90
  event === "RESPONSE_LOCATION" ||
78
91
  event === "RESPONSE_OPTION" ||
79
92
  event === "RESPONSE_AUDIO_REQUEST" ||
80
- event === "RESPONSE_SECURE_KEY") {
93
+ event === "RESPONSE_SECURE_KEY" ||
94
+ event === "RESPONSE_CREATE_SALE") {
81
95
  // Handled elsewhere
82
96
  return;
83
97
  }
@@ -175,6 +189,12 @@ class Application {
175
189
  .then(res => {
176
190
  return PaymentMethodsEnabled_1.PaymentMethodsEnabled.respond(this.bridge, res.flat(), id);
177
191
  });
192
+ case "FULFILMENT_GET_ORDER":
193
+ results = results;
194
+ return Promise.all(results)
195
+ .then(res => {
196
+ return FulfilmentGetOrder_1.FulfilmentGetOrder.respond(this.bridge, res[0], id);
197
+ });
178
198
  }
179
199
  }
180
200
  addEventListener(event, callback) {
@@ -247,6 +267,33 @@ class Application {
247
267
  c = new AudioPermissionChange_1.AudioPermissionChange(callback);
248
268
  this.listeners[event].set(callback, c);
249
269
  break;
270
+ case "FULFILMENT_GET_ORDER":
271
+ if (this.listeners[event].size !== 0) {
272
+ throw new TypeError("Application already has 'FULFILMENT_GET_ORDER' event listener registered.");
273
+ }
274
+ c = new FulfilmentGetOrder_1.FulfilmentGetOrder(callback);
275
+ this.listeners[event].set(callback, c);
276
+ break;
277
+ case "FULFILMENT_VOID_ORDER":
278
+ c = new FulfilmentVoidOrder_1.FulfilmentVoidOrder(callback);
279
+ this.listeners[event].set(callback, c);
280
+ break;
281
+ case "FULFILMENT_PROCESS_ORDER":
282
+ c = new FulfilmentProcessOrder_1.FulfilmentProcessOrder(callback);
283
+ this.listeners[event].set(callback, c);
284
+ break;
285
+ case "FULFILMENT_ORDER_APPROVAL":
286
+ c = new FulfilmentOrderApproval_1.FulfilmentOrderApproval(callback);
287
+ this.listeners[event].set(callback, c);
288
+ break;
289
+ case "FULFILMENT_ORDER_COLLECTED":
290
+ c = new FulfilmentCollectOrder_1.FulfilmentCollectOrder(callback);
291
+ this.listeners[event].set(callback, c);
292
+ break;
293
+ case "FULFILMENT_ORDER_COMPLETED":
294
+ c = new FulfilmentCompleteOrder_1.FulfilmentCompleteOrder(callback);
295
+ this.listeners[event].set(callback, c);
296
+ break;
250
297
  }
251
298
  if (typeof c === "undefined") {
252
299
  throw new TypeError(`${event} has not been defined`);
@@ -314,7 +361,7 @@ class Application {
314
361
  * Get the current sale on the sell screen, if the current device is not a register
315
362
  * then this will return false.
316
363
  *
317
- * @returns {Promise<Sale | boolean>}
364
+ * @returns {Promise<CurrentSale | boolean>}
318
365
  */
319
366
  async getCurrentSale() {
320
367
  const saleRequest = `SaleRequest-${Date.now().toString()}`;
@@ -341,7 +388,44 @@ class Application {
341
388
  if (saleState === false) {
342
389
  return saleState;
343
390
  }
344
- return new CurrentSale_1.Sale(this, saleState);
391
+ return new CurrentSale_1.CurrentSale(this, saleState);
392
+ }
393
+ dataIsCreateEvent(data) {
394
+ return typeof data.requestId === "string" &&
395
+ typeof data.success === "boolean" && (typeof data.message === "undefined" ||
396
+ typeof data.message === "string");
397
+ }
398
+ /**
399
+ * Send the sale to be created on shopfront.
400
+ *
401
+ * @param sale
402
+ */
403
+ async createSale(sale) {
404
+ const createSaleRequest = `CreateSaleRequest-${Date.now().toString()}`;
405
+ const promise = new Promise(res => {
406
+ const listener = (event, data) => {
407
+ if (event !== "RESPONSE_CREATE_SALE") {
408
+ return;
409
+ }
410
+ if (!this.dataIsCreateEvent(data)) {
411
+ return;
412
+ }
413
+ if (data.requestId !== createSaleRequest) {
414
+ return;
415
+ }
416
+ this.bridge.removeEventListener(listener);
417
+ res({
418
+ success: data.success,
419
+ message: data.message,
420
+ });
421
+ };
422
+ this.bridge.addEventListener(listener);
423
+ });
424
+ this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.CREATE_SALE, {
425
+ requestId: createSaleRequest,
426
+ sale: (0, SaleCreate_1.buildSaleData)(sale),
427
+ });
428
+ return promise;
345
429
  }
346
430
  dataIsLocation(data) {
347
431
  return typeof data.requestId === "string" &&