@shopfront/bridge 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/codeStyles/Project.xml +10 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/git_toolbox_blame.xml +6 -0
- package/.idea/git_toolbox_prj.xml +15 -0
- package/.idea/inspectionProfiles/Project_Default.xml +5 -0
- package/.idea/jsLinters/eslint.xml +6 -0
- package/.idea/modules.xml +1 -1
- package/.idea/php.xml +15 -0
- package/lib/APIs/Database/BaseDatabase.d.ts +28 -0
- package/lib/APIs/Database/BaseDatabase.js +5 -0
- package/lib/APIs/Database/Database.d.ts +19 -7
- package/lib/APIs/Database/Database.js +22 -12
- package/lib/APIs/Database/types/BaseBarcodeTemplateRepository.d.ts +8 -0
- package/lib/APIs/Database/types/BaseBarcodeTemplateRepository.js +1 -0
- package/lib/APIs/Database/types/BaseClassificationRepository.d.ts +11 -0
- package/lib/APIs/Database/types/BaseClassificationRepository.js +1 -0
- package/lib/APIs/Database/types/BaseCustomerDisplayRepository.d.ts +10 -0
- package/lib/APIs/Database/types/BaseCustomerDisplayRepository.js +1 -0
- package/lib/APIs/Database/types/BaseCustomerGroupRepository.d.ts +24 -0
- package/lib/APIs/Database/types/BaseCustomerGroupRepository.js +1 -0
- package/lib/APIs/Database/types/BaseCustomerRepository.d.ts +76 -0
- package/lib/APIs/Database/types/BaseCustomerRepository.js +1 -0
- package/lib/APIs/Database/types/BaseEnterpriseRepository.d.ts +8 -0
- package/lib/APIs/Database/types/BaseEnterpriseRepository.js +1 -0
- package/lib/APIs/Database/types/BaseGiftCardRepository.d.ts +18 -0
- package/lib/APIs/Database/types/BaseGiftCardRepository.js +1 -0
- package/lib/APIs/Database/types/BaseKitchenOrderRepository.d.ts +41 -0
- package/lib/APIs/Database/types/BaseKitchenOrderRepository.js +1 -0
- package/lib/APIs/Database/types/BaseKitchenScreenRepository.d.ts +16 -0
- package/lib/APIs/Database/types/BaseKitchenScreenRepository.js +1 -0
- package/lib/APIs/Database/types/BaseLockedResourceRepository.d.ts +12 -0
- package/lib/APIs/Database/types/BaseLockedResourceRepository.js +1 -0
- package/lib/APIs/Database/types/BaseLoyaltyRepository.d.ts +16 -0
- package/lib/APIs/Database/types/BaseLoyaltyRepository.js +1 -0
- package/lib/APIs/Database/types/BaseMovementRepository.d.ts +16 -0
- package/lib/APIs/Database/types/BaseMovementRepository.js +1 -0
- package/lib/APIs/Database/types/BaseOutletRepository.d.ts +19 -0
- package/lib/APIs/Database/types/BaseOutletRepository.js +1 -0
- package/lib/APIs/Database/types/BasePaymentMethodRepository.d.ts +27 -0
- package/lib/APIs/Database/types/BasePaymentMethodRepository.js +1 -0
- package/lib/APIs/Database/types/BasePriceListRepository.d.ts +40 -0
- package/lib/APIs/Database/types/BasePriceListRepository.js +1 -0
- package/lib/APIs/Database/types/BasePriceSetRepository.d.ts +6 -0
- package/lib/APIs/Database/types/BasePriceSetRepository.js +1 -0
- package/lib/APIs/Database/types/BaseProductRepository.d.ts +160 -0
- package/lib/APIs/Database/types/BaseProductRepository.js +1 -0
- package/lib/APIs/Database/types/BasePromotionCategoryRepository.d.ts +10 -0
- package/lib/APIs/Database/types/BasePromotionCategoryRepository.js +1 -0
- package/lib/APIs/Database/types/BasePromotionRepository.d.ts +72 -0
- package/lib/APIs/Database/types/BasePromotionRepository.js +1 -0
- package/lib/APIs/Database/types/BaseReceiptRepository.d.ts +31 -0
- package/lib/APIs/Database/types/BaseReceiptRepository.js +1 -0
- package/lib/APIs/Database/types/BaseRegisterRepository.d.ts +56 -0
- package/lib/APIs/Database/types/BaseRegisterRepository.js +1 -0
- package/lib/APIs/Database/types/BaseRepository.d.ts +41 -0
- package/lib/APIs/Database/types/BaseRepository.js +1 -0
- package/lib/APIs/Database/types/BaseSalesKeyRepository.d.ts +37 -0
- package/lib/APIs/Database/types/BaseSalesKeyRepository.js +1 -0
- package/lib/APIs/Database/types/BaseSalesRepository.d.ts +123 -0
- package/lib/APIs/Database/types/BaseSalesRepository.js +1 -0
- package/lib/APIs/Database/types/BaseSearchableRepository.d.ts +8 -0
- package/lib/APIs/Database/types/BaseSearchableRepository.js +1 -0
- package/lib/APIs/Database/types/BaseStocktakeAccumulatedRepository.d.ts +16 -0
- package/lib/APIs/Database/types/BaseStocktakeAccumulatedRepository.js +1 -0
- package/lib/APIs/Database/types/BaseStocktakeRepository.d.ts +8 -0
- package/lib/APIs/Database/types/BaseStocktakeRepository.js +1 -0
- package/lib/APIs/Database/types/BaseStocktakeScannedRepository.d.ts +24 -0
- package/lib/APIs/Database/types/BaseStocktakeScannedRepository.js +1 -0
- package/lib/APIs/Database/types/BaseSupplierRepository.d.ts +35 -0
- package/lib/APIs/Database/types/BaseSupplierRepository.js +1 -0
- package/lib/APIs/Database/types/BaseTakingsRepository.d.ts +13 -0
- package/lib/APIs/Database/types/BaseTakingsRepository.js +1 -0
- package/lib/APIs/Database/types/BaseTaxRateRepository.d.ts +9 -0
- package/lib/APIs/Database/types/BaseTaxRateRepository.js +1 -0
- package/lib/APIs/Database/types/BaseTransfereeRepository.d.ts +12 -0
- package/lib/APIs/Database/types/BaseTransfereeRepository.js +1 -0
- package/lib/APIs/Database/types/BaseVendorConnectionRepository.d.ts +7 -0
- package/lib/APIs/Database/types/BaseVendorConnectionRepository.js +1 -0
- package/lib/APIs/Database/types/DataSourceTables.d.ts +61 -0
- package/lib/APIs/Database/types/DataSourceTables.js +1 -0
- package/lib/APIs/Fulfilment/FulfilmentTypes.d.ts +2 -2
- package/lib/APIs/Fulfilment/FulfilmentTypes.js +1 -2
- package/lib/APIs/InternalMessages/InternalMessageSource.d.ts +6 -3
- package/lib/APIs/InternalMessages/InternalMessageSource.js +6 -7
- package/lib/APIs/Sale/BaseCurrentSale.d.ts +83 -0
- package/lib/APIs/Sale/BaseCurrentSale.js +13 -0
- package/lib/APIs/Sale/BaseSale.d.ts +3 -38
- package/lib/APIs/Sale/BaseSale.js +1 -40
- package/lib/APIs/Sale/CurrentSale.d.ts +19 -84
- package/lib/APIs/Sale/CurrentSale.js +32 -102
- package/lib/APIs/Sale/Exceptions.d.ts +3 -0
- package/lib/APIs/Sale/Exceptions.js +7 -7
- package/lib/APIs/Sale/Sale.d.ts +39 -7
- package/lib/APIs/Sale/Sale.js +41 -13
- package/lib/APIs/Sale/SaleCustomer.d.ts +0 -2
- package/lib/APIs/Sale/SaleCustomer.js +1 -7
- package/lib/APIs/Sale/SalePayment.d.ts +3 -22
- package/lib/APIs/Sale/SalePayment.js +7 -33
- package/lib/APIs/Sale/SaleProduct.d.ts +6 -46
- package/lib/APIs/Sale/SaleProduct.js +6 -53
- package/lib/APIs/Sale/ShopfrontSaleState.d.ts +7 -9
- package/lib/APIs/Sale/ShopfrontSaleState.js +1 -2
- package/lib/APIs/Sale/index.d.ts +9 -9
- package/lib/APIs/Sale/index.js +7 -39
- package/lib/Actions/BaseAction.d.ts +21 -5
- package/lib/Actions/BaseAction.js +155 -97
- package/lib/Actions/Button.d.ts +2 -2
- package/lib/Actions/Button.js +3 -7
- package/lib/Actions/CustomerListOption.d.ts +2 -2
- package/lib/Actions/CustomerListOption.js +2 -6
- package/lib/Actions/Dialog.d.ts +4 -4
- package/lib/Actions/Dialog.js +2 -6
- package/lib/Actions/Redirect.d.ts +2 -2
- package/lib/Actions/Redirect.js +7 -9
- package/lib/Actions/SaleKey.d.ts +2 -2
- package/lib/Actions/SaleKey.js +3 -7
- package/lib/Actions/SaleUpdate.d.ts +3 -3
- package/lib/Actions/SaleUpdate.js +3 -7
- package/lib/Actions/Toast.d.ts +3 -3
- package/lib/Actions/Toast.js +2 -6
- package/lib/Application.d.ts +114 -78
- package/lib/Application.js +207 -160
- package/lib/ApplicationEvents.d.ts +66 -53
- package/lib/ApplicationEvents.js +10 -6
- package/lib/BaseApplication.d.ts +169 -0
- package/lib/BaseApplication.js +40 -0
- package/lib/BaseBridge.d.ts +33 -0
- package/lib/BaseBridge.js +16 -0
- package/lib/Bridge.d.ts +46 -9
- package/lib/Bridge.js +42 -54
- package/lib/Common/EventEmitter.d.ts +10 -1
- package/lib/Common/EventEmitter.js +10 -5
- package/lib/Common/Serializable.d.ts +8 -6
- package/lib/Common/Serializable.js +1 -2
- package/lib/EmitableEvents/BaseEmitableEvent.d.ts +7 -1
- package/lib/EmitableEvents/BaseEmitableEvent.js +7 -5
- package/lib/EmitableEvents/Fulfilment/Options.d.ts +1 -1
- package/lib/EmitableEvents/Fulfilment/Options.js +4 -8
- package/lib/EmitableEvents/Fulfilment/OrderCancel.d.ts +1 -1
- package/lib/EmitableEvents/Fulfilment/OrderCancel.js +4 -8
- package/lib/EmitableEvents/Fulfilment/OrderCreate.d.ts +2 -2
- package/lib/EmitableEvents/Fulfilment/OrderCreate.js +4 -8
- package/lib/EmitableEvents/Fulfilment/OrderUpdate.d.ts +2 -2
- package/lib/EmitableEvents/Fulfilment/OrderUpdate.js +4 -8
- package/lib/EmitableEvents/Fulfilment/OrdersSync.d.ts +2 -2
- package/lib/EmitableEvents/Fulfilment/OrdersSync.js +4 -8
- package/lib/EmitableEvents/Fulfilment/RegisterIntent.d.ts +2 -2
- package/lib/EmitableEvents/Fulfilment/RegisterIntent.js +4 -8
- package/lib/EmitableEvents/Fulfilment/index.d.ts +7 -7
- package/lib/EmitableEvents/Fulfilment/index.js +6 -15
- package/lib/EmitableEvents/InternalMessage.d.ts +2 -2
- package/lib/EmitableEvents/InternalMessage.js +4 -8
- package/lib/EmitableEvents/SellScreenOption.d.ts +2 -2
- package/lib/EmitableEvents/SellScreenOption.js +7 -11
- package/lib/EmitableEvents/SellScreenPromotionApplicable.d.ts +1 -1
- package/lib/EmitableEvents/SellScreenPromotionApplicable.js +4 -8
- package/lib/EmitableEvents/TableUpdate.d.ts +2 -2
- package/lib/EmitableEvents/TableUpdate.js +4 -8
- package/lib/Events/AudioPermissionChange.d.ts +5 -2
- package/lib/Events/AudioPermissionChange.js +6 -7
- package/lib/Events/AudioReady.d.ts +5 -2
- package/lib/Events/AudioReady.js +6 -7
- package/lib/Events/BaseEvent.d.ts +8 -3
- package/lib/Events/BaseEvent.js +1 -6
- package/lib/Events/Callback.d.ts +5 -2
- package/lib/Events/Callback.js +5 -6
- package/lib/Events/FormatIntegratedProduct.d.ts +27 -32
- package/lib/Events/FormatIntegratedProduct.js +12 -9
- package/lib/Events/FulfilmentCollectOrder.d.ts +5 -2
- package/lib/Events/FulfilmentCollectOrder.js +5 -6
- package/lib/Events/FulfilmentCompleteOrder.d.ts +5 -2
- package/lib/Events/FulfilmentCompleteOrder.js +5 -6
- package/lib/Events/FulfilmentGetOrder.d.ts +12 -6
- package/lib/Events/FulfilmentGetOrder.js +10 -8
- package/lib/Events/FulfilmentOrderApproval.d.ts +5 -2
- package/lib/Events/FulfilmentOrderApproval.js +5 -6
- package/lib/Events/FulfilmentProcessOrder.d.ts +12 -10
- package/lib/Events/FulfilmentProcessOrder.js +7 -8
- package/lib/Events/FulfilmentVoidOrder.d.ts +5 -2
- package/lib/Events/FulfilmentVoidOrder.js +5 -6
- package/lib/Events/GiftCardCodeCheck.d.ts +19 -0
- package/lib/Events/GiftCardCodeCheck.js +23 -0
- package/lib/Events/InternalPageMessage.d.ts +10 -4
- package/lib/Events/InternalPageMessage.js +12 -10
- package/lib/Events/PaymentMethodsEnabled.d.ts +16 -11
- package/lib/Events/PaymentMethodsEnabled.js +10 -8
- package/lib/Events/Ready.d.ts +12 -7
- package/lib/Events/Ready.js +5 -6
- package/lib/Events/RegisterChanged.d.ts +12 -6
- package/lib/Events/RegisterChanged.js +6 -7
- package/lib/Events/RequestButtons.d.ts +17 -12
- package/lib/Events/RequestButtons.js +13 -11
- package/lib/Events/RequestCustomerListOptions.d.ts +11 -5
- package/lib/Events/RequestCustomerListOptions.js +12 -11
- package/lib/Events/RequestSaleKeys.d.ts +12 -6
- package/lib/Events/RequestSaleKeys.js +13 -11
- package/lib/Events/RequestSellScreenOptions.d.ts +18 -5
- package/lib/Events/RequestSellScreenOptions.js +17 -9
- package/lib/Events/RequestSettings.d.ts +11 -5
- package/lib/Events/RequestSettings.js +12 -10
- package/lib/Events/RequestTableColumns.d.ts +16 -11
- package/lib/Events/RequestTableColumns.js +12 -9
- package/lib/Events/SaleComplete.d.ts +15 -18
- package/lib/Events/SaleComplete.js +6 -7
- package/lib/Events/UIPipeline.d.ts +17 -5
- package/lib/Events/UIPipeline.js +17 -10
- package/lib/Mocks/APIs/Sale/MockCurrentSale.d.ts +99 -0
- package/lib/Mocks/APIs/Sale/MockCurrentSale.js +326 -0
- package/lib/Mocks/Database/MockDatabase.d.ts +96 -0
- package/lib/Mocks/Database/MockDatabase.js +89 -0
- package/lib/Mocks/MockApplication.d.ts +154 -0
- package/lib/Mocks/MockApplication.js +481 -0
- package/lib/Mocks/MockBridge.d.ts +31 -0
- package/lib/Mocks/MockBridge.js +77 -0
- package/lib/Mocks/index.d.ts +7 -0
- package/lib/Mocks/index.js +15 -0
- package/lib/Utilities/ActionEventRegistrar.d.ts +19 -4
- package/lib/Utilities/ActionEventRegistrar.js +19 -3
- package/lib/Utilities/MiscTypes.d.ts +6 -4
- package/lib/Utilities/MiscTypes.js +1 -2
- package/lib/Utilities/SaleCreate.d.ts +6 -2
- package/lib/Utilities/SaleCreate.js +10 -6
- package/lib/Utilities/Static.d.ts +3 -0
- package/lib/Utilities/Static.js +5 -7
- package/lib/Utilities/UUID.d.ts +9 -3
- package/lib/Utilities/UUID.js +10 -7
- package/lib/index.d.ts +16 -14
- package/lib/index.js +14 -49
- package/package.json +3 -2
- package/lib/APIs/CurrentSale/Exceptions.d.ts +0 -6
- package/lib/APIs/CurrentSale/Exceptions.js +0 -15
- package/lib/APIs/CurrentSale/Sale.d.ts +0 -182
- package/lib/APIs/CurrentSale/Sale.js +0 -290
- package/lib/APIs/CurrentSale/SaleCustomer.d.ts +0 -10
- package/lib/APIs/CurrentSale/SaleCustomer.js +0 -17
- package/lib/APIs/CurrentSale/SalePayment.d.ts +0 -68
- package/lib/APIs/CurrentSale/SalePayment.js +0 -99
- package/lib/APIs/CurrentSale/SaleProduct.d.ts +0 -121
- package/lib/APIs/CurrentSale/SaleProduct.js +0 -167
- package/lib/APIs/CurrentSale/ShopfrontSaleState.d.ts +0 -53
- package/lib/APIs/CurrentSale/ShopfrontSaleState.js +0 -2
- package/lib/APIs/CurrentSale/index.d.ts +0 -6
- package/lib/APIs/CurrentSale/index.js +0 -37
- /package/.idea/{embedded-bridge.iml → shopfront-embedded-bridge.iml} +0 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { Sale } from "../APIs/Sale/index.js";
|
|
2
|
+
import { DirectShopfrontEvent, DirectShopfrontEventCallback, FromShopfront, FromShopfrontCallbacks, FromShopfrontInternal, ListenableFromShopfrontEvents, RegisterChangedEvent, SellScreenActionMode, SellScreenSummaryMode, SoundEvents } from "../ApplicationEvents.js";
|
|
3
|
+
import { BaseApplication, ShopfrontEmbeddedVerificationToken } from "../BaseApplication.js";
|
|
4
|
+
import { Serializable } from "../Common/Serializable.js";
|
|
5
|
+
import { BaseEmitableEvent } from "../EmitableEvents/BaseEmitableEvent.js";
|
|
6
|
+
import { MaybePromise } from "../Utilities/MiscTypes.js";
|
|
7
|
+
import { MockCurrentSale } from "./APIs/Sale/MockCurrentSale.js";
|
|
8
|
+
import { MockBridge } from "./MockBridge.js";
|
|
9
|
+
interface AudioRequestOptions {
|
|
10
|
+
hasPermission: boolean;
|
|
11
|
+
forceError: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class MockApplication extends BaseApplication {
|
|
14
|
+
protected currentSale: MockCurrentSale | false;
|
|
15
|
+
constructor(bridge: MockBridge);
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
destroy(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Handles an application event
|
|
22
|
+
*/
|
|
23
|
+
protected handleEvent: (event: keyof FromShopfront | keyof FromShopfrontInternal, data: Record<string, unknown>, id: string) => Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Calls any registered listeners for the received event
|
|
26
|
+
*/
|
|
27
|
+
protected emit(event: ListenableFromShopfrontEvents | DirectShopfrontEvent, data: (Record<string, unknown> | string) | undefined, id: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* @inheritDoc
|
|
30
|
+
*/
|
|
31
|
+
addEventListener<E extends ListenableFromShopfrontEvents>(event: E, callback: FromShopfrontCallbacks[E]): void;
|
|
32
|
+
/**
|
|
33
|
+
* @inheritDoc
|
|
34
|
+
*/
|
|
35
|
+
addEventListener(event: DirectShopfrontEvent, callback: DirectShopfrontEventCallback): void;
|
|
36
|
+
/**
|
|
37
|
+
* @inheritDoc
|
|
38
|
+
*/
|
|
39
|
+
removeEventListener<E extends keyof FromShopfrontCallbacks>(event: E, callback: FromShopfrontCallbacks[E]): void;
|
|
40
|
+
/**
|
|
41
|
+
* @inheritDoc
|
|
42
|
+
*/
|
|
43
|
+
removeEventListener<D>(event: DirectShopfrontEvent, callback: (event: D) => MaybePromise<void>): void;
|
|
44
|
+
/**
|
|
45
|
+
* @inheritDoc
|
|
46
|
+
*/
|
|
47
|
+
send(item: BaseEmitableEvent<unknown> | Serializable<unknown>): void;
|
|
48
|
+
/**
|
|
49
|
+
* @inheritDoc
|
|
50
|
+
*/
|
|
51
|
+
download(file: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* @inheritDoc
|
|
54
|
+
*/
|
|
55
|
+
redirect(toLocation: string, externalRedirect?: boolean): void;
|
|
56
|
+
/**
|
|
57
|
+
* @inheritDoc
|
|
58
|
+
*/
|
|
59
|
+
load(): () => void;
|
|
60
|
+
/**
|
|
61
|
+
* @inheritDoc
|
|
62
|
+
*/
|
|
63
|
+
protected handleEventCallback(data: {
|
|
64
|
+
id?: string;
|
|
65
|
+
data: unknown;
|
|
66
|
+
}): void;
|
|
67
|
+
/**
|
|
68
|
+
* Updates the cached location data
|
|
69
|
+
*/
|
|
70
|
+
protected handleLocationChanged: (data: RegisterChangedEvent) => undefined;
|
|
71
|
+
/**
|
|
72
|
+
* @inheritDoc
|
|
73
|
+
*/
|
|
74
|
+
getAuthenticationKey(): string;
|
|
75
|
+
/**
|
|
76
|
+
* @inheritDoc
|
|
77
|
+
*/
|
|
78
|
+
getCurrentSale(): Promise<MockCurrentSale | false>;
|
|
79
|
+
/**
|
|
80
|
+
* @inheritDoc
|
|
81
|
+
*/
|
|
82
|
+
createSale(sale: Sale): Promise<{
|
|
83
|
+
success: boolean;
|
|
84
|
+
message?: string;
|
|
85
|
+
}>;
|
|
86
|
+
/**
|
|
87
|
+
* @inheritDoc
|
|
88
|
+
*/
|
|
89
|
+
getLocation(options?: {
|
|
90
|
+
globalMode: boolean;
|
|
91
|
+
useRegister: boolean;
|
|
92
|
+
}): Promise<{
|
|
93
|
+
register: string | null;
|
|
94
|
+
outlet: string | null;
|
|
95
|
+
user: string | null;
|
|
96
|
+
}>;
|
|
97
|
+
/**
|
|
98
|
+
* @inheritDoc
|
|
99
|
+
*/
|
|
100
|
+
printReceipt(content: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* @inheritDoc
|
|
103
|
+
*/
|
|
104
|
+
changeSellScreenActionMode(mode: SellScreenActionMode): void;
|
|
105
|
+
/**
|
|
106
|
+
* @inheritDoc
|
|
107
|
+
*/
|
|
108
|
+
changeSellScreenSummaryMode(mode: SellScreenSummaryMode): void;
|
|
109
|
+
/**
|
|
110
|
+
* @inheritDoc
|
|
111
|
+
*/
|
|
112
|
+
protected sendAudioRequest(type: SoundEvents, data?: unknown, options?: AudioRequestOptions): Promise<{
|
|
113
|
+
success: boolean;
|
|
114
|
+
message?: string;
|
|
115
|
+
}>;
|
|
116
|
+
/**
|
|
117
|
+
* @inheritDoc
|
|
118
|
+
*/
|
|
119
|
+
requestAudioPermission(options?: AudioRequestOptions): Promise<{
|
|
120
|
+
success: boolean;
|
|
121
|
+
message?: string;
|
|
122
|
+
}>;
|
|
123
|
+
/**
|
|
124
|
+
* @inheritDoc
|
|
125
|
+
*/
|
|
126
|
+
audioPreload(url: string, options?: AudioRequestOptions): Promise<{
|
|
127
|
+
success: boolean;
|
|
128
|
+
message?: string;
|
|
129
|
+
}>;
|
|
130
|
+
/**
|
|
131
|
+
* @inheritDoc
|
|
132
|
+
*/
|
|
133
|
+
audioPlay(url: string, options?: AudioRequestOptions): Promise<{
|
|
134
|
+
success: boolean;
|
|
135
|
+
message?: string;
|
|
136
|
+
}>;
|
|
137
|
+
/**
|
|
138
|
+
* @inheritDoc
|
|
139
|
+
*/
|
|
140
|
+
getOption<TValueType>(option: string, defaultValue: TValueType): Promise<TValueType>;
|
|
141
|
+
/**
|
|
142
|
+
* @inheritDoc
|
|
143
|
+
*/
|
|
144
|
+
getToken(returnTokenObject: true): Promise<ShopfrontEmbeddedVerificationToken>;
|
|
145
|
+
/**
|
|
146
|
+
* @inheritDoc
|
|
147
|
+
*/
|
|
148
|
+
getToken(returnTokenObject?: false): Promise<string>;
|
|
149
|
+
/**
|
|
150
|
+
* Mocks an event being fired from Shopfront
|
|
151
|
+
*/
|
|
152
|
+
fireEvent<T extends ListenableFromShopfrontEvents, HasParams extends (Parameters<FromShopfront[T]["emit"]> extends [never] ? false : true)>(event: T | DirectShopfrontEvent, ...data: HasParams extends true ? Parameters<FromShopfront[T]["emit"]> : [undefined]): Promise<void>;
|
|
153
|
+
}
|
|
154
|
+
export {};
|
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
import { isDirectShopfrontEvent, ToShopfront, } from "../ApplicationEvents.js";
|
|
2
|
+
import { BaseApplication } from "../BaseApplication.js";
|
|
3
|
+
import { AudioPermissionChange } from "../Events/AudioPermissionChange.js";
|
|
4
|
+
import { AudioReady } from "../Events/AudioReady.js";
|
|
5
|
+
import { FormatIntegratedProduct } from "../Events/FormatIntegratedProduct.js";
|
|
6
|
+
import { FulfilmentCollectOrder } from "../Events/FulfilmentCollectOrder.js";
|
|
7
|
+
import { FulfilmentCompleteOrder } from "../Events/FulfilmentCompleteOrder.js";
|
|
8
|
+
import { FulfilmentGetOrder } from "../Events/FulfilmentGetOrder.js";
|
|
9
|
+
import { FulfilmentOrderApproval } from "../Events/FulfilmentOrderApproval.js";
|
|
10
|
+
import { FulfilmentProcessOrder } from "../Events/FulfilmentProcessOrder.js";
|
|
11
|
+
import { FulfilmentVoidOrder } from "../Events/FulfilmentVoidOrder.js";
|
|
12
|
+
import { GiftCardCodeCheck } from "../Events/GiftCardCodeCheck.js";
|
|
13
|
+
import { InternalPageMessage } from "../Events/InternalPageMessage.js";
|
|
14
|
+
import { PaymentMethodsEnabled } from "../Events/PaymentMethodsEnabled.js";
|
|
15
|
+
import { Ready } from "../Events/Ready.js";
|
|
16
|
+
import { RegisterChanged } from "../Events/RegisterChanged.js";
|
|
17
|
+
import { RequestButtons } from "../Events/RequestButtons.js";
|
|
18
|
+
import { RequestCustomerListOptions } from "../Events/RequestCustomerListOptions.js";
|
|
19
|
+
import { RequestSaleKeys } from "../Events/RequestSaleKeys.js";
|
|
20
|
+
import { RequestSellScreenOptions } from "../Events/RequestSellScreenOptions.js";
|
|
21
|
+
import { RequestSettings } from "../Events/RequestSettings.js";
|
|
22
|
+
import { RequestTableColumns } from "../Events/RequestTableColumns.js";
|
|
23
|
+
import { SaleComplete } from "../Events/SaleComplete.js";
|
|
24
|
+
import { UIPipeline } from "../Events/UIPipeline.js";
|
|
25
|
+
import ActionEventRegistrar from "../Utilities/ActionEventRegistrar.js";
|
|
26
|
+
import { MockCurrentSale } from "./APIs/Sale/MockCurrentSale.js";
|
|
27
|
+
import { MockDatabase } from "./Database/MockDatabase.js";
|
|
28
|
+
export class MockApplication extends BaseApplication {
|
|
29
|
+
constructor(bridge) {
|
|
30
|
+
super(bridge, new MockDatabase(bridge));
|
|
31
|
+
this.currentSale = false;
|
|
32
|
+
/**
|
|
33
|
+
* Handles an application event
|
|
34
|
+
*/
|
|
35
|
+
this.handleEvent = async (event, data, id) => {
|
|
36
|
+
if (event === "READY") {
|
|
37
|
+
this.isReady = true;
|
|
38
|
+
this.key = data.key;
|
|
39
|
+
this.outlet = data.outlet;
|
|
40
|
+
this.register = data.register;
|
|
41
|
+
data = {
|
|
42
|
+
outlet: data.outlet,
|
|
43
|
+
register: data.register,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (event === "CALLBACK") {
|
|
47
|
+
// Actions aren't implemented
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (event === "CYCLE_KEY") {
|
|
51
|
+
// Not needed
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
else if (event === "LOCATION_CHANGED") {
|
|
55
|
+
// Unregister all serialized listeners as they're no longer displayed
|
|
56
|
+
ActionEventRegistrar.clear();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
else if (event === "RESPONSE_CURRENT_SALE" ||
|
|
60
|
+
event === "RESPONSE_DATABASE_REQUEST" ||
|
|
61
|
+
event === "RESPONSE_LOCATION" ||
|
|
62
|
+
event === "RESPONSE_OPTION" ||
|
|
63
|
+
event === "RESPONSE_AUDIO_REQUEST" ||
|
|
64
|
+
event === "RESPONSE_SECURE_KEY" ||
|
|
65
|
+
event === "RESPONSE_CREATE_SALE") {
|
|
66
|
+
// Handled elsewhere
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
await this.emit(event, data, id);
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Updates the cached location data
|
|
73
|
+
*/
|
|
74
|
+
this.handleLocationChanged = (data) => {
|
|
75
|
+
this.register = data.register;
|
|
76
|
+
this.outlet = data.outlet;
|
|
77
|
+
this.user = data.user;
|
|
78
|
+
};
|
|
79
|
+
this.bridge.addEventListener(this.handleEvent);
|
|
80
|
+
this.addEventListener("REGISTER_CHANGED", this.handleLocationChanged);
|
|
81
|
+
this.fireEvent.bind(this);
|
|
82
|
+
// Fire a ready event immediately
|
|
83
|
+
this.handleEvent("READY", {
|
|
84
|
+
key: "embedded-key",
|
|
85
|
+
outlet: "outlet-id",
|
|
86
|
+
register: "register-id",
|
|
87
|
+
}, "");
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @inheritDoc
|
|
91
|
+
*/
|
|
92
|
+
destroy() {
|
|
93
|
+
this.bridge.destroy();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Calls any registered listeners for the received event
|
|
97
|
+
*/
|
|
98
|
+
async emit(event, data = {}, id) {
|
|
99
|
+
if (isDirectShopfrontEvent(event)) {
|
|
100
|
+
const listeners = this.directListeners[event];
|
|
101
|
+
if (typeof listeners === "undefined") {
|
|
102
|
+
// Don't need to do anything here
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const results = [];
|
|
106
|
+
for (const e of listeners.values()) {
|
|
107
|
+
results.push(e());
|
|
108
|
+
}
|
|
109
|
+
await Promise.all(results);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const results = [];
|
|
113
|
+
if (typeof this.listeners[event] === "undefined") {
|
|
114
|
+
// Don't need to do anything here
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (this.listeners[event].size === 0) {
|
|
118
|
+
// Don't need to do anything here
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const bridge = this.bridge;
|
|
122
|
+
for (const e of this.listeners[event].values()) {
|
|
123
|
+
results.push(e.emit(data, bridge));
|
|
124
|
+
}
|
|
125
|
+
await Promise.allSettled(results);
|
|
126
|
+
// The responses have been removed as we don't currently need them
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @inheritDoc
|
|
130
|
+
*/
|
|
131
|
+
addEventListener(event, callback) {
|
|
132
|
+
if (isDirectShopfrontEvent(event)) {
|
|
133
|
+
if (typeof this.directListeners[event] === "undefined") {
|
|
134
|
+
this.directListeners[event] = new Set();
|
|
135
|
+
}
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
137
|
+
this.directListeners[event].add(callback);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
|
+
let c;
|
|
142
|
+
switch (event) {
|
|
143
|
+
case "READY":
|
|
144
|
+
c = new Ready(callback);
|
|
145
|
+
this.listeners[event].set(callback, c);
|
|
146
|
+
break;
|
|
147
|
+
case "REQUEST_SETTINGS":
|
|
148
|
+
c = new RequestSettings(callback);
|
|
149
|
+
this.listeners[event].set(callback, c);
|
|
150
|
+
break;
|
|
151
|
+
case "REQUEST_BUTTONS":
|
|
152
|
+
c = new RequestButtons(callback);
|
|
153
|
+
this.listeners[event].set(callback, c);
|
|
154
|
+
break;
|
|
155
|
+
case "REQUEST_TABLE_COLUMNS":
|
|
156
|
+
c = new RequestTableColumns(callback);
|
|
157
|
+
this.listeners[event].set(callback, c);
|
|
158
|
+
break;
|
|
159
|
+
case "REQUEST_SELL_SCREEN_OPTIONS":
|
|
160
|
+
c = new RequestSellScreenOptions(callback);
|
|
161
|
+
this.listeners[event].set(callback, c);
|
|
162
|
+
break;
|
|
163
|
+
case "INTERNAL_PAGE_MESSAGE":
|
|
164
|
+
c = new InternalPageMessage(callback, this);
|
|
165
|
+
this.listeners[event].set(callback, c);
|
|
166
|
+
break;
|
|
167
|
+
case "REGISTER_CHANGED":
|
|
168
|
+
c = new RegisterChanged(callback);
|
|
169
|
+
this.listeners[event].set(callback, c);
|
|
170
|
+
break;
|
|
171
|
+
case "REQUEST_CUSTOMER_LIST_OPTIONS":
|
|
172
|
+
c = new RequestCustomerListOptions(callback);
|
|
173
|
+
this.listeners[event].set(callback, c);
|
|
174
|
+
break;
|
|
175
|
+
case "FORMAT_INTEGRATED_PRODUCT":
|
|
176
|
+
c = new FormatIntegratedProduct(callback);
|
|
177
|
+
this.listeners[event].set(callback, c);
|
|
178
|
+
break;
|
|
179
|
+
case "REQUEST_SALE_KEYS":
|
|
180
|
+
c = new RequestSaleKeys(callback);
|
|
181
|
+
this.listeners[event].set(callback, c);
|
|
182
|
+
break;
|
|
183
|
+
case "SALE_COMPLETE":
|
|
184
|
+
c = new SaleComplete(callback);
|
|
185
|
+
this.listeners[event].set(callback, c);
|
|
186
|
+
break;
|
|
187
|
+
case "UI_PIPELINE":
|
|
188
|
+
c = new UIPipeline(callback);
|
|
189
|
+
this.listeners[event].set(callback, c);
|
|
190
|
+
break;
|
|
191
|
+
case "PAYMENT_METHODS_ENABLED":
|
|
192
|
+
c = new PaymentMethodsEnabled(callback);
|
|
193
|
+
this.listeners[event].set(callback, c);
|
|
194
|
+
break;
|
|
195
|
+
case "AUDIO_READY":
|
|
196
|
+
c = new AudioReady(callback);
|
|
197
|
+
this.listeners[event].set(callback, c);
|
|
198
|
+
break;
|
|
199
|
+
case "AUDIO_PERMISSION_CHANGE":
|
|
200
|
+
c = new AudioPermissionChange(callback);
|
|
201
|
+
this.listeners[event].set(callback, c);
|
|
202
|
+
break;
|
|
203
|
+
case "FULFILMENT_GET_ORDER":
|
|
204
|
+
if (this.listeners[event].size !== 0) {
|
|
205
|
+
throw new TypeError("Application already has 'FULFILMENT_GET_ORDER' event listener registered.");
|
|
206
|
+
}
|
|
207
|
+
c = new FulfilmentGetOrder(callback);
|
|
208
|
+
this.listeners[event].set(callback, c);
|
|
209
|
+
break;
|
|
210
|
+
case "FULFILMENT_VOID_ORDER":
|
|
211
|
+
c = new FulfilmentVoidOrder(callback);
|
|
212
|
+
this.listeners[event].set(callback, c);
|
|
213
|
+
break;
|
|
214
|
+
case "FULFILMENT_PROCESS_ORDER":
|
|
215
|
+
c = new FulfilmentProcessOrder(callback);
|
|
216
|
+
this.listeners[event].set(callback, c);
|
|
217
|
+
break;
|
|
218
|
+
case "FULFILMENT_ORDER_APPROVAL":
|
|
219
|
+
c = new FulfilmentOrderApproval(callback);
|
|
220
|
+
this.listeners[event].set(callback, c);
|
|
221
|
+
break;
|
|
222
|
+
case "FULFILMENT_ORDER_COLLECTED":
|
|
223
|
+
c = new FulfilmentCollectOrder(callback);
|
|
224
|
+
this.listeners[event].set(callback, c);
|
|
225
|
+
break;
|
|
226
|
+
case "FULFILMENT_ORDER_COMPLETED":
|
|
227
|
+
c = new FulfilmentCompleteOrder(callback);
|
|
228
|
+
this.listeners[event].set(callback, c);
|
|
229
|
+
break;
|
|
230
|
+
case "GIFT_CARD_CODE_CHECK":
|
|
231
|
+
c = new GiftCardCodeCheck(callback);
|
|
232
|
+
this.listeners[event].set(callback, c);
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
if (typeof c === "undefined") {
|
|
236
|
+
throw new TypeError(`${event} has not been defined`);
|
|
237
|
+
}
|
|
238
|
+
if (event === "READY" && this.isReady) {
|
|
239
|
+
c = c;
|
|
240
|
+
c.emit({
|
|
241
|
+
outlet: this.outlet,
|
|
242
|
+
register: this.register,
|
|
243
|
+
user: this.user,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* @inheritDoc
|
|
249
|
+
*/
|
|
250
|
+
removeEventListener(event, callback) {
|
|
251
|
+
if (isDirectShopfrontEvent(event)) {
|
|
252
|
+
this.directListeners[event]?.delete(callback);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
this.listeners[event].delete(callback);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* @inheritDoc
|
|
259
|
+
*/
|
|
260
|
+
send(item) {
|
|
261
|
+
/* empty */
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* @inheritDoc
|
|
265
|
+
*/
|
|
266
|
+
download(file) {
|
|
267
|
+
/* empty */
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* @inheritDoc
|
|
271
|
+
*/
|
|
272
|
+
redirect(toLocation, externalRedirect = true) {
|
|
273
|
+
/* empty */
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* @inheritDoc
|
|
277
|
+
*/
|
|
278
|
+
load() {
|
|
279
|
+
return () => undefined;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* @inheritDoc
|
|
283
|
+
*/
|
|
284
|
+
handleEventCallback(data) {
|
|
285
|
+
/* empty */
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* @inheritDoc
|
|
289
|
+
*/
|
|
290
|
+
getAuthenticationKey() {
|
|
291
|
+
return this.key;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* @inheritDoc
|
|
295
|
+
*/
|
|
296
|
+
async getCurrentSale() {
|
|
297
|
+
if (!this.currentSale) {
|
|
298
|
+
this.currentSale = new MockCurrentSale(this);
|
|
299
|
+
}
|
|
300
|
+
return this.currentSale;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* @inheritDoc
|
|
304
|
+
*/
|
|
305
|
+
async createSale(sale) {
|
|
306
|
+
if (!sale.getRegister() && !this.register) {
|
|
307
|
+
return {
|
|
308
|
+
success: false,
|
|
309
|
+
message: "Sale has not provided a register and Shopfront currently doesn't have a register selected.",
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
if (!this.user) {
|
|
313
|
+
return {
|
|
314
|
+
success: false,
|
|
315
|
+
message: "A sale cannot be created when there is no user logged in to Shopfront.",
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
const payments = sale.getPayments();
|
|
319
|
+
let totalPaid = 0;
|
|
320
|
+
for (const payment of payments) {
|
|
321
|
+
// TODO: Double check this is still the case
|
|
322
|
+
if (payment.getCashout()) {
|
|
323
|
+
return {
|
|
324
|
+
success: false,
|
|
325
|
+
message: "Sale payment with cash out is currently unsupported " +
|
|
326
|
+
"through the Embedded Fulfilment API.",
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
if (payment.getRounding()) {
|
|
330
|
+
return {
|
|
331
|
+
success: false,
|
|
332
|
+
message: "Sale payment with rounding is currently unsupported " +
|
|
333
|
+
"through the Embedded Fulfilment API.",
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
totalPaid += payment.getAmount();
|
|
337
|
+
}
|
|
338
|
+
// Round to 4 decimal places to keep consistent with POS
|
|
339
|
+
const remaining = Math.round((sale.getSaleTotal() - totalPaid) * 1000) / 1000;
|
|
340
|
+
if (remaining < 0) {
|
|
341
|
+
return {
|
|
342
|
+
success: false,
|
|
343
|
+
message: "Total paid is greater than sale total.",
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
success: true,
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* @inheritDoc
|
|
352
|
+
*/
|
|
353
|
+
async getLocation(options) {
|
|
354
|
+
if (options) {
|
|
355
|
+
if (options.globalMode) {
|
|
356
|
+
return {
|
|
357
|
+
register: null,
|
|
358
|
+
outlet: null,
|
|
359
|
+
user: "shopfront-user-id",
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
else if (!options.useRegister) {
|
|
363
|
+
return {
|
|
364
|
+
register: null,
|
|
365
|
+
outlet: "shopfront-outlet-id",
|
|
366
|
+
user: "shopfront-user-id",
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
register: "shopfront-register-id",
|
|
372
|
+
outlet: "shopfront-outlet-id",
|
|
373
|
+
user: "shopfront-user-id",
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* @inheritDoc
|
|
378
|
+
*/
|
|
379
|
+
printReceipt(content) {
|
|
380
|
+
/* empty */
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* @inheritDoc
|
|
384
|
+
*/
|
|
385
|
+
changeSellScreenActionMode(mode) {
|
|
386
|
+
/* empty */
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* @inheritDoc
|
|
390
|
+
*/
|
|
391
|
+
changeSellScreenSummaryMode(mode) {
|
|
392
|
+
/* empty */
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* @inheritDoc
|
|
396
|
+
*/
|
|
397
|
+
async sendAudioRequest(type, data, options) {
|
|
398
|
+
if (options) {
|
|
399
|
+
if (!options.hasPermission) {
|
|
400
|
+
return {
|
|
401
|
+
success: false,
|
|
402
|
+
message: "You do not have permission to play audio",
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
if (options.forceError) {
|
|
406
|
+
return {
|
|
407
|
+
success: false,
|
|
408
|
+
message: "An error occurred whilst trying to play the audio",
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return {
|
|
413
|
+
success: true,
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* @inheritDoc
|
|
418
|
+
*/
|
|
419
|
+
requestAudioPermission(options) {
|
|
420
|
+
return this.sendAudioRequest(ToShopfront.AUDIO_REQUEST_PERMISSION, undefined, options);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* @inheritDoc
|
|
424
|
+
*/
|
|
425
|
+
audioPreload(url, options) {
|
|
426
|
+
return this.sendAudioRequest(ToShopfront.AUDIO_PRELOAD, {
|
|
427
|
+
url,
|
|
428
|
+
}, options);
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* @inheritDoc
|
|
432
|
+
*/
|
|
433
|
+
audioPlay(url, options) {
|
|
434
|
+
return this.sendAudioRequest(ToShopfront.AUDIO_PLAY, {
|
|
435
|
+
url,
|
|
436
|
+
}, options);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* @inheritDoc
|
|
440
|
+
*/
|
|
441
|
+
async getOption(option, defaultValue) {
|
|
442
|
+
return defaultValue;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* @inheritDoc
|
|
446
|
+
*/
|
|
447
|
+
async getToken(returnTokenObject) {
|
|
448
|
+
if (returnTokenObject) {
|
|
449
|
+
return {
|
|
450
|
+
id: "token-id",
|
|
451
|
+
app: "app-id",
|
|
452
|
+
auth: "embedded-token",
|
|
453
|
+
user: "user-id",
|
|
454
|
+
url: {
|
|
455
|
+
raw: "https://testing.test",
|
|
456
|
+
loaded: "https://frame.url",
|
|
457
|
+
},
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
return "embedded-token";
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Mocks an event being fired from Shopfront
|
|
464
|
+
*/
|
|
465
|
+
async fireEvent(event, ...data) {
|
|
466
|
+
let params;
|
|
467
|
+
if (data.length > 0) {
|
|
468
|
+
if (typeof data[0] === "object") {
|
|
469
|
+
params = {
|
|
470
|
+
...data[0],
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
params = data[0];
|
|
475
|
+
}
|
|
476
|
+
// We don't care about the Bridge parameter, as that is passed in by the `emit` method
|
|
477
|
+
}
|
|
478
|
+
await this.emit(event, params, "");
|
|
479
|
+
}
|
|
480
|
+
;
|
|
481
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as ApplicationEvents from "../ApplicationEvents.js";
|
|
2
|
+
import { BaseBridge } from "../BaseBridge.js";
|
|
3
|
+
import { ApplicationEventListener } from "../Bridge.js";
|
|
4
|
+
export declare class MockBridge extends BaseBridge {
|
|
5
|
+
protected isReady: boolean;
|
|
6
|
+
constructor(key: string, url: string);
|
|
7
|
+
/**
|
|
8
|
+
* @inheritDoc
|
|
9
|
+
*/
|
|
10
|
+
destroy(): void;
|
|
11
|
+
/**
|
|
12
|
+
* @inheritDoc
|
|
13
|
+
*/
|
|
14
|
+
protected registerListeners(): void;
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
protected unregisterListeners(): void;
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
sendMessage(type: ApplicationEvents.ToShopfront, data?: unknown, id?: string): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* @inheritDoc
|
|
25
|
+
*/
|
|
26
|
+
addEventListener(listener: ApplicationEventListener): void;
|
|
27
|
+
/**
|
|
28
|
+
* @inheritDoc
|
|
29
|
+
*/
|
|
30
|
+
removeEventListener(listener: ApplicationEventListener): void;
|
|
31
|
+
}
|