@shopfront/bridge 1.10.0 → 1.11.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/{shopfront-embedded-bridge.iml → embedded-bridge.iml} +0 -0
- package/.idea/inspectionProfiles/Project_Default.xml +1 -2
- package/.idea/modules.xml +1 -1
- package/README.md +3 -2
- package/lib/APIs/CurrentSale/Sale.d.ts +12 -0
- package/lib/APIs/CurrentSale/Sale.js +18 -0
- package/lib/APIs/CurrentSale/SaleProduct.d.ts +1 -1
- package/lib/APIs/CurrentSale/SaleProduct.js +1 -2
- package/lib/APIs/CurrentSale/ShopfrontSaleState.d.ts +1 -0
- package/lib/APIs/CurrentSale/index.js +5 -1
- package/lib/APIs/InternalMessages/InternalMessageSource.d.ts +1 -1
- package/lib/Actions/BaseAction.d.ts +13 -8
- package/lib/Actions/BaseAction.js +7 -6
- package/lib/Actions/Button.js +0 -1
- package/lib/Actions/Redirect.js +0 -2
- package/lib/Actions/SaleKey.js +0 -1
- package/lib/Actions/SaleUpdate.d.ts +5 -2
- package/lib/Actions/SaleUpdate.js +0 -1
- package/lib/Actions/Toast.d.ts +1 -2
- package/lib/Application.d.ts +24 -7
- package/lib/Application.js +54 -10
- package/lib/ApplicationEvents.d.ts +37 -4
- package/lib/ApplicationEvents.js +4 -4
- package/lib/Bridge.d.ts +1 -1
- package/lib/Bridge.js +6 -2
- package/lib/Common/EventEmitter.d.ts +4 -3
- package/lib/Common/Serializable.d.ts +1 -1
- package/lib/EmitableEvents/SellScreenPromotionApplicable.d.ts +13 -0
- package/lib/EmitableEvents/SellScreenPromotionApplicable.js +19 -0
- package/lib/Events/BaseEvent.d.ts +5 -4
- package/lib/Events/BaseEvent.js +1 -0
- package/lib/Events/Callback.d.ts +1 -1
- package/lib/Events/Callback.js +2 -2
- package/lib/Events/FormatIntegratedProduct.d.ts +14 -3
- package/lib/Events/FormatIntegratedProduct.js +1 -1
- package/lib/Events/InternalPageMessage.d.ts +4 -8
- package/lib/Events/InternalPageMessage.js +1 -1
- package/lib/Events/PaymentMethodsEnabled.d.ts +15 -0
- package/lib/Events/PaymentMethodsEnabled.js +21 -0
- package/lib/Events/Ready.d.ts +2 -2
- package/lib/Events/Ready.js +1 -1
- package/lib/Events/RegisterChanged.js +1 -1
- package/lib/Events/RequestButtons.d.ts +7 -2
- package/lib/Events/RequestButtons.js +2 -2
- package/lib/Events/RequestCustomerListOptions.d.ts +3 -2
- package/lib/Events/RequestCustomerListOptions.js +3 -2
- package/lib/Events/RequestSaleKeys.d.ts +2 -1
- package/lib/Events/RequestSaleKeys.js +2 -2
- package/lib/Events/RequestSellScreenOptions.d.ts +3 -2
- package/lib/Events/RequestSellScreenOptions.js +3 -2
- package/lib/Events/RequestSettings.d.ts +3 -2
- package/lib/Events/RequestSettings.js +3 -2
- package/lib/Events/RequestTableColumns.d.ts +6 -2
- package/lib/Events/RequestTableColumns.js +1 -1
- package/lib/Events/SaleComplete.d.ts +1 -1
- package/lib/Events/SaleComplete.js +1 -1
- package/lib/Events/UIPipeline.d.ts +15 -0
- package/lib/Events/UIPipeline.js +31 -0
- package/lib/Utilities/ActionEventRegistrar.d.ts +3 -3
- package/lib/Utilities/MiscTypes.d.ts +3 -0
- package/lib/Utilities/Static.js +2 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +8 -2
- package/package.json +31 -27
- package/.idea/compiler.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/bitbucket-pipelines.yml +0 -22
|
File without changes
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<component name="InspectionProjectProfileManager">
|
|
2
2
|
<profile version="1.0">
|
|
3
3
|
<option name="myName" value="Project Default" />
|
|
4
|
-
<inspection_tool class="
|
|
5
|
-
<inspection_tool class="JSMethodCanBeStatic" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
4
|
+
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
|
|
6
5
|
</profile>
|
|
7
6
|
</component>
|
package/.idea/modules.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<project version="4">
|
|
3
3
|
<component name="ProjectModuleManager">
|
|
4
4
|
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/embedded-bridge.iml" filepath="$PROJECT_DIR$/.idea/embedded-bridge.iml" />
|
|
6
6
|
</modules>
|
|
7
7
|
</component>
|
|
8
8
|
</project>
|
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
#Shopfront Embedded Bridge
|
|
1
|
+
# Shopfront Embedded Bridge
|
|
2
|
+
|
|
2
3
|
This is the bridge library to use with the Shopfront Embedded API.
|
|
3
4
|
|
|
4
5
|
For more information, check out the documentation on the
|
|
5
|
-
[Shopfront developer website](https://developer.onshopfront.com/documentation/Embedded/Introduction).
|
|
6
|
+
[Shopfront developer website](https://developer.onshopfront.com/documentation/Embedded/Introduction).
|
|
@@ -80,6 +80,12 @@ export declare class Sale {
|
|
|
80
80
|
* @returns {string}
|
|
81
81
|
*/
|
|
82
82
|
getOrderReference(): string;
|
|
83
|
+
/**
|
|
84
|
+
* Get the current meta data for the sale
|
|
85
|
+
*
|
|
86
|
+
* @returns {Record<string, unknown>}
|
|
87
|
+
*/
|
|
88
|
+
getMetaData(): Record<string, unknown>;
|
|
83
89
|
/**
|
|
84
90
|
* Cancel the current sale in progress.
|
|
85
91
|
*
|
|
@@ -162,6 +168,12 @@ export declare class Sale {
|
|
|
162
168
|
* @returns {Promise<void>}
|
|
163
169
|
*/
|
|
164
170
|
setOrderReference(reference: string): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Set the meta data of the sale, this will override the previous meta data.
|
|
173
|
+
*
|
|
174
|
+
* @param metaData
|
|
175
|
+
*/
|
|
176
|
+
setMetaData(metaData: Record<string, unknown>): Promise<void>;
|
|
165
177
|
/**
|
|
166
178
|
* Update a product's details, currently this only updates the top-level meta data
|
|
167
179
|
* @param product
|
|
@@ -125,6 +125,14 @@ class Sale {
|
|
|
125
125
|
getOrderReference() {
|
|
126
126
|
return this.sale.orderReference;
|
|
127
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
|
+
}
|
|
128
136
|
/**
|
|
129
137
|
* Cancel the current sale in progress.
|
|
130
138
|
*
|
|
@@ -257,6 +265,16 @@ class Sale {
|
|
|
257
265
|
reference,
|
|
258
266
|
}));
|
|
259
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
|
+
}
|
|
260
278
|
/**
|
|
261
279
|
* Update a product's details, currently this only updates the top-level meta data
|
|
262
280
|
* @param product
|
|
@@ -73,7 +73,7 @@ export declare class SaleProduct {
|
|
|
73
73
|
*
|
|
74
74
|
* @returns {ShopfrontSaleProductType | undefined}
|
|
75
75
|
*/
|
|
76
|
-
getType():
|
|
76
|
+
getType(): ShopfrontSaleProductType | undefined;
|
|
77
77
|
/**
|
|
78
78
|
* Get the tax rate amount.
|
|
79
79
|
* This is the rate of the tax rate (e.g. 10 is a tax rate of 10%).
|
|
@@ -44,10 +44,9 @@ class SaleProduct {
|
|
|
44
44
|
* @param {Array<number>} indexAddress
|
|
45
45
|
*/
|
|
46
46
|
setInternal(data, indexAddress) {
|
|
47
|
-
var _a;
|
|
48
47
|
this.name = data.name;
|
|
49
48
|
this.type = data.type;
|
|
50
|
-
this.taxRateAmount =
|
|
49
|
+
this.taxRateAmount = data.tax?.amount || 0;
|
|
51
50
|
this.note = data.note;
|
|
52
51
|
this.edited = data.edited;
|
|
53
52
|
this.caseQuantity = data.caseQuantity;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
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);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { EventEmitter } from "../Common/EventEmitter";
|
|
2
2
|
import { Serializable, Serialized } from "../Common/Serializable";
|
|
3
|
+
interface BaseActionConstructor<T> {
|
|
4
|
+
new (...args: Array<never>): BaseAction<T>;
|
|
5
|
+
new (serialized: Serialized<T>): BaseAction<T>;
|
|
6
|
+
}
|
|
3
7
|
export declare class BaseAction<T> extends EventEmitter {
|
|
4
8
|
protected target: string;
|
|
5
9
|
protected events: Array<{
|
|
6
|
-
callback:
|
|
10
|
+
callback: (...args: Array<unknown>) => void;
|
|
7
11
|
type: string;
|
|
8
12
|
id: string;
|
|
9
13
|
}>;
|
|
10
|
-
protected properties: Array<
|
|
14
|
+
protected properties: Array<unknown>;
|
|
11
15
|
static serializedRegistry: {
|
|
12
|
-
[id: string]:
|
|
16
|
+
[id: string]: BaseActionConstructor<unknown>;
|
|
13
17
|
};
|
|
14
|
-
constructor(serialized: Serialized<T>, type:
|
|
18
|
+
constructor(serialized: Serialized<T>, type: BaseActionConstructor<T>);
|
|
15
19
|
serialize(): Serialized<T>;
|
|
16
|
-
protected serializeProperties(properties: Array<
|
|
20
|
+
protected serializeProperties(properties: Array<unknown>): Array<unknown>;
|
|
17
21
|
static deserialize<T extends Serializable<T>>(serialized: Serialized<T>): T;
|
|
18
|
-
addEventListener(event: string, callback:
|
|
19
|
-
removeEventListener(event: string, callback:
|
|
20
|
-
handleRegistrarEvent(id: string, data:
|
|
22
|
+
addEventListener(event: string, callback: (...args: Array<unknown>) => void): void;
|
|
23
|
+
removeEventListener(event: string, callback: (...args: Array<unknown>) => void): void;
|
|
24
|
+
handleRegistrarEvent(id: string, data: unknown): void;
|
|
21
25
|
}
|
|
26
|
+
export {};
|
|
@@ -44,17 +44,18 @@ let BaseAction = BaseAction_1 = class BaseAction extends EventEmitter_1.EventEmi
|
|
|
44
44
|
const results = [];
|
|
45
45
|
// Loop through current layer of properties
|
|
46
46
|
for (let i = 0, l = properties.length; i < l; i++) {
|
|
47
|
-
|
|
47
|
+
const property = properties[i];
|
|
48
|
+
if (Array.isArray(property)) {
|
|
48
49
|
// Prepare to recurse through next layer of properties
|
|
49
|
-
results.push(this.serializeProperties(
|
|
50
|
+
results.push(this.serializeProperties(property));
|
|
50
51
|
}
|
|
51
|
-
else if (
|
|
52
|
+
else if (property instanceof BaseAction_1) {
|
|
52
53
|
// Serialize property
|
|
53
|
-
results.push(
|
|
54
|
+
results.push(property.serialize());
|
|
54
55
|
}
|
|
55
56
|
else {
|
|
56
57
|
// Assume that the property is already serializable
|
|
57
|
-
results.push(
|
|
58
|
+
results.push(property);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
return results;
|
|
@@ -102,6 +103,6 @@ let BaseAction = BaseAction_1 = class BaseAction extends EventEmitter_1.EventEmi
|
|
|
102
103
|
};
|
|
103
104
|
BaseAction.serializedRegistry = {};
|
|
104
105
|
BaseAction = BaseAction_1 = __decorate([
|
|
105
|
-
Static_1.staticImplements()
|
|
106
|
+
(0, Static_1.staticImplements)()
|
|
106
107
|
], BaseAction);
|
|
107
108
|
exports.BaseAction = BaseAction;
|
package/lib/Actions/Button.js
CHANGED
|
@@ -19,7 +19,6 @@ class Button extends BaseAction_1.BaseAction {
|
|
|
19
19
|
})(), Button);
|
|
20
20
|
this.supportedEvents = ["click"];
|
|
21
21
|
if (typeof icon === "undefined" && typeof label !== "string") {
|
|
22
|
-
label = label;
|
|
23
22
|
this.label = label.properties[0];
|
|
24
23
|
this.icon = label.properties[1];
|
|
25
24
|
}
|
package/lib/Actions/Redirect.js
CHANGED
|
@@ -19,7 +19,6 @@ class InternalRedirect extends BaseAction_1.BaseAction {
|
|
|
19
19
|
})(), InternalRedirect);
|
|
20
20
|
this.supportedEvents = ["click"];
|
|
21
21
|
if (typeof to !== "string") {
|
|
22
|
-
to = to;
|
|
23
22
|
this.to = to.properties[0];
|
|
24
23
|
}
|
|
25
24
|
else {
|
|
@@ -47,7 +46,6 @@ class ExternalRedirect extends BaseAction_1.BaseAction {
|
|
|
47
46
|
this.to = to;
|
|
48
47
|
}
|
|
49
48
|
else {
|
|
50
|
-
to = to;
|
|
51
49
|
this.to = new URL(to.properties[0]);
|
|
52
50
|
}
|
|
53
51
|
}
|
package/lib/Actions/SaleKey.js
CHANGED
|
@@ -26,11 +26,11 @@ export interface SaleUpdateChanges {
|
|
|
26
26
|
cashout?: number;
|
|
27
27
|
status?: ShopfrontSalePaymentStatus;
|
|
28
28
|
};
|
|
29
|
-
SALE_CANCEL:
|
|
29
|
+
SALE_CANCEL: Record<string, never>;
|
|
30
30
|
CUSTOMER_ADD: {
|
|
31
31
|
id: string;
|
|
32
32
|
};
|
|
33
|
-
CUSTOMER_REMOVE:
|
|
33
|
+
CUSTOMER_REMOVE: Record<string, never>;
|
|
34
34
|
SALE_EXTERNAL_NOTE: {
|
|
35
35
|
note: string;
|
|
36
36
|
append?: boolean;
|
|
@@ -42,6 +42,9 @@ export interface SaleUpdateChanges {
|
|
|
42
42
|
SALE_ORDER_REFERENCE: {
|
|
43
43
|
reference: string;
|
|
44
44
|
};
|
|
45
|
+
SALE_META_DATA: {
|
|
46
|
+
metaData: Record<string, unknown>;
|
|
47
|
+
};
|
|
45
48
|
PRODUCT_UPDATE: {
|
|
46
49
|
id: string;
|
|
47
50
|
indexAddress: Array<number>;
|
package/lib/Actions/Toast.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { BaseAction } from "./BaseAction";
|
|
2
2
|
import { Serialized } from "../Common/Serializable";
|
|
3
|
-
declare type ToastType = "success" | "error" | "information" | "warning";
|
|
3
|
+
export declare type ToastType = "success" | "error" | "information" | "warning";
|
|
4
4
|
export declare class Toast extends BaseAction<Toast> {
|
|
5
5
|
protected supportedEvents: string[];
|
|
6
6
|
protected type: ToastType;
|
|
7
7
|
protected message: string;
|
|
8
8
|
constructor(type: Serialized<Toast> | ToastType, message?: string);
|
|
9
9
|
}
|
|
10
|
-
export {};
|
package/lib/Application.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ import { DirectShopfrontEvent, FromShopfront, FromShopfrontCallbacks, FromShopfr
|
|
|
3
3
|
import { Serializable } from "./Common/Serializable";
|
|
4
4
|
import { BaseEmitableEvent } from "./EmitableEvents/BaseEmitableEvent";
|
|
5
5
|
import { Sale } from "./APIs/CurrentSale";
|
|
6
|
+
import { ShopfrontSaleState } from "./APIs/CurrentSale/ShopfrontSaleState";
|
|
6
7
|
import { Database } from "./APIs/Database/Database";
|
|
7
8
|
import { MaybePromise } from "./Utilities/MiscTypes";
|
|
9
|
+
import { BaseEvent } from "./Events/BaseEvent";
|
|
8
10
|
export declare class Application {
|
|
9
11
|
protected bridge: Bridge;
|
|
10
12
|
protected isReady: boolean;
|
|
@@ -13,7 +15,7 @@ export declare class Application {
|
|
|
13
15
|
protected outlet: string | null;
|
|
14
16
|
protected user: string | null;
|
|
15
17
|
protected listeners: {
|
|
16
|
-
[key in keyof Omit<FromShopfront, "CALLBACK">]: Map<
|
|
18
|
+
[key in keyof Omit<FromShopfront, "CALLBACK">]: Map<(...args: Array<unknown>) => void, FromShopfront[key] & BaseEvent>;
|
|
17
19
|
};
|
|
18
20
|
protected directListeners: {
|
|
19
21
|
[K in DirectShopfrontEvent]?: Set<(data: unknown) => void | Promise<void>>;
|
|
@@ -21,22 +23,26 @@ export declare class Application {
|
|
|
21
23
|
database: Database;
|
|
22
24
|
constructor(bridge: Bridge);
|
|
23
25
|
destroy(): void;
|
|
24
|
-
protected handleEvent: (event: keyof FromShopfront | keyof FromShopfrontInternal, data:
|
|
25
|
-
protected emit(event: keyof Omit<FromShopfront, "CALLBACK"> | DirectShopfrontEvent, data:
|
|
26
|
+
protected handleEvent: (event: keyof FromShopfront | keyof FromShopfrontInternal, data: Record<string, unknown>, id: string) => void;
|
|
27
|
+
protected emit(event: keyof Omit<FromShopfront, "CALLBACK"> | DirectShopfrontEvent, data: Record<string, unknown> | undefined, id: string): void | Promise<void>;
|
|
26
28
|
addEventListener<E extends keyof FromShopfrontCallbacks>(event: E, callback: FromShopfrontCallbacks[E]): void;
|
|
27
29
|
addEventListener<D>(event: DirectShopfrontEvent, callback: (event: D) => MaybePromise<void>): void;
|
|
28
|
-
removeEventListener(event: keyof Omit<FromShopfront, "CALLBACK"> | DirectShopfrontEvent, callback: (...args: Array<
|
|
29
|
-
send(item: BaseEmitableEvent<
|
|
30
|
-
send(item: Serializable<
|
|
30
|
+
removeEventListener(event: keyof Omit<FromShopfront, "CALLBACK"> | DirectShopfrontEvent, callback: (...args: Array<unknown>) => MaybePromise<void>): void;
|
|
31
|
+
send(item: BaseEmitableEvent<unknown>): void;
|
|
32
|
+
send(item: Serializable<unknown>): void;
|
|
31
33
|
download(file: string): void;
|
|
32
34
|
redirect(toLocation: string, externalRedirect?: boolean): void;
|
|
33
35
|
load(): () => void;
|
|
34
36
|
protected handleEventCallback(data: {
|
|
35
37
|
id?: string;
|
|
36
|
-
data:
|
|
38
|
+
data: unknown;
|
|
37
39
|
}): void;
|
|
38
40
|
protected handleLocationChanged(data: RegisterChangedEvent): void;
|
|
39
41
|
getAuthenticationKey(): string;
|
|
42
|
+
protected dataIsSaleEvent(data: Record<string, unknown>): data is {
|
|
43
|
+
requestId: string;
|
|
44
|
+
saleState: ShopfrontSaleState | false;
|
|
45
|
+
};
|
|
40
46
|
/**
|
|
41
47
|
* Get the current sale on the sell screen, if the current device is not a register
|
|
42
48
|
* then this will return false.
|
|
@@ -44,6 +50,12 @@ export declare class Application {
|
|
|
44
50
|
* @returns {Promise<Sale | boolean>}
|
|
45
51
|
*/
|
|
46
52
|
getCurrentSale(): Promise<Sale | false>;
|
|
53
|
+
protected dataIsLocation(data: Record<string, unknown>): data is {
|
|
54
|
+
requestId: string;
|
|
55
|
+
register: string | null;
|
|
56
|
+
outlet: string | null;
|
|
57
|
+
user: string | null;
|
|
58
|
+
};
|
|
47
59
|
/**
|
|
48
60
|
* Get the location from Shopfront
|
|
49
61
|
*/
|
|
@@ -53,5 +65,10 @@ export declare class Application {
|
|
|
53
65
|
user: string | null;
|
|
54
66
|
}>;
|
|
55
67
|
printReceipt(content: string): void;
|
|
68
|
+
protected dataIsOption<TValueType>(data: Record<string, unknown>): data is {
|
|
69
|
+
requestId: string;
|
|
70
|
+
option: string;
|
|
71
|
+
value: TValueType | undefined;
|
|
72
|
+
};
|
|
56
73
|
getOption<TValueType>(option: string, defaultValue: TValueType): Promise<TValueType>;
|
|
57
74
|
}
|
package/lib/Application.js
CHANGED
|
@@ -21,6 +21,8 @@ const FormatIntegratedProduct_1 = require("./Events/FormatIntegratedProduct");
|
|
|
21
21
|
const RequestCustomerListOptions_1 = require("./Events/RequestCustomerListOptions");
|
|
22
22
|
const RequestSaleKeys_1 = require("./Events/RequestSaleKeys");
|
|
23
23
|
const SaleComplete_1 = require("./Events/SaleComplete");
|
|
24
|
+
const UIPipeline_1 = require("./Events/UIPipeline");
|
|
25
|
+
const PaymentMethodsEnabled_1 = require("./Events/PaymentMethodsEnabled");
|
|
24
26
|
// noinspection JSUnusedGlobalSymbols
|
|
25
27
|
class Application {
|
|
26
28
|
constructor(bridge) {
|
|
@@ -36,6 +38,8 @@ class Application {
|
|
|
36
38
|
REQUEST_CUSTOMER_LIST_OPTIONS: new Map(),
|
|
37
39
|
REQUEST_SALE_KEYS: new Map(),
|
|
38
40
|
SALE_COMPLETE: new Map(),
|
|
41
|
+
UI_PIPELINE: new Map(),
|
|
42
|
+
PAYMENT_METHODS_ENABLED: new Map(),
|
|
39
43
|
};
|
|
40
44
|
this.directListeners = {};
|
|
41
45
|
this.handleEvent = (event, data, id) => {
|
|
@@ -109,8 +113,8 @@ class Application {
|
|
|
109
113
|
if (this.listeners[event].size === 0) {
|
|
110
114
|
return this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.NOT_LISTENING_TO_EVENT, event, id);
|
|
111
115
|
}
|
|
112
|
-
for (
|
|
113
|
-
results.push(e.emit(data));
|
|
116
|
+
for (const e of this.listeners[event].values()) {
|
|
117
|
+
results.push(e.emit(data, this.bridge));
|
|
114
118
|
}
|
|
115
119
|
// Respond if necessary
|
|
116
120
|
switch (event) {
|
|
@@ -152,6 +156,18 @@ class Application {
|
|
|
152
156
|
results = results;
|
|
153
157
|
return Promise.all(results)
|
|
154
158
|
.then(res => RequestSaleKeys_1.RequestSaleKeys.respond(this.bridge, res.flat(), id));
|
|
159
|
+
case "UI_PIPELINE":
|
|
160
|
+
results = results;
|
|
161
|
+
return Promise.all(results)
|
|
162
|
+
.then(res => {
|
|
163
|
+
return UIPipeline_1.UIPipeline.respond(this.bridge, res.flat(), id);
|
|
164
|
+
});
|
|
165
|
+
case "PAYMENT_METHODS_ENABLED":
|
|
166
|
+
results = results;
|
|
167
|
+
return Promise.all(results)
|
|
168
|
+
.then(res => {
|
|
169
|
+
return PaymentMethodsEnabled_1.PaymentMethodsEnabled.respond(this.bridge, res.flat(), id);
|
|
170
|
+
});
|
|
155
171
|
}
|
|
156
172
|
}
|
|
157
173
|
addEventListener(event, callback) {
|
|
@@ -160,10 +176,13 @@ class Application {
|
|
|
160
176
|
if (typeof this.directListeners[event] === "undefined") {
|
|
161
177
|
this.directListeners[event] = new Set();
|
|
162
178
|
}
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
163
180
|
this.directListeners[event].add(callback);
|
|
164
181
|
return;
|
|
165
182
|
}
|
|
166
|
-
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
184
|
+
let c;
|
|
185
|
+
event = event;
|
|
167
186
|
switch (event) {
|
|
168
187
|
case "READY":
|
|
169
188
|
c = new Ready_1.Ready(callback);
|
|
@@ -209,8 +228,16 @@ class Application {
|
|
|
209
228
|
c = new SaleComplete_1.SaleComplete(callback);
|
|
210
229
|
this.listeners[event].set(callback, c);
|
|
211
230
|
break;
|
|
231
|
+
case "UI_PIPELINE":
|
|
232
|
+
c = new UIPipeline_1.UIPipeline(callback);
|
|
233
|
+
this.listeners[event].set(callback, c);
|
|
234
|
+
break;
|
|
235
|
+
case "PAYMENT_METHODS_ENABLED":
|
|
236
|
+
c = new PaymentMethodsEnabled_1.PaymentMethodsEnabled(callback);
|
|
237
|
+
this.listeners[event].set(callback, c);
|
|
238
|
+
break;
|
|
212
239
|
}
|
|
213
|
-
if (c ===
|
|
240
|
+
if (typeof c === "undefined") {
|
|
214
241
|
throw new TypeError(`${event} has not been defined`);
|
|
215
242
|
}
|
|
216
243
|
if (event === "READY" && this.isReady) {
|
|
@@ -223,9 +250,8 @@ class Application {
|
|
|
223
250
|
}
|
|
224
251
|
}
|
|
225
252
|
removeEventListener(event, callback) {
|
|
226
|
-
var _a;
|
|
227
253
|
if (ApplicationEvents_1.directShopfrontEvents.includes(event)) {
|
|
228
|
-
|
|
254
|
+
this.directListeners[event]?.delete(callback);
|
|
229
255
|
return;
|
|
230
256
|
}
|
|
231
257
|
this.listeners[event].delete(callback);
|
|
@@ -259,7 +285,7 @@ class Application {
|
|
|
259
285
|
if (typeof data.id === "undefined") {
|
|
260
286
|
return;
|
|
261
287
|
}
|
|
262
|
-
|
|
288
|
+
const id = data.id;
|
|
263
289
|
ActionEventRegistrar_1.default.fire(id, data.data);
|
|
264
290
|
}
|
|
265
291
|
handleLocationChanged(data) {
|
|
@@ -270,6 +296,9 @@ class Application {
|
|
|
270
296
|
getAuthenticationKey() {
|
|
271
297
|
return this.key;
|
|
272
298
|
}
|
|
299
|
+
dataIsSaleEvent(data) {
|
|
300
|
+
return typeof data.requestId === "string" && (data.saleState === false || typeof data.saleState === "object");
|
|
301
|
+
}
|
|
273
302
|
/**
|
|
274
303
|
* Get the current sale on the sell screen, if the current device is not a register
|
|
275
304
|
* then this will return false.
|
|
@@ -283,7 +312,9 @@ class Application {
|
|
|
283
312
|
if (event !== "RESPONSE_CURRENT_SALE") {
|
|
284
313
|
return;
|
|
285
314
|
}
|
|
286
|
-
data
|
|
315
|
+
if (!this.dataIsSaleEvent(data)) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
287
318
|
if (data.requestId !== saleRequest) {
|
|
288
319
|
return;
|
|
289
320
|
}
|
|
@@ -301,6 +332,12 @@ class Application {
|
|
|
301
332
|
}
|
|
302
333
|
return new CurrentSale_1.Sale(this, saleState);
|
|
303
334
|
}
|
|
335
|
+
dataIsLocation(data) {
|
|
336
|
+
return typeof data.requestId === "string" &&
|
|
337
|
+
(typeof data.register === "string" || data.register === null) &&
|
|
338
|
+
(typeof data.outlet === "string" || data.outlet === null) &&
|
|
339
|
+
(typeof data.user === "string" || data.user === null);
|
|
340
|
+
}
|
|
304
341
|
/**
|
|
305
342
|
* Get the location from Shopfront
|
|
306
343
|
*/
|
|
@@ -311,7 +348,9 @@ class Application {
|
|
|
311
348
|
if (event !== "RESPONSE_LOCATION") {
|
|
312
349
|
return;
|
|
313
350
|
}
|
|
314
|
-
data
|
|
351
|
+
if (!this.dataIsLocation(data)) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
315
354
|
if (data.requestId !== locationRequest) {
|
|
316
355
|
return;
|
|
317
356
|
}
|
|
@@ -336,6 +375,9 @@ class Application {
|
|
|
336
375
|
type: "text",
|
|
337
376
|
});
|
|
338
377
|
}
|
|
378
|
+
dataIsOption(data) {
|
|
379
|
+
return typeof data.requestId === "string" && typeof data.option === "string";
|
|
380
|
+
}
|
|
339
381
|
async getOption(option, defaultValue) {
|
|
340
382
|
const request = `OptionRequest-${Date.now().toString()}`;
|
|
341
383
|
const promise = new Promise(res => {
|
|
@@ -343,7 +385,9 @@ class Application {
|
|
|
343
385
|
if (event !== "RESPONSE_OPTION") {
|
|
344
386
|
return;
|
|
345
387
|
}
|
|
346
|
-
data
|
|
388
|
+
if (!this.dataIsOption(data)) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
347
391
|
if (data.requestId !== request) {
|
|
348
392
|
return;
|
|
349
393
|
}
|
|
@@ -15,6 +15,8 @@ import { RequestCustomerListOptions, SellScreenCustomerListOption } from "./Even
|
|
|
15
15
|
import { SaleKey } from "./Actions/SaleKey";
|
|
16
16
|
import { RequestSaleKeys } from "./Events/RequestSaleKeys";
|
|
17
17
|
import { CompletedSale, SaleComplete } from "./Events/SaleComplete";
|
|
18
|
+
import { UIPipeline } from "./Events/UIPipeline";
|
|
19
|
+
import { PaymentMethodsEnabled } from "./Events/PaymentMethodsEnabled";
|
|
18
20
|
export declare enum ToShopfront {
|
|
19
21
|
READY = "READY",
|
|
20
22
|
SERIALIZED = "SERIALIZED",
|
|
@@ -35,11 +37,12 @@ export declare enum ToShopfront {
|
|
|
35
37
|
PRINT_RECEIPT = "PRINT_RECEIPT",
|
|
36
38
|
REDIRECT = "REDIRECT",
|
|
37
39
|
GET_OPTION = "GET_OPTION",
|
|
40
|
+
RESPONSE_UI_PIPELINE = "RESPONSE_UI_PIPELINE",
|
|
38
41
|
SELL_SCREEN_OPTION_CHANGE = "SELL_SCREEN_OPTION_CHANGE",
|
|
39
42
|
INTERNAL_PAGE_MESSAGE = "INTERNAL_PAGE_MESSAGE",
|
|
40
|
-
TABLE_UPDATE = "TABLE_UPDATE"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
TABLE_UPDATE = "TABLE_UPDATE",
|
|
44
|
+
PIPELINE_TRIGGER = "PIPELINE_TRIGGER",
|
|
45
|
+
SELL_SCREEN_PROMOTION_APPLICABLE = "SELL_SCREEN_PROMOTION_APPLICABLE"
|
|
43
46
|
}
|
|
44
47
|
export interface FromShopfrontReturns {
|
|
45
48
|
READY: void;
|
|
@@ -80,11 +83,13 @@ export interface FromShopfrontReturns {
|
|
|
80
83
|
REQUEST_CUSTOMER_LIST_OPTIONS: Array<SellScreenCustomerListOption>;
|
|
81
84
|
REQUEST_SALE_KEYS: Array<SaleKey>;
|
|
82
85
|
SALE_COMPLETE: void;
|
|
86
|
+
UI_PIPELINE: Array<UIPipelineResponse>;
|
|
87
|
+
PAYMENT_METHODS_ENABLED: Array<SellScreenPaymentMethod>;
|
|
83
88
|
}
|
|
84
89
|
export interface InternalPageMessageEvent {
|
|
85
90
|
method: "REQUEST_SETTINGS" | "REQUEST_SELL_SCREEN_OPTIONS" | "EXTERNAL_APPLICATION";
|
|
86
91
|
url: string;
|
|
87
|
-
message:
|
|
92
|
+
message: unknown;
|
|
88
93
|
reference: InternalMessageSource;
|
|
89
94
|
}
|
|
90
95
|
export interface RegisterChangedEvent {
|
|
@@ -98,6 +103,30 @@ export interface FormatIntegratedProductEvent {
|
|
|
98
103
|
export interface SaleCompletedEvent {
|
|
99
104
|
sale: CompletedSale;
|
|
100
105
|
}
|
|
106
|
+
export declare type UIPipelineResponse = {
|
|
107
|
+
name: string;
|
|
108
|
+
content: string;
|
|
109
|
+
};
|
|
110
|
+
export interface UIPipelineBaseContext {
|
|
111
|
+
location: string;
|
|
112
|
+
}
|
|
113
|
+
export interface UIPipelineContext extends UIPipelineBaseContext {
|
|
114
|
+
trigger?: () => void;
|
|
115
|
+
}
|
|
116
|
+
export interface SellScreenPaymentMethod {
|
|
117
|
+
uuid: string;
|
|
118
|
+
name: string;
|
|
119
|
+
type: "global" | "cash" | "eftpos" | "giftcard" | "voucher" | "cheque" | "pc-eftpos" | "linkly-vaa" | "direct-deposit" | "tyro" | "custom";
|
|
120
|
+
default_pay_exact: boolean;
|
|
121
|
+
background_colour?: string;
|
|
122
|
+
text_colour?: string;
|
|
123
|
+
}
|
|
124
|
+
export interface PaymentMethodEnabledContext {
|
|
125
|
+
register: string;
|
|
126
|
+
customer: false | {
|
|
127
|
+
uuid: string;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
101
130
|
export interface FromShopfrontCallbacks {
|
|
102
131
|
READY: (event: RegisterChangedEvent) => MaybePromise<FromShopfrontReturns["READY"]>;
|
|
103
132
|
REQUEST_SETTINGS: () => MaybePromise<FromShopfrontReturns["REQUEST_SETTINGS"]>;
|
|
@@ -111,6 +140,8 @@ export interface FromShopfrontCallbacks {
|
|
|
111
140
|
REQUEST_CUSTOMER_LIST_OPTIONS: () => MaybePromise<FromShopfrontReturns["REQUEST_CUSTOMER_LIST_OPTIONS"]>;
|
|
112
141
|
REQUEST_SALE_KEYS: () => MaybePromise<FromShopfrontReturns["REQUEST_SALE_KEYS"]>;
|
|
113
142
|
SALE_COMPLETE: (event: SaleCompletedEvent) => MaybePromise<FromShopfrontReturns["SALE_COMPLETE"]>;
|
|
143
|
+
UI_PIPELINE: (event: Array<UIPipelineResponse>, context: UIPipelineContext) => MaybePromise<FromShopfrontReturns["UI_PIPELINE"]>;
|
|
144
|
+
PAYMENT_METHODS_ENABLED: (event: Array<SellScreenPaymentMethod>, context: PaymentMethodEnabledContext) => MaybePromise<FromShopfrontReturns["PAYMENT_METHODS_ENABLED"]>;
|
|
114
145
|
}
|
|
115
146
|
export interface FromShopfront {
|
|
116
147
|
READY: Ready;
|
|
@@ -125,6 +156,8 @@ export interface FromShopfront {
|
|
|
125
156
|
REQUEST_CUSTOMER_LIST_OPTIONS: RequestCustomerListOptions;
|
|
126
157
|
SALE_COMPLETE: SaleComplete;
|
|
127
158
|
REQUEST_SALE_KEYS: RequestSaleKeys;
|
|
159
|
+
UI_PIPELINE: UIPipeline;
|
|
160
|
+
PAYMENT_METHODS_ENABLED: PaymentMethodsEnabled;
|
|
128
161
|
}
|
|
129
162
|
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"];
|
|
130
163
|
export declare type DirectShopfrontEvent = typeof directShopfrontEvents[number];
|
package/lib/ApplicationEvents.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.directShopfrontEvents = exports.
|
|
3
|
+
exports.directShopfrontEvents = exports.ToShopfront = void 0;
|
|
4
4
|
var ToShopfront;
|
|
5
5
|
(function (ToShopfront) {
|
|
6
6
|
ToShopfront["READY"] = "READY";
|
|
@@ -22,14 +22,14 @@ var ToShopfront;
|
|
|
22
22
|
ToShopfront["PRINT_RECEIPT"] = "PRINT_RECEIPT";
|
|
23
23
|
ToShopfront["REDIRECT"] = "REDIRECT";
|
|
24
24
|
ToShopfront["GET_OPTION"] = "GET_OPTION";
|
|
25
|
+
ToShopfront["RESPONSE_UI_PIPELINE"] = "RESPONSE_UI_PIPELINE";
|
|
25
26
|
// Emitable Events
|
|
26
27
|
ToShopfront["SELL_SCREEN_OPTION_CHANGE"] = "SELL_SCREEN_OPTION_CHANGE";
|
|
27
28
|
ToShopfront["INTERNAL_PAGE_MESSAGE"] = "INTERNAL_PAGE_MESSAGE";
|
|
28
29
|
ToShopfront["TABLE_UPDATE"] = "TABLE_UPDATE";
|
|
30
|
+
ToShopfront["PIPELINE_TRIGGER"] = "PIPELINE_TRIGGER";
|
|
31
|
+
ToShopfront["SELL_SCREEN_PROMOTION_APPLICABLE"] = "SELL_SCREEN_PROMOTION_APPLICABLE";
|
|
29
32
|
})(ToShopfront = exports.ToShopfront || (exports.ToShopfront = {}));
|
|
30
|
-
var WithinApplication;
|
|
31
|
-
(function (WithinApplication) {
|
|
32
|
-
})(WithinApplication = exports.WithinApplication || (exports.WithinApplication = {}));
|
|
33
33
|
exports.directShopfrontEvents = [
|
|
34
34
|
"SALE_ADD_PRODUCT",
|
|
35
35
|
"SALE_REMOVE_PRODUCT",
|
package/lib/Bridge.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ interface ApplicationOptions {
|
|
|
5
5
|
vendor: string;
|
|
6
6
|
}
|
|
7
7
|
interface ApplicationEventListener {
|
|
8
|
-
(event: keyof ApplicationEvents.FromShopfront | keyof ApplicationEvents.FromShopfrontInternal, data:
|
|
8
|
+
(event: keyof ApplicationEvents.FromShopfront | keyof ApplicationEvents.FromShopfrontInternal, data: Record<string, unknown>, id: string): void;
|
|
9
9
|
}
|
|
10
10
|
export declare class Bridge {
|
|
11
11
|
static createApplication(options: ApplicationOptions): Application;
|