@expressms/smartapp-sdk 1.12.0-alpha.5 → 1.12.0-alpha.7

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 (46) hide show
  1. package/build/main/index.d.ts +10 -9
  2. package/build/main/index.js +25 -56
  3. package/build/main/lib/client/index.d.ts +1 -2
  4. package/build/main/lib/client/index.js +2 -9
  5. package/build/main/lib/devices/bluetooth.d.ts +52 -0
  6. package/build/main/lib/devices/bluetooth.js +160 -0
  7. package/build/main/lib/devices/gps.d.ts +5 -0
  8. package/build/main/lib/devices/gps.js +20 -0
  9. package/build/main/lib/devices/index.d.ts +5 -0
  10. package/build/main/lib/devices/index.js +35 -0
  11. package/build/main/lib/devices/nfc.d.ts +6 -0
  12. package/build/main/lib/devices/nfc.js +24 -0
  13. package/build/main/lib/notification/index.d.ts +1 -2
  14. package/build/main/lib/notification/index.js +1 -1
  15. package/build/main/lib/routing/index.d.ts +6 -7
  16. package/build/main/lib/routing/index.js +2 -2
  17. package/build/main/types/bridge.d.ts +8 -1
  18. package/build/main/types/bridge.js +8 -1
  19. package/build/main/types/devices.d.ts +53 -0
  20. package/build/main/types/devices.js +3 -0
  21. package/build/main/types/index.d.ts +1 -0
  22. package/build/main/types/index.js +2 -1
  23. package/build/module/index.d.ts +10 -9
  24. package/build/module/index.js +11 -10
  25. package/build/module/lib/client/index.d.ts +1 -2
  26. package/build/module/lib/client/index.js +2 -8
  27. package/build/module/lib/devices/bluetooth.d.ts +52 -0
  28. package/build/module/lib/devices/bluetooth.js +148 -0
  29. package/build/module/lib/devices/gps.d.ts +5 -0
  30. package/build/module/lib/devices/gps.js +13 -0
  31. package/build/module/lib/devices/index.d.ts +5 -0
  32. package/build/module/lib/devices/index.js +6 -0
  33. package/build/module/lib/devices/nfc.d.ts +6 -0
  34. package/build/module/lib/devices/nfc.js +17 -0
  35. package/build/module/lib/notification/index.d.ts +1 -2
  36. package/build/module/lib/notification/index.js +2 -3
  37. package/build/module/lib/routing/index.d.ts +6 -7
  38. package/build/module/lib/routing/index.js +7 -8
  39. package/build/module/types/bridge.d.ts +8 -1
  40. package/build/module/types/bridge.js +8 -1
  41. package/build/module/types/devices.d.ts +53 -0
  42. package/build/module/types/devices.js +2 -0
  43. package/build/module/types/index.d.ts +1 -0
  44. package/build/module/types/index.js +2 -1
  45. package/build/umd/index.js +232 -35
  46. package/package.json +1 -1
@@ -0,0 +1,53 @@
1
+ import { EmitterEventPayload } from '@expressms/smartapp-bridge/build/main/types/eventEmitter';
2
+ import { STATUS, StatusResponse } from './bridge';
3
+ export type BluetoothErrorCode = 'permission_denied' | 'bluetooth_not_found' | 'ble_device_not_found' | 'ble_device_not_connected' | 'ble_gatt_service_not_found' | 'ble_gatt_characteristic_not_found' | 'io_error' | 'error';
4
+ export type BleDevice = {
5
+ address: string;
6
+ name: string;
7
+ };
8
+ export type BleGattCharacteristic = {
9
+ uuid: string;
10
+ };
11
+ export type BleGattService = {
12
+ uuid: string;
13
+ characteristics: Array<BleGattCharacteristic>;
14
+ };
15
+ export interface BluetoothStatusResponse extends StatusResponse {
16
+ payload: {
17
+ status: STATUS;
18
+ errorCode?: BluetoothErrorCode;
19
+ };
20
+ }
21
+ export interface BluetoothScanBleDevicesResponse extends EmitterEventPayload {
22
+ payload: {
23
+ status: STATUS;
24
+ errorCode?: BluetoothErrorCode;
25
+ bleDevices: Array<BleDevice>;
26
+ };
27
+ }
28
+ export interface BluetoothDiscoverGattServicesResponse extends EmitterEventPayload {
29
+ payload: {
30
+ status: STATUS;
31
+ errorCode?: BluetoothErrorCode;
32
+ gattServices: Array<BleGattService>;
33
+ };
34
+ }
35
+ export interface BluetoothBleDeviceFoundEvent extends EmitterEventPayload {
36
+ payload: {
37
+ status: STATUS;
38
+ bleDevice: BleDevice;
39
+ };
40
+ }
41
+ export type BleDeviceCallback = (device: BleDevice) => {};
42
+ export type NfcErrorCode = 'permission_denied' | 'nfc_not_found' | 'nfc_write_error' | 'cancelled_by_user' | 'error';
43
+ export type NfcMessage = Array<number>;
44
+ export interface NfcReadTagResponse extends EmitterEventPayload {
45
+ payload: {
46
+ status: STATUS;
47
+ errorCode?: NfcErrorCode;
48
+ nfcTag: {
49
+ id: string;
50
+ messages: Array<NfcMessage>;
51
+ };
52
+ };
53
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGV2aWNlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy90eXBlcy9kZXZpY2VzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIifQ==
@@ -4,3 +4,4 @@ export * from "./contacts";
4
4
  export * from "./client";
5
5
  export * from "./storage";
6
6
  export * from "./events";
7
+ export * from "./devices";
@@ -4,4 +4,5 @@ export * from "./contacts";
4
4
  export * from "./client";
5
5
  export * from "./storage";
6
6
  export * from "./events";
7
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdHlwZXMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxVQUFVLENBQUE7QUFDeEIsY0FBYyxXQUFXLENBQUE7QUFDekIsY0FBYyxZQUFZLENBQUE7QUFDMUIsY0FBYyxVQUFVLENBQUE7QUFDeEIsY0FBYyxXQUFXLENBQUE7QUFDekIsY0FBYyxVQUFVLENBQUEifQ==
7
+ export * from "./devices";
8
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdHlwZXMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxVQUFVLENBQUE7QUFDeEIsY0FBYyxXQUFXLENBQUE7QUFDekIsY0FBYyxZQUFZLENBQUE7QUFDMUIsY0FBYyxVQUFVLENBQUE7QUFDeEIsY0FBYyxXQUFXLENBQUE7QUFDekIsY0FBYyxVQUFVLENBQUE7QUFDeEIsY0FBYyxXQUFXLENBQUEifQ==
@@ -1999,6 +1999,13 @@
1999
1999
  METHODS["GET_CREDENTIALS"] = "get_credentials";
2000
2000
  METHODS["SET_CREDENTIALS"] = "set_credentials";
2001
2001
  METHODS["RUN_WEB_COMMANDS_PIPELINE"] = "run_web_commands_pipeline";
2002
+ METHODS["ENABLE_BLUETOOTH"] = "enable_bluetooth";
2003
+ METHODS["SCAN_BLE_DEVICES"] = "scan_ble_devices";
2004
+ METHODS["CONNECT_BLE_DEVICE"] = "connect_ble_device";
2005
+ METHODS["DISCONNECT_BLE_DEVICE"] = "disconnect_ble_device";
2006
+ METHODS["DISCOVER_BLE_GATT_SERVICES"] = "discover_ble_gatt_services";
2007
+ METHODS["READ_BLE_GATT_CHARACTERISTIC"] = "read_ble_gatt_characteristic";
2008
+ METHODS["READ_NFC_TAG"] = "read_nfc_tag";
2002
2009
  })(METHODS || (METHODS = {}));
2003
2010
  var STATUS;
2004
2011
  (function (STATUS) {
@@ -2053,7 +2060,7 @@
2053
2060
  const id = getSubscriptionId(eventType, payload);
2054
2061
  return subscriptions.some(sub => sub.id == id);
2055
2062
  };
2056
- const installBridgeEventListener = () => {
2063
+ const installBridgeEventListener$1 = () => {
2057
2064
  if (bridgeEventListenerInstalled || !bridge)
2058
2065
  return;
2059
2066
  bridgeEventListenerInstalled = true;
@@ -2092,7 +2099,7 @@
2092
2099
  const id = getSubscriptionId(eventType, payload);
2093
2100
  if (response.payload.status !== STATUS.SUCCESS)
2094
2101
  return response;
2095
- installBridgeEventListener();
2102
+ installBridgeEventListener$1();
2096
2103
  subscriptions.push({ id, callback });
2097
2104
  return response;
2098
2105
  });
@@ -2242,12 +2249,6 @@
2242
2249
  },
2243
2250
  });
2244
2251
  };
2245
- const requestLocation = () => {
2246
- return bridge?.sendClientEvent({
2247
- method: METHODS.REQUEST_LOCATION,
2248
- params: {},
2249
- });
2250
- };
2251
2252
  /**
2252
2253
  * Get client current connection status. It's based on client's WebSocket connection state.
2253
2254
  * @returns Promise that'll be fullfilled with status data on success, otherwise rejected with reason
@@ -2545,6 +2546,45 @@
2545
2546
  });
2546
2547
  };
2547
2548
 
2549
+ const routingChanged = (isRoot) => {
2550
+ return bridge?.sendClientEvent({
2551
+ method: METHODS.ROUTING_CHANGED,
2552
+ params: {
2553
+ location: isRoot ? LOCATION.ROOT : LOCATION.NESTED,
2554
+ },
2555
+ });
2556
+ };
2557
+ const onBackPressed = (handleBackPressed) => {
2558
+ return bridge?.onReceive(event => {
2559
+ if (event.type === METHODS.BACK_PRESSED)
2560
+ handleBackPressed();
2561
+ });
2562
+ };
2563
+ const openSmartApp = ({ appId, meta }) => {
2564
+ return bridge?.sendClientEvent({
2565
+ method: METHODS.OPEN_SMART_APP,
2566
+ params: meta ? { appId, meta } : { appId },
2567
+ });
2568
+ };
2569
+ const closeSmartApp = () => {
2570
+ return bridge?.sendClientEvent({
2571
+ method: METHODS.CLOSE_SMART_APP,
2572
+ params: {},
2573
+ });
2574
+ };
2575
+ const onMoveToRoot = (handleMoveToRoot) => {
2576
+ return bridge?.onReceive(event => {
2577
+ if (event.type === METHODS.MOVE_TO_ROOT)
2578
+ handleMoveToRoot();
2579
+ });
2580
+ };
2581
+ const exitSmartAppToCatalog = () => {
2582
+ return bridge?.sendClientEvent({
2583
+ method: METHODS.OPEN_SMART_APP,
2584
+ params: { appId: '' },
2585
+ });
2586
+ };
2587
+
2548
2588
  /**
2549
2589
  * Set cookies for web resouce. It's needed for SSO auth cases.
2550
2590
  * @param cookies List of cookie strings !with domains!
@@ -2634,46 +2674,202 @@
2634
2674
  .then(event => event);
2635
2675
  };
2636
2676
 
2637
- const routingChanged = (isRoot) => {
2638
- return bridge?.sendClientEvent({
2639
- method: METHODS.ROUTING_CHANGED,
2640
- params: {
2641
- location: isRoot ? LOCATION.ROOT : LOCATION.NESTED,
2642
- },
2677
+ const deviceCallbacks = [];
2678
+ /**
2679
+ * Install bridge event listener for founded devices during scan
2680
+ */
2681
+ const installBridgeEventListener = () => {
2682
+ if (!bridge)
2683
+ return;
2684
+ bridge.onReceive(event => {
2685
+ if (event.type !== 'ble_device_found')
2686
+ return;
2687
+ const { payload: { bleDevice }, } = event;
2688
+ deviceCallbacks.map(cb => cb(bleDevice));
2643
2689
  });
2644
2690
  };
2645
- const onBackPressed = (handleBackPressed) => {
2646
- return bridge?.onReceive(event => {
2647
- if (event.type === METHODS.BACK_PRESSED)
2648
- handleBackPressed();
2649
- });
2691
+ /**
2692
+ * Add callback to list
2693
+ */
2694
+ const addDeviceCallback = (callback) => {
2695
+ if (callback)
2696
+ deviceCallbacks.push(callback);
2650
2697
  };
2651
- const openSmartApp = ({ appId, meta }) => {
2652
- return bridge?.sendClientEvent({
2653
- method: METHODS.OPEN_SMART_APP,
2654
- params: meta ? { appId, meta } : { appId },
2655
- });
2698
+ /**
2699
+ * Remove callback from list
2700
+ */
2701
+ const removeDeviceCallback = (callback) => {
2702
+ if (!callback)
2703
+ return;
2704
+ const index = deviceCallbacks.findIndex(cb => cb === callback);
2705
+ if (index !== -1)
2706
+ deviceCallbacks.splice(index, 1);
2656
2707
  };
2657
- const closeSmartApp = () => {
2658
- return bridge?.sendClientEvent({
2659
- method: METHODS.CLOSE_SMART_APP,
2708
+ /**
2709
+ * Enable bluetooth
2710
+ * @returns Promise that'll be fullfilled on success, otherwise rejected with reason
2711
+ */
2712
+ const enable = () => {
2713
+ if (!bridge)
2714
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2715
+ return bridge
2716
+ .sendClientEvent({
2717
+ method: METHODS.ENABLE_BLUETOOTH,
2660
2718
  params: {},
2661
- });
2719
+ })
2720
+ .then(event => event);
2662
2721
  };
2663
- const onMoveToRoot = (handleMoveToRoot) => {
2664
- return bridge?.onReceive(event => {
2665
- if (event.type === METHODS.MOVE_TO_ROOT)
2666
- handleMoveToRoot();
2722
+ /**
2723
+ * Scan BLE devices nearby
2724
+ * @param scanDuration Duration to scan devices in milliseconds
2725
+ * @param deviceCallback Callback that triggered on device found
2726
+ * @returns Promise that'll be fullfilled with `payload.bleDevices` on success, otherwise rejected with reason
2727
+ */
2728
+ const scanBleDevices = ({ scanDuration, deviceCallback, }) => {
2729
+ if (!bridge)
2730
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2731
+ addDeviceCallback(deviceCallback);
2732
+ return bridge
2733
+ .sendClientEvent({
2734
+ method: METHODS.SCAN_BLE_DEVICES,
2735
+ params: {
2736
+ scanDuration,
2737
+ },
2738
+ })
2739
+ .then(event => {
2740
+ removeDeviceCallback(deviceCallback);
2741
+ return event;
2742
+ })
2743
+ .catch(() => {
2744
+ removeDeviceCallback(deviceCallback);
2745
+ return Promise.reject();
2667
2746
  });
2668
2747
  };
2669
- const exitSmartAppToCatalog = () => {
2748
+ /**
2749
+ * Connect bluetooth BLE device
2750
+ * @param bleDeviceAddress Address of the BLE device
2751
+ * @returns Promise that'll be fullfilled on success, otherwise rejected with reason
2752
+ */
2753
+ const connectBleDevice = ({ bleDeviceAddress, }) => {
2754
+ if (!bridge)
2755
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2756
+ return bridge
2757
+ .sendClientEvent({
2758
+ method: METHODS.CONNECT_BLE_DEVICE,
2759
+ params: {
2760
+ bleDeviceAddress,
2761
+ },
2762
+ })
2763
+ .then(event => event);
2764
+ };
2765
+ /**
2766
+ * Disonnect bluetooth BLE device
2767
+ * @param bleDeviceAddress Address of the BLE device
2768
+ * @returns Promise that'll be fullfilled on success, otherwise rejected with reason
2769
+ */
2770
+ const disconnectBleDevice = ({ bleDeviceAddress, }) => {
2771
+ if (!bridge)
2772
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2773
+ return bridge
2774
+ .sendClientEvent({
2775
+ method: METHODS.DISCONNECT_BLE_DEVICE,
2776
+ params: {
2777
+ bleDeviceAddress,
2778
+ },
2779
+ })
2780
+ .then(event => event);
2781
+ };
2782
+ /**
2783
+ * Discover services and characteristics of the BLE device
2784
+ * @param bleDeviceAddress Address of the BLE device
2785
+ * @returns Promise that'll be fullfilled with `payload.gattServices` on success, otherwise rejected with reason
2786
+ */
2787
+ const discoverGattServices = ({ bleDeviceAddress, }) => {
2788
+ if (!bridge)
2789
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2790
+ return bridge
2791
+ .sendClientEvent({
2792
+ method: METHODS.DISCOVER_BLE_GATT_SERVICES,
2793
+ params: {
2794
+ bleDeviceAddress,
2795
+ },
2796
+ })
2797
+ .then(event => event);
2798
+ };
2799
+ /**
2800
+ * Read BLE GATT characteristic
2801
+ * @param bleDeviceAddress Address of the BLE device
2802
+ * @param gattServiceUuid UUID of the GATT service
2803
+ * @param gattCharacteristicUuid UUID of the GATT characteristic
2804
+ * @returns Promise that'll be fullfilled with `payload.value` on success, otherwise rejected with reason
2805
+ */
2806
+ const readBleGattCharacteristic = ({ bleDeviceAddress, gattServiceUuid, gattCharacteristicUuid, }) => {
2807
+ if (!bridge)
2808
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2809
+ return bridge
2810
+ .sendClientEvent({
2811
+ method: METHODS.READ_BLE_GATT_CHARACTERISTIC,
2812
+ params: {
2813
+ bleDeviceAddress,
2814
+ gattServiceUuid,
2815
+ gattCharacteristicUuid,
2816
+ },
2817
+ })
2818
+ .then(event => event);
2819
+ };
2820
+ // Init device event listener
2821
+ installBridgeEventListener();
2822
+
2823
+ var bluetooth = /*#__PURE__*/Object.freeze({
2824
+ __proto__: null,
2825
+ enable: enable,
2826
+ scanBleDevices: scanBleDevices,
2827
+ connectBleDevice: connectBleDevice,
2828
+ disconnectBleDevice: disconnectBleDevice,
2829
+ discoverGattServices: discoverGattServices,
2830
+ readBleGattCharacteristic: readBleGattCharacteristic
2831
+ });
2832
+
2833
+ /**
2834
+ * Request GPS position
2835
+ * @returns Promise that'll be fullfilled with `payload.*` on success, otherwise rejected with reason
2836
+ */
2837
+ const requestLocation = () => {
2670
2838
  return bridge?.sendClientEvent({
2671
- method: METHODS.OPEN_SMART_APP,
2672
- params: { appId: '' },
2839
+ method: METHODS.REQUEST_LOCATION,
2840
+ params: {},
2673
2841
  });
2674
2842
  };
2675
2843
 
2844
+ var gps = /*#__PURE__*/Object.freeze({
2845
+ __proto__: null,
2846
+ requestLocation: requestLocation
2847
+ });
2848
+
2849
+ /**
2850
+ * Enable bluetooth
2851
+ * @returns Promise that'll be fullfilled with `payload.nfcTag` on success, otherwise rejected with reason
2852
+ */
2853
+ const readTag = () => {
2854
+ if (!bridge)
2855
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2856
+ return bridge
2857
+ .sendClientEvent({
2858
+ method: METHODS.ENABLE_BLUETOOTH,
2859
+ params: {},
2860
+ })
2861
+ .then(event => event);
2862
+ };
2863
+
2864
+ var nfc = /*#__PURE__*/Object.freeze({
2865
+ __proto__: null,
2866
+ readTag: readTag
2867
+ });
2868
+
2869
+ exports.Bluetooth = bluetooth;
2676
2870
  exports.Bridge = bridge;
2871
+ exports.GPS = gps;
2872
+ exports.NFC = nfc;
2677
2873
  exports.addContact = addContact;
2678
2874
  exports.cleanCache = cleanCache;
2679
2875
  exports.clientStorageClear = clientStorageClear;
@@ -2683,6 +2879,7 @@
2683
2879
  exports.closeSmartApp = closeSmartApp;
2684
2880
  exports.createDeeplink = createDeeplink;
2685
2881
  exports.createPersonalChat = createPersonalChat;
2882
+ exports.disableCopy = disableCopy;
2686
2883
  exports.exitSmartAppToCatalog = exitSmartAppToCatalog;
2687
2884
  exports.getAppVisibility = getAppVisibility;
2688
2885
  exports.getChats = getChats;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressms/smartapp-sdk",
3
- "version": "1.12.0-alpha.5",
3
+ "version": "1.12.0-alpha.7",
4
4
  "description": "Smartapp SDK",
5
5
  "main": "build/main/index.js",
6
6
  "typings": "build/main/index.d.ts",