@expressms/smartapp-sdk 1.1.8 → 1.2.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.
Files changed (37) hide show
  1. package/README.md +161 -13
  2. package/build/main/index.d.ts +4 -4
  3. package/build/main/index.js +7 -2
  4. package/build/main/lib/client/index.d.ts +3 -2
  5. package/build/main/lib/client/index.js +10 -3
  6. package/build/main/lib/contacts/index.d.ts +6 -2
  7. package/build/main/lib/contacts/index.js +19 -3
  8. package/build/main/lib/index.d.ts +0 -3
  9. package/build/main/lib/index.js +1 -4
  10. package/build/main/lib/logging/index.d.ts +2 -4
  11. package/build/main/lib/logging/index.js +2 -6
  12. package/build/main/lib/notification/index.d.ts +0 -3
  13. package/build/main/lib/notification/index.js +1 -4
  14. package/build/main/lib/routing/index.d.ts +7 -12
  15. package/build/main/lib/routing/index.js +20 -21
  16. package/build/main/types/bridge.d.ts +17 -2
  17. package/build/main/types/bridge.js +8 -3
  18. package/build/main/types/contacts.d.ts +24 -0
  19. package/build/module/index.d.ts +4 -4
  20. package/build/module/index.js +5 -5
  21. package/build/module/lib/client/index.d.ts +3 -2
  22. package/build/module/lib/client/index.js +9 -3
  23. package/build/module/lib/contacts/index.d.ts +6 -2
  24. package/build/module/lib/contacts/index.js +18 -4
  25. package/build/module/lib/index.d.ts +0 -3
  26. package/build/module/lib/index.js +1 -4
  27. package/build/module/lib/logging/index.d.ts +2 -4
  28. package/build/module/lib/logging/index.js +2 -6
  29. package/build/module/lib/notification/index.d.ts +0 -3
  30. package/build/module/lib/notification/index.js +1 -4
  31. package/build/module/lib/routing/index.d.ts +7 -12
  32. package/build/module/lib/routing/index.js +19 -22
  33. package/build/module/types/bridge.d.ts +17 -2
  34. package/build/module/types/bridge.js +8 -3
  35. package/build/module/types/contacts.d.ts +24 -0
  36. package/build/umd/index.js +60 -51
  37. package/package.json +2 -2
@@ -1404,13 +1404,11 @@
1404
1404
  hasCommunicationObject;
1405
1405
  logsEnabled;
1406
1406
  isRenameParamsEnabledForBotx;
1407
- handler;
1408
1407
  constructor() {
1409
1408
  this.hasCommunicationObject = typeof window.express !== 'undefined' && !!window.express.handleSmartAppEvent;
1410
1409
  this.eventEmitter = new ExtendedEventEmitter();
1411
1410
  this.logsEnabled = false;
1412
1411
  this.isRenameParamsEnabledForBotx = true;
1413
- this.handler = null;
1414
1412
  if (!this.hasCommunicationObject) {
1415
1413
  log('No method "express.handleSmartAppEvent", cannot send message to Android');
1416
1414
  return;
@@ -1421,13 +1419,13 @@
1421
1419
  console.log('Bridge ~ Incoming event', JSON.stringify({ ref, data, files }, null, 2));
1422
1420
  const { type, ...payload } = data;
1423
1421
  const emitterType = ref || EVENT_TYPE.RECEIVE;
1424
- const isRenameParamsEnabled = this.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true;
1425
- const eventFiles = isRenameParamsEnabled ?
1422
+ // const isRenameParamsEnabled = data.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true // TODO uncomment when client is ready
1423
+ const eventFiles = this.isRenameParamsEnabledForBotx ?
1426
1424
  files?.map((file) => snakeCaseToCamelCase(file)) : files;
1427
1425
  const event = {
1428
1426
  ref,
1429
1427
  type,
1430
- payload: isRenameParamsEnabled ? snakeCaseToCamelCase(payload) : payload,
1428
+ payload: this.isRenameParamsEnabledForBotx ? snakeCaseToCamelCase(payload) : payload,
1431
1429
  files: eventFiles,
1432
1430
  };
1433
1431
  this.eventEmitter.emit(emitterType, event);
@@ -1589,7 +1587,6 @@
1589
1587
  hasCommunicationObject;
1590
1588
  logsEnabled;
1591
1589
  isRenameParamsEnabledForBotx;
1592
- handler;
1593
1590
  constructor() {
1594
1591
  this.hasCommunicationObject =
1595
1592
  window.webkit &&
@@ -1599,7 +1596,6 @@
1599
1596
  this.eventEmitter = new ExtendedEventEmitter();
1600
1597
  this.logsEnabled = false;
1601
1598
  this.isRenameParamsEnabledForBotx = true;
1602
- this.handler = null;
1603
1599
  if (!this.hasCommunicationObject) {
1604
1600
  log('No method "express.postMessage", cannot send message to iOS');
1605
1601
  return;
@@ -1610,13 +1606,13 @@
1610
1606
  console.log('Bridge ~ Incoming event', JSON.stringify({ ref, data, files }, null, 2));
1611
1607
  const { type, ...payload } = data;
1612
1608
  const emitterType = ref || EVENT_TYPE.RECEIVE;
1613
- const isRenameParamsEnabled = this.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true;
1614
- const eventFiles = isRenameParamsEnabled ?
1609
+ // const isRenameParamsEnabled = data.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true // TODO uncomment when client is ready
1610
+ const eventFiles = this.isRenameParamsEnabledForBotx ?
1615
1611
  files?.map((file) => snakeCaseToCamelCase(file)) : files;
1616
1612
  const event = {
1617
1613
  ref,
1618
1614
  type,
1619
- payload: isRenameParamsEnabled ? snakeCaseToCamelCase(payload) : payload,
1615
+ payload: this.isRenameParamsEnabledForBotx ? snakeCaseToCamelCase(payload) : payload,
1620
1616
  files: eventFiles,
1621
1617
  };
1622
1618
  this.eventEmitter.emit(emitterType, event);
@@ -1640,7 +1636,6 @@
1640
1636
  if (!this.hasCommunicationObject)
1641
1637
  return Promise.reject();
1642
1638
  const ref = v4(); // UUID to detect express response.
1643
- this.handler = handler;
1644
1639
  const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : true;
1645
1640
  const eventProps = {
1646
1641
  ref,
@@ -1780,13 +1775,11 @@
1780
1775
  eventEmitter;
1781
1776
  logsEnabled;
1782
1777
  isRenameParamsEnabledForBotx;
1783
- handler;
1784
1778
  constructor() {
1785
1779
  this.eventEmitter = new ExtendedEventEmitter();
1786
1780
  this.addGlobalListener();
1787
1781
  this.logsEnabled = false;
1788
1782
  this.isRenameParamsEnabledForBotx = true;
1789
- this.handler = null;
1790
1783
  }
1791
1784
  addGlobalListener() {
1792
1785
  window.addEventListener('message', (event) => {
@@ -1795,7 +1788,7 @@
1795
1788
  typeof event.data.data.type !== 'string')
1796
1789
  return;
1797
1790
  const { ref, data: { type, ...payload }, files, } = event.data;
1798
- const isRenameParamsEnabled = this.handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : false;
1791
+ const isRenameParamsEnabled = this.isRenameParamsEnabledForBotx; // TODO fix when handler is passed
1799
1792
  if (this.logsEnabled)
1800
1793
  console.log('Bridge ~ Incoming event', event.data);
1801
1794
  const emitterType = ref || EVENT_TYPE.RECEIVE;
@@ -1804,7 +1797,7 @@
1804
1797
  this.eventEmitter.emit(emitterType, {
1805
1798
  ref,
1806
1799
  type,
1807
- payload: isRenameParamsEnabled ? snakeCaseToCamelCase(payload) : payload,
1800
+ payload: this.isRenameParamsEnabledForBotx ? snakeCaseToCamelCase(payload) : payload,
1808
1801
  files: eventFiles,
1809
1802
  });
1810
1803
  });
@@ -1826,7 +1819,6 @@
1826
1819
  sendEvent({ handler, method, params, files, timeout = RESPONSE_TIMEOUT, guaranteed_delivery_required = false, }) {
1827
1820
  const isRenameParamsEnabled = handler === HANDLER.BOTX ? this.isRenameParamsEnabledForBotx : false;
1828
1821
  const ref = v4(); // UUID to detect express response.
1829
- this.handler = handler;
1830
1822
  const payload = {
1831
1823
  ref,
1832
1824
  type: WEB_COMMAND_TYPE_RPC,
@@ -1956,7 +1948,7 @@
1956
1948
  }
1957
1949
  }
1958
1950
 
1959
- const LIB_VERSION = "1.1.9";
1951
+ const LIB_VERSION = "1.2.0";
1960
1952
 
1961
1953
  const getBridge = () => {
1962
1954
  if (process.env.NODE_ENV === 'test')
@@ -1981,8 +1973,9 @@
1981
1973
  var METHODS;
1982
1974
  (function (METHODS) {
1983
1975
  METHODS["READY"] = "ready";
1984
- METHODS["ROUTING_CHANGED"] = "routing_changed";
1976
+ METHODS["ROUTING_CHANGED"] = "routing_changes";
1985
1977
  METHODS["BACK_PRESSED"] = "back_pressed";
1978
+ METHODS["MOVE_TO_ROOT"] = "move_to_root";
1986
1979
  METHODS["ADD_CONTACT"] = "add_contact";
1987
1980
  METHODS["GET_CONTACT"] = "get_contact";
1988
1981
  METHODS["CREATE_PERSONAL_CHAT"] = "create_personal_chat";
@@ -1992,8 +1985,12 @@
1992
1985
  METHODS["OPEN_CLIENT_SETTINGS"] = "open_client_settings";
1993
1986
  METHODS["GET_CHATS"] = "get_chats";
1994
1987
  METHODS["SEARCH_CORPORATE_PHONEBOOK"] = "search_corporate_phonebook";
1995
- METHODS["OPEN_GROUP_CHAT"] = "open_group_chat";
1996
1988
  METHODS["SEND_BOT_COMMAND"] = "send_bot_command";
1989
+ METHODS["OPEN_GROUP_CHAT"] = "open_group_chat";
1990
+ METHODS["OPEN_CONTACT_CARD"] = "open_contact_card";
1991
+ METHODS["REQUEST_LOCATION"] = "request_location";
1992
+ METHODS["REQUEST_SELF_PROFILE"] = "request_self_profile";
1993
+ METHODS["CLOSE_SMART_APP"] = "close_smart_app";
1997
1994
  })(METHODS || (METHODS = {}));
1998
1995
 
1999
1996
  var LOCATION;
@@ -2026,7 +2023,7 @@
2026
2023
  params: { groupChatId },
2027
2024
  });
2028
2025
  };
2029
- const sendBotCommand = ({ userHuid, body, data }) => {
2026
+ const sendBotCommand = ({ userHuid, body, data, }) => {
2030
2027
  if (typeof data !== 'object')
2031
2028
  return;
2032
2029
  return bridge?.sendClientEvent({
@@ -2040,6 +2037,12 @@
2040
2037
  },
2041
2038
  });
2042
2039
  };
2040
+ const requestLocation = () => {
2041
+ return bridge?.sendClientEvent({
2042
+ method: METHODS.REQUEST_LOCATION,
2043
+ params: {},
2044
+ });
2045
+ };
2043
2046
 
2044
2047
  const addContact = ({ phone, name }) => {
2045
2048
  return bridge?.sendClientEvent({
@@ -2062,7 +2065,7 @@
2062
2065
  params: { huid },
2063
2066
  });
2064
2067
  };
2065
- const sendMessage = ({ userHuid = null, groupChatId = null, messageBody = "", messageMeta = {}, }) => {
2068
+ const sendMessage = ({ userHuid = null, groupChatId = null, messageBody = '', messageMeta = {}, }) => {
2066
2069
  return bridge?.sendClientEvent({
2067
2070
  method: METHODS.SEND_MESSAGE,
2068
2071
  params: {
@@ -2075,15 +2078,26 @@
2075
2078
  },
2076
2079
  });
2077
2080
  };
2081
+ const openContactCard = ({ userHuid }) => {
2082
+ if (!userHuid)
2083
+ return;
2084
+ return bridge?.sendClientEvent({
2085
+ method: METHODS.OPEN_CONTACT_CARD,
2086
+ params: { userHuid }
2087
+ });
2088
+ };
2089
+ const requestSelfProfile = () => {
2090
+ return bridge?.sendClientEvent({
2091
+ method: METHODS.REQUEST_SELF_PROFILE,
2092
+ params: {},
2093
+ });
2094
+ };
2078
2095
 
2079
2096
  const useQuery = () => {
2080
2097
  const urlSearchParams = new URLSearchParams(window.location.search);
2081
2098
  return Object.fromEntries(urlSearchParams.entries());
2082
2099
  };
2083
2100
 
2084
- /**
2085
- * @param timeout
2086
- */
2087
2101
  const bridgeSendReady = (timeout) => {
2088
2102
  const event = {
2089
2103
  method: METHODS.READY,
@@ -2092,21 +2106,14 @@
2092
2106
  return bridge?.sendClientEvent(timeout ? { ...event, timeout } : event);
2093
2107
  };
2094
2108
 
2095
- /**
2096
- * @param timeout
2097
- */
2098
2109
  const ready = async (timeout) => {
2099
2110
  const response = await bridgeSendReady(timeout);
2100
- const Bridge = bridge;
2101
2111
  const isLogsEnabled = response?.payload?.logsEnabled;
2102
2112
  if (isLogsEnabled)
2103
- Bridge?.enableLogs?.();
2113
+ bridge?.enableLogs?.();
2104
2114
  return response;
2105
2115
  };
2106
2116
 
2107
- /**
2108
- * @param handleNotification
2109
- */
2110
2117
  const onNotification = async (handleNotification) => {
2111
2118
  const response = await bridge?.sendClientEvent({
2112
2119
  method: METHODS.NOTIFICATION,
@@ -2119,9 +2126,6 @@
2119
2126
  });
2120
2127
  };
2121
2128
 
2122
- /**
2123
- * @param isRoot
2124
- */
2125
2129
  const routingChanged = (isRoot) => {
2126
2130
  return bridge?.sendClientEvent({
2127
2131
  method: METHODS.ROUTING_CHANGED,
@@ -2130,49 +2134,54 @@
2130
2134
  },
2131
2135
  });
2132
2136
  };
2133
- /**
2134
- * @param handleBackPressed
2135
- */
2136
2137
  const onBackPressed = (handleBackPressed) => {
2137
- return bridge?.onReceive((event) => {
2138
+ return bridge?.onReceive(event => {
2138
2139
  if (event.type === METHODS.BACK_PRESSED)
2139
2140
  handleBackPressed();
2140
2141
  });
2141
2142
  };
2142
- /**
2143
- * @param appId
2144
- * @param meta
2145
- */
2146
- const openSmartApp = (appId, meta) => {
2143
+ const openSmartApp = ({ appId, meta }) => {
2147
2144
  return bridge?.sendClientEvent({
2148
2145
  method: METHODS.OPEN_SMART_APP,
2149
- params: {
2150
- appId,
2151
- meta,
2152
- },
2146
+ params: meta ? { appId, meta } : { appId },
2147
+ });
2148
+ };
2149
+ const closeSmartApp = () => {
2150
+ return bridge?.sendClientEvent({
2151
+ method: METHODS.CLOSE_SMART_APP,
2152
+ params: {},
2153
+ });
2154
+ };
2155
+ const onMoveToRoot = (handleMoveToRoot) => {
2156
+ return bridge?.onReceive(event => {
2157
+ if (event.type === METHODS.MOVE_TO_ROOT)
2158
+ handleMoveToRoot();
2153
2159
  });
2154
2160
  };
2155
2161
  const exitSmartAppToCatalog = () => {
2156
2162
  return bridge?.sendClientEvent({
2157
2163
  method: METHODS.OPEN_SMART_APP,
2158
- params: {
2159
- appId: "",
2160
- },
2164
+ params: { appId: '' },
2161
2165
  });
2162
2166
  };
2163
2167
 
2164
2168
  exports.Bridge = bridge;
2165
2169
  exports.addContact = addContact;
2170
+ exports.closeSmartApp = closeSmartApp;
2166
2171
  exports.createPersonalChat = createPersonalChat;
2167
2172
  exports.exitSmartAppToCatalog = exitSmartAppToCatalog;
2168
2173
  exports.getChats = getChats;
2169
2174
  exports.getContact = getContact;
2170
2175
  exports.onBackPressed = onBackPressed;
2176
+ exports.onMoveToRoot = onMoveToRoot;
2171
2177
  exports.onNotification = onNotification;
2172
2178
  exports.openClientSettings = openClientSettings;
2179
+ exports.openContactCard = openContactCard;
2173
2180
  exports.openGroupChat = openGroupChat;
2174
2181
  exports.openSmartApp = openSmartApp;
2175
2182
  exports.ready = ready;
2183
+ exports.requestLocation = requestLocation;
2184
+ exports.requestSelfProfile = requestSelfProfile;
2176
2185
  exports.routingChanged = routingChanged;
2177
2186
  exports.searchCorporatePhonebook = searchCorporatePhonebook;
2178
2187
  exports.sendBotCommand = sendBotCommand;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressms/smartapp-sdk",
3
- "version": "1.1.8",
3
+ "version": "1.2.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.9",
41
+ "@expressms/smartapp-bridge": "^1.2.0",
42
42
  "webpack-manifest-plugin": "2.2.0",
43
43
  "workbox-cacheable-response": "^6.5.4",
44
44
  "workbox-expiration": "^6.5.4",