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.4KB

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