You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // @flow
  2. import { doGetJSON } from '../base/util';
  3. import { isInBreakoutRoom } from '../breakout-rooms/functions';
  4. /**
  5. * Determines whether Salesforce is enabled for the current conference.
  6. *
  7. * @param {Function|Object} state - The redux store, the redux
  8. * {@code getState} function, or the redux state itself.
  9. * @returns {boolean}
  10. */
  11. export const isSalesforceEnabled = (state: Function | Object) => {
  12. const { salesforceUrl } = state['features/base/config'];
  13. const isBreakoutRoom = isInBreakoutRoom(state);
  14. return Boolean(salesforceUrl) && !isBreakoutRoom;
  15. };
  16. /**
  17. * Fetches the Salesforce records that were most recently interacted with.
  18. *
  19. * @param {string} url - The endpoint for the session records.
  20. * @param {string} jwt - The JWT needed for authentication.
  21. * @returns {Promise<any>}
  22. */
  23. export async function getRecentSessionRecords(
  24. url: string,
  25. jwt: string
  26. ) {
  27. return doGetJSON(`${url}/records/recents`, true, {
  28. headers: {
  29. 'Authorization': `Bearer ${jwt}`
  30. }
  31. });
  32. }
  33. /**
  34. * Fetches the Salesforce records that match the search criteria.
  35. *
  36. * @param {string} url - The endpoint for the session records.
  37. * @param {string} jwt - The JWT needed for authentication.
  38. * @param {string} text - The search term for the session record to find.
  39. * @returns {Promise<any>}
  40. */
  41. export async function searchSessionRecords(
  42. url: string,
  43. jwt: string,
  44. text: string
  45. ) {
  46. return doGetJSON(`${url}/records?text=${text}`, true, {
  47. headers: {
  48. 'Authorization': `Bearer ${jwt}`
  49. }
  50. });
  51. }
  52. /**
  53. * Fetches the Salesforce record details from the server.
  54. *
  55. * @param {string} url - The endpoint for the record details.
  56. * @param {string} jwt - The JWT needed for authentication.
  57. * @param {Object} item - The item for which details are being retrieved.
  58. * @returns {Promise<any>}
  59. */
  60. export async function getSessionRecordDetails(
  61. url: string,
  62. jwt: string,
  63. item: Object
  64. ) {
  65. const fullUrl = `${url}/records/${item.id}?type=${item.type}`;
  66. return doGetJSON(fullUrl, true, {
  67. headers: {
  68. 'Authorization': `Bearer ${jwt}`
  69. }
  70. });
  71. }
  72. /**
  73. * Executes the meeting linking.
  74. *
  75. * @param {string} url - The endpoint for meeting linking.
  76. * @param {string} jwt - The JWT needed for authentication.
  77. * @param {string} sessionId - The ID of the meeting session.
  78. * @param {Object} body - The body of the request.
  79. * @returns {Object}
  80. */
  81. export async function executeLinkMeetingRequest(
  82. url: string,
  83. jwt: string,
  84. sessionId: String,
  85. body: Object
  86. ) {
  87. const fullUrl = `${url}/sessions/${sessionId}/records/${body.id}`;
  88. const res = await fetch(fullUrl, {
  89. method: 'PUT',
  90. headers: {
  91. 'Content-Type': 'application/json',
  92. 'Authorization': `Bearer ${jwt}`
  93. },
  94. body: JSON.stringify(body)
  95. });
  96. const json = await res.json();
  97. return res.ok ? json : Promise.reject(json);
  98. }