@expressms/smartapp-sdk 1.12.0-alpha.0 → 1.12.0-alpha.10

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 (56) hide show
  1. package/build/main/index.d.ts +10 -9
  2. package/build/main/index.js +25 -54
  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/helpers/helpers.js +8 -6
  14. package/build/main/lib/logging/index.js +2 -2
  15. package/build/main/lib/notification/index.d.ts +1 -2
  16. package/build/main/lib/notification/index.js +1 -1
  17. package/build/main/lib/proxy/index.d.ts +14 -5
  18. package/build/main/lib/proxy/index.js +25 -9
  19. package/build/main/lib/routing/index.d.ts +6 -7
  20. package/build/main/lib/routing/index.js +2 -2
  21. package/build/main/types/bridge.d.ts +9 -1
  22. package/build/main/types/bridge.js +9 -1
  23. package/build/main/types/devices.d.ts +62 -0
  24. package/build/main/types/devices.js +3 -0
  25. package/build/main/types/index.d.ts +1 -0
  26. package/build/main/types/index.js +2 -1
  27. package/build/main/types/proxy.d.ts +4 -2
  28. package/build/module/index.d.ts +10 -9
  29. package/build/module/index.js +11 -10
  30. package/build/module/lib/client/index.d.ts +1 -2
  31. package/build/module/lib/client/index.js +2 -8
  32. package/build/module/lib/devices/bluetooth.d.ts +52 -0
  33. package/build/module/lib/devices/bluetooth.js +148 -0
  34. package/build/module/lib/devices/gps.d.ts +5 -0
  35. package/build/module/lib/devices/gps.js +13 -0
  36. package/build/module/lib/devices/index.d.ts +5 -0
  37. package/build/module/lib/devices/index.js +6 -0
  38. package/build/module/lib/devices/nfc.d.ts +6 -0
  39. package/build/module/lib/devices/nfc.js +17 -0
  40. package/build/module/lib/helpers/helpers.js +8 -5
  41. package/build/module/lib/logging/index.js +2 -2
  42. package/build/module/lib/notification/index.d.ts +1 -2
  43. package/build/module/lib/notification/index.js +2 -3
  44. package/build/module/lib/proxy/index.d.ts +14 -5
  45. package/build/module/lib/proxy/index.js +23 -8
  46. package/build/module/lib/routing/index.d.ts +6 -7
  47. package/build/module/lib/routing/index.js +7 -8
  48. package/build/module/types/bridge.d.ts +9 -1
  49. package/build/module/types/bridge.js +9 -1
  50. package/build/module/types/devices.d.ts +62 -0
  51. package/build/module/types/devices.js +2 -0
  52. package/build/module/types/index.d.ts +1 -0
  53. package/build/module/types/index.js +2 -1
  54. package/build/module/types/proxy.d.ts +4 -2
  55. package/build/umd/index.js +296 -40
  56. package/package.json +1 -1
@@ -1998,7 +1998,15 @@
1998
1998
  METHODS["SET_ALLOWED_NAVIGATION_DOMAINS"] = "set_allowed_navigation_domains";
1999
1999
  METHODS["GET_CREDENTIALS"] = "get_credentials";
2000
2000
  METHODS["SET_CREDENTIALS"] = "set_credentials";
2001
+ METHODS["DELETE_CREDENTIALS"] = "delete_credentials";
2001
2002
  METHODS["RUN_WEB_COMMANDS_PIPELINE"] = "run_web_commands_pipeline";
2003
+ METHODS["ENABLE_BLUETOOTH"] = "enable_bluetooth";
2004
+ METHODS["SCAN_BLE_DEVICES"] = "scan_ble_devices";
2005
+ METHODS["CONNECT_BLE_DEVICE"] = "connect_ble_device";
2006
+ METHODS["DISCONNECT_BLE_DEVICE"] = "disconnect_ble_device";
2007
+ METHODS["DISCOVER_BLE_GATT_SERVICES"] = "discover_ble_gatt_services";
2008
+ METHODS["READ_BLE_GATT_CHARACTERISTIC"] = "read_ble_gatt_characteristic";
2009
+ METHODS["READ_NFC_TAG"] = "read_nfc_tag";
2002
2010
  })(METHODS || (METHODS = {}));
2003
2011
  var STATUS;
2004
2012
  (function (STATUS) {
@@ -2053,7 +2061,7 @@
2053
2061
  const id = getSubscriptionId(eventType, payload);
2054
2062
  return subscriptions.some(sub => sub.id == id);
2055
2063
  };
2056
- const installBridgeEventListener = () => {
2064
+ const installBridgeEventListener$1 = () => {
2057
2065
  if (bridgeEventListenerInstalled || !bridge)
2058
2066
  return;
2059
2067
  bridgeEventListenerInstalled = true;
@@ -2092,7 +2100,7 @@
2092
2100
  const id = getSubscriptionId(eventType, payload);
2093
2101
  if (response.payload.status !== STATUS.SUCCESS)
2094
2102
  return response;
2095
- installBridgeEventListener();
2103
+ installBridgeEventListener$1();
2096
2104
  subscriptions.push({ id, callback });
2097
2105
  return response;
2098
2106
  });
@@ -2242,12 +2250,6 @@
2242
2250
  },
2243
2251
  });
2244
2252
  };
2245
- const requestLocation = () => {
2246
- return bridge?.sendClientEvent({
2247
- method: METHODS.REQUEST_LOCATION,
2248
- params: {},
2249
- });
2250
- };
2251
2253
  /**
2252
2254
  * Get client current connection status. It's based on client's WebSocket connection state.
2253
2255
  * @returns Promise that'll be fullfilled with status data on success, otherwise rejected with reason
@@ -2501,11 +2503,14 @@
2501
2503
  const urlSearchParams = new URLSearchParams(window.location.search);
2502
2504
  return Object.fromEntries(urlSearchParams.entries());
2503
2505
  };
2506
+ const noop = (event) => {
2507
+ event.preventDefault();
2508
+ return false;
2509
+ };
2504
2510
  const disableCopy = () => {
2505
- document.getElementById('body')?.addEventListener('copy', e => {
2506
- e.preventDefault();
2507
- return false;
2508
- });
2511
+ document.addEventListener('selectstart', noop);
2512
+ document.addEventListener('contextmenu', noop);
2513
+ document.addEventListener('copy', noop);
2509
2514
  };
2510
2515
 
2511
2516
  const bridgeSendReady = (timeout) => {
@@ -2521,7 +2526,7 @@
2521
2526
  return Promise.reject(ERROR_CODES.NO_BRIDGE);
2522
2527
  const response = await bridgeSendReady(timeout);
2523
2528
  const isLogsEnabled = response?.payload?.logsEnabled;
2524
- const isCopyDisabled = !response?.payload?.rules?.find(rule => rule.action === 'copy');
2529
+ const isCopyDisabled = !!response?.payload?.rules?.find(rule => rule.action === 'copy');
2525
2530
  if (isLogsEnabled)
2526
2531
  bridge.enableLogs();
2527
2532
  if (isCopyDisabled)
@@ -2542,6 +2547,45 @@
2542
2547
  });
2543
2548
  };
2544
2549
 
2550
+ const routingChanged = (isRoot) => {
2551
+ return bridge?.sendClientEvent({
2552
+ method: METHODS.ROUTING_CHANGED,
2553
+ params: {
2554
+ location: isRoot ? LOCATION.ROOT : LOCATION.NESTED,
2555
+ },
2556
+ });
2557
+ };
2558
+ const onBackPressed = (handleBackPressed) => {
2559
+ return bridge?.onReceive(event => {
2560
+ if (event.type === METHODS.BACK_PRESSED)
2561
+ handleBackPressed();
2562
+ });
2563
+ };
2564
+ const openSmartApp = ({ appId, meta }) => {
2565
+ return bridge?.sendClientEvent({
2566
+ method: METHODS.OPEN_SMART_APP,
2567
+ params: meta ? { appId, meta } : { appId },
2568
+ });
2569
+ };
2570
+ const closeSmartApp = () => {
2571
+ return bridge?.sendClientEvent({
2572
+ method: METHODS.CLOSE_SMART_APP,
2573
+ params: {},
2574
+ });
2575
+ };
2576
+ const onMoveToRoot = (handleMoveToRoot) => {
2577
+ return bridge?.onReceive(event => {
2578
+ if (event.type === METHODS.MOVE_TO_ROOT)
2579
+ handleMoveToRoot();
2580
+ });
2581
+ };
2582
+ const exitSmartAppToCatalog = () => {
2583
+ return bridge?.sendClientEvent({
2584
+ method: METHODS.OPEN_SMART_APP,
2585
+ params: { appId: '' },
2586
+ });
2587
+ };
2588
+
2545
2589
  /**
2546
2590
  * Set cookies for web resouce. It's needed for SSO auth cases.
2547
2591
  * @param cookies List of cookie strings !with domains!
@@ -2577,6 +2621,58 @@
2577
2621
  })
2578
2622
  .then(event => event);
2579
2623
  };
2624
+ /**
2625
+ * Get saved web resource credentials
2626
+ * @returns Promise that'll be fullfilled with credentials on success, otherwise rejected with reason
2627
+ */
2628
+ const getCredentials = () => {
2629
+ if (!bridge)
2630
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2631
+ return bridge
2632
+ .sendClientEvent({
2633
+ method: METHODS.GET_CREDENTIALS,
2634
+ params: {},
2635
+ timeout: 10_000,
2636
+ hide_recv_event_data: true,
2637
+ })
2638
+ .then(event => event);
2639
+ };
2640
+ /**
2641
+ * Save web resource credentials
2642
+ * @param login User login
2643
+ * @param password User pass
2644
+ * @returns Promise that'll be fullfilled with credentials on success, otherwise rejected with reason
2645
+ */
2646
+ const setCredentials = ({ login, password, type, }) => {
2647
+ if (!bridge)
2648
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2649
+ return bridge
2650
+ .sendClientEvent({
2651
+ method: METHODS.SET_CREDENTIALS,
2652
+ params: {
2653
+ login,
2654
+ password,
2655
+ type,
2656
+ },
2657
+ timeout: 10_000,
2658
+ hide_send_event_data: true,
2659
+ })
2660
+ .then(event => event);
2661
+ };
2662
+ /**
2663
+ * Delete web resource credentials
2664
+ * @returns Promise that'll be fullfilled with credentials on success, otherwise rejected with reason
2665
+ */
2666
+ const deleteCredentials = () => {
2667
+ if (!bridge)
2668
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2669
+ return bridge
2670
+ .sendClientEvent({
2671
+ method: METHODS.DELETE_CREDENTIALS,
2672
+ params: {},
2673
+ })
2674
+ .then(event => event);
2675
+ };
2580
2676
  /**
2581
2677
  * Run pipeline for manipulating web resource
2582
2678
  * @param pipeline Pipeline with jobs & command
@@ -2596,46 +2692,202 @@
2596
2692
  .then(event => event);
2597
2693
  };
2598
2694
 
2599
- const routingChanged = (isRoot) => {
2600
- return bridge?.sendClientEvent({
2601
- method: METHODS.ROUTING_CHANGED,
2602
- params: {
2603
- location: isRoot ? LOCATION.ROOT : LOCATION.NESTED,
2604
- },
2695
+ const deviceCallbacks = [];
2696
+ /**
2697
+ * Install bridge event listener for founded devices during scan
2698
+ */
2699
+ const installBridgeEventListener = () => {
2700
+ if (!bridge)
2701
+ return;
2702
+ bridge.onReceive(event => {
2703
+ if (event.type !== 'ble_device_found')
2704
+ return;
2705
+ const { payload: { bleDevice }, } = event;
2706
+ deviceCallbacks.map(cb => cb(bleDevice));
2605
2707
  });
2606
2708
  };
2607
- const onBackPressed = (handleBackPressed) => {
2608
- return bridge?.onReceive(event => {
2609
- if (event.type === METHODS.BACK_PRESSED)
2610
- handleBackPressed();
2611
- });
2709
+ /**
2710
+ * Add callback to list
2711
+ */
2712
+ const addDeviceCallback = (callback) => {
2713
+ if (callback)
2714
+ deviceCallbacks.push(callback);
2612
2715
  };
2613
- const openSmartApp = ({ appId, meta }) => {
2614
- return bridge?.sendClientEvent({
2615
- method: METHODS.OPEN_SMART_APP,
2616
- params: meta ? { appId, meta } : { appId },
2617
- });
2716
+ /**
2717
+ * Remove callback from list
2718
+ */
2719
+ const removeDeviceCallback = (callback) => {
2720
+ if (!callback)
2721
+ return;
2722
+ const index = deviceCallbacks.findIndex(cb => cb === callback);
2723
+ if (index !== -1)
2724
+ deviceCallbacks.splice(index, 1);
2618
2725
  };
2619
- const closeSmartApp = () => {
2620
- return bridge?.sendClientEvent({
2621
- method: METHODS.CLOSE_SMART_APP,
2726
+ /**
2727
+ * Enable bluetooth
2728
+ * @returns Promise that'll be fullfilled on success, otherwise rejected with reason
2729
+ */
2730
+ const enable = () => {
2731
+ if (!bridge)
2732
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2733
+ return bridge
2734
+ .sendClientEvent({
2735
+ method: METHODS.ENABLE_BLUETOOTH,
2622
2736
  params: {},
2623
- });
2737
+ })
2738
+ .then(event => event);
2624
2739
  };
2625
- const onMoveToRoot = (handleMoveToRoot) => {
2626
- return bridge?.onReceive(event => {
2627
- if (event.type === METHODS.MOVE_TO_ROOT)
2628
- handleMoveToRoot();
2740
+ /**
2741
+ * Scan BLE devices nearby
2742
+ * @param scanDuration Duration to scan devices in milliseconds
2743
+ * @param deviceCallback Callback that triggered on device found
2744
+ * @returns Promise that'll be fullfilled with `payload.bleDevices` on success, otherwise rejected with reason
2745
+ */
2746
+ const scanBleDevices = ({ scanDuration, deviceCallback, }) => {
2747
+ if (!bridge)
2748
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2749
+ addDeviceCallback(deviceCallback);
2750
+ return bridge
2751
+ .sendClientEvent({
2752
+ method: METHODS.SCAN_BLE_DEVICES,
2753
+ params: {
2754
+ scanDuration,
2755
+ },
2756
+ })
2757
+ .then(event => {
2758
+ removeDeviceCallback(deviceCallback);
2759
+ return event;
2760
+ })
2761
+ .catch(() => {
2762
+ removeDeviceCallback(deviceCallback);
2763
+ return Promise.reject();
2629
2764
  });
2630
2765
  };
2631
- const exitSmartAppToCatalog = () => {
2766
+ /**
2767
+ * Connect bluetooth BLE device
2768
+ * @param bleDeviceAddress Address of the BLE device
2769
+ * @returns Promise that'll be fullfilled on success, otherwise rejected with reason
2770
+ */
2771
+ const connectBleDevice = ({ bleDeviceAddress, }) => {
2772
+ if (!bridge)
2773
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2774
+ return bridge
2775
+ .sendClientEvent({
2776
+ method: METHODS.CONNECT_BLE_DEVICE,
2777
+ params: {
2778
+ bleDeviceAddress,
2779
+ },
2780
+ })
2781
+ .then(event => event);
2782
+ };
2783
+ /**
2784
+ * Disonnect bluetooth BLE device
2785
+ * @param bleDeviceAddress Address of the BLE device
2786
+ * @returns Promise that'll be fullfilled on success, otherwise rejected with reason
2787
+ */
2788
+ const disconnectBleDevice = ({ bleDeviceAddress, }) => {
2789
+ if (!bridge)
2790
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2791
+ return bridge
2792
+ .sendClientEvent({
2793
+ method: METHODS.DISCONNECT_BLE_DEVICE,
2794
+ params: {
2795
+ bleDeviceAddress,
2796
+ },
2797
+ })
2798
+ .then(event => event);
2799
+ };
2800
+ /**
2801
+ * Discover services and characteristics of the BLE device
2802
+ * @param bleDeviceAddress Address of the BLE device
2803
+ * @returns Promise that'll be fullfilled with `payload.gattServices` on success, otherwise rejected with reason
2804
+ */
2805
+ const discoverGattServices = ({ bleDeviceAddress, }) => {
2806
+ if (!bridge)
2807
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2808
+ return bridge
2809
+ .sendClientEvent({
2810
+ method: METHODS.DISCOVER_BLE_GATT_SERVICES,
2811
+ params: {
2812
+ bleDeviceAddress,
2813
+ },
2814
+ })
2815
+ .then(event => event);
2816
+ };
2817
+ /**
2818
+ * Read BLE GATT characteristic
2819
+ * @param bleDeviceAddress Address of the BLE device
2820
+ * @param gattServiceUuid UUID of the GATT service
2821
+ * @param gattCharacteristicUuid UUID of the GATT characteristic
2822
+ * @returns Promise that'll be fullfilled with `payload.value` on success, otherwise rejected with reason
2823
+ */
2824
+ const readBleGattCharacteristic = ({ bleDeviceAddress, gattServiceUuid, gattCharacteristicUuid, }) => {
2825
+ if (!bridge)
2826
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2827
+ return bridge
2828
+ .sendClientEvent({
2829
+ method: METHODS.READ_BLE_GATT_CHARACTERISTIC,
2830
+ params: {
2831
+ bleDeviceAddress,
2832
+ gattServiceUuid,
2833
+ gattCharacteristicUuid,
2834
+ },
2835
+ })
2836
+ .then(event => event);
2837
+ };
2838
+ // Init device event listener
2839
+ installBridgeEventListener();
2840
+
2841
+ var bluetooth = /*#__PURE__*/Object.freeze({
2842
+ __proto__: null,
2843
+ enable: enable,
2844
+ scanBleDevices: scanBleDevices,
2845
+ connectBleDevice: connectBleDevice,
2846
+ disconnectBleDevice: disconnectBleDevice,
2847
+ discoverGattServices: discoverGattServices,
2848
+ readBleGattCharacteristic: readBleGattCharacteristic
2849
+ });
2850
+
2851
+ /**
2852
+ * Request GPS position
2853
+ * @returns Promise that'll be fullfilled with `payload.*` on success, otherwise rejected with reason
2854
+ */
2855
+ const requestLocation = () => {
2632
2856
  return bridge?.sendClientEvent({
2633
- method: METHODS.OPEN_SMART_APP,
2634
- params: { appId: '' },
2857
+ method: METHODS.REQUEST_LOCATION,
2858
+ params: {},
2635
2859
  });
2636
2860
  };
2637
2861
 
2862
+ var gps = /*#__PURE__*/Object.freeze({
2863
+ __proto__: null,
2864
+ requestLocation: requestLocation
2865
+ });
2866
+
2867
+ /**
2868
+ * Enable bluetooth
2869
+ * @returns Promise that'll be fullfilled with `payload.nfcTag` on success, otherwise rejected with reason
2870
+ */
2871
+ const readTag = () => {
2872
+ if (!bridge)
2873
+ return Promise.reject(ERROR_CODES.NO_BRIDGE);
2874
+ return bridge
2875
+ .sendClientEvent({
2876
+ method: METHODS.READ_NFC_TAG,
2877
+ params: {},
2878
+ })
2879
+ .then(event => event);
2880
+ };
2881
+
2882
+ var nfc = /*#__PURE__*/Object.freeze({
2883
+ __proto__: null,
2884
+ readTag: readTag
2885
+ });
2886
+
2887
+ exports.Bluetooth = bluetooth;
2638
2888
  exports.Bridge = bridge;
2889
+ exports.GPS = gps;
2890
+ exports.NFC = nfc;
2639
2891
  exports.addContact = addContact;
2640
2892
  exports.cleanCache = cleanCache;
2641
2893
  exports.clientStorageClear = clientStorageClear;
@@ -2645,11 +2897,14 @@
2645
2897
  exports.closeSmartApp = closeSmartApp;
2646
2898
  exports.createDeeplink = createDeeplink;
2647
2899
  exports.createPersonalChat = createPersonalChat;
2900
+ exports.deleteCredentials = deleteCredentials;
2901
+ exports.disableCopy = disableCopy;
2648
2902
  exports.exitSmartAppToCatalog = exitSmartAppToCatalog;
2649
2903
  exports.getAppVisibility = getAppVisibility;
2650
2904
  exports.getChats = getChats;
2651
2905
  exports.getConnectionStatus = getConnectionStatus;
2652
2906
  exports.getContact = getContact;
2907
+ exports.getCredentials = getCredentials;
2653
2908
  exports.getLayoutType = getLayoutType;
2654
2909
  exports.getSmartAppList = getSmartAppList;
2655
2910
  exports.getUnreadCounter = getUnreadCounter;
@@ -2674,6 +2929,7 @@
2674
2929
  exports.sendBotCommand = sendBotCommand;
2675
2930
  exports.sendMessage = sendMessage;
2676
2931
  exports.setAllowedNavigationDomains = setAllowedNavigationDomains;
2932
+ exports.setCredentials = setCredentials;
2677
2933
  exports.setWebResourceCookies = setWebResourceCookies;
2678
2934
  exports.subscribeClientEvents = subscribeClientEvents;
2679
2935
  exports.unsubscribeClientEvents = unsubscribeClientEvents;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressms/smartapp-sdk",
3
- "version": "1.12.0-alpha.0",
3
+ "version": "1.12.0-alpha.10",
4
4
  "description": "Smartapp SDK",
5
5
  "main": "build/main/index.js",
6
6
  "typings": "build/main/index.d.ts",