@shopfront/bridge 1.6.0 → 1.10.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.
- package/.idea/compiler.xml +6 -0
- package/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/shopfront-embedded-bridge.iml +10 -0
- package/.idea/vcs.xml +6 -0
- package/lib/APIs/CurrentSale/Sale.d.ts +5 -0
- package/lib/APIs/CurrentSale/Sale.js +12 -0
- package/lib/APIs/CurrentSale/SaleProduct.d.ts +14 -1
- package/lib/APIs/CurrentSale/SaleProduct.js +18 -0
- package/lib/APIs/CurrentSale/ShopfrontSaleState.d.ts +1 -0
- package/lib/Actions/CustomerListOption.d.ts +7 -0
- package/lib/Actions/CustomerListOption.js +26 -0
- package/lib/Actions/SaleKey.d.ts +8 -0
- package/lib/Actions/SaleKey.js +37 -0
- package/lib/Actions/SaleUpdate.d.ts +6 -0
- package/lib/Application.d.ts +10 -5
- package/lib/Application.js +81 -2
- package/lib/ApplicationEvents.d.ts +41 -10
- package/lib/ApplicationEvents.js +10 -1
- package/lib/Bridge.d.ts +1 -1
- package/lib/Events/FormatIntegratedProduct.d.ts +72 -0
- package/lib/Events/FormatIntegratedProduct.js +24 -0
- package/lib/Events/RequestCustomerListOptions.d.ts +12 -0
- package/lib/Events/RequestCustomerListOptions.js +31 -0
- package/lib/Events/RequestSaleKeys.d.ts +9 -0
- package/lib/Events/RequestSaleKeys.js +34 -0
- package/lib/Events/SaleComplete.d.ts +112 -0
- package/lib/Events/SaleComplete.js +13 -0
- package/lib/Utilities/MiscTypes.d.ts +4 -0
- package/lib/Utilities/MiscTypes.js +2 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +5 -1
- package/package.json +1 -1
- package/yarn.lock +0 -8
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
|
2
|
+
<profile version="1.0">
|
|
3
|
+
<option name="myName" value="Project Default" />
|
|
4
|
+
<inspection_tool class="JSIgnoredPromiseFromCall" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
|
5
|
+
<inspection_tool class="JSMethodCanBeStatic" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
6
|
+
</profile>
|
|
7
|
+
</component>
|
package/.idea/misc.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/shopfront-embedded-bridge.iml" filepath="$PROJECT_DIR$/.idea/shopfront-embedded-bridge.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/lib" />
|
|
6
|
+
</content>
|
|
7
|
+
<orderEntry type="inheritedJdk" />
|
|
8
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
9
|
+
</component>
|
|
10
|
+
</module>
|
package/.idea/vcs.xml
ADDED
|
@@ -162,4 +162,9 @@ export declare class Sale {
|
|
|
162
162
|
* @returns {Promise<void>}
|
|
163
163
|
*/
|
|
164
164
|
setOrderReference(reference: string): Promise<void>;
|
|
165
|
+
/**
|
|
166
|
+
* Update a product's details, currently this only updates the top-level meta data
|
|
167
|
+
* @param product
|
|
168
|
+
*/
|
|
169
|
+
updateProduct(product: SaleProduct): Promise<void>;
|
|
165
170
|
}
|
|
@@ -146,6 +146,7 @@ class Sale {
|
|
|
146
146
|
quantity: product.getQuantity(),
|
|
147
147
|
price: product.getPrice(),
|
|
148
148
|
indexAddress: product.getIndexAddress(),
|
|
149
|
+
metaData: product.getMetaData(),
|
|
149
150
|
}));
|
|
150
151
|
}
|
|
151
152
|
/**
|
|
@@ -256,5 +257,16 @@ class Sale {
|
|
|
256
257
|
reference,
|
|
257
258
|
}));
|
|
258
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Update a product's details, currently this only updates the top-level meta data
|
|
262
|
+
* @param product
|
|
263
|
+
*/
|
|
264
|
+
updateProduct(product) {
|
|
265
|
+
return this.sendSaleUpdate(new SaleUpdate_1.SaleUpdate("PRODUCT_UPDATE", {
|
|
266
|
+
id: product.getId(),
|
|
267
|
+
indexAddress: product.getIndexAddress(),
|
|
268
|
+
metaData: product.getMetaData(),
|
|
269
|
+
}));
|
|
270
|
+
}
|
|
259
271
|
}
|
|
260
272
|
exports.Sale = Sale;
|
|
@@ -11,6 +11,7 @@ export declare class SaleProduct {
|
|
|
11
11
|
protected contains: Array<SaleProduct>;
|
|
12
12
|
protected edited: boolean;
|
|
13
13
|
protected caseQuantity?: number;
|
|
14
|
+
protected metaData: Record<string, unknown>;
|
|
14
15
|
constructor(id: string, quantity: number, price?: number, indexAddress?: Array<number>);
|
|
15
16
|
/**
|
|
16
17
|
* Hydrate a sale product from the SaleState.
|
|
@@ -72,7 +73,7 @@ export declare class SaleProduct {
|
|
|
72
73
|
*
|
|
73
74
|
* @returns {ShopfrontSaleProductType | undefined}
|
|
74
75
|
*/
|
|
75
|
-
getType(): "Normal" | "
|
|
76
|
+
getType(): "Normal" | "Voucher" | "Basket" | "Package" | "Component" | undefined;
|
|
76
77
|
/**
|
|
77
78
|
* Get the tax rate amount.
|
|
78
79
|
* This is the rate of the tax rate (e.g. 10 is a tax rate of 10%).
|
|
@@ -105,4 +106,16 @@ export declare class SaleProduct {
|
|
|
105
106
|
* @returns {number | undefined}
|
|
106
107
|
*/
|
|
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;
|
|
108
121
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SaleProduct = void 0;
|
|
4
4
|
class SaleProduct {
|
|
5
5
|
constructor(id, quantity, price, indexAddress) {
|
|
6
|
+
this.metaData = {};
|
|
6
7
|
this.id = id;
|
|
7
8
|
this.quantity = quantity;
|
|
8
9
|
this.price = price;
|
|
@@ -50,6 +51,7 @@ class SaleProduct {
|
|
|
50
51
|
this.note = data.note;
|
|
51
52
|
this.edited = data.edited;
|
|
52
53
|
this.caseQuantity = data.caseQuantity;
|
|
54
|
+
this.metaData = data.metaData;
|
|
53
55
|
for (let i = 0, l = data.products.length; i < l; i++) {
|
|
54
56
|
this.appendProduct(SaleProduct.HydrateFromState(data.products[i], [
|
|
55
57
|
...indexAddress,
|
|
@@ -146,5 +148,21 @@ class SaleProduct {
|
|
|
146
148
|
getCaseQuantity() {
|
|
147
149
|
return this.caseQuantity;
|
|
148
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Get the meta data for the product.
|
|
153
|
+
*
|
|
154
|
+
* @returns {Record<string, unknown>}
|
|
155
|
+
*/
|
|
156
|
+
getMetaData() {
|
|
157
|
+
return this.metaData;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Set the metaData for a product
|
|
161
|
+
* @param key
|
|
162
|
+
* @param value
|
|
163
|
+
*/
|
|
164
|
+
setMetaData(key, value) {
|
|
165
|
+
this.metaData[key] = value;
|
|
166
|
+
}
|
|
149
167
|
}
|
|
150
168
|
exports.SaleProduct = SaleProduct;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseAction } from "./BaseAction";
|
|
2
|
+
import { Serialized } from "../Common/Serializable";
|
|
3
|
+
export declare class CustomerListOption extends BaseAction<CustomerListOption> {
|
|
4
|
+
protected supportedEvents: string[];
|
|
5
|
+
protected contents: string;
|
|
6
|
+
constructor(contents: Serialized<CustomerListOption> | string);
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomerListOption = void 0;
|
|
4
|
+
const BaseAction_1 = require("./BaseAction");
|
|
5
|
+
class CustomerListOption extends BaseAction_1.BaseAction {
|
|
6
|
+
constructor(contents) {
|
|
7
|
+
super((() => {
|
|
8
|
+
if (typeof contents === "string") {
|
|
9
|
+
return {
|
|
10
|
+
properties: [contents],
|
|
11
|
+
events: {},
|
|
12
|
+
type: "CustomerListOption",
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return contents;
|
|
16
|
+
})(), CustomerListOption);
|
|
17
|
+
this.supportedEvents = ["click"];
|
|
18
|
+
if (typeof contents === "string") {
|
|
19
|
+
this.contents = contents;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this.contents = contents.properties[0];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.CustomerListOption = CustomerListOption;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseAction } from "./BaseAction";
|
|
2
|
+
import { Serialized } from "../Common/Serializable";
|
|
3
|
+
export declare class SaleKey extends BaseAction<SaleKey> {
|
|
4
|
+
protected supportedEvents: string[];
|
|
5
|
+
protected id: string;
|
|
6
|
+
protected name: string;
|
|
7
|
+
constructor(id: Serialized<SaleKey> | string, name?: string);
|
|
8
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SaleKey = void 0;
|
|
4
|
+
const BaseAction_1 = require("./BaseAction");
|
|
5
|
+
class SaleKey extends BaseAction_1.BaseAction {
|
|
6
|
+
constructor(id, name) {
|
|
7
|
+
// https://github.com/Microsoft/TypeScript/issues/8277
|
|
8
|
+
super((() => {
|
|
9
|
+
if (typeof id === "string") {
|
|
10
|
+
return {
|
|
11
|
+
properties: [id, name],
|
|
12
|
+
events: {},
|
|
13
|
+
type: "Button"
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return id;
|
|
18
|
+
}
|
|
19
|
+
})(), SaleKey);
|
|
20
|
+
this.supportedEvents = ["click"];
|
|
21
|
+
if (typeof name === "undefined" && typeof id !== "string") {
|
|
22
|
+
id = id;
|
|
23
|
+
this.id = id.properties[0];
|
|
24
|
+
this.name = id.properties[1];
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.id = id;
|
|
28
|
+
if (typeof name === "undefined") {
|
|
29
|
+
this.name = "";
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.name = name;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.SaleKey = SaleKey;
|
|
@@ -8,6 +8,7 @@ export interface SaleUpdateChanges {
|
|
|
8
8
|
price?: number;
|
|
9
9
|
consolidate?: boolean;
|
|
10
10
|
indexAddress?: Array<number>;
|
|
11
|
+
metaData: Record<string, unknown>;
|
|
11
12
|
};
|
|
12
13
|
PRODUCT_REMOVE: {
|
|
13
14
|
id: string;
|
|
@@ -41,6 +42,11 @@ export interface SaleUpdateChanges {
|
|
|
41
42
|
SALE_ORDER_REFERENCE: {
|
|
42
43
|
reference: string;
|
|
43
44
|
};
|
|
45
|
+
PRODUCT_UPDATE: {
|
|
46
|
+
id: string;
|
|
47
|
+
indexAddress: Array<number>;
|
|
48
|
+
metaData: Record<string, unknown>;
|
|
49
|
+
};
|
|
44
50
|
}
|
|
45
51
|
export declare class SaleUpdate<K extends keyof SaleUpdateChanges> extends BaseAction<SaleUpdate<K>> {
|
|
46
52
|
protected supportedEvents: never[];
|
package/lib/Application.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Bridge } from "./Bridge";
|
|
2
|
-
import { DirectShopfrontEvent, FromShopfront, FromShopfrontInternal, RegisterChangedEvent } from "./ApplicationEvents";
|
|
2
|
+
import { DirectShopfrontEvent, FromShopfront, FromShopfrontCallbacks, FromShopfrontInternal, RegisterChangedEvent } from "./ApplicationEvents";
|
|
3
3
|
import { Serializable } from "./Common/Serializable";
|
|
4
4
|
import { BaseEmitableEvent } from "./EmitableEvents/BaseEmitableEvent";
|
|
5
5
|
import { Sale } from "./APIs/CurrentSale";
|
|
6
6
|
import { Database } from "./APIs/Database/Database";
|
|
7
|
+
import { MaybePromise } from "./Utilities/MiscTypes";
|
|
7
8
|
export declare class Application {
|
|
8
9
|
protected bridge: Bridge;
|
|
9
10
|
protected isReady: boolean;
|
|
@@ -15,18 +16,20 @@ export declare class Application {
|
|
|
15
16
|
[key in keyof Omit<FromShopfront, "CALLBACK">]: Map<Function, FromShopfront[key]>;
|
|
16
17
|
};
|
|
17
18
|
protected directListeners: {
|
|
18
|
-
[K in DirectShopfrontEvent]?: Set<() => void | Promise<void>>;
|
|
19
|
+
[K in DirectShopfrontEvent]?: Set<(data: unknown) => void | Promise<void>>;
|
|
19
20
|
};
|
|
20
21
|
database: Database;
|
|
21
22
|
constructor(bridge: Bridge);
|
|
22
23
|
destroy(): void;
|
|
23
24
|
protected handleEvent: (event: keyof FromShopfront | keyof FromShopfrontInternal, data: any, id: string) => void;
|
|
24
|
-
protected emit(event: keyof Omit<FromShopfront, "CALLBACK"> | DirectShopfrontEvent, data: any, id: string):
|
|
25
|
-
addEventListener
|
|
26
|
-
|
|
25
|
+
protected emit(event: keyof Omit<FromShopfront, "CALLBACK"> | DirectShopfrontEvent, data: any, id: string): MaybePromise<void>;
|
|
26
|
+
addEventListener<E extends keyof FromShopfrontCallbacks>(event: E, callback: FromShopfrontCallbacks[E]): void;
|
|
27
|
+
addEventListener<D>(event: DirectShopfrontEvent, callback: (event: D) => MaybePromise<void>): void;
|
|
28
|
+
removeEventListener(event: keyof Omit<FromShopfront, "CALLBACK"> | DirectShopfrontEvent, callback: (...args: Array<any>) => MaybePromise<any>): void;
|
|
27
29
|
send(item: BaseEmitableEvent<any>): void;
|
|
28
30
|
send(item: Serializable<any>): void;
|
|
29
31
|
download(file: string): void;
|
|
32
|
+
redirect(toLocation: string, externalRedirect?: boolean): void;
|
|
30
33
|
load(): () => void;
|
|
31
34
|
protected handleEventCallback(data: {
|
|
32
35
|
id?: string;
|
|
@@ -49,4 +52,6 @@ export declare class Application {
|
|
|
49
52
|
outlet: string | null;
|
|
50
53
|
user: string | null;
|
|
51
54
|
}>;
|
|
55
|
+
printReceipt(content: string): void;
|
|
56
|
+
getOption<TValueType>(option: string, defaultValue: TValueType): Promise<TValueType>;
|
|
52
57
|
}
|
package/lib/Application.js
CHANGED
|
@@ -17,6 +17,11 @@ const CurrentSale_1 = require("./APIs/CurrentSale");
|
|
|
17
17
|
const InternalPageMessage_1 = require("./Events/InternalPageMessage");
|
|
18
18
|
const RegisterChanged_1 = require("./Events/RegisterChanged");
|
|
19
19
|
const Database_1 = require("./APIs/Database/Database");
|
|
20
|
+
const FormatIntegratedProduct_1 = require("./Events/FormatIntegratedProduct");
|
|
21
|
+
const RequestCustomerListOptions_1 = require("./Events/RequestCustomerListOptions");
|
|
22
|
+
const RequestSaleKeys_1 = require("./Events/RequestSaleKeys");
|
|
23
|
+
const SaleComplete_1 = require("./Events/SaleComplete");
|
|
24
|
+
// noinspection JSUnusedGlobalSymbols
|
|
20
25
|
class Application {
|
|
21
26
|
constructor(bridge) {
|
|
22
27
|
this.listeners = {
|
|
@@ -27,6 +32,10 @@ class Application {
|
|
|
27
32
|
REQUEST_SELL_SCREEN_OPTIONS: new Map(),
|
|
28
33
|
INTERNAL_PAGE_MESSAGE: new Map(),
|
|
29
34
|
REGISTER_CHANGED: new Map(),
|
|
35
|
+
FORMAT_INTEGRATED_PRODUCT: new Map(),
|
|
36
|
+
REQUEST_CUSTOMER_LIST_OPTIONS: new Map(),
|
|
37
|
+
REQUEST_SALE_KEYS: new Map(),
|
|
38
|
+
SALE_COMPLETE: new Map(),
|
|
30
39
|
};
|
|
31
40
|
this.directListeners = {};
|
|
32
41
|
this.handleEvent = (event, data, id) => {
|
|
@@ -56,7 +65,8 @@ class Application {
|
|
|
56
65
|
}
|
|
57
66
|
else if (event === "RESPONSE_CURRENT_SALE" ||
|
|
58
67
|
event === "RESPONSE_DATABASE_REQUEST" ||
|
|
59
|
-
event === "RESPONSE_LOCATION"
|
|
68
|
+
event === "RESPONSE_LOCATION" ||
|
|
69
|
+
event === "RESPONSE_OPTION") {
|
|
60
70
|
// Handled elsewhere
|
|
61
71
|
return;
|
|
62
72
|
}
|
|
@@ -84,7 +94,7 @@ class Application {
|
|
|
84
94
|
}
|
|
85
95
|
const results = [];
|
|
86
96
|
for (const e of listeners.values()) {
|
|
87
|
-
results.push(e());
|
|
97
|
+
results.push(e(data));
|
|
88
98
|
}
|
|
89
99
|
return Promise.all(results)
|
|
90
100
|
.then(() => {
|
|
@@ -128,6 +138,20 @@ class Application {
|
|
|
128
138
|
.then((res) => {
|
|
129
139
|
return RequestSellScreenOptions_1.RequestSellScreenOptions.respond(this.bridge, res.flat(), id);
|
|
130
140
|
});
|
|
141
|
+
case "FORMAT_INTEGRATED_PRODUCT":
|
|
142
|
+
results = results;
|
|
143
|
+
return Promise.all(results)
|
|
144
|
+
.then((res) => {
|
|
145
|
+
return FormatIntegratedProduct_1.FormatIntegratedProduct.respond(this.bridge, res.flat(), id);
|
|
146
|
+
});
|
|
147
|
+
case "REQUEST_CUSTOMER_LIST_OPTIONS":
|
|
148
|
+
results = results;
|
|
149
|
+
return Promise.all(results)
|
|
150
|
+
.then(res => RequestCustomerListOptions_1.RequestCustomerListOptions.respond(this.bridge, res.flat(), id));
|
|
151
|
+
case "REQUEST_SALE_KEYS":
|
|
152
|
+
results = results;
|
|
153
|
+
return Promise.all(results)
|
|
154
|
+
.then(res => RequestSaleKeys_1.RequestSaleKeys.respond(this.bridge, res.flat(), id));
|
|
131
155
|
}
|
|
132
156
|
}
|
|
133
157
|
addEventListener(event, callback) {
|
|
@@ -137,6 +161,7 @@ class Application {
|
|
|
137
161
|
this.directListeners[event] = new Set();
|
|
138
162
|
}
|
|
139
163
|
this.directListeners[event].add(callback);
|
|
164
|
+
return;
|
|
140
165
|
}
|
|
141
166
|
let c = null;
|
|
142
167
|
switch (event) {
|
|
@@ -168,6 +193,22 @@ class Application {
|
|
|
168
193
|
c = new RegisterChanged_1.RegisterChanged(callback);
|
|
169
194
|
this.listeners[event].set(callback, c);
|
|
170
195
|
break;
|
|
196
|
+
case "REQUEST_CUSTOMER_LIST_OPTIONS":
|
|
197
|
+
c = new RequestCustomerListOptions_1.RequestCustomerListOptions(callback);
|
|
198
|
+
this.listeners[event].set(callback, c);
|
|
199
|
+
break;
|
|
200
|
+
case "FORMAT_INTEGRATED_PRODUCT":
|
|
201
|
+
c = new FormatIntegratedProduct_1.FormatIntegratedProduct(callback);
|
|
202
|
+
this.listeners[event].set(callback, c);
|
|
203
|
+
break;
|
|
204
|
+
case "REQUEST_SALE_KEYS":
|
|
205
|
+
c = new RequestSaleKeys_1.RequestSaleKeys(callback);
|
|
206
|
+
this.listeners[event].set(callback, c);
|
|
207
|
+
break;
|
|
208
|
+
case "SALE_COMPLETE":
|
|
209
|
+
c = new SaleComplete_1.SaleComplete(callback);
|
|
210
|
+
this.listeners[event].set(callback, c);
|
|
211
|
+
break;
|
|
171
212
|
}
|
|
172
213
|
if (c === null) {
|
|
173
214
|
throw new TypeError(`${event} has not been defined`);
|
|
@@ -204,6 +245,12 @@ class Application {
|
|
|
204
245
|
download(file) {
|
|
205
246
|
this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.DOWNLOAD, file);
|
|
206
247
|
}
|
|
248
|
+
redirect(toLocation, externalRedirect = true) {
|
|
249
|
+
this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.REDIRECT, {
|
|
250
|
+
to: toLocation,
|
|
251
|
+
external: externalRedirect,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
207
254
|
load() {
|
|
208
255
|
this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.LOAD, true);
|
|
209
256
|
return () => this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.LOAD, false);
|
|
@@ -283,5 +330,37 @@ class Application {
|
|
|
283
330
|
user: location.user,
|
|
284
331
|
};
|
|
285
332
|
}
|
|
333
|
+
printReceipt(content) {
|
|
334
|
+
this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.PRINT_RECEIPT, {
|
|
335
|
+
content,
|
|
336
|
+
type: "text",
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
async getOption(option, defaultValue) {
|
|
340
|
+
const request = `OptionRequest-${Date.now().toString()}`;
|
|
341
|
+
const promise = new Promise(res => {
|
|
342
|
+
const listener = (event, data) => {
|
|
343
|
+
if (event !== "RESPONSE_OPTION") {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
data = data;
|
|
347
|
+
if (data.requestId !== request) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
this.bridge.removeEventListener(listener);
|
|
351
|
+
res(data.value);
|
|
352
|
+
};
|
|
353
|
+
this.bridge.addEventListener(listener);
|
|
354
|
+
});
|
|
355
|
+
this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.GET_OPTION, {
|
|
356
|
+
requestId: request,
|
|
357
|
+
option,
|
|
358
|
+
});
|
|
359
|
+
const optionValue = await promise;
|
|
360
|
+
if (typeof optionValue === "undefined") {
|
|
361
|
+
return defaultValue;
|
|
362
|
+
}
|
|
363
|
+
return optionValue;
|
|
364
|
+
}
|
|
286
365
|
}
|
|
287
366
|
exports.Application = Application;
|
|
@@ -9,6 +9,12 @@ import { ShopfrontSaleState } from "./APIs/CurrentSale/ShopfrontSaleState";
|
|
|
9
9
|
import { InternalPageMessage } from "./Events/InternalPageMessage";
|
|
10
10
|
import { InternalMessageSource } from "./APIs/InternalMessages/InternalMessageSource";
|
|
11
11
|
import { RegisterChanged } from "./Events/RegisterChanged";
|
|
12
|
+
import { FormatIntegratedProduct, FormattedSaleProduct } from "./Events/FormatIntegratedProduct";
|
|
13
|
+
import { MaybePromise } from "./Utilities/MiscTypes";
|
|
14
|
+
import { RequestCustomerListOptions, SellScreenCustomerListOption } from "./Events/RequestCustomerListOptions";
|
|
15
|
+
import { SaleKey } from "./Actions/SaleKey";
|
|
16
|
+
import { RequestSaleKeys } from "./Events/RequestSaleKeys";
|
|
17
|
+
import { CompletedSale, SaleComplete } from "./Events/SaleComplete";
|
|
12
18
|
export declare enum ToShopfront {
|
|
13
19
|
READY = "READY",
|
|
14
20
|
SERIALIZED = "SERIALIZED",
|
|
@@ -23,6 +29,12 @@ export declare enum ToShopfront {
|
|
|
23
29
|
UNSUPPORTED_EVENT = "UNSUPPORTED_EVENT",
|
|
24
30
|
NOT_LISTENING_TO_EVENT = "NOT_LISTENING_TO_EVENT",
|
|
25
31
|
REQUEST_LOCATION = "REQUEST_LOCATION",
|
|
32
|
+
RESPONSE_FORMAT_PRODUCT = "RESPONSE_FORMAT_PRODUCT",
|
|
33
|
+
RESPONSE_CUSTOMER_LIST_OPTIONS = "RESPONSE_CUSTOMER_LIST_OPTIONS",
|
|
34
|
+
RESPONSE_SALE_KEYS = "RESPONSE_SALE_KEYS",
|
|
35
|
+
PRINT_RECEIPT = "PRINT_RECEIPT",
|
|
36
|
+
REDIRECT = "REDIRECT",
|
|
37
|
+
GET_OPTION = "GET_OPTION",
|
|
26
38
|
SELL_SCREEN_OPTION_CHANGE = "SELL_SCREEN_OPTION_CHANGE",
|
|
27
39
|
INTERNAL_PAGE_MESSAGE = "INTERNAL_PAGE_MESSAGE",
|
|
28
40
|
TABLE_UPDATE = "TABLE_UPDATE"
|
|
@@ -64,6 +76,10 @@ export interface FromShopfrontReturns {
|
|
|
64
76
|
outlet: string | null;
|
|
65
77
|
user: string | null;
|
|
66
78
|
};
|
|
79
|
+
FORMAT_INTEGRATED_PRODUCT: FormatIntegratedProductEvent;
|
|
80
|
+
REQUEST_CUSTOMER_LIST_OPTIONS: Array<SellScreenCustomerListOption>;
|
|
81
|
+
REQUEST_SALE_KEYS: Array<SaleKey>;
|
|
82
|
+
SALE_COMPLETE: void;
|
|
67
83
|
}
|
|
68
84
|
export interface InternalPageMessageEvent {
|
|
69
85
|
method: "REQUEST_SETTINGS" | "REQUEST_SELL_SCREEN_OPTIONS" | "EXTERNAL_APPLICATION";
|
|
@@ -76,15 +92,25 @@ export interface RegisterChangedEvent {
|
|
|
76
92
|
outlet: null | string;
|
|
77
93
|
user: null | string;
|
|
78
94
|
}
|
|
95
|
+
export interface FormatIntegratedProductEvent {
|
|
96
|
+
product: FormattedSaleProduct;
|
|
97
|
+
}
|
|
98
|
+
export interface SaleCompletedEvent {
|
|
99
|
+
sale: CompletedSale;
|
|
100
|
+
}
|
|
79
101
|
export interface FromShopfrontCallbacks {
|
|
80
|
-
READY: (event: RegisterChangedEvent) =>
|
|
81
|
-
REQUEST_SETTINGS: () =>
|
|
82
|
-
REQUEST_BUTTONS: () =>
|
|
83
|
-
REQUEST_TABLE_COLUMNS: () =>
|
|
84
|
-
REQUEST_SELL_SCREEN_OPTIONS: () =>
|
|
85
|
-
INTERNAL_PAGE_MESSAGE: (event: InternalPageMessageEvent) =>
|
|
86
|
-
REGISTER_CHANGED: (event: RegisterChangedEvent) =>
|
|
87
|
-
CALLBACK: () =>
|
|
102
|
+
READY: (event: RegisterChangedEvent) => MaybePromise<FromShopfrontReturns["READY"]>;
|
|
103
|
+
REQUEST_SETTINGS: () => MaybePromise<FromShopfrontReturns["REQUEST_SETTINGS"]>;
|
|
104
|
+
REQUEST_BUTTONS: () => MaybePromise<FromShopfrontReturns["REQUEST_BUTTONS"]>;
|
|
105
|
+
REQUEST_TABLE_COLUMNS: () => MaybePromise<FromShopfrontReturns["REQUEST_TABLE_COLUMNS"]>;
|
|
106
|
+
REQUEST_SELL_SCREEN_OPTIONS: () => MaybePromise<FromShopfrontReturns["REQUEST_SELL_SCREEN_OPTIONS"]>;
|
|
107
|
+
INTERNAL_PAGE_MESSAGE: (event: InternalPageMessageEvent) => MaybePromise<FromShopfrontReturns["INTERNAL_PAGE_MESSAGE"]>;
|
|
108
|
+
REGISTER_CHANGED: (event: RegisterChangedEvent) => MaybePromise<FromShopfrontReturns["REGISTER_CHANGED"]>;
|
|
109
|
+
CALLBACK: () => MaybePromise<FromShopfrontReturns["CALLBACK"]>;
|
|
110
|
+
FORMAT_INTEGRATED_PRODUCT: (event: FormatIntegratedProductEvent) => MaybePromise<FromShopfrontReturns["FORMAT_INTEGRATED_PRODUCT"]>;
|
|
111
|
+
REQUEST_CUSTOMER_LIST_OPTIONS: () => MaybePromise<FromShopfrontReturns["REQUEST_CUSTOMER_LIST_OPTIONS"]>;
|
|
112
|
+
REQUEST_SALE_KEYS: () => MaybePromise<FromShopfrontReturns["REQUEST_SALE_KEYS"]>;
|
|
113
|
+
SALE_COMPLETE: (event: SaleCompletedEvent) => MaybePromise<FromShopfrontReturns["SALE_COMPLETE"]>;
|
|
88
114
|
}
|
|
89
115
|
export interface FromShopfront {
|
|
90
116
|
READY: Ready;
|
|
@@ -92,11 +118,15 @@ export interface FromShopfront {
|
|
|
92
118
|
REQUEST_BUTTONS: RequestButtons;
|
|
93
119
|
REQUEST_TABLE_COLUMNS: RequestTableColumns;
|
|
94
120
|
REQUEST_SELL_SCREEN_OPTIONS: RequestSellScreenOptions;
|
|
121
|
+
CALLBACK: Callback;
|
|
95
122
|
INTERNAL_PAGE_MESSAGE: InternalPageMessage;
|
|
96
123
|
REGISTER_CHANGED: RegisterChanged;
|
|
97
|
-
|
|
124
|
+
FORMAT_INTEGRATED_PRODUCT: FormatIntegratedProduct;
|
|
125
|
+
REQUEST_CUSTOMER_LIST_OPTIONS: RequestCustomerListOptions;
|
|
126
|
+
SALE_COMPLETE: SaleComplete;
|
|
127
|
+
REQUEST_SALE_KEYS: RequestSaleKeys;
|
|
98
128
|
}
|
|
99
|
-
export declare const directShopfrontEvents: readonly ["SALE_ADD_PRODUCT", "SALE_REMOVE_PRODUCT", "SALE_ADD_CUSTOMER", "SALE_REMOVE_CUSTOMER"];
|
|
129
|
+
export declare const directShopfrontEvents: readonly ["SALE_ADD_PRODUCT", "SALE_REMOVE_PRODUCT", "SALE_UPDATE_PRODUCTS", "SALE_CHANGE_QUANTITY", "SALE_ADD_CUSTOMER", "SALE_REMOVE_CUSTOMER", "SALE_CLEAR"];
|
|
100
130
|
export declare type DirectShopfrontEvent = typeof directShopfrontEvents[number];
|
|
101
131
|
export interface FromShopfrontInternal {
|
|
102
132
|
CYCLE_KEY: "CYCLE_KEY";
|
|
@@ -104,4 +134,5 @@ export interface FromShopfrontInternal {
|
|
|
104
134
|
RESPONSE_CURRENT_SALE: "RESPONSE_CURRENT_SALE";
|
|
105
135
|
RESPONSE_DATABASE_REQUEST: "RESPONSE_DATABASE_REQUEST";
|
|
106
136
|
RESPONSE_LOCATION: "RESPONSE_LOCATION";
|
|
137
|
+
RESPONSE_OPTION: "RESPONSE_OPTION";
|
|
107
138
|
}
|
package/lib/ApplicationEvents.js
CHANGED
|
@@ -16,6 +16,12 @@ var ToShopfront;
|
|
|
16
16
|
ToShopfront["UNSUPPORTED_EVENT"] = "UNSUPPORTED_EVENT";
|
|
17
17
|
ToShopfront["NOT_LISTENING_TO_EVENT"] = "NOT_LISTENING_TO_EVENT";
|
|
18
18
|
ToShopfront["REQUEST_LOCATION"] = "REQUEST_LOCATION";
|
|
19
|
+
ToShopfront["RESPONSE_FORMAT_PRODUCT"] = "RESPONSE_FORMAT_PRODUCT";
|
|
20
|
+
ToShopfront["RESPONSE_CUSTOMER_LIST_OPTIONS"] = "RESPONSE_CUSTOMER_LIST_OPTIONS";
|
|
21
|
+
ToShopfront["RESPONSE_SALE_KEYS"] = "RESPONSE_SALE_KEYS";
|
|
22
|
+
ToShopfront["PRINT_RECEIPT"] = "PRINT_RECEIPT";
|
|
23
|
+
ToShopfront["REDIRECT"] = "REDIRECT";
|
|
24
|
+
ToShopfront["GET_OPTION"] = "GET_OPTION";
|
|
19
25
|
// Emitable Events
|
|
20
26
|
ToShopfront["SELL_SCREEN_OPTION_CHANGE"] = "SELL_SCREEN_OPTION_CHANGE";
|
|
21
27
|
ToShopfront["INTERNAL_PAGE_MESSAGE"] = "INTERNAL_PAGE_MESSAGE";
|
|
@@ -27,6 +33,9 @@ var WithinApplication;
|
|
|
27
33
|
exports.directShopfrontEvents = [
|
|
28
34
|
"SALE_ADD_PRODUCT",
|
|
29
35
|
"SALE_REMOVE_PRODUCT",
|
|
36
|
+
"SALE_UPDATE_PRODUCTS",
|
|
37
|
+
"SALE_CHANGE_QUANTITY",
|
|
30
38
|
"SALE_ADD_CUSTOMER",
|
|
31
|
-
"SALE_REMOVE_CUSTOMER"
|
|
39
|
+
"SALE_REMOVE_CUSTOMER",
|
|
40
|
+
"SALE_CLEAR",
|
|
32
41
|
];
|
package/lib/Bridge.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class Bridge {
|
|
|
19
19
|
protected registerListeners(): void;
|
|
20
20
|
protected unregisterListeners(): void;
|
|
21
21
|
protected handleMessage: (event: MessageEvent) => void;
|
|
22
|
-
sendMessage(type: ApplicationEvents.ToShopfront, data?:
|
|
22
|
+
sendMessage(type: ApplicationEvents.ToShopfront, data?: unknown, id?: string): void;
|
|
23
23
|
addEventListener(listener: ApplicationEventListener): void;
|
|
24
24
|
removeEventListener(listener: ApplicationEventListener): void;
|
|
25
25
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { BaseEvent } from "./BaseEvent";
|
|
2
|
+
import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
|
|
3
|
+
import { Bridge } from "../Bridge";
|
|
4
|
+
export declare type FormattedSaleProductType = "Normal" | "Product" | "GiftCard" | "Voucher" | "Basket" | "Package" | "Component" | "Integrated";
|
|
5
|
+
export interface SaleGiftCard {
|
|
6
|
+
code: string;
|
|
7
|
+
amount: number;
|
|
8
|
+
expiry: string;
|
|
9
|
+
}
|
|
10
|
+
export interface FormattedSaleProduct {
|
|
11
|
+
uuid: string;
|
|
12
|
+
type: FormattedSaleProductType;
|
|
13
|
+
name: string;
|
|
14
|
+
caseQuantity: number;
|
|
15
|
+
isCase: boolean;
|
|
16
|
+
quantity: number;
|
|
17
|
+
loyalty: {
|
|
18
|
+
earn: number;
|
|
19
|
+
redeem: number;
|
|
20
|
+
};
|
|
21
|
+
prices: {
|
|
22
|
+
price: number;
|
|
23
|
+
unlockedPrice: number;
|
|
24
|
+
normal: number;
|
|
25
|
+
base: number;
|
|
26
|
+
addPrice: number;
|
|
27
|
+
removePrice: number;
|
|
28
|
+
additionalPrice: number;
|
|
29
|
+
};
|
|
30
|
+
tax: {
|
|
31
|
+
id: false | string;
|
|
32
|
+
amount: number;
|
|
33
|
+
};
|
|
34
|
+
products: Array<FormattedSaleProduct>;
|
|
35
|
+
defaultProducts: Array<FormattedSaleProduct>;
|
|
36
|
+
special: boolean;
|
|
37
|
+
edited: boolean;
|
|
38
|
+
promotions: {
|
|
39
|
+
[id: string]: {
|
|
40
|
+
name: string;
|
|
41
|
+
active: boolean;
|
|
42
|
+
quantity: number;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
rebates: {
|
|
46
|
+
[id: string]: {
|
|
47
|
+
amount: number;
|
|
48
|
+
quantity: number;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
giftCard: SaleGiftCard | null;
|
|
52
|
+
note: string;
|
|
53
|
+
userId: null | string;
|
|
54
|
+
priceSet?: string;
|
|
55
|
+
deleted?: boolean;
|
|
56
|
+
initiallyDeleted?: boolean;
|
|
57
|
+
familyId: string | null;
|
|
58
|
+
canUnlock: boolean;
|
|
59
|
+
discountReason?: string;
|
|
60
|
+
requestPrice?: boolean;
|
|
61
|
+
lockQuantity: boolean;
|
|
62
|
+
metaData: {
|
|
63
|
+
[key: string]: any;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export declare class FormatIntegratedProduct extends BaseEvent {
|
|
67
|
+
constructor(callback: FromShopfrontCallbacks["FORMAT_INTEGRATED_PRODUCT"]);
|
|
68
|
+
emit(data: {
|
|
69
|
+
product: FormattedSaleProduct;
|
|
70
|
+
}): Promise<FromShopfrontReturns["FORMAT_INTEGRATED_PRODUCT"]>;
|
|
71
|
+
static respond(bridge: Bridge, data: Array<FromShopfrontReturns["FORMAT_INTEGRATED_PRODUCT"]>, id: string): Promise<void>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FormatIntegratedProduct = void 0;
|
|
4
|
+
const BaseEvent_1 = require("./BaseEvent");
|
|
5
|
+
const ApplicationEvents_1 = require("../ApplicationEvents");
|
|
6
|
+
class FormatIntegratedProduct extends BaseEvent_1.BaseEvent {
|
|
7
|
+
constructor(callback) {
|
|
8
|
+
super(callback);
|
|
9
|
+
}
|
|
10
|
+
async emit(data) {
|
|
11
|
+
const result = await Promise.resolve(this.callback(data));
|
|
12
|
+
if (typeof result !== "object" || result === null) {
|
|
13
|
+
throw new TypeError("Callback must return an object");
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
static async respond(bridge, data, id) {
|
|
18
|
+
if (data.length > 1) {
|
|
19
|
+
throw new Error("Multiple integrated product responses found, please ensure you are only subscribed to FORMAT_INTEGRATED_PRODUCT once");
|
|
20
|
+
}
|
|
21
|
+
bridge.sendMessage(ApplicationEvents_1.ToShopfront.RESPONSE_FORMAT_PRODUCT, data[0], id);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.FormatIntegratedProduct = FormatIntegratedProduct;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
|
|
2
|
+
import { Bridge } from "..";
|
|
3
|
+
import { BaseEvent } from "./BaseEvent";
|
|
4
|
+
export interface SellScreenCustomerListOption {
|
|
5
|
+
contents: string;
|
|
6
|
+
onClick: () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare class RequestCustomerListOptions extends BaseEvent {
|
|
9
|
+
constructor(callback: FromShopfrontCallbacks["REQUEST_CUSTOMER_LIST_OPTIONS"]);
|
|
10
|
+
emit(data: {}): Promise<FromShopfrontReturns["REQUEST_CUSTOMER_LIST_OPTIONS"]>;
|
|
11
|
+
static respond(bridge: Bridge, options: Array<SellScreenCustomerListOption>, id: string): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestCustomerListOptions = void 0;
|
|
4
|
+
const ApplicationEvents_1 = require("../ApplicationEvents");
|
|
5
|
+
const BaseEvent_1 = require("./BaseEvent");
|
|
6
|
+
const CustomerListOption_1 = require("../Actions/CustomerListOption");
|
|
7
|
+
class RequestCustomerListOptions extends BaseEvent_1.BaseEvent {
|
|
8
|
+
constructor(callback) {
|
|
9
|
+
super(callback);
|
|
10
|
+
}
|
|
11
|
+
async emit(data) {
|
|
12
|
+
let result = await Promise.resolve(this.callback());
|
|
13
|
+
if (!Array.isArray(result)) {
|
|
14
|
+
result = [result];
|
|
15
|
+
}
|
|
16
|
+
for (let i = 0, l = result.length; i < l; i++) {
|
|
17
|
+
if (!result[i].contents || !result[i].onClick) {
|
|
18
|
+
throw new TypeError("You must specify both the contents and an onClick callback");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
static async respond(bridge, options, id) {
|
|
24
|
+
bridge.sendMessage(ApplicationEvents_1.ToShopfront.RESPONSE_CUSTOMER_LIST_OPTIONS, options.map(option => {
|
|
25
|
+
const o = new CustomerListOption_1.CustomerListOption(option.contents);
|
|
26
|
+
o.addEventListener("click", option.onClick);
|
|
27
|
+
return o.serialize();
|
|
28
|
+
}), id);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.RequestCustomerListOptions = RequestCustomerListOptions;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
|
|
2
|
+
import { Bridge } from "..";
|
|
3
|
+
import { BaseEvent } from "./BaseEvent";
|
|
4
|
+
import { SaleKey } from "../Actions/SaleKey";
|
|
5
|
+
export declare class RequestSaleKeys extends BaseEvent {
|
|
6
|
+
constructor(callback: FromShopfrontCallbacks["REQUEST_SALE_KEYS"]);
|
|
7
|
+
emit(): Promise<FromShopfrontReturns["REQUEST_SALE_KEYS"]>;
|
|
8
|
+
static respond(bridge: Bridge, keys: Array<SaleKey>, id: string): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestSaleKeys = void 0;
|
|
4
|
+
const ApplicationEvents_1 = require("../ApplicationEvents");
|
|
5
|
+
const BaseEvent_1 = require("./BaseEvent");
|
|
6
|
+
const SaleKey_1 = require("../Actions/SaleKey");
|
|
7
|
+
class RequestSaleKeys extends BaseEvent_1.BaseEvent {
|
|
8
|
+
constructor(callback) {
|
|
9
|
+
super(callback);
|
|
10
|
+
}
|
|
11
|
+
async emit() {
|
|
12
|
+
let result = await Promise.resolve(this.callback());
|
|
13
|
+
if (!Array.isArray(result)) {
|
|
14
|
+
result = [result];
|
|
15
|
+
}
|
|
16
|
+
for (let i = 0, l = result.length; i < l; i++) {
|
|
17
|
+
if (!(result[i] instanceof SaleKey_1.SaleKey)) {
|
|
18
|
+
throw new TypeError("You must return an instance of SaleKey");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
static async respond(bridge, keys, id) {
|
|
24
|
+
let response = [];
|
|
25
|
+
for (let i = 0, l = keys.length; i < l; i++) {
|
|
26
|
+
if (!(keys[i] instanceof SaleKey_1.SaleKey)) {
|
|
27
|
+
throw new TypeError("Invalid response returned, expected SaleKey");
|
|
28
|
+
}
|
|
29
|
+
response.push(keys[i].serialize());
|
|
30
|
+
}
|
|
31
|
+
bridge.sendMessage(ApplicationEvents_1.ToShopfront.RESPONSE_SALE_KEYS, response, id);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.RequestSaleKeys = RequestSaleKeys;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BaseEvent } from "./BaseEvent";
|
|
2
|
+
import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
|
|
3
|
+
interface CompletedSaleProduct {
|
|
4
|
+
uuid: string;
|
|
5
|
+
type: "Normal" | "Product" | "GiftCard" | "Voucher" | "Basket" | "Package" | "Component" | "Integrated";
|
|
6
|
+
name: string;
|
|
7
|
+
caseQuantity: number;
|
|
8
|
+
isCase: boolean;
|
|
9
|
+
quantity: number;
|
|
10
|
+
loyalty: {
|
|
11
|
+
earn: number;
|
|
12
|
+
redeem: number;
|
|
13
|
+
};
|
|
14
|
+
prices: {
|
|
15
|
+
price: number;
|
|
16
|
+
unlockedPrice: number;
|
|
17
|
+
normal: number;
|
|
18
|
+
base: number;
|
|
19
|
+
addPrice: number;
|
|
20
|
+
removePrice: number;
|
|
21
|
+
additionalPrice: number;
|
|
22
|
+
};
|
|
23
|
+
tax: {
|
|
24
|
+
id: false | string;
|
|
25
|
+
amount: number;
|
|
26
|
+
};
|
|
27
|
+
products: Array<CompletedSaleProduct>;
|
|
28
|
+
defaultProducts: Array<CompletedSaleProduct>;
|
|
29
|
+
special: boolean;
|
|
30
|
+
edited: boolean;
|
|
31
|
+
promotions: {
|
|
32
|
+
[id: string]: {
|
|
33
|
+
name: string;
|
|
34
|
+
active: boolean;
|
|
35
|
+
quantity: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
rebates: {
|
|
39
|
+
[id: string]: {
|
|
40
|
+
amount: number;
|
|
41
|
+
quantity: number;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
giftCard: {
|
|
45
|
+
code: string;
|
|
46
|
+
amount: number;
|
|
47
|
+
expiry: string;
|
|
48
|
+
} | null;
|
|
49
|
+
note: string;
|
|
50
|
+
userId: null | string;
|
|
51
|
+
priceSet?: string;
|
|
52
|
+
deleted?: boolean;
|
|
53
|
+
initiallyDeleted?: boolean;
|
|
54
|
+
familyId: string | null;
|
|
55
|
+
canUnlock: boolean;
|
|
56
|
+
discountReason?: string;
|
|
57
|
+
requestPrice?: boolean;
|
|
58
|
+
lockQuantity: boolean;
|
|
59
|
+
metaData: {
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
interface CompletedSalePayment {
|
|
64
|
+
method: string;
|
|
65
|
+
type: string;
|
|
66
|
+
status: "approved" | "cancelled" | "declined" | "completed" | "failed";
|
|
67
|
+
amount: number;
|
|
68
|
+
cashout: number;
|
|
69
|
+
rounding: number | undefined;
|
|
70
|
+
metadata: string;
|
|
71
|
+
registerId: string;
|
|
72
|
+
userId?: string;
|
|
73
|
+
processTime?: string;
|
|
74
|
+
receipt?: string;
|
|
75
|
+
reverted: boolean;
|
|
76
|
+
uploaded?: boolean;
|
|
77
|
+
voucherRefund?: boolean;
|
|
78
|
+
}
|
|
79
|
+
export interface CompletedSale {
|
|
80
|
+
products: Array<CompletedSaleProduct>;
|
|
81
|
+
customer: false | {
|
|
82
|
+
uuid: string;
|
|
83
|
+
};
|
|
84
|
+
payments: Array<CompletedSalePayment>;
|
|
85
|
+
notes: {
|
|
86
|
+
internal: string;
|
|
87
|
+
sale: string;
|
|
88
|
+
};
|
|
89
|
+
totals: {
|
|
90
|
+
sale: number;
|
|
91
|
+
remaining: number;
|
|
92
|
+
paid: number;
|
|
93
|
+
savings: number;
|
|
94
|
+
discount: number;
|
|
95
|
+
change: number;
|
|
96
|
+
cashout: number;
|
|
97
|
+
rounding: number;
|
|
98
|
+
};
|
|
99
|
+
registerId: string;
|
|
100
|
+
userId: string;
|
|
101
|
+
orderReference: string;
|
|
102
|
+
refundReason: string;
|
|
103
|
+
status: "COMPLETED";
|
|
104
|
+
id: string;
|
|
105
|
+
invoiceId: string;
|
|
106
|
+
createdAt: string;
|
|
107
|
+
}
|
|
108
|
+
export declare class SaleComplete extends BaseEvent {
|
|
109
|
+
constructor(callback: FromShopfrontCallbacks["SALE_COMPLETE"]);
|
|
110
|
+
emit(data: CompletedSale): Promise<FromShopfrontReturns["SALE_COMPLETE"]>;
|
|
111
|
+
}
|
|
112
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SaleComplete = void 0;
|
|
4
|
+
const BaseEvent_1 = require("./BaseEvent");
|
|
5
|
+
class SaleComplete extends BaseEvent_1.BaseEvent {
|
|
6
|
+
constructor(callback) {
|
|
7
|
+
super(callback);
|
|
8
|
+
}
|
|
9
|
+
async emit(data) {
|
|
10
|
+
this.callback(data);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.SaleComplete = SaleComplete;
|
package/lib/index.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ export { Button } from "./Actions/Button";
|
|
|
3
3
|
export { Redirect } from "./Actions/Redirect";
|
|
4
4
|
export { Toast } from "./Actions/Toast";
|
|
5
5
|
export { Dialog } from "./Actions/Dialog";
|
|
6
|
+
export { SaleKey } from "./Actions/SaleKey";
|
|
6
7
|
export { SellScreenOption } from "./EmitableEvents/SellScreenOption";
|
|
7
8
|
export { TableUpdate } from "./EmitableEvents/TableUpdate";
|
|
9
|
+
export { CompletedSale } from "./Events/SaleComplete";
|
|
10
|
+
export { Application } from "./Application";
|
|
8
11
|
export * as Sales from "./APIs/CurrentSale/index";
|
package/lib/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.Sales = exports.TableUpdate = exports.SellScreenOption = exports.Dialog = exports.Toast = exports.Redirect = exports.Button = exports.Bridge = void 0;
|
|
22
|
+
exports.Sales = exports.Application = exports.TableUpdate = exports.SellScreenOption = exports.SaleKey = exports.Dialog = exports.Toast = exports.Redirect = exports.Button = exports.Bridge = void 0;
|
|
23
23
|
var Bridge_1 = require("./Bridge");
|
|
24
24
|
Object.defineProperty(exports, "Bridge", { enumerable: true, get: function () { return Bridge_1.Bridge; } });
|
|
25
25
|
var Button_1 = require("./Actions/Button");
|
|
@@ -30,8 +30,12 @@ var Toast_1 = require("./Actions/Toast");
|
|
|
30
30
|
Object.defineProperty(exports, "Toast", { enumerable: true, get: function () { return Toast_1.Toast; } });
|
|
31
31
|
var Dialog_1 = require("./Actions/Dialog");
|
|
32
32
|
Object.defineProperty(exports, "Dialog", { enumerable: true, get: function () { return Dialog_1.Dialog; } });
|
|
33
|
+
var SaleKey_1 = require("./Actions/SaleKey");
|
|
34
|
+
Object.defineProperty(exports, "SaleKey", { enumerable: true, get: function () { return SaleKey_1.SaleKey; } });
|
|
33
35
|
var SellScreenOption_1 = require("./EmitableEvents/SellScreenOption");
|
|
34
36
|
Object.defineProperty(exports, "SellScreenOption", { enumerable: true, get: function () { return SellScreenOption_1.SellScreenOption; } });
|
|
35
37
|
var TableUpdate_1 = require("./EmitableEvents/TableUpdate");
|
|
36
38
|
Object.defineProperty(exports, "TableUpdate", { enumerable: true, get: function () { return TableUpdate_1.TableUpdate; } });
|
|
39
|
+
var Application_1 = require("./Application");
|
|
40
|
+
Object.defineProperty(exports, "Application", { enumerable: true, get: function () { return Application_1.Application; } });
|
|
37
41
|
exports.Sales = __importStar(require("./APIs/CurrentSale/index"));
|
package/package.json
CHANGED
package/yarn.lock
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
2
|
-
# yarn lockfile v1
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
typescript@^4.1.2:
|
|
6
|
-
version "4.1.2"
|
|
7
|
-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.2.tgz#6369ef22516fe5e10304aae5a5c4862db55380e9"
|
|
8
|
-
integrity sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ==
|