@shopfront/bridge 1.8.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/embedded-bridge.iml +10 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- 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 +26 -7
- package/lib/Application.js +87 -10
- package/lib/ApplicationEvents.d.ts +42 -6
- package/lib/ApplicationEvents.js +6 -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/bitbucket-pipelines.yml +0 -22
- package/yarn.lock +0 -8
|
@@ -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>
|
|
@@ -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/embedded-bridge.iml" filepath="$PROJECT_DIR$/.idea/embedded-bridge.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/.idea/vcs.xml
ADDED
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,21 +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;
|
|
34
|
+
redirect(toLocation: string, externalRedirect?: boolean): void;
|
|
32
35
|
load(): () => void;
|
|
33
36
|
protected handleEventCallback(data: {
|
|
34
37
|
id?: string;
|
|
35
|
-
data:
|
|
38
|
+
data: unknown;
|
|
36
39
|
}): void;
|
|
37
40
|
protected handleLocationChanged(data: RegisterChangedEvent): void;
|
|
38
41
|
getAuthenticationKey(): string;
|
|
42
|
+
protected dataIsSaleEvent(data: Record<string, unknown>): data is {
|
|
43
|
+
requestId: string;
|
|
44
|
+
saleState: ShopfrontSaleState | false;
|
|
45
|
+
};
|
|
39
46
|
/**
|
|
40
47
|
* Get the current sale on the sell screen, if the current device is not a register
|
|
41
48
|
* then this will return false.
|
|
@@ -43,6 +50,12 @@ export declare class Application {
|
|
|
43
50
|
* @returns {Promise<Sale | boolean>}
|
|
44
51
|
*/
|
|
45
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
|
+
};
|
|
46
59
|
/**
|
|
47
60
|
* Get the location from Shopfront
|
|
48
61
|
*/
|
|
@@ -52,4 +65,10 @@ export declare class Application {
|
|
|
52
65
|
user: string | null;
|
|
53
66
|
}>;
|
|
54
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
|
+
};
|
|
73
|
+
getOption<TValueType>(option: string, defaultValue: TValueType): Promise<TValueType>;
|
|
55
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) => {
|
|
@@ -65,7 +69,8 @@ class Application {
|
|
|
65
69
|
}
|
|
66
70
|
else if (event === "RESPONSE_CURRENT_SALE" ||
|
|
67
71
|
event === "RESPONSE_DATABASE_REQUEST" ||
|
|
68
|
-
event === "RESPONSE_LOCATION"
|
|
72
|
+
event === "RESPONSE_LOCATION" ||
|
|
73
|
+
event === "RESPONSE_OPTION") {
|
|
69
74
|
// Handled elsewhere
|
|
70
75
|
return;
|
|
71
76
|
}
|
|
@@ -108,8 +113,8 @@ class Application {
|
|
|
108
113
|
if (this.listeners[event].size === 0) {
|
|
109
114
|
return this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.NOT_LISTENING_TO_EVENT, event, id);
|
|
110
115
|
}
|
|
111
|
-
for (
|
|
112
|
-
results.push(e.emit(data));
|
|
116
|
+
for (const e of this.listeners[event].values()) {
|
|
117
|
+
results.push(e.emit(data, this.bridge));
|
|
113
118
|
}
|
|
114
119
|
// Respond if necessary
|
|
115
120
|
switch (event) {
|
|
@@ -151,6 +156,18 @@ class Application {
|
|
|
151
156
|
results = results;
|
|
152
157
|
return Promise.all(results)
|
|
153
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
|
+
});
|
|
154
171
|
}
|
|
155
172
|
}
|
|
156
173
|
addEventListener(event, callback) {
|
|
@@ -159,10 +176,13 @@ class Application {
|
|
|
159
176
|
if (typeof this.directListeners[event] === "undefined") {
|
|
160
177
|
this.directListeners[event] = new Set();
|
|
161
178
|
}
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
162
180
|
this.directListeners[event].add(callback);
|
|
163
181
|
return;
|
|
164
182
|
}
|
|
165
|
-
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
184
|
+
let c;
|
|
185
|
+
event = event;
|
|
166
186
|
switch (event) {
|
|
167
187
|
case "READY":
|
|
168
188
|
c = new Ready_1.Ready(callback);
|
|
@@ -208,8 +228,16 @@ class Application {
|
|
|
208
228
|
c = new SaleComplete_1.SaleComplete(callback);
|
|
209
229
|
this.listeners[event].set(callback, c);
|
|
210
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;
|
|
211
239
|
}
|
|
212
|
-
if (c ===
|
|
240
|
+
if (typeof c === "undefined") {
|
|
213
241
|
throw new TypeError(`${event} has not been defined`);
|
|
214
242
|
}
|
|
215
243
|
if (event === "READY" && this.isReady) {
|
|
@@ -222,9 +250,8 @@ class Application {
|
|
|
222
250
|
}
|
|
223
251
|
}
|
|
224
252
|
removeEventListener(event, callback) {
|
|
225
|
-
var _a;
|
|
226
253
|
if (ApplicationEvents_1.directShopfrontEvents.includes(event)) {
|
|
227
|
-
|
|
254
|
+
this.directListeners[event]?.delete(callback);
|
|
228
255
|
return;
|
|
229
256
|
}
|
|
230
257
|
this.listeners[event].delete(callback);
|
|
@@ -244,6 +271,12 @@ class Application {
|
|
|
244
271
|
download(file) {
|
|
245
272
|
this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.DOWNLOAD, file);
|
|
246
273
|
}
|
|
274
|
+
redirect(toLocation, externalRedirect = true) {
|
|
275
|
+
this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.REDIRECT, {
|
|
276
|
+
to: toLocation,
|
|
277
|
+
external: externalRedirect,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
247
280
|
load() {
|
|
248
281
|
this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.LOAD, true);
|
|
249
282
|
return () => this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.LOAD, false);
|
|
@@ -252,7 +285,7 @@ class Application {
|
|
|
252
285
|
if (typeof data.id === "undefined") {
|
|
253
286
|
return;
|
|
254
287
|
}
|
|
255
|
-
|
|
288
|
+
const id = data.id;
|
|
256
289
|
ActionEventRegistrar_1.default.fire(id, data.data);
|
|
257
290
|
}
|
|
258
291
|
handleLocationChanged(data) {
|
|
@@ -263,6 +296,9 @@ class Application {
|
|
|
263
296
|
getAuthenticationKey() {
|
|
264
297
|
return this.key;
|
|
265
298
|
}
|
|
299
|
+
dataIsSaleEvent(data) {
|
|
300
|
+
return typeof data.requestId === "string" && (data.saleState === false || typeof data.saleState === "object");
|
|
301
|
+
}
|
|
266
302
|
/**
|
|
267
303
|
* Get the current sale on the sell screen, if the current device is not a register
|
|
268
304
|
* then this will return false.
|
|
@@ -276,7 +312,9 @@ class Application {
|
|
|
276
312
|
if (event !== "RESPONSE_CURRENT_SALE") {
|
|
277
313
|
return;
|
|
278
314
|
}
|
|
279
|
-
data
|
|
315
|
+
if (!this.dataIsSaleEvent(data)) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
280
318
|
if (data.requestId !== saleRequest) {
|
|
281
319
|
return;
|
|
282
320
|
}
|
|
@@ -294,6 +332,12 @@ class Application {
|
|
|
294
332
|
}
|
|
295
333
|
return new CurrentSale_1.Sale(this, saleState);
|
|
296
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
|
+
}
|
|
297
341
|
/**
|
|
298
342
|
* Get the location from Shopfront
|
|
299
343
|
*/
|
|
@@ -304,7 +348,9 @@ class Application {
|
|
|
304
348
|
if (event !== "RESPONSE_LOCATION") {
|
|
305
349
|
return;
|
|
306
350
|
}
|
|
307
|
-
data
|
|
351
|
+
if (!this.dataIsLocation(data)) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
308
354
|
if (data.requestId !== locationRequest) {
|
|
309
355
|
return;
|
|
310
356
|
}
|
|
@@ -329,5 +375,36 @@ class Application {
|
|
|
329
375
|
type: "text",
|
|
330
376
|
});
|
|
331
377
|
}
|
|
378
|
+
dataIsOption(data) {
|
|
379
|
+
return typeof data.requestId === "string" && typeof data.option === "string";
|
|
380
|
+
}
|
|
381
|
+
async getOption(option, defaultValue) {
|
|
382
|
+
const request = `OptionRequest-${Date.now().toString()}`;
|
|
383
|
+
const promise = new Promise(res => {
|
|
384
|
+
const listener = (event, data) => {
|
|
385
|
+
if (event !== "RESPONSE_OPTION") {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (!this.dataIsOption(data)) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
if (data.requestId !== request) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
this.bridge.removeEventListener(listener);
|
|
395
|
+
res(data.value);
|
|
396
|
+
};
|
|
397
|
+
this.bridge.addEventListener(listener);
|
|
398
|
+
});
|
|
399
|
+
this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.GET_OPTION, {
|
|
400
|
+
requestId: request,
|
|
401
|
+
option,
|
|
402
|
+
});
|
|
403
|
+
const optionValue = await promise;
|
|
404
|
+
if (typeof optionValue === "undefined") {
|
|
405
|
+
return defaultValue;
|
|
406
|
+
}
|
|
407
|
+
return optionValue;
|
|
408
|
+
}
|
|
332
409
|
}
|
|
333
410
|
exports.Application = Application;
|