@expressms/smartapp-sdk 1.14.0-alpha.6 → 1.14.0-alpha.8
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.
|
@@ -182,6 +182,7 @@ export type ReadyEventResponse = {
|
|
|
182
182
|
initialData?: InitialDataEmail | InitialDataProfileAction | InitialDataPush | InitialDataDeeplink | InitialDataMenuAction | InitialDataLink;
|
|
183
183
|
rules?: Array<RuleDownload | RuleUpload | RuleShare | RuleCopy>;
|
|
184
184
|
isPinned?: boolean;
|
|
185
|
+
toolbarVisible?: boolean;
|
|
185
186
|
};
|
|
186
187
|
} | undefined;
|
|
187
188
|
export interface File {
|
|
@@ -182,6 +182,7 @@ export type ReadyEventResponse = {
|
|
|
182
182
|
initialData?: InitialDataEmail | InitialDataProfileAction | InitialDataPush | InitialDataDeeplink | InitialDataMenuAction | InitialDataLink;
|
|
183
183
|
rules?: Array<RuleDownload | RuleUpload | RuleShare | RuleCopy>;
|
|
184
184
|
isPinned?: boolean;
|
|
185
|
+
toolbarVisible?: boolean;
|
|
185
186
|
};
|
|
186
187
|
} | undefined;
|
|
187
188
|
export interface File {
|
package/build/umd/index.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
PLATFORM["WEB"] = "web";
|
|
10
10
|
PLATFORM["IOS"] = "ios";
|
|
11
11
|
PLATFORM["ANDROID"] = "android";
|
|
12
|
+
PLATFORM["AURORA"] = "aurora";
|
|
12
13
|
PLATFORM["UNKNOWN"] = "unknown";
|
|
13
14
|
})(PLATFORM || (PLATFORM = {}));
|
|
14
15
|
var EVENT_TYPE;
|
|
@@ -42,6 +43,9 @@
|
|
|
42
43
|
(navigator.userAgent.includes('Mac') && 'ontouchend' in document)) &&
|
|
43
44
|
!window.MSStream)
|
|
44
45
|
return PLATFORM.IOS;
|
|
46
|
+
if (/aurora/i.test(navigator.userAgent)) {
|
|
47
|
+
return PLATFORM.AURORA;
|
|
48
|
+
}
|
|
45
49
|
return PLATFORM.WEB;
|
|
46
50
|
};
|
|
47
51
|
/**
|
|
@@ -50,7 +54,7 @@
|
|
|
50
54
|
* ```typescript
|
|
51
55
|
* const platform = getPlatform();
|
|
52
56
|
*
|
|
53
|
-
* // => 'web' | 'ios' | 'android'
|
|
57
|
+
* // => 'web' | 'ios' | 'android' | 'aurora'
|
|
54
58
|
* ```
|
|
55
59
|
*/
|
|
56
60
|
const getPlatform = () => {
|
|
@@ -1598,6 +1602,170 @@
|
|
|
1598
1602
|
}
|
|
1599
1603
|
}
|
|
1600
1604
|
|
|
1605
|
+
class AuroraBridge extends Logger {
|
|
1606
|
+
eventEmitter;
|
|
1607
|
+
isRenameParamsEnabledForBotx;
|
|
1608
|
+
constructor() {
|
|
1609
|
+
super();
|
|
1610
|
+
this.eventEmitter = new ExtendedEventEmitter();
|
|
1611
|
+
this.isRenameParamsEnabledForBotx = true;
|
|
1612
|
+
window.handleAuroraEvent = this.handleAuroraEvent.bind(this);
|
|
1613
|
+
}
|
|
1614
|
+
handleAuroraEvent({ ref, data, files, }) {
|
|
1615
|
+
this.logRecvEvent({ ref, data, files });
|
|
1616
|
+
const { type, ...payload } = data;
|
|
1617
|
+
const emitterType = ref || EVENT_TYPE.RECEIVE;
|
|
1618
|
+
const eventFiles = this.isRenameParamsEnabledForBotx ? files?.map((file) => snakeCaseToCamelCase(file)) : files;
|
|
1619
|
+
const event = {
|
|
1620
|
+
ref,
|
|
1621
|
+
type,
|
|
1622
|
+
payload: this.isRenameParamsEnabledForBotx ? snakeCaseToCamelCase(payload) : payload,
|
|
1623
|
+
files: eventFiles,
|
|
1624
|
+
};
|
|
1625
|
+
this.eventEmitter.emit(emitterType, event);
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Set callback function to handle events without **ref**
|
|
1629
|
+
* (notifications for example).
|
|
1630
|
+
*
|
|
1631
|
+
* ```js
|
|
1632
|
+
* bridge.onRecieve(({ type, handler, payload }) => {
|
|
1633
|
+
* // Handle event data
|
|
1634
|
+
* console.log('event', type, handler, payload)
|
|
1635
|
+
* })
|
|
1636
|
+
* ```
|
|
1637
|
+
* @param callback - Callback function.
|
|
1638
|
+
*/
|
|
1639
|
+
onReceive(callback) {
|
|
1640
|
+
this.eventEmitter.on(EVENT_TYPE.RECEIVE, callback);
|
|
1641
|
+
}
|
|
1642
|
+
sendEvent({ handler, method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required = false, sync_request = false, sync_request_timeout = SYNC_RESPONSE_TIMEOUT, hide_send_event_data = false, hide_recv_event_data = false, }) {
|
|
1643
|
+
const ref = v4(); // UUID to detect express response.
|
|
1644
|
+
const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true;
|
|
1645
|
+
const eventProps = {
|
|
1646
|
+
ref,
|
|
1647
|
+
type: WEB_COMMAND_TYPE_RPC,
|
|
1648
|
+
method,
|
|
1649
|
+
handler,
|
|
1650
|
+
payload: isRenameParamsEnabled ? camelCaseToSnakeCase(params) : params,
|
|
1651
|
+
guaranteed_delivery_required,
|
|
1652
|
+
sync_request,
|
|
1653
|
+
sync_request_timeout,
|
|
1654
|
+
hide_send_event_data,
|
|
1655
|
+
hide_recv_event_data,
|
|
1656
|
+
};
|
|
1657
|
+
const eventFiles = isRenameParamsEnabled ? files?.map((file) => camelCaseToSnakeCase(file)) : files;
|
|
1658
|
+
const event = files ? { ...eventProps, files: eventFiles } : eventProps;
|
|
1659
|
+
this.logSendEvent(event);
|
|
1660
|
+
const customEvent = new CustomEvent('framescript:action', { detail: event });
|
|
1661
|
+
document.dispatchEvent(customEvent);
|
|
1662
|
+
return this.eventEmitter.onceWithTimeout(ref, timeout);
|
|
1663
|
+
}
|
|
1664
|
+
/**
|
|
1665
|
+
* Send event and wait response from express client.
|
|
1666
|
+
*
|
|
1667
|
+
* ```js
|
|
1668
|
+
* bridge
|
|
1669
|
+
* .sendBotEvent(
|
|
1670
|
+
* {
|
|
1671
|
+
* method: 'get_weather',
|
|
1672
|
+
* params: {
|
|
1673
|
+
* city: 'Moscow',
|
|
1674
|
+
* },
|
|
1675
|
+
* files: []
|
|
1676
|
+
* }
|
|
1677
|
+
* )
|
|
1678
|
+
* .then(data => {
|
|
1679
|
+
* // Handle response
|
|
1680
|
+
* console.log('response', data)
|
|
1681
|
+
* })
|
|
1682
|
+
* ```
|
|
1683
|
+
*/
|
|
1684
|
+
sendBotEvent({ method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required, sync_request, sync_request_timeout, hide_send_event_data, hide_recv_event_data, }) {
|
|
1685
|
+
return this.sendEvent({
|
|
1686
|
+
handler: HANDLER.BOTX,
|
|
1687
|
+
method,
|
|
1688
|
+
params,
|
|
1689
|
+
files,
|
|
1690
|
+
timeout,
|
|
1691
|
+
guaranteed_delivery_required,
|
|
1692
|
+
sync_request,
|
|
1693
|
+
sync_request_timeout,
|
|
1694
|
+
hide_send_event_data,
|
|
1695
|
+
hide_recv_event_data,
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
/**
|
|
1699
|
+
* Send event and wait response from express client.
|
|
1700
|
+
*
|
|
1701
|
+
* ```js
|
|
1702
|
+
* bridge
|
|
1703
|
+
* .sendClientEvent(
|
|
1704
|
+
* {
|
|
1705
|
+
* type: 'get_weather',
|
|
1706
|
+
* handler: 'express',
|
|
1707
|
+
* payload: {
|
|
1708
|
+
* city: 'Moscow',
|
|
1709
|
+
* },
|
|
1710
|
+
* }
|
|
1711
|
+
* )
|
|
1712
|
+
* .then(data => {
|
|
1713
|
+
* // Handle response
|
|
1714
|
+
* console.log('response', data)
|
|
1715
|
+
* })
|
|
1716
|
+
* ```
|
|
1717
|
+
*/
|
|
1718
|
+
sendClientEvent({ method, params, timeout = RESPONSE_TIMEOUT, hide_send_event_data, hide_recv_event_data, }) {
|
|
1719
|
+
return this.sendEvent({
|
|
1720
|
+
handler: HANDLER.EXPRESS,
|
|
1721
|
+
method,
|
|
1722
|
+
params,
|
|
1723
|
+
timeout,
|
|
1724
|
+
hide_send_event_data,
|
|
1725
|
+
hide_recv_event_data,
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
/**
|
|
1729
|
+
* Enabling renaming event params from camelCase to snake_case and vice versa
|
|
1730
|
+
* ```js
|
|
1731
|
+
* bridge
|
|
1732
|
+
* .enableRenameParams()
|
|
1733
|
+
* ```
|
|
1734
|
+
*/
|
|
1735
|
+
enableRenameParams() {
|
|
1736
|
+
this.isRenameParamsEnabledForBotx = true;
|
|
1737
|
+
console.log('Bridge ~ Enabled renaming event params from camelCase to snake_case and vice versa');
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Enabling renaming event params from camelCase to snake_case and vice versa
|
|
1741
|
+
* ```js
|
|
1742
|
+
* bridge
|
|
1743
|
+
* .disableRenameParams()
|
|
1744
|
+
* ```
|
|
1745
|
+
*/
|
|
1746
|
+
disableRenameParams() {
|
|
1747
|
+
this.isRenameParamsEnabledForBotx = false;
|
|
1748
|
+
console.log('Bridge ~ Disabled renaming event params from camelCase to snake_case and vice versa');
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Write log to client
|
|
1752
|
+
* @param data Any data to log
|
|
1753
|
+
*/
|
|
1754
|
+
log(data) {
|
|
1755
|
+
let value = '';
|
|
1756
|
+
if (typeof data === 'string') {
|
|
1757
|
+
value = data;
|
|
1758
|
+
}
|
|
1759
|
+
else if (typeof data === 'object') {
|
|
1760
|
+
value = JSON.stringify(data, null, 2);
|
|
1761
|
+
}
|
|
1762
|
+
else
|
|
1763
|
+
return;
|
|
1764
|
+
const event = new CustomEvent('framescript:action', { detail: { 'SmartApp Log': value } });
|
|
1765
|
+
document.dispatchEvent(event);
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1601
1769
|
class IosBridge extends Logger {
|
|
1602
1770
|
eventEmitter;
|
|
1603
1771
|
hasCommunicationObject;
|
|
@@ -1945,7 +2113,7 @@
|
|
|
1945
2113
|
}
|
|
1946
2114
|
}
|
|
1947
2115
|
|
|
1948
|
-
const LIB_VERSION = "1.
|
|
2116
|
+
const LIB_VERSION = "1.5.0-alpha.0";
|
|
1949
2117
|
|
|
1950
2118
|
const getBridge = () => {
|
|
1951
2119
|
if (process.env.NODE_ENV === 'test')
|
|
@@ -1955,6 +2123,8 @@
|
|
|
1955
2123
|
switch (platform) {
|
|
1956
2124
|
case PLATFORM.ANDROID:
|
|
1957
2125
|
return new AndroidBridge();
|
|
2126
|
+
case PLATFORM.AURORA:
|
|
2127
|
+
return new AuroraBridge();
|
|
1958
2128
|
case PLATFORM.IOS:
|
|
1959
2129
|
return new IosBridge();
|
|
1960
2130
|
case PLATFORM.WEB:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expressms/smartapp-sdk",
|
|
3
|
-
"version": "1.14.0-alpha.
|
|
3
|
+
"version": "1.14.0-alpha.8",
|
|
4
4
|
"description": "Smartapp SDK",
|
|
5
5
|
"main": "build/main/index.js",
|
|
6
6
|
"typings": "build/main/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"vitest": "^1.6.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@expressms/smartapp-bridge": "1.
|
|
43
|
+
"@expressms/smartapp-bridge": "1.5.0-alpha.0"
|
|
44
44
|
},
|
|
45
45
|
"files": [
|
|
46
46
|
"build/main",
|