@expressms/smartapp-sdk 1.1.5 → 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.
|
@@ -11,6 +11,8 @@ declare const openGroupChat: ({ groupChatId }: {
|
|
|
11
11
|
declare const sendBotCommand: ({ userHuid, body, data }: {
|
|
12
12
|
userHuid: string;
|
|
13
13
|
body: string;
|
|
14
|
-
data:
|
|
14
|
+
data: {
|
|
15
|
+
command: string;
|
|
16
|
+
} | null;
|
|
15
17
|
}) => Promise<import("@expressms/smartapp-bridge/build/main/types/eventEmitter").EmitterEventPayload> | undefined;
|
|
16
18
|
export { openClientSettings, getChats, searchCorporatePhonebook, sendBotCommand, openGroupChat, };
|
|
@@ -35,6 +35,8 @@ const openGroupChat = ({ groupChatId }) => {
|
|
|
35
35
|
};
|
|
36
36
|
exports.openGroupChat = openGroupChat;
|
|
37
37
|
const sendBotCommand = ({ userHuid, body, data }) => {
|
|
38
|
+
if (typeof data !== 'object')
|
|
39
|
+
return;
|
|
38
40
|
return smartapp_bridge_1.default === null || smartapp_bridge_1.default === void 0 ? void 0 : smartapp_bridge_1.default.sendClientEvent({
|
|
39
41
|
method: types_1.METHODS.SEND_BOT_COMMAND,
|
|
40
42
|
params: {
|
|
@@ -47,4 +49,4 @@ const sendBotCommand = ({ userHuid, body, data }) => {
|
|
|
47
49
|
});
|
|
48
50
|
};
|
|
49
51
|
exports.sendBotCommand = sendBotCommand;
|
|
50
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
52
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvbGliL2NsaWVudC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSxpRkFBK0M7QUFDL0MsdUNBQXFDO0FBRXJDLE1BQU0sa0JBQWtCLEdBQUcsR0FBRyxFQUFFO0lBQzlCLE9BQU8seUJBQU0sYUFBTix5QkFBTSx1QkFBTix5QkFBTSxDQUFFLGVBQWUsQ0FBQztRQUM3QixNQUFNLEVBQUUsZUFBTyxDQUFDLG9CQUFvQjtRQUNwQyxNQUFNLEVBQUUsRUFBRTtLQUNYLENBQUMsQ0FBQTtBQUNKLENBQUMsQ0FBQTtBQWlEQyxnREFBa0I7QUEvQ3BCLE1BQU0sUUFBUSxHQUFHLENBQUMsRUFBRSxNQUFNLEdBQUcsSUFBSSxFQUE2QixFQUFFLEVBQUU7SUFDaEUsT0FBTyx5QkFBTSxhQUFOLHlCQUFNLHVCQUFOLHlCQUFNLENBQUUsZUFBZSxDQUFDO1FBQzdCLE1BQU0sRUFBRSxlQUFPLENBQUMsU0FBUztRQUN6QixNQUFNLEVBQUUsRUFBRSxNQUFNLEVBQUU7S0FDbkIsQ0FBQyxDQUFBO0FBQ0osQ0FBQyxDQUFBO0FBMkNDLDRCQUFRO0FBekNWLE1BQU0sd0JBQXdCLEdBQUcsQ0FBQyxFQUFFLE1BQU0sR0FBRyxJQUFJLEVBQTZCLEVBQUUsRUFBRTtJQUNoRixPQUFPLHlCQUFNLGFBQU4seUJBQU0sdUJBQU4seUJBQU0sQ0FBRSxlQUFlLENBQUM7UUFDN0IsTUFBTSxFQUFFLGVBQU8sQ0FBQywwQkFBMEI7UUFDMUMsTUFBTSxFQUFFLEVBQUUsTUFBTSxFQUFFO0tBQ25CLENBQUMsQ0FBQTtBQUNKLENBQUMsQ0FBQTtBQXFDQyw0REFBd0I7QUFuQzFCLE1BQU0sYUFBYSxHQUFHLENBQUMsRUFBRSxXQUFXLEVBQTJCLEVBQUUsRUFBRTtJQUNqRSxPQUFPLHlCQUFNLGFBQU4seUJBQU0sdUJBQU4seUJBQU0sQ0FBRSxlQUFlLENBQUM7UUFDN0IsTUFBTSxFQUFFLGVBQU8sQ0FBQyxlQUFlO1FBQy9CLE1BQU0sRUFBRSxFQUFFLFdBQVcsRUFBRTtLQUN4QixDQUFDLENBQUE7QUFDSixDQUFDLENBQUE7QUFnQ0Msc0NBQWE7QUE5QmYsTUFBTSxjQUFjLEdBQUcsQ0FDckIsRUFDRSxRQUFRLEVBQ1IsSUFBSSxFQUNKLElBQUksRUFLTCxFQUNELEVBQUU7SUFDRixJQUFJLE9BQU8sSUFBSSxLQUFLLFFBQVE7UUFBRSxPQUFNO0lBRXBDLE9BQU8seUJBQU0sYUFBTix5QkFBTSx1QkFBTix5QkFBTSxDQUFFLGVBQWUsQ0FBQztRQUM3QixNQUFNLEVBQUUsZUFBTyxDQUFDLGdCQUFnQjtRQUNoQyxNQUFNLEVBQUU7WUFDTixRQUFRO1lBQ1IsT0FBTyxFQUFFO2dCQUNQLElBQUk7Z0JBQ0osSUFBSTthQUNMO1NBQ0Y7S0FDRixDQUFDLENBQUE7QUFDSixDQUFDLENBQUE7QUFNQyx3Q0FBYyJ9
|
|
@@ -11,6 +11,8 @@ declare const openGroupChat: ({ groupChatId }: {
|
|
|
11
11
|
declare const sendBotCommand: ({ userHuid, body, data }: {
|
|
12
12
|
userHuid: string;
|
|
13
13
|
body: string;
|
|
14
|
-
data:
|
|
14
|
+
data: {
|
|
15
|
+
command: string;
|
|
16
|
+
} | null;
|
|
15
17
|
}) => Promise<import("@expressms/smartapp-bridge/build/main/types/eventEmitter").EmitterEventPayload> | undefined;
|
|
16
18
|
export { openClientSettings, getChats, searchCorporatePhonebook, sendBotCommand, openGroupChat, };
|
|
@@ -25,6 +25,8 @@ const openGroupChat = ({ groupChatId }) => {
|
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
27
|
const sendBotCommand = ({ userHuid, body, data }) => {
|
|
28
|
+
if (typeof data !== 'object')
|
|
29
|
+
return;
|
|
28
30
|
return bridge?.sendClientEvent({
|
|
29
31
|
method: METHODS.SEND_BOT_COMMAND,
|
|
30
32
|
params: {
|
|
@@ -37,4 +39,4 @@ const sendBotCommand = ({ userHuid, body, data }) => {
|
|
|
37
39
|
});
|
|
38
40
|
};
|
|
39
41
|
export { openClientSettings, getChats, searchCorporatePhonebook, sendBotCommand, openGroupChat, };
|
|
40
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
42
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvbGliL2NsaWVudC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLE1BQU0sTUFBTSw0QkFBNEIsQ0FBQTtBQUMvQyxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sYUFBYSxDQUFBO0FBRXJDLE1BQU0sa0JBQWtCLEdBQUcsR0FBRyxFQUFFO0lBQzlCLE9BQU8sTUFBTSxFQUFFLGVBQWUsQ0FBQztRQUM3QixNQUFNLEVBQUUsT0FBTyxDQUFDLG9CQUFvQjtRQUNwQyxNQUFNLEVBQUUsRUFBRTtLQUNYLENBQUMsQ0FBQTtBQUNKLENBQUMsQ0FBQTtBQUVELE1BQU0sUUFBUSxHQUFHLENBQUMsRUFBRSxNQUFNLEdBQUcsSUFBSSxFQUE2QixFQUFFLEVBQUU7SUFDaEUsT0FBTyxNQUFNLEVBQUUsZUFBZSxDQUFDO1FBQzdCLE1BQU0sRUFBRSxPQUFPLENBQUMsU0FBUztRQUN6QixNQUFNLEVBQUUsRUFBRSxNQUFNLEVBQUU7S0FDbkIsQ0FBQyxDQUFBO0FBQ0osQ0FBQyxDQUFBO0FBRUQsTUFBTSx3QkFBd0IsR0FBRyxDQUFDLEVBQUUsTUFBTSxHQUFHLElBQUksRUFBNkIsRUFBRSxFQUFFO0lBQ2hGLE9BQU8sTUFBTSxFQUFFLGVBQWUsQ0FBQztRQUM3QixNQUFNLEVBQUUsT0FBTyxDQUFDLDBCQUEwQjtRQUMxQyxNQUFNLEVBQUUsRUFBRSxNQUFNLEVBQUU7S0FDbkIsQ0FBQyxDQUFBO0FBQ0osQ0FBQyxDQUFBO0FBRUQsTUFBTSxhQUFhLEdBQUcsQ0FBQyxFQUFFLFdBQVcsRUFBMkIsRUFBRSxFQUFFO0lBQ2pFLE9BQU8sTUFBTSxFQUFFLGVBQWUsQ0FBQztRQUM3QixNQUFNLEVBQUUsT0FBTyxDQUFDLGVBQWU7UUFDL0IsTUFBTSxFQUFFLEVBQUUsV0FBVyxFQUFFO0tBQ3hCLENBQUMsQ0FBQTtBQUNKLENBQUMsQ0FBQTtBQUVELE1BQU0sY0FBYyxHQUFHLENBQ3JCLEVBQ0UsUUFBUSxFQUNSLElBQUksRUFDSixJQUFJLEVBS0wsRUFDRCxFQUFFO0lBQ0YsSUFBSSxPQUFPLElBQUksS0FBSyxRQUFRO1FBQUUsT0FBTTtJQUVwQyxPQUFPLE1BQU0sRUFBRSxlQUFlLENBQUM7UUFDN0IsTUFBTSxFQUFFLE9BQU8sQ0FBQyxnQkFBZ0I7UUFDaEMsTUFBTSxFQUFFO1lBQ04sUUFBUTtZQUNSLE9BQU8sRUFBRTtnQkFDUCxJQUFJO2dCQUNKLElBQUk7YUFDTDtTQUNGO0tBQ0YsQ0FBQyxDQUFBO0FBQ0osQ0FBQyxDQUFBO0FBRUQsT0FBTyxFQUNMLGtCQUFrQixFQUNsQixRQUFRLEVBQ1Isd0JBQXdCLEVBQ3hCLGNBQWMsRUFDZCxhQUFhLEdBQ2QsQ0FBQSJ9
|
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,17 +1573,14 @@
|
|
|
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) {
|
|
1573
|
-
if (!this.hasCommunicationObject)
|
|
1574
|
-
|
|
1575
|
-
let value = '';
|
|
1576
|
-
if (typeof data !== 'string' && typeof data !== 'object')
|
|
1580
|
+
if ((!this.hasCommunicationObject || !data) ||
|
|
1581
|
+
(typeof data !== 'string' && typeof data !== 'object'))
|
|
1577
1582
|
return;
|
|
1578
|
-
|
|
1579
|
-
window.express.handleSmartAppEvent(JSON.stringify({ 'SmartApp Log': value }, null, 2));
|
|
1583
|
+
window.express.handleSmartAppEvent(JSON.stringify({ 'SmartApp Log': data }, null, 2));
|
|
1580
1584
|
}
|
|
1581
1585
|
}
|
|
1582
1586
|
|
|
@@ -1584,7 +1588,8 @@
|
|
|
1584
1588
|
eventEmitter;
|
|
1585
1589
|
hasCommunicationObject;
|
|
1586
1590
|
logsEnabled;
|
|
1587
|
-
|
|
1591
|
+
isRenameParamsEnabledForBotx;
|
|
1592
|
+
handler;
|
|
1588
1593
|
constructor() {
|
|
1589
1594
|
this.hasCommunicationObject =
|
|
1590
1595
|
window.webkit &&
|
|
@@ -1593,7 +1598,8 @@
|
|
|
1593
1598
|
!!window.webkit.messageHandlers.express.postMessage;
|
|
1594
1599
|
this.eventEmitter = new ExtendedEventEmitter();
|
|
1595
1600
|
this.logsEnabled = false;
|
|
1596
|
-
this.
|
|
1601
|
+
this.isRenameParamsEnabledForBotx = true;
|
|
1602
|
+
this.handler = null;
|
|
1597
1603
|
if (!this.hasCommunicationObject) {
|
|
1598
1604
|
log('No method "express.postMessage", cannot send message to iOS');
|
|
1599
1605
|
return;
|
|
@@ -1604,12 +1610,13 @@
|
|
|
1604
1610
|
console.log('Bridge ~ Incoming event', JSON.stringify({ ref, data, files }, null, 2));
|
|
1605
1611
|
const { type, ...payload } = data;
|
|
1606
1612
|
const emitterType = ref || EVENT_TYPE.RECEIVE;
|
|
1607
|
-
const
|
|
1613
|
+
const isRenameParamsEnabled = this.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true;
|
|
1614
|
+
const eventFiles = isRenameParamsEnabled ?
|
|
1608
1615
|
files?.map((file) => snakeCaseToCamelCase(file)) : files;
|
|
1609
1616
|
const event = {
|
|
1610
1617
|
ref,
|
|
1611
1618
|
type,
|
|
1612
|
-
payload:
|
|
1619
|
+
payload: isRenameParamsEnabled ? snakeCaseToCamelCase(payload) : payload,
|
|
1613
1620
|
files: eventFiles,
|
|
1614
1621
|
};
|
|
1615
1622
|
this.eventEmitter.emit(emitterType, event);
|
|
@@ -1633,15 +1640,17 @@
|
|
|
1633
1640
|
if (!this.hasCommunicationObject)
|
|
1634
1641
|
return Promise.reject();
|
|
1635
1642
|
const ref = v4(); // UUID to detect express response.
|
|
1643
|
+
this.handler = handler;
|
|
1644
|
+
const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true;
|
|
1636
1645
|
const eventProps = {
|
|
1637
1646
|
ref,
|
|
1638
1647
|
type: WEB_COMMAND_TYPE_RPC,
|
|
1639
1648
|
method,
|
|
1640
1649
|
handler,
|
|
1641
|
-
payload:
|
|
1650
|
+
payload: isRenameParamsEnabled ? camelCaseToSnakeCase(params) : params,
|
|
1642
1651
|
guaranteed_delivery_required,
|
|
1643
1652
|
};
|
|
1644
|
-
const eventFiles =
|
|
1653
|
+
const eventFiles = isRenameParamsEnabled ?
|
|
1645
1654
|
files?.map((file) => camelCaseToSnakeCase(file)) : files;
|
|
1646
1655
|
const event = files ? { ...eventProps, files: eventFiles } : eventProps;
|
|
1647
1656
|
if (this.logsEnabled)
|
|
@@ -1737,7 +1746,7 @@
|
|
|
1737
1746
|
* ```
|
|
1738
1747
|
*/
|
|
1739
1748
|
enableRenameParams() {
|
|
1740
|
-
this.
|
|
1749
|
+
this.isRenameParamsEnabledForBotx = true;
|
|
1741
1750
|
console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa');
|
|
1742
1751
|
}
|
|
1743
1752
|
/**
|
|
@@ -1748,19 +1757,21 @@
|
|
|
1748
1757
|
* ```
|
|
1749
1758
|
*/
|
|
1750
1759
|
disableRenameParams() {
|
|
1751
|
-
this.
|
|
1760
|
+
this.isRenameParamsEnabledForBotx = false;
|
|
1752
1761
|
console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa');
|
|
1753
1762
|
}
|
|
1754
1763
|
log(data) {
|
|
1755
|
-
if (!this.hasCommunicationObject)
|
|
1764
|
+
if (!this.hasCommunicationObject || !data)
|
|
1756
1765
|
return;
|
|
1757
1766
|
let value = '';
|
|
1758
|
-
if (typeof data
|
|
1767
|
+
if (typeof data === 'string') {
|
|
1759
1768
|
value = data;
|
|
1760
1769
|
}
|
|
1761
|
-
else if (typeof data
|
|
1770
|
+
else if (typeof data === 'object') {
|
|
1762
1771
|
value = JSON.stringify(data, null, 2);
|
|
1763
1772
|
}
|
|
1773
|
+
else
|
|
1774
|
+
return;
|
|
1764
1775
|
window.webkit.messageHandlers.express.postMessage({ 'SmartApp Log': value });
|
|
1765
1776
|
}
|
|
1766
1777
|
}
|
|
@@ -1768,38 +1779,34 @@
|
|
|
1768
1779
|
class WebBridge {
|
|
1769
1780
|
eventEmitter;
|
|
1770
1781
|
logsEnabled;
|
|
1771
|
-
|
|
1782
|
+
isRenameParamsEnabledForBotx;
|
|
1783
|
+
handler;
|
|
1772
1784
|
constructor() {
|
|
1773
1785
|
this.eventEmitter = new ExtendedEventEmitter();
|
|
1774
1786
|
this.addGlobalListener();
|
|
1775
1787
|
this.logsEnabled = false;
|
|
1776
|
-
this.
|
|
1788
|
+
this.isRenameParamsEnabledForBotx = true;
|
|
1789
|
+
this.handler = null;
|
|
1777
1790
|
}
|
|
1778
1791
|
addGlobalListener() {
|
|
1779
1792
|
window.addEventListener('message', (event) => {
|
|
1780
|
-
const isRenameParamsWasEnabled = this.isRenameParamsEnabled;
|
|
1781
|
-
if (getPlatform() === PLATFORM.WEB &&
|
|
1782
|
-
event.data.handler === HANDLER.EXPRESS &&
|
|
1783
|
-
this.isRenameParamsEnabled)
|
|
1784
|
-
this.isRenameParamsEnabled = false;
|
|
1785
1793
|
if (typeof event.data !== 'object' ||
|
|
1786
1794
|
typeof event.data.data !== 'object' ||
|
|
1787
1795
|
typeof event.data.data.type !== 'string')
|
|
1788
1796
|
return;
|
|
1797
|
+
const { ref, data: { type, ...payload }, files, } = event.data;
|
|
1798
|
+
const isRenameParamsEnabled = this.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : false;
|
|
1789
1799
|
if (this.logsEnabled)
|
|
1790
1800
|
console.log('Bridge ~ Incoming event', event.data);
|
|
1791
|
-
const { ref, data: { type, ...payload }, files, } = event.data;
|
|
1792
1801
|
const emitterType = ref || EVENT_TYPE.RECEIVE;
|
|
1793
|
-
const eventFiles =
|
|
1802
|
+
const eventFiles = isRenameParamsEnabled ?
|
|
1794
1803
|
files?.map((file) => snakeCaseToCamelCase(file)) : files;
|
|
1795
1804
|
this.eventEmitter.emit(emitterType, {
|
|
1796
1805
|
ref,
|
|
1797
1806
|
type,
|
|
1798
|
-
payload:
|
|
1807
|
+
payload: isRenameParamsEnabled ? snakeCaseToCamelCase(payload) : payload,
|
|
1799
1808
|
files: eventFiles,
|
|
1800
1809
|
});
|
|
1801
|
-
if (isRenameParamsWasEnabled)
|
|
1802
|
-
this.isRenameParamsEnabled = true;
|
|
1803
1810
|
});
|
|
1804
1811
|
}
|
|
1805
1812
|
/**
|
|
@@ -1817,21 +1824,18 @@
|
|
|
1817
1824
|
this.eventEmitter.on(EVENT_TYPE.RECEIVE, callback);
|
|
1818
1825
|
}
|
|
1819
1826
|
sendEvent({ handler, method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) {
|
|
1820
|
-
const
|
|
1821
|
-
if (getPlatform() === PLATFORM.WEB &&
|
|
1822
|
-
handler === HANDLER.EXPRESS &&
|
|
1823
|
-
this.isRenameParamsEnabled)
|
|
1824
|
-
this.isRenameParamsEnabled = false;
|
|
1827
|
+
const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : false;
|
|
1825
1828
|
const ref = v4(); // UUID to detect express response.
|
|
1829
|
+
this.handler = handler;
|
|
1826
1830
|
const payload = {
|
|
1827
1831
|
ref,
|
|
1828
1832
|
type: WEB_COMMAND_TYPE_RPC,
|
|
1829
1833
|
method,
|
|
1830
1834
|
handler,
|
|
1831
|
-
payload:
|
|
1835
|
+
payload: isRenameParamsEnabled ? camelCaseToSnakeCase(params) : params,
|
|
1832
1836
|
guaranteed_delivery_required,
|
|
1833
1837
|
};
|
|
1834
|
-
const eventFiles =
|
|
1838
|
+
const eventFiles = isRenameParamsEnabled ?
|
|
1835
1839
|
files?.map((file) => camelCaseToSnakeCase(file)) : files;
|
|
1836
1840
|
const event = files ? { ...payload, files: eventFiles } : payload;
|
|
1837
1841
|
if (this.logsEnabled)
|
|
@@ -1840,8 +1844,6 @@
|
|
|
1840
1844
|
type: WEB_COMMAND_TYPE,
|
|
1841
1845
|
payload: event,
|
|
1842
1846
|
}, '*');
|
|
1843
|
-
if (isRenameParamsInitiallyEnabled)
|
|
1844
|
-
this.isRenameParamsEnabled = true;
|
|
1845
1847
|
return this.eventEmitter.onceWithTimeout(ref, timeout);
|
|
1846
1848
|
}
|
|
1847
1849
|
/**
|
|
@@ -1938,7 +1940,7 @@
|
|
|
1938
1940
|
* ```
|
|
1939
1941
|
*/
|
|
1940
1942
|
enableRenameParams() {
|
|
1941
|
-
this.
|
|
1943
|
+
this.isRenameParamsEnabledForBotx = true;
|
|
1942
1944
|
console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa');
|
|
1943
1945
|
}
|
|
1944
1946
|
/**
|
|
@@ -1949,12 +1951,12 @@
|
|
|
1949
1951
|
* ```
|
|
1950
1952
|
*/
|
|
1951
1953
|
disableRenameParams() {
|
|
1952
|
-
this.
|
|
1954
|
+
this.isRenameParamsEnabledForBotx = false;
|
|
1953
1955
|
console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa');
|
|
1954
1956
|
}
|
|
1955
1957
|
}
|
|
1956
1958
|
|
|
1957
|
-
const LIB_VERSION = "1.1.
|
|
1959
|
+
const LIB_VERSION = "1.1.8";
|
|
1958
1960
|
|
|
1959
1961
|
const getBridge = () => {
|
|
1960
1962
|
if (process.env.NODE_ENV === 'test')
|
|
@@ -2025,6 +2027,8 @@
|
|
|
2025
2027
|
});
|
|
2026
2028
|
};
|
|
2027
2029
|
const sendBotCommand = ({ userHuid, body, data }) => {
|
|
2030
|
+
if (typeof data !== 'object')
|
|
2031
|
+
return;
|
|
2028
2032
|
return bridge?.sendClientEvent({
|
|
2029
2033
|
method: METHODS.SEND_BOT_COMMAND,
|
|
2030
2034
|
params: {
|
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",
|