@shopfront/bridge 2.0.2 → 2.0.4
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/.github/workflows/npm-publish.yml +13 -2
- package/lib/Application.d.ts +2 -18
- package/lib/Application.js +1 -141
- package/lib/ApplicationEvents.d.ts +54 -5
- package/lib/BaseApplication.d.ts +11 -17
- package/lib/BaseApplication.js +197 -1
- package/lib/BaseBridge.d.ts +1 -0
- package/lib/BaseBridge.js +1 -3
- package/lib/Bridge.d.ts +0 -19
- package/lib/Bridge.js +2 -1
- package/lib/Events/DirectEvents/BaseDirectEvent.d.ts +13 -0
- package/lib/Events/DirectEvents/BaseDirectEvent.js +5 -0
- package/lib/Events/DirectEvents/SaleAddCustomer.d.ts +13 -0
- package/lib/Events/DirectEvents/SaleAddCustomer.js +24 -0
- package/lib/Events/DirectEvents/SaleAddProduct.d.ts +13 -0
- package/lib/Events/DirectEvents/SaleAddProduct.js +24 -0
- package/lib/Events/DirectEvents/SaleChangeQuantity.d.ts +13 -0
- package/lib/Events/DirectEvents/SaleChangeQuantity.js +24 -0
- package/lib/Events/DirectEvents/SaleClear.d.ts +13 -0
- package/lib/Events/DirectEvents/SaleClear.js +21 -0
- package/lib/Events/DirectEvents/SaleRemoveCustomer.d.ts +13 -0
- package/lib/Events/DirectEvents/SaleRemoveCustomer.js +21 -0
- package/lib/Events/DirectEvents/SaleRemoveProduct.d.ts +13 -0
- package/lib/Events/DirectEvents/SaleRemoveProduct.js +24 -0
- package/lib/Events/DirectEvents/SaleUpdateProducts.d.ts +13 -0
- package/lib/Events/DirectEvents/SaleUpdateProducts.js +24 -0
- package/lib/Events/DirectEvents/types/SaleEventData.d.ts +70 -0
- package/lib/Events/DirectEvents/types/SaleEventData.js +1 -0
- package/lib/Mocks/APIs/Sale/MockCurrentSale.d.ts +7 -2
- package/lib/Mocks/APIs/Sale/MockCurrentSale.js +94 -10
- package/lib/Mocks/MockApplication.d.ts +7 -20
- package/lib/Mocks/MockApplication.js +4 -156
- package/lib/Mocks/MockBridge.js +2 -0
- package/package.json +1 -1
- package/.idea/codeStyles/Project.xml +0 -10
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/git_toolbox_blame.xml +0 -6
- package/.idea/git_toolbox_prj.xml +0 -15
- package/.idea/inspectionProfiles/Project_Default.xml +0 -11
- package/.idea/jsLinters/eslint.xml +0 -6
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/php.xml +0 -33
- package/.idea/shopfront-embedded-bridge.iml +0 -10
- package/.idea/vcs.xml +0 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
name: Pack and Distribute
|
|
2
2
|
on:
|
|
3
|
-
|
|
4
|
-
types: [
|
|
3
|
+
pull_request:
|
|
4
|
+
types: [ synchronize ]
|
|
5
5
|
jobs:
|
|
6
6
|
build:
|
|
7
7
|
runs-on: ubuntu-latest
|
|
@@ -10,20 +10,31 @@ jobs:
|
|
|
10
10
|
- uses: actions/setup-node@v3
|
|
11
11
|
with:
|
|
12
12
|
node-version: '20.x'
|
|
13
|
+
registry-url: 'https://registry.npmjs.org/'
|
|
14
|
+
- run: |
|
|
15
|
+
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc
|
|
13
16
|
- run: npm ci
|
|
14
17
|
- run: npm run-script build
|
|
18
|
+
env:
|
|
19
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
20
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
15
21
|
publish-npm:
|
|
16
22
|
needs: build
|
|
17
23
|
runs-on: ubuntu-latest
|
|
18
24
|
permissions:
|
|
25
|
+
contents: read
|
|
19
26
|
id-token: write
|
|
27
|
+
packages: read
|
|
20
28
|
steps:
|
|
21
29
|
- uses: actions/checkout@v4
|
|
22
30
|
- uses: actions/setup-node@v3
|
|
23
31
|
with:
|
|
24
32
|
node-version: '20.x'
|
|
25
33
|
registry-url: 'https://registry.npmjs.org/'
|
|
34
|
+
- run: |
|
|
35
|
+
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc
|
|
26
36
|
- run: npm ci
|
|
27
37
|
- run: npm publish --provenance --access public
|
|
28
38
|
env:
|
|
39
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
29
40
|
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
package/lib/Application.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CurrentSale } from "./APIs/Sale/CurrentSale.js";
|
|
2
2
|
import { Sale, ShopfrontSaleState } from "./APIs/Sale/index.js";
|
|
3
|
-
import { DirectShopfrontEvent,
|
|
3
|
+
import { DirectShopfrontEvent, FromShopfront, FromShopfrontInternal, ListenableFromShopfrontEvent, RegisterChangedEvent, SellScreenActionMode, SellScreenSummaryMode, SoundEvents } from "./ApplicationEvents.js";
|
|
4
4
|
import { BaseApplication, ShopfrontEmbeddedTokenError, ShopfrontEmbeddedVerificationToken, ShopfrontResponse } from "./BaseApplication.js";
|
|
5
5
|
import { Bridge } from "./Bridge.js";
|
|
6
6
|
import { Serializable } from "./Common/Serializable.js";
|
|
@@ -19,23 +19,7 @@ export declare class Application extends BaseApplication {
|
|
|
19
19
|
/**
|
|
20
20
|
* Calls any registered listeners for the received event
|
|
21
21
|
*/
|
|
22
|
-
protected emit(event:
|
|
23
|
-
/**
|
|
24
|
-
* @inheritDoc
|
|
25
|
-
*/
|
|
26
|
-
addEventListener<E extends ListenableFromShopfrontEvents>(event: E, callback: FromShopfrontCallbacks[E]): void;
|
|
27
|
-
/**
|
|
28
|
-
* @inheritDoc
|
|
29
|
-
*/
|
|
30
|
-
addEventListener(event: DirectShopfrontEvent, callback: DirectShopfrontEventCallback): void;
|
|
31
|
-
/**
|
|
32
|
-
* @inheritDoc
|
|
33
|
-
*/
|
|
34
|
-
removeEventListener<E extends keyof FromShopfrontCallbacks>(event: E, callback: FromShopfrontCallbacks[E]): void;
|
|
35
|
-
/**
|
|
36
|
-
* @inheritDoc
|
|
37
|
-
*/
|
|
38
|
-
removeEventListener<D>(event: DirectShopfrontEvent, callback: (event: D) => MaybePromise<void>): void;
|
|
22
|
+
protected emit(event: ListenableFromShopfrontEvent | DirectShopfrontEvent, data: Record<string, unknown> | undefined, id: string): MaybePromise<void>;
|
|
39
23
|
/**
|
|
40
24
|
* @inheritDoc
|
|
41
25
|
*/
|
package/lib/Application.js
CHANGED
|
@@ -4,27 +4,16 @@ import { CurrentSale } from "./APIs/Sale/CurrentSale.js";
|
|
|
4
4
|
import { isDirectShopfrontEvent, ToShopfront, } from "./ApplicationEvents.js";
|
|
5
5
|
import { BaseApplication, ShopfrontTokenDecodingError, ShopfrontTokenRequestError, } from "./BaseApplication.js";
|
|
6
6
|
import { BaseEmitableEvent } from "./EmitableEvents/BaseEmitableEvent.js";
|
|
7
|
-
import { AudioPermissionChange } from "./Events/AudioPermissionChange.js";
|
|
8
|
-
import { AudioReady } from "./Events/AudioReady.js";
|
|
9
7
|
import { FormatIntegratedProduct } from "./Events/FormatIntegratedProduct.js";
|
|
10
|
-
import { FulfilmentCollectOrder } from "./Events/FulfilmentCollectOrder.js";
|
|
11
|
-
import { FulfilmentCompleteOrder } from "./Events/FulfilmentCompleteOrder.js";
|
|
12
8
|
import { FulfilmentGetOrder } from "./Events/FulfilmentGetOrder.js";
|
|
13
|
-
import { FulfilmentOrderApproval } from "./Events/FulfilmentOrderApproval.js";
|
|
14
|
-
import { FulfilmentProcessOrder } from "./Events/FulfilmentProcessOrder.js";
|
|
15
|
-
import { FulfilmentVoidOrder } from "./Events/FulfilmentVoidOrder.js";
|
|
16
9
|
import { GiftCardCodeCheck } from "./Events/GiftCardCodeCheck.js";
|
|
17
|
-
import { InternalPageMessage } from "./Events/InternalPageMessage.js";
|
|
18
10
|
import { PaymentMethodsEnabled } from "./Events/PaymentMethodsEnabled.js";
|
|
19
|
-
import { Ready } from "./Events/Ready.js";
|
|
20
|
-
import { RegisterChanged } from "./Events/RegisterChanged.js";
|
|
21
11
|
import { RequestButtons } from "./Events/RequestButtons.js";
|
|
22
12
|
import { RequestCustomerListOptions } from "./Events/RequestCustomerListOptions.js";
|
|
23
13
|
import { RequestSaleKeys } from "./Events/RequestSaleKeys.js";
|
|
24
14
|
import { RequestSellScreenOptions } from "./Events/RequestSellScreenOptions.js";
|
|
25
15
|
import { RequestSettings } from "./Events/RequestSettings.js";
|
|
26
16
|
import { RequestTableColumns } from "./Events/RequestTableColumns.js";
|
|
27
|
-
import { SaleComplete } from "./Events/SaleComplete.js";
|
|
28
17
|
import { UIPipeline } from "./Events/UIPipeline.js";
|
|
29
18
|
import ActionEventRegistrar from "./Utilities/ActionEventRegistrar.js";
|
|
30
19
|
import { buildSaleData } from "./Utilities/SaleCreate.js";
|
|
@@ -93,7 +82,7 @@ export class Application extends BaseApplication {
|
|
|
93
82
|
}
|
|
94
83
|
const results = [];
|
|
95
84
|
for (const e of listeners.values()) {
|
|
96
|
-
results.push(e());
|
|
85
|
+
results.push(e.emit(data));
|
|
97
86
|
}
|
|
98
87
|
return Promise.all(results)
|
|
99
88
|
.then(() => {
|
|
@@ -176,135 +165,6 @@ export class Application extends BaseApplication {
|
|
|
176
165
|
});
|
|
177
166
|
}
|
|
178
167
|
}
|
|
179
|
-
/**
|
|
180
|
-
* @inheritDoc
|
|
181
|
-
*/
|
|
182
|
-
addEventListener(event, callback) {
|
|
183
|
-
if (isDirectShopfrontEvent(event)) {
|
|
184
|
-
if (typeof this.directListeners[event] === "undefined") {
|
|
185
|
-
this.directListeners[event] = new Set();
|
|
186
|
-
}
|
|
187
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
188
|
-
this.directListeners[event].add(callback);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
192
|
-
let c;
|
|
193
|
-
switch (event) {
|
|
194
|
-
case "READY":
|
|
195
|
-
c = new Ready(callback);
|
|
196
|
-
this.listeners[event].set(callback, c);
|
|
197
|
-
break;
|
|
198
|
-
case "REQUEST_SETTINGS":
|
|
199
|
-
c = new RequestSettings(callback);
|
|
200
|
-
this.listeners[event].set(callback, c);
|
|
201
|
-
break;
|
|
202
|
-
case "REQUEST_BUTTONS":
|
|
203
|
-
c = new RequestButtons(callback);
|
|
204
|
-
this.listeners[event].set(callback, c);
|
|
205
|
-
break;
|
|
206
|
-
case "REQUEST_TABLE_COLUMNS":
|
|
207
|
-
c = new RequestTableColumns(callback);
|
|
208
|
-
this.listeners[event].set(callback, c);
|
|
209
|
-
break;
|
|
210
|
-
case "REQUEST_SELL_SCREEN_OPTIONS":
|
|
211
|
-
c = new RequestSellScreenOptions(callback);
|
|
212
|
-
this.listeners[event].set(callback, c);
|
|
213
|
-
break;
|
|
214
|
-
case "INTERNAL_PAGE_MESSAGE":
|
|
215
|
-
c = new InternalPageMessage(callback, this);
|
|
216
|
-
this.listeners[event].set(callback, c);
|
|
217
|
-
break;
|
|
218
|
-
case "REGISTER_CHANGED":
|
|
219
|
-
c = new RegisterChanged(callback);
|
|
220
|
-
this.listeners[event].set(callback, c);
|
|
221
|
-
break;
|
|
222
|
-
case "REQUEST_CUSTOMER_LIST_OPTIONS":
|
|
223
|
-
c = new RequestCustomerListOptions(callback);
|
|
224
|
-
this.listeners[event].set(callback, c);
|
|
225
|
-
break;
|
|
226
|
-
case "FORMAT_INTEGRATED_PRODUCT":
|
|
227
|
-
c = new FormatIntegratedProduct(callback);
|
|
228
|
-
this.listeners[event].set(callback, c);
|
|
229
|
-
break;
|
|
230
|
-
case "REQUEST_SALE_KEYS":
|
|
231
|
-
c = new RequestSaleKeys(callback);
|
|
232
|
-
this.listeners[event].set(callback, c);
|
|
233
|
-
break;
|
|
234
|
-
case "SALE_COMPLETE":
|
|
235
|
-
c = new SaleComplete(callback);
|
|
236
|
-
this.listeners[event].set(callback, c);
|
|
237
|
-
break;
|
|
238
|
-
case "UI_PIPELINE":
|
|
239
|
-
c = new UIPipeline(callback);
|
|
240
|
-
this.listeners[event].set(callback, c);
|
|
241
|
-
break;
|
|
242
|
-
case "PAYMENT_METHODS_ENABLED":
|
|
243
|
-
c = new PaymentMethodsEnabled(callback);
|
|
244
|
-
this.listeners[event].set(callback, c);
|
|
245
|
-
break;
|
|
246
|
-
case "AUDIO_READY":
|
|
247
|
-
c = new AudioReady(callback);
|
|
248
|
-
this.listeners[event].set(callback, c);
|
|
249
|
-
break;
|
|
250
|
-
case "AUDIO_PERMISSION_CHANGE":
|
|
251
|
-
c = new AudioPermissionChange(callback);
|
|
252
|
-
this.listeners[event].set(callback, c);
|
|
253
|
-
break;
|
|
254
|
-
case "FULFILMENT_GET_ORDER":
|
|
255
|
-
if (this.listeners[event].size !== 0) {
|
|
256
|
-
throw new TypeError("Application already has 'FULFILMENT_GET_ORDER' event listener registered.");
|
|
257
|
-
}
|
|
258
|
-
c = new FulfilmentGetOrder(callback);
|
|
259
|
-
this.listeners[event].set(callback, c);
|
|
260
|
-
break;
|
|
261
|
-
case "FULFILMENT_VOID_ORDER":
|
|
262
|
-
c = new FulfilmentVoidOrder(callback);
|
|
263
|
-
this.listeners[event].set(callback, c);
|
|
264
|
-
break;
|
|
265
|
-
case "FULFILMENT_PROCESS_ORDER":
|
|
266
|
-
c = new FulfilmentProcessOrder(callback);
|
|
267
|
-
this.listeners[event].set(callback, c);
|
|
268
|
-
break;
|
|
269
|
-
case "FULFILMENT_ORDER_APPROVAL":
|
|
270
|
-
c = new FulfilmentOrderApproval(callback);
|
|
271
|
-
this.listeners[event].set(callback, c);
|
|
272
|
-
break;
|
|
273
|
-
case "FULFILMENT_ORDER_COLLECTED":
|
|
274
|
-
c = new FulfilmentCollectOrder(callback);
|
|
275
|
-
this.listeners[event].set(callback, c);
|
|
276
|
-
break;
|
|
277
|
-
case "FULFILMENT_ORDER_COMPLETED":
|
|
278
|
-
c = new FulfilmentCompleteOrder(callback);
|
|
279
|
-
this.listeners[event].set(callback, c);
|
|
280
|
-
break;
|
|
281
|
-
case "GIFT_CARD_CODE_CHECK":
|
|
282
|
-
c = new GiftCardCodeCheck(callback);
|
|
283
|
-
this.listeners[event].set(callback, c);
|
|
284
|
-
break;
|
|
285
|
-
}
|
|
286
|
-
if (typeof c === "undefined") {
|
|
287
|
-
throw new TypeError(`${event} has not been defined`);
|
|
288
|
-
}
|
|
289
|
-
if (event === "READY" && this.isReady) {
|
|
290
|
-
c = c;
|
|
291
|
-
c.emit({
|
|
292
|
-
outlet: this.outlet,
|
|
293
|
-
register: this.register,
|
|
294
|
-
user: this.user,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* @inheritDoc
|
|
300
|
-
*/
|
|
301
|
-
removeEventListener(event, callback) {
|
|
302
|
-
if (isDirectShopfrontEvent(event)) {
|
|
303
|
-
this.directListeners[event]?.delete(callback);
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
this.listeners[event].delete(callback);
|
|
307
|
-
}
|
|
308
168
|
/**
|
|
309
169
|
* @inheritDoc
|
|
310
170
|
*/
|
|
@@ -6,6 +6,14 @@ import { Sale, ShopfrontSaleState } from "./APIs/Sale/index.js";
|
|
|
6
6
|
import { AudioPermissionChange } from "./Events/AudioPermissionChange.js";
|
|
7
7
|
import { AudioReady } from "./Events/AudioReady.js";
|
|
8
8
|
import { Callback } from "./Events/Callback.js";
|
|
9
|
+
import { SaleAddCustomer } from "./Events/DirectEvents/SaleAddCustomer.js";
|
|
10
|
+
import { SaleAddProduct } from "./Events/DirectEvents/SaleAddProduct.js";
|
|
11
|
+
import { SaleChangeQuantity } from "./Events/DirectEvents/SaleChangeQuantity.js";
|
|
12
|
+
import { SaleClear } from "./Events/DirectEvents/SaleClear.js";
|
|
13
|
+
import { SaleRemoveCustomer } from "./Events/DirectEvents/SaleRemoveCustomer.js";
|
|
14
|
+
import { SaleRemoveProduct } from "./Events/DirectEvents/SaleRemoveProduct.js";
|
|
15
|
+
import { SaleUpdateProducts } from "./Events/DirectEvents/SaleUpdateProducts.js";
|
|
16
|
+
import { SaleEventProduct } from "./Events/DirectEvents/types/SaleEventData.js";
|
|
9
17
|
import { FormatIntegratedProduct, FormattedSaleProduct } from "./Events/FormatIntegratedProduct.js";
|
|
10
18
|
import { FulfilmentCollectOrder } from "./Events/FulfilmentCollectOrder.js";
|
|
11
19
|
import { FulfilmentCompleteOrder } from "./Events/FulfilmentCompleteOrder.js";
|
|
@@ -237,14 +245,55 @@ export interface FromShopfront {
|
|
|
237
245
|
FULFILMENT_ORDER_COMPLETED: FulfilmentCompleteOrder;
|
|
238
246
|
GIFT_CARD_CODE_CHECK: GiftCardCodeCheck;
|
|
239
247
|
}
|
|
240
|
-
export type
|
|
241
|
-
export
|
|
248
|
+
export type ListenableFromShopfrontEvent = keyof Omit<FromShopfront, "CALLBACK">;
|
|
249
|
+
export interface DirectShopfrontEventData {
|
|
250
|
+
SALE_ADD_PRODUCT: {
|
|
251
|
+
product: SaleEventProduct;
|
|
252
|
+
indexAddress: Array<number>;
|
|
253
|
+
};
|
|
254
|
+
SALE_REMOVE_PRODUCT: {
|
|
255
|
+
indexAddress: Array<number>;
|
|
256
|
+
};
|
|
257
|
+
SALE_CHANGE_QUANTITY: {
|
|
258
|
+
indexAddress: Array<number>;
|
|
259
|
+
amount: number;
|
|
260
|
+
absolute: boolean;
|
|
261
|
+
};
|
|
262
|
+
SALE_UPDATE_PRODUCTS: {
|
|
263
|
+
products: Array<SaleEventProduct>;
|
|
264
|
+
};
|
|
265
|
+
SALE_ADD_CUSTOMER: {
|
|
266
|
+
customer: {
|
|
267
|
+
uuid: string;
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
SALE_REMOVE_CUSTOMER: undefined;
|
|
271
|
+
SALE_CLEAR: undefined;
|
|
272
|
+
}
|
|
273
|
+
export interface DirectShopfrontCallbacks {
|
|
274
|
+
SALE_ADD_PRODUCT: (event: DirectShopfrontEventData["SALE_ADD_PRODUCT"]) => MaybePromise<void>;
|
|
275
|
+
SALE_REMOVE_PRODUCT: (event: DirectShopfrontEventData["SALE_REMOVE_PRODUCT"]) => MaybePromise<void>;
|
|
276
|
+
SALE_CHANGE_QUANTITY: (event: DirectShopfrontEventData["SALE_CHANGE_QUANTITY"]) => MaybePromise<void>;
|
|
277
|
+
SALE_UPDATE_PRODUCTS: (event: DirectShopfrontEventData["SALE_UPDATE_PRODUCTS"]) => MaybePromise<void>;
|
|
278
|
+
SALE_ADD_CUSTOMER: (event: DirectShopfrontEventData["SALE_ADD_CUSTOMER"]) => MaybePromise<void>;
|
|
279
|
+
SALE_REMOVE_CUSTOMER: () => MaybePromise<void>;
|
|
280
|
+
SALE_CLEAR: () => MaybePromise<void>;
|
|
281
|
+
}
|
|
282
|
+
export interface DirectShopfront {
|
|
283
|
+
SALE_ADD_PRODUCT: SaleAddProduct;
|
|
284
|
+
SALE_REMOVE_PRODUCT: SaleRemoveProduct;
|
|
285
|
+
SALE_CHANGE_QUANTITY: SaleChangeQuantity;
|
|
286
|
+
SALE_UPDATE_PRODUCTS: SaleUpdateProducts;
|
|
287
|
+
SALE_ADD_CUSTOMER: SaleAddCustomer;
|
|
288
|
+
SALE_REMOVE_CUSTOMER: SaleRemoveCustomer;
|
|
289
|
+
SALE_CLEAR: SaleClear;
|
|
290
|
+
}
|
|
291
|
+
export type DirectShopfrontEvent = keyof DirectShopfront;
|
|
292
|
+
export declare const directShopfrontEvents: Array<DirectShopfrontEvent>;
|
|
242
293
|
/**
|
|
243
294
|
* Checks whether the event is a direct Shopfront event
|
|
244
295
|
*/
|
|
245
|
-
export declare const isDirectShopfrontEvent: (event: DirectShopfrontEvent |
|
|
246
|
-
export type DirectShopfrontEvent = typeof directShopfrontEvents[number];
|
|
247
|
-
export type DirectShopfrontEventCallback = () => void | Promise<void>;
|
|
296
|
+
export declare const isDirectShopfrontEvent: (event: DirectShopfrontEvent | ListenableFromShopfrontEvent) => event is DirectShopfrontEvent;
|
|
248
297
|
export interface FromShopfrontInternal {
|
|
249
298
|
CYCLE_KEY: "CYCLE_KEY";
|
|
250
299
|
LOCATION_CHANGED: "LOCATION_CHANGED";
|
package/lib/BaseApplication.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { BaseDatabase } from "./APIs/Database/BaseDatabase.js";
|
|
2
2
|
import { BaseCurrentSale } from "./APIs/Sale/BaseCurrentSale.js";
|
|
3
3
|
import { Sale } from "./APIs/Sale/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { DirectShopfront, DirectShopfrontCallbacks, DirectShopfrontEvent, FromShopfront, FromShopfrontCallbacks, FromShopfrontInternal, ListenableFromShopfrontEvent, RegisterChangedEvent, SellScreenActionMode, SellScreenSummaryMode, SoundEvents } from "./ApplicationEvents.js";
|
|
5
5
|
import { BaseBridge } from "./BaseBridge.js";
|
|
6
6
|
import { Serializable } from "./Common/Serializable.js";
|
|
7
7
|
import { BaseEmitableEvent } from "./EmitableEvents/BaseEmitableEvent.js";
|
|
8
8
|
import { BaseEvent } from "./Events/BaseEvent.js";
|
|
9
|
-
import { MaybePromise } from "./Utilities/MiscTypes.js";
|
|
9
|
+
import { AnyFunction, MaybePromise } from "./Utilities/MiscTypes.js";
|
|
10
10
|
export interface ShopfrontResponse {
|
|
11
11
|
success: boolean;
|
|
12
12
|
message?: string;
|
|
@@ -38,9 +38,11 @@ export declare abstract class BaseApplication {
|
|
|
38
38
|
protected user: string | null;
|
|
39
39
|
protected signingKey: CryptoKeyPair | undefined;
|
|
40
40
|
protected listeners: {
|
|
41
|
-
[key in
|
|
41
|
+
[key in ListenableFromShopfrontEvent]: Map<AnyFunction, FromShopfront[key] & BaseEvent>;
|
|
42
|
+
};
|
|
43
|
+
protected directListeners: {
|
|
44
|
+
[key in DirectShopfrontEvent]: Map<AnyFunction, DirectShopfront[key]>;
|
|
42
45
|
};
|
|
43
|
-
protected directListeners: Partial<Record<DirectShopfrontEvent, Set<DirectShopfrontEventCallback>>>;
|
|
44
46
|
database: BaseDatabase;
|
|
45
47
|
protected constructor(bridge: BaseBridge, database: BaseDatabase);
|
|
46
48
|
/**
|
|
@@ -54,31 +56,23 @@ export declare abstract class BaseApplication {
|
|
|
54
56
|
/**
|
|
55
57
|
* Calls any registered listeners for the received event
|
|
56
58
|
*/
|
|
57
|
-
protected abstract emit(event:
|
|
58
|
-
/**
|
|
59
|
-
* Register a listener for a Shopfront event
|
|
60
|
-
*/
|
|
61
|
-
abstract addEventListener<E extends ListenableFromShopfrontEvents>(event: E, callback: FromShopfrontCallbacks[E]): void;
|
|
59
|
+
protected abstract emit(event: ListenableFromShopfrontEvent | DirectShopfrontEvent, data: Record<string, unknown>, id: string): MaybePromise<void>;
|
|
62
60
|
/**
|
|
63
61
|
* Register a listener for a Shopfront event
|
|
64
62
|
*/
|
|
65
|
-
|
|
63
|
+
addEventListener<E extends ListenableFromShopfrontEvent>(event: E, callback: FromShopfrontCallbacks[E]): void;
|
|
66
64
|
/**
|
|
67
65
|
* Register a listener for a Shopfront event
|
|
68
66
|
*/
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Removed a registered listener for a Shopfront event
|
|
72
|
-
*/
|
|
73
|
-
abstract removeEventListener<E extends keyof FromShopfrontCallbacks>(event: E, callback: FromShopfrontCallbacks[E]): void;
|
|
67
|
+
addEventListener<D extends DirectShopfrontEvent>(event: D, callback: DirectShopfrontCallbacks[D]): void;
|
|
74
68
|
/**
|
|
75
69
|
* Removed a registered listener for a Shopfront event
|
|
76
70
|
*/
|
|
77
|
-
|
|
71
|
+
removeEventListener<E extends ListenableFromShopfrontEvent>(event: E, callback: FromShopfrontCallbacks[E]): void;
|
|
78
72
|
/**
|
|
79
73
|
* Removed a registered listener for a Shopfront event
|
|
80
74
|
*/
|
|
81
|
-
|
|
75
|
+
removeEventListener<D extends DirectShopfrontEvent>(event: D, callback: DirectShopfrontCallbacks[D]): void;
|
|
82
76
|
/**
|
|
83
77
|
* Send data to Shopfront
|
|
84
78
|
*/
|
package/lib/BaseApplication.js
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
import { isDirectShopfrontEvent, } from "./ApplicationEvents.js";
|
|
2
|
+
import { AudioPermissionChange } from "./Events/AudioPermissionChange.js";
|
|
3
|
+
import { AudioReady } from "./Events/AudioReady.js";
|
|
4
|
+
import { SaleAddCustomer } from "./Events/DirectEvents/SaleAddCustomer.js";
|
|
5
|
+
import { SaleAddProduct } from "./Events/DirectEvents/SaleAddProduct.js";
|
|
6
|
+
import { SaleChangeQuantity } from "./Events/DirectEvents/SaleChangeQuantity.js";
|
|
7
|
+
import { SaleClear } from "./Events/DirectEvents/SaleClear.js";
|
|
8
|
+
import { SaleRemoveCustomer } from "./Events/DirectEvents/SaleRemoveCustomer.js";
|
|
9
|
+
import { SaleRemoveProduct } from "./Events/DirectEvents/SaleRemoveProduct.js";
|
|
10
|
+
import { SaleUpdateProducts } from "./Events/DirectEvents/SaleUpdateProducts.js";
|
|
11
|
+
import { FormatIntegratedProduct } from "./Events/FormatIntegratedProduct.js";
|
|
12
|
+
import { FulfilmentCollectOrder } from "./Events/FulfilmentCollectOrder.js";
|
|
13
|
+
import { FulfilmentCompleteOrder } from "./Events/FulfilmentCompleteOrder.js";
|
|
14
|
+
import { FulfilmentGetOrder } from "./Events/FulfilmentGetOrder.js";
|
|
15
|
+
import { FulfilmentOrderApproval } from "./Events/FulfilmentOrderApproval.js";
|
|
16
|
+
import { FulfilmentProcessOrder } from "./Events/FulfilmentProcessOrder.js";
|
|
17
|
+
import { FulfilmentVoidOrder } from "./Events/FulfilmentVoidOrder.js";
|
|
18
|
+
import { GiftCardCodeCheck } from "./Events/GiftCardCodeCheck.js";
|
|
19
|
+
import { InternalPageMessage } from "./Events/InternalPageMessage.js";
|
|
20
|
+
import { PaymentMethodsEnabled } from "./Events/PaymentMethodsEnabled.js";
|
|
21
|
+
import { Ready } from "./Events/Ready.js";
|
|
22
|
+
import { RegisterChanged } from "./Events/RegisterChanged.js";
|
|
23
|
+
import { RequestButtons } from "./Events/RequestButtons.js";
|
|
24
|
+
import { RequestCustomerListOptions } from "./Events/RequestCustomerListOptions.js";
|
|
25
|
+
import { RequestSaleKeys } from "./Events/RequestSaleKeys.js";
|
|
26
|
+
import { RequestSellScreenOptions } from "./Events/RequestSellScreenOptions.js";
|
|
27
|
+
import { RequestSettings } from "./Events/RequestSettings.js";
|
|
28
|
+
import { RequestTableColumns } from "./Events/RequestTableColumns.js";
|
|
29
|
+
import { SaleComplete } from "./Events/SaleComplete.js";
|
|
30
|
+
import { UIPipeline } from "./Events/UIPipeline.js";
|
|
1
31
|
export class ShopfrontTokenDecodingError extends Error {
|
|
2
32
|
}
|
|
3
33
|
export class ShopfrontTokenRequestError extends Error {
|
|
@@ -28,7 +58,15 @@ export class BaseApplication {
|
|
|
28
58
|
FULFILMENT_ORDER_COMPLETED: new Map(),
|
|
29
59
|
GIFT_CARD_CODE_CHECK: new Map(),
|
|
30
60
|
};
|
|
31
|
-
this.directListeners = {
|
|
61
|
+
this.directListeners = {
|
|
62
|
+
SALE_ADD_PRODUCT: new Map(),
|
|
63
|
+
SALE_REMOVE_PRODUCT: new Map(),
|
|
64
|
+
SALE_CHANGE_QUANTITY: new Map(),
|
|
65
|
+
SALE_UPDATE_PRODUCTS: new Map(),
|
|
66
|
+
SALE_ADD_CUSTOMER: new Map(),
|
|
67
|
+
SALE_REMOVE_CUSTOMER: new Map(),
|
|
68
|
+
SALE_CLEAR: new Map(),
|
|
69
|
+
};
|
|
32
70
|
this.bridge = bridge;
|
|
33
71
|
this.isReady = false;
|
|
34
72
|
this.key = "";
|
|
@@ -37,4 +75,162 @@ export class BaseApplication {
|
|
|
37
75
|
this.user = null;
|
|
38
76
|
this.database = database;
|
|
39
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Register a listener for a Shopfront event
|
|
80
|
+
*/
|
|
81
|
+
addEventListener(event, callback) {
|
|
82
|
+
if (isDirectShopfrontEvent(event)) {
|
|
83
|
+
let c;
|
|
84
|
+
switch (event) {
|
|
85
|
+
case "SALE_ADD_PRODUCT":
|
|
86
|
+
c = new SaleAddProduct(callback);
|
|
87
|
+
this.directListeners[event].set(callback, c);
|
|
88
|
+
break;
|
|
89
|
+
case "SALE_REMOVE_PRODUCT":
|
|
90
|
+
c = new SaleRemoveProduct(callback);
|
|
91
|
+
this.directListeners[event].set(callback, c);
|
|
92
|
+
break;
|
|
93
|
+
case "SALE_CHANGE_QUANTITY":
|
|
94
|
+
c = new SaleChangeQuantity(callback);
|
|
95
|
+
this.directListeners[event].set(callback, c);
|
|
96
|
+
break;
|
|
97
|
+
case "SALE_UPDATE_PRODUCTS":
|
|
98
|
+
c = new SaleUpdateProducts(callback);
|
|
99
|
+
this.directListeners[event].set(callback, c);
|
|
100
|
+
break;
|
|
101
|
+
case "SALE_ADD_CUSTOMER":
|
|
102
|
+
c = new SaleAddCustomer(callback);
|
|
103
|
+
this.directListeners[event].set(callback, c);
|
|
104
|
+
break;
|
|
105
|
+
case "SALE_REMOVE_CUSTOMER":
|
|
106
|
+
c = new SaleRemoveCustomer(callback);
|
|
107
|
+
this.directListeners[event].set(callback, c);
|
|
108
|
+
break;
|
|
109
|
+
case "SALE_CLEAR":
|
|
110
|
+
c = new SaleClear(callback);
|
|
111
|
+
this.directListeners[event].set(callback, c);
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
if (typeof c === "undefined") {
|
|
115
|
+
throw new TypeError(`${event} has not been defined`);
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
+
let c;
|
|
121
|
+
switch (event) {
|
|
122
|
+
case "READY":
|
|
123
|
+
c = new Ready(callback);
|
|
124
|
+
this.listeners[event].set(callback, c);
|
|
125
|
+
break;
|
|
126
|
+
case "REQUEST_SETTINGS":
|
|
127
|
+
c = new RequestSettings(callback);
|
|
128
|
+
this.listeners[event].set(callback, c);
|
|
129
|
+
break;
|
|
130
|
+
case "REQUEST_BUTTONS":
|
|
131
|
+
c = new RequestButtons(callback);
|
|
132
|
+
this.listeners[event].set(callback, c);
|
|
133
|
+
break;
|
|
134
|
+
case "REQUEST_TABLE_COLUMNS":
|
|
135
|
+
c = new RequestTableColumns(callback);
|
|
136
|
+
this.listeners[event].set(callback, c);
|
|
137
|
+
break;
|
|
138
|
+
case "REQUEST_SELL_SCREEN_OPTIONS":
|
|
139
|
+
c = new RequestSellScreenOptions(callback);
|
|
140
|
+
this.listeners[event].set(callback, c);
|
|
141
|
+
break;
|
|
142
|
+
case "INTERNAL_PAGE_MESSAGE":
|
|
143
|
+
c = new InternalPageMessage(callback, this);
|
|
144
|
+
this.listeners[event].set(callback, c);
|
|
145
|
+
break;
|
|
146
|
+
case "REGISTER_CHANGED":
|
|
147
|
+
c = new RegisterChanged(callback);
|
|
148
|
+
this.listeners[event].set(callback, c);
|
|
149
|
+
break;
|
|
150
|
+
case "REQUEST_CUSTOMER_LIST_OPTIONS":
|
|
151
|
+
c = new RequestCustomerListOptions(callback);
|
|
152
|
+
this.listeners[event].set(callback, c);
|
|
153
|
+
break;
|
|
154
|
+
case "FORMAT_INTEGRATED_PRODUCT":
|
|
155
|
+
c = new FormatIntegratedProduct(callback);
|
|
156
|
+
this.listeners[event].set(callback, c);
|
|
157
|
+
break;
|
|
158
|
+
case "REQUEST_SALE_KEYS":
|
|
159
|
+
c = new RequestSaleKeys(callback);
|
|
160
|
+
this.listeners[event].set(callback, c);
|
|
161
|
+
break;
|
|
162
|
+
case "SALE_COMPLETE":
|
|
163
|
+
c = new SaleComplete(callback);
|
|
164
|
+
this.listeners[event].set(callback, c);
|
|
165
|
+
break;
|
|
166
|
+
case "UI_PIPELINE":
|
|
167
|
+
c = new UIPipeline(callback);
|
|
168
|
+
this.listeners[event].set(callback, c);
|
|
169
|
+
break;
|
|
170
|
+
case "PAYMENT_METHODS_ENABLED":
|
|
171
|
+
c = new PaymentMethodsEnabled(callback);
|
|
172
|
+
this.listeners[event].set(callback, c);
|
|
173
|
+
break;
|
|
174
|
+
case "AUDIO_READY":
|
|
175
|
+
c = new AudioReady(callback);
|
|
176
|
+
this.listeners[event].set(callback, c);
|
|
177
|
+
break;
|
|
178
|
+
case "AUDIO_PERMISSION_CHANGE":
|
|
179
|
+
c = new AudioPermissionChange(callback);
|
|
180
|
+
this.listeners[event].set(callback, c);
|
|
181
|
+
break;
|
|
182
|
+
case "FULFILMENT_GET_ORDER":
|
|
183
|
+
if (this.listeners[event].size !== 0) {
|
|
184
|
+
throw new TypeError("Application already has 'FULFILMENT_GET_ORDER' event listener registered.");
|
|
185
|
+
}
|
|
186
|
+
c = new FulfilmentGetOrder(callback);
|
|
187
|
+
this.listeners[event].set(callback, c);
|
|
188
|
+
break;
|
|
189
|
+
case "FULFILMENT_VOID_ORDER":
|
|
190
|
+
c = new FulfilmentVoidOrder(callback);
|
|
191
|
+
this.listeners[event].set(callback, c);
|
|
192
|
+
break;
|
|
193
|
+
case "FULFILMENT_PROCESS_ORDER":
|
|
194
|
+
c = new FulfilmentProcessOrder(callback);
|
|
195
|
+
this.listeners[event].set(callback, c);
|
|
196
|
+
break;
|
|
197
|
+
case "FULFILMENT_ORDER_APPROVAL":
|
|
198
|
+
c = new FulfilmentOrderApproval(callback);
|
|
199
|
+
this.listeners[event].set(callback, c);
|
|
200
|
+
break;
|
|
201
|
+
case "FULFILMENT_ORDER_COLLECTED":
|
|
202
|
+
c = new FulfilmentCollectOrder(callback);
|
|
203
|
+
this.listeners[event].set(callback, c);
|
|
204
|
+
break;
|
|
205
|
+
case "FULFILMENT_ORDER_COMPLETED":
|
|
206
|
+
c = new FulfilmentCompleteOrder(callback);
|
|
207
|
+
this.listeners[event].set(callback, c);
|
|
208
|
+
break;
|
|
209
|
+
case "GIFT_CARD_CODE_CHECK":
|
|
210
|
+
c = new GiftCardCodeCheck(callback);
|
|
211
|
+
this.listeners[event].set(callback, c);
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
if (typeof c === "undefined") {
|
|
215
|
+
throw new TypeError(`${event} has not been defined`);
|
|
216
|
+
}
|
|
217
|
+
if (event === "READY" && this.isReady) {
|
|
218
|
+
c = c;
|
|
219
|
+
c.emit({
|
|
220
|
+
outlet: this.outlet,
|
|
221
|
+
register: this.register,
|
|
222
|
+
user: this.user,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Removed a registered listener for a Shopfront event
|
|
228
|
+
*/
|
|
229
|
+
removeEventListener(event, callback) {
|
|
230
|
+
if (isDirectShopfrontEvent(event)) {
|
|
231
|
+
this.directListeners[event].delete(callback);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
this.listeners[event].delete(callback);
|
|
235
|
+
}
|
|
40
236
|
}
|
package/lib/BaseBridge.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare abstract class BaseBridge {
|
|
|
5
5
|
url: URL;
|
|
6
6
|
protected listeners: Array<ApplicationEventListener>;
|
|
7
7
|
protected hasListener: boolean;
|
|
8
|
+
protected target: Window | null;
|
|
8
9
|
protected constructor(key: string, url: string);
|
|
9
10
|
/**
|
|
10
11
|
* Destroys the Bridge by unregistering all listeners
|
package/lib/BaseBridge.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as ApplicationEvents from "./ApplicationEvents.js";
|
|
2
1
|
export class BaseBridge {
|
|
3
2
|
constructor(key, url) {
|
|
4
3
|
this.listeners = [];
|
|
5
4
|
this.hasListener = false;
|
|
5
|
+
this.target = null;
|
|
6
6
|
this.key = key;
|
|
7
7
|
if (url.split(".").length === 1) {
|
|
8
8
|
this.url = new URL(`https://${url}.onshopfront.com`);
|
|
@@ -10,7 +10,5 @@ export class BaseBridge {
|
|
|
10
10
|
else {
|
|
11
11
|
this.url = new URL(url);
|
|
12
12
|
}
|
|
13
|
-
this.registerListeners();
|
|
14
|
-
this.sendMessage(ApplicationEvents.ToShopfront.READY);
|
|
15
13
|
}
|
|
16
14
|
}
|
package/lib/Bridge.d.ts
CHANGED
|
@@ -6,30 +6,11 @@ interface ApplicationOptions {
|
|
|
6
6
|
vendor: string;
|
|
7
7
|
}
|
|
8
8
|
export type ApplicationEventListener = (event: keyof ApplicationEvents.FromShopfront | keyof ApplicationEvents.FromShopfrontInternal, data: Record<string, unknown>, id: string) => void;
|
|
9
|
-
export interface BridgeInterface {
|
|
10
|
-
/**
|
|
11
|
-
* Destroys the Bridge by unregistering all listeners
|
|
12
|
-
*/
|
|
13
|
-
destroy(): void;
|
|
14
|
-
/**
|
|
15
|
-
* Sends an event to Shopfront
|
|
16
|
-
*/
|
|
17
|
-
sendMessage(type: ApplicationEvents.ToShopfront, data?: unknown, id?: string): void;
|
|
18
|
-
/**
|
|
19
|
-
* Adds a listener for a Shopfront event
|
|
20
|
-
*/
|
|
21
|
-
addEventListener(listener: ApplicationEventListener): void;
|
|
22
|
-
/**
|
|
23
|
-
* Removes a listener for a Shopfront event
|
|
24
|
-
*/
|
|
25
|
-
removeEventListener(listener: ApplicationEventListener): void;
|
|
26
|
-
}
|
|
27
9
|
export declare class Bridge extends BaseBridge {
|
|
28
10
|
/**
|
|
29
11
|
* A static method for instantiating an Application
|
|
30
12
|
*/
|
|
31
13
|
static createApplication(options: ApplicationOptions): Application;
|
|
32
|
-
protected target: Window | null;
|
|
33
14
|
constructor(key: string, url: string);
|
|
34
15
|
/**
|
|
35
16
|
* @inheritDoc
|