@expressms/smartapp-sdk 1.1.4 → 1.1.5

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 (2) hide show
  1. package/build/umd/index.js +59 -50
  2. package/package.json +2 -2
@@ -1381,16 +1381,10 @@
1381
1381
  * emitter.onceWithTimeout('d6910a9d-ea24-5fc6-a654-28781ef21f8f', 20000)
1382
1382
  * // => Promise
1383
1383
  * ```
1384
- * @param type - Event type, uuid or EVENT_TYPE.RECV for standalone events from client
1385
- * @param timeout - Timeout in ms
1386
- * @returns Promise.
1387
1384
  */
1388
1385
  onceWithTimeout(type, timeout) {
1389
1386
  return new Promise((resolve, reject) => {
1390
- const timer = setTimeout(() => {
1391
- console.error("Bridge ~ Timeout event", timer);
1392
- reject();
1393
- }, timeout);
1387
+ const timer = setTimeout(() => reject(), timeout);
1394
1388
  this.once(type, (event) => {
1395
1389
  clearTimeout(timer);
1396
1390
  resolve(event);
@@ -1575,6 +1569,15 @@
1575
1569
  this.isRenameParamsEnabled = false;
1576
1570
  console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa');
1577
1571
  }
1572
+ log(data) {
1573
+ if (!this.hasCommunicationObject)
1574
+ return;
1575
+ let value = '';
1576
+ if (typeof data !== 'string' && typeof data !== 'object')
1577
+ return;
1578
+ value = data;
1579
+ window.express.handleSmartAppEvent(JSON.stringify({ 'SmartApp Log': value }, null, 2));
1580
+ }
1578
1581
  }
1579
1582
 
1580
1583
  class IosBridge {
@@ -1598,11 +1601,7 @@
1598
1601
  // Expect json data as string
1599
1602
  window.handleIosEvent = ({ ref, data, files, }) => {
1600
1603
  if (this.logsEnabled)
1601
- console.log('Bridge ~ Incoming event', JSON.stringify({
1602
- ref,
1603
- data,
1604
- files,
1605
- }, null, 2));
1604
+ console.log('Bridge ~ Incoming event', JSON.stringify({ ref, data, files }, null, 2));
1606
1605
  const { type, ...payload } = data;
1607
1606
  const emitterType = ref || EVENT_TYPE.RECEIVE;
1608
1607
  const eventFiles = this.isRenameParamsEnabled ?
@@ -1626,7 +1625,6 @@
1626
1625
  * console.log('event', type, handler, payload)
1627
1626
  * })
1628
1627
  * ```
1629
- * @param callback - Callback function.
1630
1628
  */
1631
1629
  onReceive(callback) {
1632
1630
  this.eventEmitter.on(EVENT_TYPE.RECEIVE, callback);
@@ -1670,14 +1668,16 @@
1670
1668
  * console.log('response', data)
1671
1669
  * })
1672
1670
  * ```
1673
- * @param method - Event type.
1674
- * @param params
1675
- * @param files
1676
- * @param timeout - Timeout in ms.
1677
- * @param guaranteed_delivery_required - boolean.
1678
1671
  */
1679
1672
  sendBotEvent({ method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required, }) {
1680
- return this.sendEvent({ handler: HANDLER.BOTX, method, params, files, timeout, guaranteed_delivery_required });
1673
+ return this.sendEvent({
1674
+ handler: HANDLER.BOTX,
1675
+ method,
1676
+ params,
1677
+ files,
1678
+ timeout,
1679
+ guaranteed_delivery_required,
1680
+ });
1681
1681
  }
1682
1682
  /**
1683
1683
  * Send event and wait response from express client.
@@ -1698,12 +1698,14 @@
1698
1698
  * console.log('response', data)
1699
1699
  * })
1700
1700
  * ```
1701
- * @param method - Event type.
1702
- * @param params
1703
- * @param timeout - Timeout in ms.
1704
1701
  */
1705
- sendClientEvent({ method, params, timeout = RESPONSE_TIMEOUT }) {
1706
- return this.sendEvent({ handler: HANDLER.EXPRESS, method, params, timeout });
1702
+ sendClientEvent({ method, params, timeout = RESPONSE_TIMEOUT, }) {
1703
+ return this.sendEvent({
1704
+ handler: HANDLER.EXPRESS,
1705
+ method,
1706
+ params,
1707
+ timeout,
1708
+ });
1707
1709
  }
1708
1710
  /**
1709
1711
  * Enabling logs.
@@ -1749,6 +1751,18 @@
1749
1751
  this.isRenameParamsEnabled = false;
1750
1752
  console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa');
1751
1753
  }
1754
+ log(data) {
1755
+ if (!this.hasCommunicationObject)
1756
+ return;
1757
+ let value = '';
1758
+ if (typeof data !== 'string') {
1759
+ value = data;
1760
+ }
1761
+ else if (typeof data !== 'object') {
1762
+ value = JSON.stringify(data, null, 2);
1763
+ }
1764
+ window.webkit.messageHandlers.express.postMessage({ 'SmartApp Log': value });
1765
+ }
1752
1766
  }
1753
1767
 
1754
1768
  class WebBridge {
@@ -1762,18 +1776,18 @@
1762
1776
  this.isRenameParamsEnabled = true;
1763
1777
  }
1764
1778
  addGlobalListener() {
1765
- window.addEventListener("message", (event) => {
1779
+ window.addEventListener('message', (event) => {
1766
1780
  const isRenameParamsWasEnabled = this.isRenameParamsEnabled;
1767
1781
  if (getPlatform() === PLATFORM.WEB &&
1768
1782
  event.data.handler === HANDLER.EXPRESS &&
1769
1783
  this.isRenameParamsEnabled)
1770
1784
  this.isRenameParamsEnabled = false;
1771
- if (typeof event.data !== "object" ||
1772
- typeof event.data.data !== "object" ||
1773
- typeof event.data.data.type !== "string")
1785
+ if (typeof event.data !== 'object' ||
1786
+ typeof event.data.data !== 'object' ||
1787
+ typeof event.data.data.type !== 'string')
1774
1788
  return;
1775
1789
  if (this.logsEnabled)
1776
- console.log("Bridge ~ Incoming event", event.data);
1790
+ console.log('Bridge ~ Incoming event', event.data);
1777
1791
  const { ref, data: { type, ...payload }, files, } = event.data;
1778
1792
  const emitterType = ref || EVENT_TYPE.RECEIVE;
1779
1793
  const eventFiles = this.isRenameParamsEnabled ?
@@ -1798,17 +1812,16 @@
1798
1812
  * console.log('event', type, handler, payload)
1799
1813
  * })
1800
1814
  * ```
1801
- * @param callback - Callback function.
1802
1815
  */
1803
1816
  onReceive(callback) {
1804
1817
  this.eventEmitter.on(EVENT_TYPE.RECEIVE, callback);
1805
1818
  }
1806
1819
  sendEvent({ handler, method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) {
1807
- const isRenameParamsWasEnabled = this.isRenameParamsEnabled;
1820
+ const isRenameParamsInitiallyEnabled = this.isRenameParamsEnabled;
1808
1821
  if (getPlatform() === PLATFORM.WEB &&
1809
1822
  handler === HANDLER.EXPRESS &&
1810
1823
  this.isRenameParamsEnabled)
1811
- this.disableRenameParams();
1824
+ this.isRenameParamsEnabled = false;
1812
1825
  const ref = v4(); // UUID to detect express response.
1813
1826
  const payload = {
1814
1827
  ref,
@@ -1822,13 +1835,13 @@
1822
1835
  files?.map((file) => camelCaseToSnakeCase(file)) : files;
1823
1836
  const event = files ? { ...payload, files: eventFiles } : payload;
1824
1837
  if (this.logsEnabled)
1825
- console.log("Bridge ~ Outgoing event", event);
1838
+ console.log('Bridge ~ Outgoing event', event);
1826
1839
  window.parent.postMessage({
1827
1840
  type: WEB_COMMAND_TYPE,
1828
1841
  payload: event,
1829
- }, "*");
1830
- if (isRenameParamsWasEnabled)
1831
- this.enableRenameParams();
1842
+ }, '*');
1843
+ if (isRenameParamsInitiallyEnabled)
1844
+ this.isRenameParamsEnabled = true;
1832
1845
  return this.eventEmitter.onceWithTimeout(ref, timeout);
1833
1846
  }
1834
1847
  /**
@@ -1849,12 +1862,6 @@
1849
1862
  * console.log('response', data)
1850
1863
  * })
1851
1864
  * ```
1852
- * @param method - Event type.
1853
- * @param params
1854
- * @param files
1855
- * @param is_rename_params_fields - boolean.
1856
- * @param timeout - Timeout in ms.
1857
- * @param guaranteed_delivery_required - boolean.
1858
1865
  */
1859
1866
  sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }) {
1860
1867
  return this.sendEvent({
@@ -1884,12 +1891,14 @@
1884
1891
  * console.log('response', data)
1885
1892
  * })
1886
1893
  * ```
1887
- * @param method - Event type.
1888
- * @param params
1889
- * @param timeout - Timeout in ms.
1890
1894
  */
1891
1895
  sendClientEvent({ method, params, timeout }) {
1892
- return this.sendEvent({ handler: HANDLER.EXPRESS, method, params, timeout });
1896
+ return this.sendEvent({
1897
+ handler: HANDLER.EXPRESS,
1898
+ method,
1899
+ params,
1900
+ timeout,
1901
+ });
1893
1902
  }
1894
1903
  /**
1895
1904
  * Enabling logs.
@@ -1906,7 +1915,7 @@
1906
1915
  window.parent.postMessage({
1907
1916
  type: WEB_COMMAND_TYPE_RPC_LOGS,
1908
1917
  payload: rest,
1909
- }, "*");
1918
+ }, '*');
1910
1919
  _log.apply(console, rest);
1911
1920
  };
1912
1921
  }
@@ -1930,7 +1939,7 @@
1930
1939
  */
1931
1940
  enableRenameParams() {
1932
1941
  this.isRenameParamsEnabled = true;
1933
- console.log("Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa");
1942
+ console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa');
1934
1943
  }
1935
1944
  /**
1936
1945
  * Enabling renaming event params from camelCase to snake_case and vice versa
@@ -1941,11 +1950,11 @@
1941
1950
  */
1942
1951
  disableRenameParams() {
1943
1952
  this.isRenameParamsEnabled = false;
1944
- console.log("Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa");
1953
+ console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa');
1945
1954
  }
1946
1955
  }
1947
1956
 
1948
- const LIB_VERSION = "1.1.5";
1957
+ const LIB_VERSION = "1.1.6";
1949
1958
 
1950
1959
  const getBridge = () => {
1951
1960
  if (process.env.NODE_ENV === 'test')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressms/smartapp-sdk",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Smartapp SDK",
5
5
  "main": "build/main/index.js",
6
6
  "typings": "build/main/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "typescript": "^4.0.2"
39
39
  },
40
40
  "dependencies": {
41
- "@expressms/smartapp-bridge": "^1.1.5",
41
+ "@expressms/smartapp-bridge": "^1.1.6",
42
42
  "webpack-manifest-plugin": "2.2.0",
43
43
  "workbox-cacheable-response": "^6.5.4",
44
44
  "workbox-expiration": "^6.5.4",