@expressms/smartapp-sdk 1.12.0-alpha.1 → 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 -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/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 +264 -47
  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!
@@ -2578,29 +2622,28 @@
2578
2622
  .then(event => event);
2579
2623
  };
2580
2624
  /**
2581
- * DRAFT: Get saved credentials of web resource
2625
+ * Get saved web resource credentials
2582
2626
  * @returns Promise that'll be fullfilled with credentials on success, otherwise rejected with reason
2583
2627
  */
2584
- const getCredentials = (domains) => {
2628
+ const getCredentials = () => {
2585
2629
  if (!bridge)
2586
2630
  return Promise.reject(ERROR_CODES.NO_BRIDGE);
2587
2631
  return bridge
2588
2632
  .sendClientEvent({
2589
2633
  method: METHODS.GET_CREDENTIALS,
2590
- params: {
2591
- domains,
2592
- },
2634
+ params: {},
2593
2635
  timeout: 10_000,
2636
+ hide_recv_event_data: true,
2594
2637
  })
2595
2638
  .then(event => event);
2596
2639
  };
2597
2640
  /**
2598
- * DRAFT: Save credentials of web resource
2641
+ * Save web resource credentials
2599
2642
  * @param login User login
2600
2643
  * @param password User pass
2601
2644
  * @returns Promise that'll be fullfilled with credentials on success, otherwise rejected with reason
2602
2645
  */
2603
- const setCredentials = (login, password) => {
2646
+ const setCredentials = ({ login, password, type, }) => {
2604
2647
  if (!bridge)
2605
2648
  return Promise.reject(ERROR_CODES.NO_BRIDGE);
2606
2649
  return bridge
@@ -2609,8 +2652,24 @@
2609
2652
  params: {
2610
2653
  login,
2611
2654
  password,
2655
+ type,
2612
2656
  },
2613
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: {},
2614
2673
  })
2615
2674
  .then(event => event);
2616
2675
  };
@@ -2633,46 +2692,202 @@
2633
2692
  .then(event => event);
2634
2693
  };
2635
2694
 
2636
- const routingChanged = (isRoot) => {
2637
- return bridge?.sendClientEvent({
2638
- method: METHODS.ROUTING_CHANGED,
2639
- params: {
2640
- location: isRoot ? LOCATION.ROOT : LOCATION.NESTED,
2641
- },
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));
2642
2707
  });
2643
2708
  };
2644
- const onBackPressed = (handleBackPressed) => {
2645
- return bridge?.onReceive(event => {
2646
- if (event.type === METHODS.BACK_PRESSED)
2647
- handleBackPressed();
2648
- });
2709
+ /**
2710
+ * Add callback to list
2711
+ */
2712
+ const addDeviceCallback = (callback) => {
2713
+ if (callback)
2714
+ deviceCallbacks.push(callback);
2649
2715
  };
2650
- const openSmartApp = ({ appId, meta }) => {
2651
- return bridge?.sendClientEvent({
2652
- method: METHODS.OPEN_SMART_APP,
2653
- params: meta ? { appId, meta } : { appId },
2654
- });
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);
2655
2725
  };
2656
- const closeSmartApp = () => {
2657
- return bridge?.sendClientEvent({
2658
- 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,
2659
2736
  params: {},
2660
- });
2737
+ })
2738
+ .then(event => event);
2661
2739
  };
2662
- const onMoveToRoot = (handleMoveToRoot) => {
2663
- return bridge?.onReceive(event => {
2664
- if (event.type === METHODS.MOVE_TO_ROOT)
2665
- 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();
2666
2764
  });
2667
2765
  };
2668
- 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 = () => {
2669
2856
  return bridge?.sendClientEvent({
2670
- method: METHODS.OPEN_SMART_APP,
2671
- params: { appId: '' },
2857
+ method: METHODS.REQUEST_LOCATION,
2858
+ params: {},
2672
2859
  });
2673
2860
  };
2674
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;
2675
2888
  exports.Bridge = bridge;
2889
+ exports.GPS = gps;
2890
+ exports.NFC = nfc;
2676
2891
  exports.addContact = addContact;
2677
2892
  exports.cleanCache = cleanCache;
2678
2893
  exports.clientStorageClear = clientStorageClear;
@@ -2682,6 +2897,8 @@
2682
2897
  exports.closeSmartApp = closeSmartApp;
2683
2898
  exports.createDeeplink = createDeeplink;
2684
2899
  exports.createPersonalChat = createPersonalChat;
2900
+ exports.deleteCredentials = deleteCredentials;
2901
+ exports.disableCopy = disableCopy;
2685
2902
  exports.exitSmartAppToCatalog = exitSmartAppToCatalog;
2686
2903
  exports.getAppVisibility = getAppVisibility;
2687
2904
  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.1",
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",