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.ts 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { IReduxState } from '../app/types';
  2. import { doGetJSON } from '../base/util/httpUtils';
  3. import { isInBreakoutRoom } from '../breakout-rooms/functions';
  4. /**
  5. * Determines whether Salesforce is enabled for the current conference.
  6. *
  7. * @param {IReduxState} state - The redux store, the redux
  8. * {@code getState} function, or the redux state itself.
  9. * @returns {boolean}
  10. */
  11. export const isSalesforceEnabled = (state: IReduxState) => {
  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: {
  64. id: string;
  65. type: string;
  66. } | null
  67. ) {
  68. const fullUrl = `${url}/records/${item?.id}?type=${item?.type}`;
  69. return doGetJSON(fullUrl, true, {
  70. headers: {
  71. 'Authorization': `Bearer ${jwt}`
  72. }
  73. });
  74. }
  75. /**
  76. * Executes the meeting linking.
  77. *
  78. * @param {string} url - The endpoint for meeting linking.
  79. * @param {string} jwt - The JWT needed for authentication.
  80. * @param {string} sessionId - The ID of the meeting session.
  81. * @param {Object} body - The body of the request.
  82. * @returns {Object}
  83. */
  84. export async function executeLinkMeetingRequest(
  85. url: string,
  86. jwt: string,
  87. sessionId: String,
  88. body: {
  89. id?: string;
  90. notes: string;
  91. type?: string;
  92. }
  93. ) {
  94. const fullUrl = `${url}/sessions/${sessionId}/records/${body.id}`;
  95. const res = await fetch(fullUrl, {
  96. method: 'PUT',
  97. headers: {
  98. 'Content-Type': 'application/json',
  99. 'Authorization': `Bearer ${jwt}`
  100. },
  101. body: JSON.stringify(body)
  102. });
  103. const json = await res.json();
  104. return res.ok ? json : Promise.reject(json);
  105. }