@shopfront/bridge 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/.idea/{shopfront-embedded-bridge.iml → embedded-bridge.iml} +0 -0
  2. package/.idea/inspectionProfiles/Project_Default.xml +1 -2
  3. package/.idea/modules.xml +1 -1
  4. package/README.md +3 -2
  5. package/lib/APIs/CurrentSale/Sale.d.ts +12 -0
  6. package/lib/APIs/CurrentSale/Sale.js +18 -0
  7. package/lib/APIs/CurrentSale/SaleProduct.d.ts +1 -1
  8. package/lib/APIs/CurrentSale/SaleProduct.js +1 -2
  9. package/lib/APIs/CurrentSale/ShopfrontSaleState.d.ts +1 -0
  10. package/lib/APIs/CurrentSale/index.js +5 -1
  11. package/lib/APIs/InternalMessages/InternalMessageSource.d.ts +1 -1
  12. package/lib/Actions/BaseAction.d.ts +13 -8
  13. package/lib/Actions/BaseAction.js +7 -6
  14. package/lib/Actions/Button.js +0 -1
  15. package/lib/Actions/Redirect.js +0 -2
  16. package/lib/Actions/SaleKey.js +0 -1
  17. package/lib/Actions/SaleUpdate.d.ts +5 -2
  18. package/lib/Actions/SaleUpdate.js +0 -1
  19. package/lib/Actions/Toast.d.ts +1 -2
  20. package/lib/Application.d.ts +24 -7
  21. package/lib/Application.js +54 -10
  22. package/lib/ApplicationEvents.d.ts +37 -4
  23. package/lib/ApplicationEvents.js +4 -4
  24. package/lib/Bridge.d.ts +1 -1
  25. package/lib/Bridge.js +6 -2
  26. package/lib/Common/EventEmitter.d.ts +4 -3
  27. package/lib/Common/Serializable.d.ts +1 -1
  28. package/lib/EmitableEvents/SellScreenPromotionApplicable.d.ts +13 -0
  29. package/lib/EmitableEvents/SellScreenPromotionApplicable.js +19 -0
  30. package/lib/Events/BaseEvent.d.ts +5 -4
  31. package/lib/Events/BaseEvent.js +1 -0
  32. package/lib/Events/Callback.d.ts +1 -1
  33. package/lib/Events/Callback.js +2 -2
  34. package/lib/Events/FormatIntegratedProduct.d.ts +14 -3
  35. package/lib/Events/FormatIntegratedProduct.js +1 -1
  36. package/lib/Events/InternalPageMessage.d.ts +4 -8
  37. package/lib/Events/InternalPageMessage.js +1 -1
  38. package/lib/Events/PaymentMethodsEnabled.d.ts +15 -0
  39. package/lib/Events/PaymentMethodsEnabled.js +21 -0
  40. package/lib/Events/Ready.d.ts +2 -2
  41. package/lib/Events/Ready.js +1 -1
  42. package/lib/Events/RegisterChanged.js +1 -1
  43. package/lib/Events/RequestButtons.d.ts +7 -2
  44. package/lib/Events/RequestButtons.js +2 -2
  45. package/lib/Events/RequestCustomerListOptions.d.ts +3 -2
  46. package/lib/Events/RequestCustomerListOptions.js +3 -2
  47. package/lib/Events/RequestSaleKeys.d.ts +2 -1
  48. package/lib/Events/RequestSaleKeys.js +2 -2
  49. package/lib/Events/RequestSellScreenOptions.d.ts +3 -2
  50. package/lib/Events/RequestSellScreenOptions.js +3 -2
  51. package/lib/Events/RequestSettings.d.ts +3 -2
  52. package/lib/Events/RequestSettings.js +3 -2
  53. package/lib/Events/RequestTableColumns.d.ts +6 -2
  54. package/lib/Events/RequestTableColumns.js +1 -1
  55. package/lib/Events/SaleComplete.d.ts +1 -1
  56. package/lib/Events/SaleComplete.js +1 -1
  57. package/lib/Events/UIPipeline.d.ts +15 -0
  58. package/lib/Events/UIPipeline.js +31 -0
  59. package/lib/Utilities/ActionEventRegistrar.d.ts +3 -3
  60. package/lib/Utilities/MiscTypes.d.ts +3 -0
  61. package/lib/Utilities/Static.js +2 -0
  62. package/lib/index.d.ts +2 -1
  63. package/lib/index.js +8 -2
  64. package/package.json +31 -27
  65. package/.idea/compiler.xml +0 -6
  66. package/.idea/misc.xml +0 -6
  67. package/bitbucket-pipelines.yml +0 -22
package/lib/Bridge.js CHANGED
@@ -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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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];
@@ -143,7 +147,7 @@ class Bridge {
143
147
  }
144
148
  }
145
149
  removeEventListener(listener) {
146
- let index = this.listeners.indexOf(listener);
150
+ const index = this.listeners.indexOf(listener);
147
151
  if (index === -1) {
148
152
  return;
149
153
  }
@@ -1,7 +1,8 @@
1
+ import { MaybePromise } from "../Utilities/MiscTypes";
1
2
  export declare class EventEmitter {
2
3
  protected supportedEvents: Array<string>;
3
4
  private listeners;
4
- addEventListener(event: string, callback: Function): void;
5
- removeEventListener(event: string, callback: Function): void;
6
- protected emit(event: string, ...args: any[]): Promise<Array<any>>;
5
+ addEventListener(event: string, callback: (...args: Array<unknown>) => MaybePromise<unknown>): void;
6
+ removeEventListener(event: string, callback: (...args: Array<unknown>) => MaybePromise<unknown>): void;
7
+ protected emit(event: string, ...args: Array<unknown>): Promise<Array<unknown>>;
7
8
  }
@@ -1,5 +1,5 @@
1
1
  export interface Serialized<T> {
2
- properties: Array<any>;
2
+ properties: Array<unknown>;
3
3
  events: {
4
4
  [event: string]: Array<string>;
5
5
  };
@@ -0,0 +1,13 @@
1
+ import { BaseEmitableEvent } from "./BaseEmitableEvent";
2
+ export interface PromotionApplicableData {
3
+ enable: boolean;
4
+ key: string;
5
+ }
6
+ export declare class SellScreenPromotionApplicable extends BaseEmitableEvent<PromotionApplicableData> {
7
+ /**
8
+ * Enable or disable a set of already created "applicable" promotions
9
+ * @param key {string} The key to enable or disable, this supports wildcards using an asterisk
10
+ * @param enable {boolean} Whether the key should be enabled or disabled
11
+ */
12
+ constructor(key: string, enable: boolean);
13
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SellScreenPromotionApplicable = void 0;
4
+ const BaseEmitableEvent_1 = require("./BaseEmitableEvent");
5
+ const ApplicationEvents_1 = require("../ApplicationEvents");
6
+ class SellScreenPromotionApplicable extends BaseEmitableEvent_1.BaseEmitableEvent {
7
+ /**
8
+ * Enable or disable a set of already created "applicable" promotions
9
+ * @param key {string} The key to enable or disable, this supports wildcards using an asterisk
10
+ * @param enable {boolean} Whether the key should be enabled or disabled
11
+ */
12
+ constructor(key, enable) {
13
+ super(ApplicationEvents_1.ToShopfront.SELL_SCREEN_PROMOTION_APPLICABLE, {
14
+ key,
15
+ enable,
16
+ });
17
+ }
18
+ }
19
+ exports.SellScreenPromotionApplicable = SellScreenPromotionApplicable;
@@ -1,5 +1,6 @@
1
- export declare abstract class BaseEvent {
2
- protected callback: Function;
3
- protected constructor(callback: Function);
4
- abstract emit(data: object): Promise<any>;
1
+ import { Bridge } from "../Bridge";
2
+ export declare abstract class BaseEvent<TData = any, TCallbackReturn = void, TEmitReturn = any, TCallbackData = TData, TCallbackContext = undefined> {
3
+ protected callback: (data: TCallbackData, context: TCallbackContext) => TCallbackReturn;
4
+ protected constructor(callback: (data: TCallbackData, context: TCallbackContext) => TCallbackReturn);
5
+ abstract emit(data: TData, bridge?: Bridge): Promise<TEmitReturn>;
5
6
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseEvent = void 0;
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
5
  class BaseEvent {
5
6
  constructor(callback) {
6
7
  this.callback = callback;
@@ -2,5 +2,5 @@ import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEven
2
2
  import { BaseEvent } from "./BaseEvent";
3
3
  export declare class Callback extends BaseEvent {
4
4
  constructor(callback: FromShopfrontCallbacks["CALLBACK"]);
5
- emit(data: {}): Promise<FromShopfrontReturns["CALLBACK"]>;
5
+ emit(): Promise<FromShopfrontReturns["CALLBACK"]>;
6
6
  }
@@ -6,8 +6,8 @@ class Callback extends BaseEvent_1.BaseEvent {
6
6
  constructor(callback) {
7
7
  super(callback);
8
8
  }
9
- async emit(data) {
10
- return this.callback();
9
+ async emit() {
10
+ return this.callback(undefined, undefined);
11
11
  }
12
12
  }
13
13
  exports.Callback = Callback;
@@ -1,6 +1,7 @@
1
1
  import { BaseEvent } from "./BaseEvent";
2
2
  import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
3
3
  import { Bridge } from "../Bridge";
4
+ import { MaybePromise } from "../Utilities/MiscTypes";
4
5
  export declare type FormattedSaleProductType = "Normal" | "Product" | "GiftCard" | "Voucher" | "Basket" | "Package" | "Component" | "Integrated";
5
6
  export interface SaleGiftCard {
6
7
  code: string;
@@ -60,13 +61,23 @@ export interface FormattedSaleProduct {
60
61
  requestPrice?: boolean;
61
62
  lockQuantity: boolean;
62
63
  metaData: {
63
- [key: string]: any;
64
+ [key: string]: unknown;
64
65
  };
65
66
  }
66
- export declare class FormatIntegratedProduct extends BaseEvent {
67
+ export declare class FormatIntegratedProduct extends BaseEvent<{
68
+ data: {
69
+ product: FormattedSaleProduct;
70
+ };
71
+ context: Record<string, never>;
72
+ }, MaybePromise<FromShopfrontReturns["FORMAT_INTEGRATED_PRODUCT"]>, FromShopfrontReturns["FORMAT_INTEGRATED_PRODUCT"], {
73
+ product: FormattedSaleProduct;
74
+ }, Record<string, never>> {
67
75
  constructor(callback: FromShopfrontCallbacks["FORMAT_INTEGRATED_PRODUCT"]);
68
76
  emit(data: {
69
- product: FormattedSaleProduct;
77
+ data: {
78
+ product: FormattedSaleProduct;
79
+ };
80
+ context: Record<string, never>;
70
81
  }): Promise<FromShopfrontReturns["FORMAT_INTEGRATED_PRODUCT"]>;
71
82
  static respond(bridge: Bridge, data: Array<FromShopfrontReturns["FORMAT_INTEGRATED_PRODUCT"]>, id: string): Promise<void>;
72
83
  }
@@ -8,7 +8,7 @@ class FormatIntegratedProduct extends BaseEvent_1.BaseEvent {
8
8
  super(callback);
9
9
  }
10
10
  async emit(data) {
11
- const result = await Promise.resolve(this.callback(data));
11
+ const result = await this.callback(data.data, data.context);
12
12
  if (typeof result !== "object" || result === null) {
13
13
  throw new TypeError("Callback must return an object");
14
14
  }
@@ -1,14 +1,10 @@
1
1
  import { BaseEvent } from "./BaseEvent";
2
- import { FromShopfront, FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
2
+ import { FromShopfront, FromShopfrontCallbacks, FromShopfrontReturns, InternalPageMessageEvent } from "../ApplicationEvents";
3
3
  import { InternalMessageSource } from "../APIs/InternalMessages/InternalMessageSource";
4
4
  import { Application } from "../Application";
5
- export declare class InternalPageMessage extends BaseEvent {
5
+ export declare class InternalPageMessage extends BaseEvent<InternalPageMessageEvent> {
6
6
  protected application: Application;
7
7
  constructor(callback: FromShopfrontCallbacks["INTERNAL_PAGE_MESSAGE"], application: Application);
8
- protected createReference(method: keyof FromShopfront, url: string): InternalMessageSource;
9
- emit(data: {
10
- method: keyof FromShopfront;
11
- url: string;
12
- message: any;
13
- }): Promise<FromShopfrontReturns["INTERNAL_PAGE_MESSAGE"]>;
8
+ protected createReference(method: keyof FromShopfront | "EXTERNAL_APPLICATION", url: string): InternalMessageSource;
9
+ emit(data: InternalPageMessageEvent): Promise<FromShopfrontReturns["INTERNAL_PAGE_MESSAGE"]>;
14
10
  }
@@ -17,7 +17,7 @@ class InternalPageMessage extends BaseEvent_1.BaseEvent {
17
17
  url: data.url,
18
18
  message: data.message,
19
19
  reference: this.createReference(data.method, data.url)
20
- });
20
+ }, undefined);
21
21
  }
22
22
  }
23
23
  exports.InternalPageMessage = InternalPageMessage;
@@ -0,0 +1,15 @@
1
+ import { BaseEvent } from "./BaseEvent";
2
+ import { FromShopfrontCallbacks, FromShopfrontReturns, PaymentMethodEnabledContext, SellScreenPaymentMethod } from "../ApplicationEvents";
3
+ import { Bridge } from "../Bridge";
4
+ import { MaybePromise } from "../Utilities/MiscTypes";
5
+ export declare class PaymentMethodsEnabled extends BaseEvent<{
6
+ data: Array<SellScreenPaymentMethod>;
7
+ context: PaymentMethodEnabledContext;
8
+ }, MaybePromise<FromShopfrontReturns["PAYMENT_METHODS_ENABLED"]>, FromShopfrontReturns["PAYMENT_METHODS_ENABLED"], Array<SellScreenPaymentMethod>, PaymentMethodEnabledContext> {
9
+ constructor(callback: FromShopfrontCallbacks["PAYMENT_METHODS_ENABLED"]);
10
+ emit(data: {
11
+ data: Array<SellScreenPaymentMethod>;
12
+ context: PaymentMethodEnabledContext;
13
+ }): Promise<FromShopfrontReturns["PAYMENT_METHODS_ENABLED"]>;
14
+ static respond(bridge: Bridge, data: FromShopfrontReturns["PAYMENT_METHODS_ENABLED"], id: string): Promise<void>;
15
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaymentMethodsEnabled = void 0;
4
+ const BaseEvent_1 = require("./BaseEvent");
5
+ const ApplicationEvents_1 = require("../ApplicationEvents");
6
+ class PaymentMethodsEnabled extends BaseEvent_1.BaseEvent {
7
+ constructor(callback) {
8
+ super(callback);
9
+ }
10
+ async emit(data) {
11
+ const result = await this.callback(data.data, data.context);
12
+ if (typeof result !== "object" || result === null) {
13
+ throw new TypeError("Callback must return an object");
14
+ }
15
+ return result;
16
+ }
17
+ static async respond(bridge, data, id) {
18
+ bridge.sendMessage(ApplicationEvents_1.ToShopfront.RESPONSE_UI_PIPELINE, data, id);
19
+ }
20
+ }
21
+ exports.PaymentMethodsEnabled = PaymentMethodsEnabled;
@@ -1,6 +1,6 @@
1
- import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
1
+ import { FromShopfrontCallbacks, FromShopfrontReturns, RegisterChangedEvent } from "../ApplicationEvents";
2
2
  import { BaseEvent } from "./BaseEvent";
3
- export declare class Ready extends BaseEvent {
3
+ export declare class Ready extends BaseEvent<RegisterChangedEvent> {
4
4
  constructor(callback: FromShopfrontCallbacks["READY"]);
5
5
  emit(data: {
6
6
  outlet: string | null;
@@ -11,7 +11,7 @@ class Ready extends BaseEvent_1.BaseEvent {
11
11
  outlet: data.outlet,
12
12
  register: data.register,
13
13
  user: data.user,
14
- });
14
+ }, undefined);
15
15
  }
16
16
  }
17
17
  exports.Ready = Ready;
@@ -7,7 +7,7 @@ class RegisterChanged extends BaseEvent_1.BaseEvent {
7
7
  super(callback);
8
8
  }
9
9
  async emit(data) {
10
- this.callback(data);
10
+ this.callback(data, undefined);
11
11
  }
12
12
  }
13
13
  exports.RegisterChanged = RegisterChanged;
@@ -1,12 +1,17 @@
1
1
  import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
2
2
  import { Bridge, Button } from "..";
3
3
  import { BaseEvent } from "./BaseEvent";
4
- export declare class RequestButtons extends BaseEvent {
4
+ import { MaybePromise } from "../Utilities/MiscTypes";
5
+ export declare class RequestButtons extends BaseEvent<{
6
+ location: string;
7
+ id: string;
8
+ context: unknown;
9
+ }, MaybePromise<FromShopfrontReturns["REQUEST_BUTTONS"]>, MaybePromise<FromShopfrontReturns["REQUEST_BUTTONS"]>, string, unknown> {
5
10
  constructor(callback: FromShopfrontCallbacks["REQUEST_BUTTONS"]);
6
11
  emit(data: {
7
12
  location: string;
8
13
  id: string;
9
- context: any;
14
+ context: unknown;
10
15
  }): Promise<FromShopfrontReturns["REQUEST_BUTTONS"]>;
11
16
  static respond(bridge: Bridge, buttons: Array<Button>, id: string): Promise<void>;
12
17
  }
@@ -9,7 +9,7 @@ class RequestButtons extends BaseEvent_1.BaseEvent {
9
9
  super(callback);
10
10
  }
11
11
  async emit(data) {
12
- let result = await Promise.resolve(this.callback(data.location, data.context));
12
+ let result = await this.callback(data.location, data.context);
13
13
  if (!Array.isArray(result)) {
14
14
  result = [result];
15
15
  }
@@ -21,7 +21,7 @@ class RequestButtons extends BaseEvent_1.BaseEvent {
21
21
  return result;
22
22
  }
23
23
  static async respond(bridge, buttons, id) {
24
- let response = [];
24
+ const response = [];
25
25
  for (let i = 0, l = buttons.length; i < l; i++) {
26
26
  if (!(buttons[i] instanceof __1.Button)) {
27
27
  throw new TypeError("Invalid response returned, expected button");
@@ -1,12 +1,13 @@
1
1
  import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
2
2
  import { Bridge } from "..";
3
3
  import { BaseEvent } from "./BaseEvent";
4
+ import { MaybePromise } from "../Utilities/MiscTypes";
4
5
  export interface SellScreenCustomerListOption {
5
6
  contents: string;
6
7
  onClick: () => void;
7
8
  }
8
- export declare class RequestCustomerListOptions extends BaseEvent {
9
+ export declare class RequestCustomerListOptions extends BaseEvent<Record<string, unknown>, MaybePromise<FromShopfrontReturns["REQUEST_CUSTOMER_LIST_OPTIONS"]>, FromShopfrontReturns["REQUEST_CUSTOMER_LIST_OPTIONS"], undefined> {
9
10
  constructor(callback: FromShopfrontCallbacks["REQUEST_CUSTOMER_LIST_OPTIONS"]);
10
- emit(data: {}): Promise<FromShopfrontReturns["REQUEST_CUSTOMER_LIST_OPTIONS"]>;
11
+ emit(_: Record<string, unknown>): Promise<FromShopfrontReturns["REQUEST_CUSTOMER_LIST_OPTIONS"]>;
11
12
  static respond(bridge: Bridge, options: Array<SellScreenCustomerListOption>, id: string): Promise<void>;
12
13
  }
@@ -8,8 +8,9 @@ class RequestCustomerListOptions extends BaseEvent_1.BaseEvent {
8
8
  constructor(callback) {
9
9
  super(callback);
10
10
  }
11
- async emit(data) {
12
- let result = await Promise.resolve(this.callback());
11
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
+ async emit(_) {
13
+ let result = await this.callback(undefined, undefined);
13
14
  if (!Array.isArray(result)) {
14
15
  result = [result];
15
16
  }
@@ -2,7 +2,8 @@ import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEven
2
2
  import { Bridge } from "..";
3
3
  import { BaseEvent } from "./BaseEvent";
4
4
  import { SaleKey } from "../Actions/SaleKey";
5
- export declare class RequestSaleKeys extends BaseEvent {
5
+ import { MaybePromise } from "../Utilities/MiscTypes";
6
+ export declare class RequestSaleKeys extends BaseEvent<undefined, MaybePromise<Array<SaleKey>>, Array<SaleKey>> {
6
7
  constructor(callback: FromShopfrontCallbacks["REQUEST_SALE_KEYS"]);
7
8
  emit(): Promise<FromShopfrontReturns["REQUEST_SALE_KEYS"]>;
8
9
  static respond(bridge: Bridge, keys: Array<SaleKey>, id: string): Promise<void>;
@@ -9,7 +9,7 @@ class RequestSaleKeys extends BaseEvent_1.BaseEvent {
9
9
  super(callback);
10
10
  }
11
11
  async emit() {
12
- let result = await Promise.resolve(this.callback());
12
+ let result = await this.callback(undefined, undefined);
13
13
  if (!Array.isArray(result)) {
14
14
  result = [result];
15
15
  }
@@ -21,7 +21,7 @@ class RequestSaleKeys extends BaseEvent_1.BaseEvent {
21
21
  return result;
22
22
  }
23
23
  static async respond(bridge, keys, id) {
24
- let response = [];
24
+ const response = [];
25
25
  for (let i = 0, l = keys.length; i < l; i++) {
26
26
  if (!(keys[i] instanceof SaleKey_1.SaleKey)) {
27
27
  throw new TypeError("Invalid response returned, expected SaleKey");
@@ -1,15 +1,16 @@
1
1
  import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
2
2
  import { Bridge } from "..";
3
3
  import { BaseEvent } from "./BaseEvent";
4
+ import { MaybePromise } from "../Utilities/MiscTypes";
4
5
  export interface SellScreenOption {
5
6
  url: string;
6
7
  title: string;
7
8
  id?: string;
8
9
  }
9
- export declare class RequestSellScreenOptions extends BaseEvent {
10
+ export declare class RequestSellScreenOptions extends BaseEvent<undefined, MaybePromise<FromShopfrontReturns["REQUEST_SELL_SCREEN_OPTIONS"]>, FromShopfrontReturns["REQUEST_SELL_SCREEN_OPTIONS"]> {
10
11
  constructor(callback: FromShopfrontCallbacks["REQUEST_SELL_SCREEN_OPTIONS"]);
11
12
  static getOptionId(url: string): string;
12
13
  static validateURL(url: string): void;
13
- emit(data: {}): Promise<FromShopfrontReturns["REQUEST_SELL_SCREEN_OPTIONS"]>;
14
+ emit(_: never): Promise<FromShopfrontReturns["REQUEST_SELL_SCREEN_OPTIONS"]>;
14
15
  static respond(bridge: Bridge, options: Array<SellScreenOption>, id: string): Promise<void>;
15
16
  }
@@ -22,8 +22,9 @@ class RequestSellScreenOptions extends BaseEvent_1.BaseEvent {
22
22
  throw new TypeError(`The URL "${url}" is invalid, please ensure that you're using the HTTPS protocol`);
23
23
  }
24
24
  }
25
- async emit(data) {
26
- let result = await Promise.resolve(this.callback());
25
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
26
+ async emit(_) {
27
+ let result = await this.callback(undefined, undefined);
27
28
  if (!Array.isArray(result)) {
28
29
  result = [result];
29
30
  }
@@ -1,8 +1,9 @@
1
1
  import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
2
2
  import { BaseEvent } from "./BaseEvent";
3
3
  import { Bridge } from "../Bridge";
4
- export declare class RequestSettings extends BaseEvent {
4
+ import { MaybePromise } from "../Utilities/MiscTypes";
5
+ export declare class RequestSettings extends BaseEvent<undefined, MaybePromise<FromShopfrontReturns["REQUEST_SETTINGS"]>, FromShopfrontReturns["REQUEST_SETTINGS"]> {
5
6
  constructor(callback: FromShopfrontCallbacks["REQUEST_SETTINGS"]);
6
- emit(data: {}): Promise<FromShopfrontReturns["REQUEST_SETTINGS"]>;
7
+ emit(_: never): Promise<FromShopfrontReturns["REQUEST_SETTINGS"]>;
7
8
  static respond(bridge: Bridge, settings: Array<FromShopfrontReturns["REQUEST_SETTINGS"]>, id: string): Promise<void>;
8
9
  }
@@ -7,8 +7,9 @@ class RequestSettings extends BaseEvent_1.BaseEvent {
7
7
  constructor(callback) {
8
8
  super(callback);
9
9
  }
10
- async emit(data) {
11
- const result = await Promise.resolve(this.callback());
10
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+ async emit(_) {
12
+ const result = await this.callback(undefined, undefined);
12
13
  if (typeof result !== "object" || result === null) {
13
14
  throw new TypeError("Callback must return an object");
14
15
  }
@@ -1,11 +1,15 @@
1
1
  import { FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
2
2
  import { BaseEvent } from "./BaseEvent";
3
3
  import { Bridge } from "../Bridge";
4
- export declare class RequestTableColumns extends BaseEvent {
4
+ import { MaybePromise } from "../Utilities/MiscTypes";
5
+ export declare class RequestTableColumns extends BaseEvent<{
6
+ location: string;
7
+ context: unknown;
8
+ }, MaybePromise<FromShopfrontReturns["REQUEST_TABLE_COLUMNS"]>, FromShopfrontReturns["REQUEST_TABLE_COLUMNS"], string, unknown> {
5
9
  constructor(callback: FromShopfrontCallbacks["REQUEST_TABLE_COLUMNS"]);
6
10
  emit(data: {
7
11
  location: string;
8
- context: any;
12
+ context: unknown;
9
13
  }): Promise<FromShopfrontReturns["REQUEST_TABLE_COLUMNS"]>;
10
14
  static respond(bridge: Bridge, columns: Array<FromShopfrontReturns["REQUEST_TABLE_COLUMNS"]>, id: string): Promise<void>;
11
15
  }
@@ -8,7 +8,7 @@ class RequestTableColumns extends BaseEvent_1.BaseEvent {
8
8
  super(callback);
9
9
  }
10
10
  async emit(data) {
11
- const result = await Promise.resolve(this.callback(data.location, data.context));
11
+ const result = await this.callback(data.location, data.context);
12
12
  if (typeof result !== "object") {
13
13
  throw new TypeError("Callback must return an object");
14
14
  }
@@ -57,7 +57,7 @@ interface CompletedSaleProduct {
57
57
  requestPrice?: boolean;
58
58
  lockQuantity: boolean;
59
59
  metaData: {
60
- [key: string]: any;
60
+ [key: string]: unknown;
61
61
  };
62
62
  }
63
63
  interface CompletedSalePayment {
@@ -7,7 +7,7 @@ class SaleComplete extends BaseEvent_1.BaseEvent {
7
7
  super(callback);
8
8
  }
9
9
  async emit(data) {
10
- this.callback(data);
10
+ this.callback(data, undefined);
11
11
  }
12
12
  }
13
13
  exports.SaleComplete = SaleComplete;
@@ -0,0 +1,15 @@
1
+ import { BaseEvent } from "./BaseEvent";
2
+ import { FromShopfrontCallbacks, FromShopfrontReturns, UIPipelineBaseContext, UIPipelineContext, UIPipelineResponse } from "../ApplicationEvents";
3
+ import { Bridge } from "../Bridge";
4
+ import { MaybePromise } from "../Utilities/MiscTypes";
5
+ interface UIPPipelineIncomingData {
6
+ data: Array<UIPipelineResponse>;
7
+ context: UIPipelineBaseContext;
8
+ pipelineId?: string;
9
+ }
10
+ export declare class UIPipeline extends BaseEvent<UIPPipelineIncomingData, MaybePromise<FromShopfrontReturns["UI_PIPELINE"]>, FromShopfrontReturns["UI_PIPELINE"], Array<UIPipelineResponse>, UIPipelineContext> {
11
+ constructor(callback: FromShopfrontCallbacks["UI_PIPELINE"]);
12
+ emit(data: UIPPipelineIncomingData, bridge: Bridge): Promise<FromShopfrontReturns["UI_PIPELINE"]>;
13
+ static respond(bridge: Bridge, data: FromShopfrontReturns["UI_PIPELINE"], id: string): Promise<void>;
14
+ }
15
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UIPipeline = void 0;
4
+ const BaseEvent_1 = require("./BaseEvent");
5
+ const ApplicationEvents_1 = require("../ApplicationEvents");
6
+ class UIPipeline extends BaseEvent_1.BaseEvent {
7
+ constructor(callback) {
8
+ super(callback);
9
+ }
10
+ async emit(data, bridge) {
11
+ const context = {
12
+ ...data.context
13
+ };
14
+ if (typeof data.pipelineId === "string") {
15
+ context.trigger = () => {
16
+ bridge.sendMessage(ApplicationEvents_1.ToShopfront.PIPELINE_TRIGGER, {
17
+ id: data.pipelineId,
18
+ });
19
+ };
20
+ }
21
+ const result = await this.callback(data.data, context);
22
+ if (typeof result !== "object" || result === null) {
23
+ throw new TypeError("Callback must return an object");
24
+ }
25
+ return result;
26
+ }
27
+ static async respond(bridge, data, id) {
28
+ bridge.sendMessage(ApplicationEvents_1.ToShopfront.RESPONSE_UI_PIPELINE, data, id);
29
+ }
30
+ }
31
+ exports.UIPipeline = UIPipeline;
@@ -1,12 +1,12 @@
1
1
  import { BaseAction } from "../Actions/BaseAction";
2
2
  declare class ActionEventRegistrar {
3
3
  events: {
4
- [id: string]: BaseAction<any>;
4
+ [id: string]: BaseAction<undefined>;
5
5
  };
6
6
  constructor();
7
- add(id: string, action: BaseAction<any>): void;
7
+ add(id: string, action: BaseAction<undefined>): void;
8
8
  remove(id: string): void;
9
- fire(id: string, data: any): void;
9
+ fire(id: string, data: unknown): void;
10
10
  clear(): void;
11
11
  }
12
12
  declare const _default: ActionEventRegistrar;
@@ -2,3 +2,6 @@
2
2
  * A property which might be a promise or the promise's wrapped type
3
3
  */
4
4
  export declare type MaybePromise<P> = P | Promise<P>;
5
+ export interface ConstructorClass<T> {
6
+ new (...args: Array<unknown>): T;
7
+ }
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ // noinspection JSUnusedLocalSymbols
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.staticImplements = void 0;
4
5
  function staticImplements() {
6
+ // eslint-disable-next-line @typescript-eslint/no-empty-function,@typescript-eslint/no-unused-vars
5
7
  return (constructor) => { };
6
8
  }
7
9
  exports.staticImplements = staticImplements;
package/lib/index.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  export { Bridge } from "./Bridge";
2
2
  export { Button } from "./Actions/Button";
3
3
  export { Redirect } from "./Actions/Redirect";
4
- export { Toast } from "./Actions/Toast";
4
+ export { Toast, ToastType } from "./Actions/Toast";
5
5
  export { Dialog } from "./Actions/Dialog";
6
6
  export { SaleKey } from "./Actions/SaleKey";
7
7
  export { SellScreenOption } from "./EmitableEvents/SellScreenOption";
8
8
  export { TableUpdate } from "./EmitableEvents/TableUpdate";
9
+ export { SellScreenPromotionApplicable } from "./EmitableEvents/SellScreenPromotionApplicable";
9
10
  export { CompletedSale } from "./Events/SaleComplete";
10
11
  export { Application } from "./Application";
11
12
  export * as Sales from "./APIs/CurrentSale/index";
package/lib/index.js CHANGED
@@ -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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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];
@@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
23
  return result;
20
24
  };
21
25
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.Sales = exports.Application = exports.TableUpdate = exports.SellScreenOption = exports.SaleKey = exports.Dialog = exports.Toast = exports.Redirect = exports.Button = exports.Bridge = void 0;
26
+ exports.Sales = exports.Application = exports.SellScreenPromotionApplicable = exports.TableUpdate = exports.SellScreenOption = exports.SaleKey = exports.Dialog = exports.Toast = exports.Redirect = exports.Button = exports.Bridge = void 0;
23
27
  var Bridge_1 = require("./Bridge");
24
28
  Object.defineProperty(exports, "Bridge", { enumerable: true, get: function () { return Bridge_1.Bridge; } });
25
29
  var Button_1 = require("./Actions/Button");
@@ -36,6 +40,8 @@ var SellScreenOption_1 = require("./EmitableEvents/SellScreenOption");
36
40
  Object.defineProperty(exports, "SellScreenOption", { enumerable: true, get: function () { return SellScreenOption_1.SellScreenOption; } });
37
41
  var TableUpdate_1 = require("./EmitableEvents/TableUpdate");
38
42
  Object.defineProperty(exports, "TableUpdate", { enumerable: true, get: function () { return TableUpdate_1.TableUpdate; } });
43
+ var SellScreenPromotionApplicable_1 = require("./EmitableEvents/SellScreenPromotionApplicable");
44
+ Object.defineProperty(exports, "SellScreenPromotionApplicable", { enumerable: true, get: function () { return SellScreenPromotionApplicable_1.SellScreenPromotionApplicable; } });
39
45
  var Application_1 = require("./Application");
40
46
  Object.defineProperty(exports, "Application", { enumerable: true, get: function () { return Application_1.Application; } });
41
47
  exports.Sales = __importStar(require("./APIs/CurrentSale/index"));