@expressms/smartapp-sdk 1.1.6 → 1.1.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.
- package/build/umd/index.js +50 -47
- package/package.json +2 -2
package/build/umd/index.js
CHANGED
|
@@ -1403,12 +1403,14 @@
|
|
|
1403
1403
|
eventEmitter;
|
|
1404
1404
|
hasCommunicationObject;
|
|
1405
1405
|
logsEnabled;
|
|
1406
|
-
|
|
1406
|
+
isRenameParamsEnabledForBotx;
|
|
1407
|
+
handler;
|
|
1407
1408
|
constructor() {
|
|
1408
1409
|
this.hasCommunicationObject = typeof window.express !== 'undefined' && !!window.express.handleSmartAppEvent;
|
|
1409
1410
|
this.eventEmitter = new ExtendedEventEmitter();
|
|
1410
1411
|
this.logsEnabled = false;
|
|
1411
|
-
this.
|
|
1412
|
+
this.isRenameParamsEnabledForBotx = true;
|
|
1413
|
+
this.handler = null;
|
|
1412
1414
|
if (!this.hasCommunicationObject) {
|
|
1413
1415
|
log('No method "express.handleSmartAppEvent", cannot send message to Android');
|
|
1414
1416
|
return;
|
|
@@ -1416,19 +1418,16 @@
|
|
|
1416
1418
|
// Expect json data as string
|
|
1417
1419
|
window.handleAndroidEvent = ({ ref, data, files, }) => {
|
|
1418
1420
|
if (this.logsEnabled)
|
|
1419
|
-
console.log('Bridge ~ Incoming event', JSON.stringify({
|
|
1420
|
-
ref,
|
|
1421
|
-
data,
|
|
1422
|
-
files,
|
|
1423
|
-
}, null, 2));
|
|
1421
|
+
console.log('Bridge ~ Incoming event', JSON.stringify({ ref, data, files }, null, 2));
|
|
1424
1422
|
const { type, ...payload } = data;
|
|
1425
1423
|
const emitterType = ref || EVENT_TYPE.RECEIVE;
|
|
1426
|
-
const
|
|
1424
|
+
const isRenameParamsEnabled = this.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true;
|
|
1425
|
+
const eventFiles = isRenameParamsEnabled ?
|
|
1427
1426
|
files?.map((file) => snakeCaseToCamelCase(file)) : files;
|
|
1428
1427
|
const event = {
|
|
1429
1428
|
ref,
|
|
1430
1429
|
type,
|
|
1431
|
-
payload:
|
|
1430
|
+
payload: isRenameParamsEnabled ? snakeCaseToCamelCase(payload) : payload,
|
|
1432
1431
|
files: eventFiles,
|
|
1433
1432
|
};
|
|
1434
1433
|
this.eventEmitter.emit(emitterType, event);
|
|
@@ -1452,16 +1451,17 @@
|
|
|
1452
1451
|
sendEvent({ handler, method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) {
|
|
1453
1452
|
if (!this.hasCommunicationObject)
|
|
1454
1453
|
return Promise.reject();
|
|
1454
|
+
const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true;
|
|
1455
1455
|
const ref = v4(); // UUID to detect express response.
|
|
1456
1456
|
const eventParams = {
|
|
1457
1457
|
ref,
|
|
1458
1458
|
type: WEB_COMMAND_TYPE_RPC,
|
|
1459
1459
|
method,
|
|
1460
1460
|
handler,
|
|
1461
|
-
payload:
|
|
1461
|
+
payload: isRenameParamsEnabled ? camelCaseToSnakeCase(params) : params,
|
|
1462
1462
|
guaranteed_delivery_required,
|
|
1463
1463
|
};
|
|
1464
|
-
const eventFiles =
|
|
1464
|
+
const eventFiles = isRenameParamsEnabled ?
|
|
1465
1465
|
files?.map((file) => camelCaseToSnakeCase(file)) : files;
|
|
1466
1466
|
const event = JSON.stringify(files ? { ...eventParams, files: eventFiles } : eventParams);
|
|
1467
1467
|
if (this.logsEnabled)
|
|
@@ -1495,8 +1495,15 @@
|
|
|
1495
1495
|
* @param guaranteed_delivery_required - boolean.
|
|
1496
1496
|
* @returns Promise.
|
|
1497
1497
|
*/
|
|
1498
|
-
sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required }) {
|
|
1499
|
-
return this.sendEvent({
|
|
1498
|
+
sendBotEvent({ method, params, files, timeout, guaranteed_delivery_required, }) {
|
|
1499
|
+
return this.sendEvent({
|
|
1500
|
+
handler: HANDLER.BOTX,
|
|
1501
|
+
method,
|
|
1502
|
+
params,
|
|
1503
|
+
files,
|
|
1504
|
+
timeout,
|
|
1505
|
+
guaranteed_delivery_required,
|
|
1506
|
+
});
|
|
1500
1507
|
}
|
|
1501
1508
|
/**
|
|
1502
1509
|
* Send event and wait response from express client.
|
|
@@ -1555,7 +1562,7 @@
|
|
|
1555
1562
|
* ```
|
|
1556
1563
|
*/
|
|
1557
1564
|
enableRenameParams() {
|
|
1558
|
-
this.
|
|
1565
|
+
this.isRenameParamsEnabledForBotx = true;
|
|
1559
1566
|
console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa');
|
|
1560
1567
|
}
|
|
1561
1568
|
/**
|
|
@@ -1566,7 +1573,7 @@
|
|
|
1566
1573
|
* ```
|
|
1567
1574
|
*/
|
|
1568
1575
|
disableRenameParams() {
|
|
1569
|
-
this.
|
|
1576
|
+
this.isRenameParamsEnabledForBotx = false;
|
|
1570
1577
|
console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa');
|
|
1571
1578
|
}
|
|
1572
1579
|
log(data) {
|
|
@@ -1581,7 +1588,8 @@
|
|
|
1581
1588
|
eventEmitter;
|
|
1582
1589
|
hasCommunicationObject;
|
|
1583
1590
|
logsEnabled;
|
|
1584
|
-
|
|
1591
|
+
isRenameParamsEnabledForBotx;
|
|
1592
|
+
handler;
|
|
1585
1593
|
constructor() {
|
|
1586
1594
|
this.hasCommunicationObject =
|
|
1587
1595
|
window.webkit &&
|
|
@@ -1590,7 +1598,8 @@
|
|
|
1590
1598
|
!!window.webkit.messageHandlers.express.postMessage;
|
|
1591
1599
|
this.eventEmitter = new ExtendedEventEmitter();
|
|
1592
1600
|
this.logsEnabled = false;
|
|
1593
|
-
this.
|
|
1601
|
+
this.isRenameParamsEnabledForBotx = true;
|
|
1602
|
+
this.handler = null;
|
|
1594
1603
|
if (!this.hasCommunicationObject) {
|
|
1595
1604
|
log('No method "express.postMessage", cannot send message to iOS');
|
|
1596
1605
|
return;
|
|
@@ -1601,12 +1610,13 @@
|
|
|
1601
1610
|
console.log('Bridge ~ Incoming event', JSON.stringify({ ref, data, files }, null, 2));
|
|
1602
1611
|
const { type, ...payload } = data;
|
|
1603
1612
|
const emitterType = ref || EVENT_TYPE.RECEIVE;
|
|
1604
|
-
const
|
|
1613
|
+
const isRenameParamsEnabled = this.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true;
|
|
1614
|
+
const eventFiles = isRenameParamsEnabled ?
|
|
1605
1615
|
files?.map((file) => snakeCaseToCamelCase(file)) : files;
|
|
1606
1616
|
const event = {
|
|
1607
1617
|
ref,
|
|
1608
1618
|
type,
|
|
1609
|
-
payload:
|
|
1619
|
+
payload: isRenameParamsEnabled ? snakeCaseToCamelCase(payload) : payload,
|
|
1610
1620
|
files: eventFiles,
|
|
1611
1621
|
};
|
|
1612
1622
|
this.eventEmitter.emit(emitterType, event);
|
|
@@ -1630,15 +1640,17 @@
|
|
|
1630
1640
|
if (!this.hasCommunicationObject)
|
|
1631
1641
|
return Promise.reject();
|
|
1632
1642
|
const ref = v4(); // UUID to detect express response.
|
|
1643
|
+
this.handler = handler;
|
|
1644
|
+
const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true;
|
|
1633
1645
|
const eventProps = {
|
|
1634
1646
|
ref,
|
|
1635
1647
|
type: WEB_COMMAND_TYPE_RPC,
|
|
1636
1648
|
method,
|
|
1637
1649
|
handler,
|
|
1638
|
-
payload:
|
|
1650
|
+
payload: isRenameParamsEnabled ? camelCaseToSnakeCase(params) : params,
|
|
1639
1651
|
guaranteed_delivery_required,
|
|
1640
1652
|
};
|
|
1641
|
-
const eventFiles =
|
|
1653
|
+
const eventFiles = isRenameParamsEnabled ?
|
|
1642
1654
|
files?.map((file) => camelCaseToSnakeCase(file)) : files;
|
|
1643
1655
|
const event = files ? { ...eventProps, files: eventFiles } : eventProps;
|
|
1644
1656
|
if (this.logsEnabled)
|
|
@@ -1734,7 +1746,7 @@
|
|
|
1734
1746
|
* ```
|
|
1735
1747
|
*/
|
|
1736
1748
|
enableRenameParams() {
|
|
1737
|
-
this.
|
|
1749
|
+
this.isRenameParamsEnabledForBotx = true;
|
|
1738
1750
|
console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa');
|
|
1739
1751
|
}
|
|
1740
1752
|
/**
|
|
@@ -1745,7 +1757,7 @@
|
|
|
1745
1757
|
* ```
|
|
1746
1758
|
*/
|
|
1747
1759
|
disableRenameParams() {
|
|
1748
|
-
this.
|
|
1760
|
+
this.isRenameParamsEnabledForBotx = false;
|
|
1749
1761
|
console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa');
|
|
1750
1762
|
}
|
|
1751
1763
|
log(data) {
|
|
@@ -1767,38 +1779,34 @@
|
|
|
1767
1779
|
class WebBridge {
|
|
1768
1780
|
eventEmitter;
|
|
1769
1781
|
logsEnabled;
|
|
1770
|
-
|
|
1782
|
+
isRenameParamsEnabledForBotx;
|
|
1783
|
+
handler;
|
|
1771
1784
|
constructor() {
|
|
1772
1785
|
this.eventEmitter = new ExtendedEventEmitter();
|
|
1773
1786
|
this.addGlobalListener();
|
|
1774
1787
|
this.logsEnabled = false;
|
|
1775
|
-
this.
|
|
1788
|
+
this.isRenameParamsEnabledForBotx = true;
|
|
1789
|
+
this.handler = null;
|
|
1776
1790
|
}
|
|
1777
1791
|
addGlobalListener() {
|
|
1778
1792
|
window.addEventListener('message', (event) => {
|
|
1779
|
-
const isRenameParamsWasEnabled = this.isRenameParamsEnabled;
|
|
1780
|
-
if (getPlatform() === PLATFORM.WEB &&
|
|
1781
|
-
event.data.handler === HANDLER.EXPRESS &&
|
|
1782
|
-
this.isRenameParamsEnabled)
|
|
1783
|
-
this.isRenameParamsEnabled = false;
|
|
1784
1793
|
if (typeof event.data !== 'object' ||
|
|
1785
1794
|
typeof event.data.data !== 'object' ||
|
|
1786
1795
|
typeof event.data.data.type !== 'string')
|
|
1787
1796
|
return;
|
|
1797
|
+
const { ref, data: { type, ...payload }, files, } = event.data;
|
|
1798
|
+
const isRenameParamsEnabled = this.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : false;
|
|
1788
1799
|
if (this.logsEnabled)
|
|
1789
1800
|
console.log('Bridge ~ Incoming event', event.data);
|
|
1790
|
-
const { ref, data: { type, ...payload }, files, } = event.data;
|
|
1791
1801
|
const emitterType = ref || EVENT_TYPE.RECEIVE;
|
|
1792
|
-
const eventFiles =
|
|
1802
|
+
const eventFiles = isRenameParamsEnabled ?
|
|
1793
1803
|
files?.map((file) => snakeCaseToCamelCase(file)) : files;
|
|
1794
1804
|
this.eventEmitter.emit(emitterType, {
|
|
1795
1805
|
ref,
|
|
1796
1806
|
type,
|
|
1797
|
-
payload:
|
|
1807
|
+
payload: isRenameParamsEnabled ? snakeCaseToCamelCase(payload) : payload,
|
|
1798
1808
|
files: eventFiles,
|
|
1799
1809
|
});
|
|
1800
|
-
if (isRenameParamsWasEnabled)
|
|
1801
|
-
this.isRenameParamsEnabled = true;
|
|
1802
1810
|
});
|
|
1803
1811
|
}
|
|
1804
1812
|
/**
|
|
@@ -1816,21 +1824,18 @@
|
|
|
1816
1824
|
this.eventEmitter.on(EVENT_TYPE.RECEIVE, callback);
|
|
1817
1825
|
}
|
|
1818
1826
|
sendEvent({ handler, method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) {
|
|
1819
|
-
const
|
|
1820
|
-
if (getPlatform() === PLATFORM.WEB &&
|
|
1821
|
-
handler === HANDLER.EXPRESS &&
|
|
1822
|
-
this.isRenameParamsEnabled)
|
|
1823
|
-
this.isRenameParamsEnabled = false;
|
|
1827
|
+
const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : false;
|
|
1824
1828
|
const ref = v4(); // UUID to detect express response.
|
|
1829
|
+
this.handler = handler;
|
|
1825
1830
|
const payload = {
|
|
1826
1831
|
ref,
|
|
1827
1832
|
type: WEB_COMMAND_TYPE_RPC,
|
|
1828
1833
|
method,
|
|
1829
1834
|
handler,
|
|
1830
|
-
payload:
|
|
1835
|
+
payload: isRenameParamsEnabled ? camelCaseToSnakeCase(params) : params,
|
|
1831
1836
|
guaranteed_delivery_required,
|
|
1832
1837
|
};
|
|
1833
|
-
const eventFiles =
|
|
1838
|
+
const eventFiles = isRenameParamsEnabled ?
|
|
1834
1839
|
files?.map((file) => camelCaseToSnakeCase(file)) : files;
|
|
1835
1840
|
const event = files ? { ...payload, files: eventFiles } : payload;
|
|
1836
1841
|
if (this.logsEnabled)
|
|
@@ -1839,8 +1844,6 @@
|
|
|
1839
1844
|
type: WEB_COMMAND_TYPE,
|
|
1840
1845
|
payload: event,
|
|
1841
1846
|
}, '*');
|
|
1842
|
-
if (isRenameParamsInitiallyEnabled)
|
|
1843
|
-
this.isRenameParamsEnabled = true;
|
|
1844
1847
|
return this.eventEmitter.onceWithTimeout(ref, timeout);
|
|
1845
1848
|
}
|
|
1846
1849
|
/**
|
|
@@ -1937,7 +1940,7 @@
|
|
|
1937
1940
|
* ```
|
|
1938
1941
|
*/
|
|
1939
1942
|
enableRenameParams() {
|
|
1940
|
-
this.
|
|
1943
|
+
this.isRenameParamsEnabledForBotx = true;
|
|
1941
1944
|
console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa');
|
|
1942
1945
|
}
|
|
1943
1946
|
/**
|
|
@@ -1948,12 +1951,12 @@
|
|
|
1948
1951
|
* ```
|
|
1949
1952
|
*/
|
|
1950
1953
|
disableRenameParams() {
|
|
1951
|
-
this.
|
|
1954
|
+
this.isRenameParamsEnabledForBotx = false;
|
|
1952
1955
|
console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa');
|
|
1953
1956
|
}
|
|
1954
1957
|
}
|
|
1955
1958
|
|
|
1956
|
-
const LIB_VERSION = "1.1.
|
|
1959
|
+
const LIB_VERSION = "1.1.8";
|
|
1957
1960
|
|
|
1958
1961
|
const getBridge = () => {
|
|
1959
1962
|
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.
|
|
3
|
+
"version": "1.1.7",
|
|
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.
|
|
41
|
+
"@expressms/smartapp-bridge": "^1.1.8",
|
|
42
42
|
"webpack-manifest-plugin": "2.2.0",
|
|
43
43
|
"workbox-cacheable-response": "^6.5.4",
|
|
44
44
|
"workbox-expiration": "^6.5.4",
|