@shopfront/bridge 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.idea/misc.xml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JavaScriptSettings">
4
+ <option name="languageLevel" value="ES6" />
5
+ </component>
6
+ <component name="NodePackageJsonFileManager">
7
+ <packageJsonPaths />
8
+ </component>
9
+ </project>
package/.idea/modules.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <project version="4">
3
3
  <component name="ProjectModuleManager">
4
4
  <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/embedded-bridge.iml" filepath="$PROJECT_DIR$/.idea/embedded-bridge.iml" />
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/shopfront-embedded-bridge.iml" filepath="$PROJECT_DIR$/.idea/shopfront-embedded-bridge.iml" />
6
6
  </modules>
7
7
  </component>
8
8
  </project>
package/.idea/php.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="PhpProjectSharedConfiguration" php_language_level="7.2" />
4
+ </project>
@@ -1,9 +1,7 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <module type="WEB_MODULE" version="4">
3
3
  <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$">
5
- <excludeFolder url="file://$MODULE_DIR$/lib" />
6
- </content>
4
+ <content url="file://$MODULE_DIR$" />
7
5
  <orderEntry type="inheritedJdk" />
8
6
  <orderEntry type="sourceFolder" forTests="false" />
9
7
  </component>
@@ -1,5 +1,5 @@
1
1
  import { Bridge } from "./Bridge";
2
- import { DirectShopfrontEvent, FromShopfront, FromShopfrontCallbacks, FromShopfrontInternal, RegisterChangedEvent } from "./ApplicationEvents";
2
+ import { DirectShopfrontEvent, FromShopfront, FromShopfrontCallbacks, FromShopfrontInternal, RegisterChangedEvent, SoundEvents } from "./ApplicationEvents";
3
3
  import { Serializable } from "./Common/Serializable";
4
4
  import { BaseEmitableEvent } from "./EmitableEvents/BaseEmitableEvent";
5
5
  import { Sale } from "./APIs/CurrentSale";
@@ -65,6 +65,38 @@ export declare class Application {
65
65
  user: string | null;
66
66
  }>;
67
67
  printReceipt(content: string): void;
68
+ protected dataIsAudioResponse(data: Record<string, unknown>): data is {
69
+ requestId: string;
70
+ success: boolean;
71
+ message?: string;
72
+ };
73
+ protected sendAudioRequest(type: SoundEvents, data?: unknown): Promise<{
74
+ success: boolean;
75
+ message?: string;
76
+ }>;
77
+ /**
78
+ * Requests permission from the user to be able to play audio
79
+ */
80
+ requestAudioPermission(): Promise<{
81
+ success: boolean;
82
+ message?: string;
83
+ }>;
84
+ /**
85
+ * Requests shopfront to preload audio so that it can be pre-cached before being played
86
+ * @param url
87
+ */
88
+ audioPreload(url: string): Promise<{
89
+ success: boolean;
90
+ message?: string;
91
+ }>;
92
+ /**
93
+ * Requests the sound to be played
94
+ * @param url
95
+ */
96
+ audioPlay(url: string): Promise<{
97
+ success: boolean;
98
+ message?: string;
99
+ }>;
68
100
  protected dataIsOption<TValueType>(data: Record<string, unknown>): data is {
69
101
  requestId: string;
70
102
  option: string;
@@ -23,6 +23,7 @@ const RequestSaleKeys_1 = require("./Events/RequestSaleKeys");
23
23
  const SaleComplete_1 = require("./Events/SaleComplete");
24
24
  const UIPipeline_1 = require("./Events/UIPipeline");
25
25
  const PaymentMethodsEnabled_1 = require("./Events/PaymentMethodsEnabled");
26
+ const AudioPermissionChange_1 = require("./Events/AudioPermissionChange");
26
27
  // noinspection JSUnusedGlobalSymbols
27
28
  class Application {
28
29
  constructor(bridge) {
@@ -40,6 +41,7 @@ class Application {
40
41
  SALE_COMPLETE: new Map(),
41
42
  UI_PIPELINE: new Map(),
42
43
  PAYMENT_METHODS_ENABLED: new Map(),
44
+ AUDIO_PERMISSION_CHANGE: new Map(),
43
45
  };
44
46
  this.directListeners = {};
45
47
  this.handleEvent = (event, data, id) => {
@@ -70,7 +72,8 @@ class Application {
70
72
  else if (event === "RESPONSE_CURRENT_SALE" ||
71
73
  event === "RESPONSE_DATABASE_REQUEST" ||
72
74
  event === "RESPONSE_LOCATION" ||
73
- event === "RESPONSE_OPTION") {
75
+ event === "RESPONSE_OPTION" ||
76
+ event === "RESPONSE_AUDIO_REQUEST") {
74
77
  // Handled elsewhere
75
78
  return;
76
79
  }
@@ -236,6 +239,10 @@ class Application {
236
239
  c = new PaymentMethodsEnabled_1.PaymentMethodsEnabled(callback);
237
240
  this.listeners[event].set(callback, c);
238
241
  break;
242
+ case "AUDIO_PERMISSION_CHANGE":
243
+ c = new AudioPermissionChange_1.AudioPermissionChange(callback);
244
+ this.listeners[event].set(callback, c);
245
+ break;
239
246
  }
240
247
  if (typeof c === "undefined") {
241
248
  throw new TypeError(`${event} has not been defined`);
@@ -375,6 +382,62 @@ class Application {
375
382
  type: "text",
376
383
  });
377
384
  }
385
+ dataIsAudioResponse(data) {
386
+ return typeof data.requestId === "string" &&
387
+ typeof data.success === "boolean" && (typeof data.message === "string" ||
388
+ typeof data.message === "undefined");
389
+ }
390
+ sendAudioRequest(type, data) {
391
+ const request = `AudioRequest-${type}-${Date.now().toString()}`;
392
+ const promise = new Promise(res => {
393
+ const listener = (event, data) => {
394
+ if (event !== "RESPONSE_AUDIO_REQUEST") {
395
+ return;
396
+ }
397
+ if (!this.dataIsAudioResponse(data)) {
398
+ return;
399
+ }
400
+ if (data.requestId !== request) {
401
+ return;
402
+ }
403
+ this.bridge.removeEventListener(listener);
404
+ res({
405
+ success: data.success,
406
+ message: data.message,
407
+ });
408
+ };
409
+ this.bridge.addEventListener(listener);
410
+ });
411
+ this.bridge.sendMessage(type, {
412
+ requestId: request,
413
+ data,
414
+ });
415
+ return promise;
416
+ }
417
+ /**
418
+ * Requests permission from the user to be able to play audio
419
+ */
420
+ requestAudioPermission() {
421
+ return this.sendAudioRequest(ApplicationEvents_1.ToShopfront.AUDIO_REQUEST_PERMISSION);
422
+ }
423
+ /**
424
+ * Requests shopfront to preload audio so that it can be pre-cached before being played
425
+ * @param url
426
+ */
427
+ audioPreload(url) {
428
+ return this.sendAudioRequest(ApplicationEvents_1.ToShopfront.AUDIO_PRELOAD, {
429
+ url
430
+ });
431
+ }
432
+ /**
433
+ * Requests the sound to be played
434
+ * @param url
435
+ */
436
+ audioPlay(url) {
437
+ return this.sendAudioRequest(ApplicationEvents_1.ToShopfront.AUDIO_PLAY, {
438
+ url
439
+ });
440
+ }
378
441
  dataIsOption(data) {
379
442
  return typeof data.requestId === "string" && typeof data.option === "string";
380
443
  }
@@ -17,6 +17,7 @@ import { RequestSaleKeys } from "./Events/RequestSaleKeys";
17
17
  import { CompletedSale, SaleComplete } from "./Events/SaleComplete";
18
18
  import { UIPipeline } from "./Events/UIPipeline";
19
19
  import { PaymentMethodsEnabled } from "./Events/PaymentMethodsEnabled";
20
+ import { AudioPermissionChange } from "./Events/AudioPermissionChange";
20
21
  export declare enum ToShopfront {
21
22
  READY = "READY",
22
23
  SERIALIZED = "SERIALIZED",
@@ -38,12 +39,16 @@ export declare enum ToShopfront {
38
39
  REDIRECT = "REDIRECT",
39
40
  GET_OPTION = "GET_OPTION",
40
41
  RESPONSE_UI_PIPELINE = "RESPONSE_UI_PIPELINE",
42
+ AUDIO_REQUEST_PERMISSION = "AUDIO_REQUEST_PERMISSION",
43
+ AUDIO_PRELOAD = "AUDIO_PRELOAD",
44
+ AUDIO_PLAY = "AUDIO_PLAY",
41
45
  SELL_SCREEN_OPTION_CHANGE = "SELL_SCREEN_OPTION_CHANGE",
42
46
  INTERNAL_PAGE_MESSAGE = "INTERNAL_PAGE_MESSAGE",
43
47
  TABLE_UPDATE = "TABLE_UPDATE",
44
48
  PIPELINE_TRIGGER = "PIPELINE_TRIGGER",
45
49
  SELL_SCREEN_PROMOTION_APPLICABLE = "SELL_SCREEN_PROMOTION_APPLICABLE"
46
50
  }
51
+ export declare type SoundEvents = ToShopfront.AUDIO_REQUEST_PERMISSION | ToShopfront.AUDIO_PRELOAD | ToShopfront.AUDIO_PLAY;
47
52
  export interface FromShopfrontReturns {
48
53
  READY: void;
49
54
  REQUEST_SETTINGS: {
@@ -79,12 +84,18 @@ export interface FromShopfrontReturns {
79
84
  outlet: string | null;
80
85
  user: string | null;
81
86
  };
87
+ RESPONSE_AUDIO_REQUEST: {
88
+ requestId: string;
89
+ success: boolean;
90
+ message?: string;
91
+ };
82
92
  FORMAT_INTEGRATED_PRODUCT: FormatIntegratedProductEvent;
83
93
  REQUEST_CUSTOMER_LIST_OPTIONS: Array<SellScreenCustomerListOption>;
84
94
  REQUEST_SALE_KEYS: Array<SaleKey>;
85
95
  SALE_COMPLETE: void;
86
96
  UI_PIPELINE: Array<UIPipelineResponse>;
87
97
  PAYMENT_METHODS_ENABLED: Array<SellScreenPaymentMethod>;
98
+ AUDIO_PERMISSION_CHANGE: void;
88
99
  }
89
100
  export interface InternalPageMessageEvent {
90
101
  method: "REQUEST_SETTINGS" | "REQUEST_SELL_SCREEN_OPTIONS" | "EXTERNAL_APPLICATION";
@@ -103,6 +114,9 @@ export interface FormatIntegratedProductEvent {
103
114
  export interface SaleCompletedEvent {
104
115
  sale: CompletedSale;
105
116
  }
117
+ export interface AudioPermissionChangeEvent {
118
+ permitted: boolean;
119
+ }
106
120
  export declare type UIPipelineResponse = {
107
121
  name: string;
108
122
  content: string;
@@ -142,6 +156,7 @@ export interface FromShopfrontCallbacks {
142
156
  SALE_COMPLETE: (event: SaleCompletedEvent) => MaybePromise<FromShopfrontReturns["SALE_COMPLETE"]>;
143
157
  UI_PIPELINE: (event: Array<UIPipelineResponse>, context: UIPipelineContext) => MaybePromise<FromShopfrontReturns["UI_PIPELINE"]>;
144
158
  PAYMENT_METHODS_ENABLED: (event: Array<SellScreenPaymentMethod>, context: PaymentMethodEnabledContext) => MaybePromise<FromShopfrontReturns["PAYMENT_METHODS_ENABLED"]>;
159
+ AUDIO_PERMISSION_CHANGE: (event: AudioPermissionChangeEvent) => MaybePromise<FromShopfrontReturns["AUDIO_PERMISSION_CHANGE"]>;
145
160
  }
146
161
  export interface FromShopfront {
147
162
  READY: Ready;
@@ -158,6 +173,7 @@ export interface FromShopfront {
158
173
  REQUEST_SALE_KEYS: RequestSaleKeys;
159
174
  UI_PIPELINE: UIPipeline;
160
175
  PAYMENT_METHODS_ENABLED: PaymentMethodsEnabled;
176
+ AUDIO_PERMISSION_CHANGE: AudioPermissionChange;
161
177
  }
162
178
  export declare const directShopfrontEvents: readonly ["SALE_ADD_PRODUCT", "SALE_REMOVE_PRODUCT", "SALE_UPDATE_PRODUCTS", "SALE_CHANGE_QUANTITY", "SALE_ADD_CUSTOMER", "SALE_REMOVE_CUSTOMER", "SALE_CLEAR"];
163
179
  export declare type DirectShopfrontEvent = typeof directShopfrontEvents[number];
@@ -168,4 +184,5 @@ export interface FromShopfrontInternal {
168
184
  RESPONSE_DATABASE_REQUEST: "RESPONSE_DATABASE_REQUEST";
169
185
  RESPONSE_LOCATION: "RESPONSE_LOCATION";
170
186
  RESPONSE_OPTION: "RESPONSE_OPTION";
187
+ RESPONSE_AUDIO_REQUEST: "RESPONSE_AUDIO_REQUEST";
171
188
  }
@@ -23,6 +23,10 @@ var ToShopfront;
23
23
  ToShopfront["REDIRECT"] = "REDIRECT";
24
24
  ToShopfront["GET_OPTION"] = "GET_OPTION";
25
25
  ToShopfront["RESPONSE_UI_PIPELINE"] = "RESPONSE_UI_PIPELINE";
26
+ // Audio Events
27
+ ToShopfront["AUDIO_REQUEST_PERMISSION"] = "AUDIO_REQUEST_PERMISSION";
28
+ ToShopfront["AUDIO_PRELOAD"] = "AUDIO_PRELOAD";
29
+ ToShopfront["AUDIO_PLAY"] = "AUDIO_PLAY";
26
30
  // Emitable Events
27
31
  ToShopfront["SELL_SCREEN_OPTION_CHANGE"] = "SELL_SCREEN_OPTION_CHANGE";
28
32
  ToShopfront["INTERNAL_PAGE_MESSAGE"] = "INTERNAL_PAGE_MESSAGE";
@@ -0,0 +1,6 @@
1
+ import { BaseEvent } from "./BaseEvent";
2
+ import { AudioPermissionChangeEvent, FromShopfrontCallbacks, FromShopfrontReturns } from "../ApplicationEvents";
3
+ export declare class AudioPermissionChange extends BaseEvent<AudioPermissionChangeEvent> {
4
+ constructor(callback: FromShopfrontCallbacks["AUDIO_PERMISSION_CHANGE"]);
5
+ emit(data: AudioPermissionChangeEvent): Promise<FromShopfrontReturns["AUDIO_PERMISSION_CHANGE"]>;
6
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AudioPermissionChange = void 0;
4
+ const BaseEvent_1 = require("./BaseEvent");
5
+ class AudioPermissionChange extends BaseEvent_1.BaseEvent {
6
+ constructor(callback) {
7
+ super(callback);
8
+ }
9
+ async emit(data) {
10
+ this.callback(data, undefined);
11
+ }
12
+ }
13
+ exports.AudioPermissionChange = AudioPermissionChange;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopfront/bridge",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "main": "./lib/index.js",
5
5
  "license": "ISC",
6
6
  "description": "The bridge used to embed your application within Shopfront",
@@ -1,6 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5
- </profile>
6
- </component>