Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

functions.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. // @flow
  2. import { i18next } from '../base/i18n';
  3. import { isLocalParticipantModerator } from '../base/participants';
  4. import { toState } from '../base/redux';
  5. import { doGetJSON, parseURIString } from '../base/util';
  6. import { isVpaasMeeting } from '../billing-counter/functions';
  7. import logger from './logger';
  8. declare var $: Function;
  9. declare var interfaceConfig: Object;
  10. /**
  11. * Sends an ajax request to check if the phone number can be called.
  12. *
  13. * @param {string} dialNumber - The dial number to check for validity.
  14. * @param {string} dialOutAuthUrl - The endpoint to use for checking validity.
  15. * @returns {Promise} - The promise created by the request.
  16. */
  17. export function checkDialNumber(
  18. dialNumber: string,
  19. dialOutAuthUrl: string
  20. ): Promise<Object> {
  21. const fullUrl = `${dialOutAuthUrl}?phone=${dialNumber}`;
  22. return new Promise((resolve, reject) => {
  23. $.getJSON(fullUrl)
  24. .then(resolve)
  25. .catch(reject);
  26. });
  27. }
  28. /**
  29. * Sends a GET request to obtain the conference ID necessary for identifying
  30. * which conference to join after diaing the dial-in service.
  31. *
  32. * @param {string} baseUrl - The url for obtaining the conference ID (pin) for
  33. * dialing into a conference.
  34. * @param {string} roomName - The conference name to find the associated
  35. * conference ID.
  36. * @param {string} mucURL - In which MUC the conference exists.
  37. * @returns {Promise} - The promise created by the request.
  38. */
  39. export function getDialInConferenceID(
  40. baseUrl: string,
  41. roomName: string,
  42. mucURL: string
  43. ): Promise<Object> {
  44. const conferenceIDURL = `${baseUrl}?conference=${roomName}@${mucURL}`;
  45. return doGetJSON(conferenceIDURL, true);
  46. }
  47. /**
  48. * Sends a GET request for phone numbers used to dial into a conference.
  49. *
  50. * @param {string} url - The service that returns conference dial-in numbers.
  51. * @param {string} roomName - The conference name to find the associated
  52. * conference ID.
  53. * @param {string} mucURL - In which MUC the conference exists.
  54. * @returns {Promise} - The promise created by the request. The returned numbers
  55. * may be an array of Objects containing numbers, with keys countryCode,
  56. * tollFree, formattedNumber or an object with countries as keys and arrays of
  57. * phone number strings, as the second one should not be used and is deprecated.
  58. */
  59. export function getDialInNumbers(
  60. url: string,
  61. roomName: string,
  62. mucURL: string
  63. ): Promise<*> {
  64. const fullUrl = `${url}?conference=${roomName}@${mucURL}`;
  65. return doGetJSON(fullUrl, true);
  66. }
  67. /**
  68. * Removes all non-numeric characters from a string.
  69. *
  70. * @param {string} text - The string from which to remove all characters except
  71. * numbers.
  72. * @returns {string} A string with only numbers.
  73. */
  74. export function getDigitsOnly(text: string = ''): string {
  75. return text.replace(/\D/g, '');
  76. }
  77. /**
  78. * Type of the options to use when sending a search query.
  79. */
  80. export type GetInviteResultsOptions = {
  81. /**
  82. * The endpoint to use for checking phone number validity.
  83. */
  84. dialOutAuthUrl: string,
  85. /**
  86. * Whether or not to search for people.
  87. */
  88. addPeopleEnabled: boolean,
  89. /**
  90. * Whether or not to check phone numbers.
  91. */
  92. dialOutEnabled: boolean,
  93. /**
  94. * Array with the query types that will be executed -
  95. * "conferenceRooms" | "user" | "room".
  96. */
  97. peopleSearchQueryTypes: Array<string>,
  98. /**
  99. * The url to query for people.
  100. */
  101. peopleSearchUrl: string,
  102. /**
  103. * The jwt token to pass to the search service.
  104. */
  105. jwt: string
  106. };
  107. /**
  108. * Combines directory search with phone number validation to produce a single
  109. * set of invite search results.
  110. *
  111. * @param {string} query - Text to search.
  112. * @param {GetInviteResultsOptions} options - Options to use when searching.
  113. * @returns {Promise<*>}
  114. */
  115. export function getInviteResultsForQuery(
  116. query: string,
  117. options: GetInviteResultsOptions
  118. ): Promise<*> {
  119. const text = query.trim();
  120. const {
  121. dialOutAuthUrl,
  122. addPeopleEnabled,
  123. dialOutEnabled,
  124. peopleSearchQueryTypes,
  125. peopleSearchUrl,
  126. jwt
  127. } = options;
  128. let peopleSearchPromise;
  129. if (addPeopleEnabled && text) {
  130. peopleSearchPromise = searchDirectory(
  131. peopleSearchUrl,
  132. jwt,
  133. text,
  134. peopleSearchQueryTypes);
  135. } else {
  136. peopleSearchPromise = Promise.resolve([]);
  137. }
  138. let hasCountryCode = text.startsWith('+');
  139. let phoneNumberPromise;
  140. // Phone numbers are handled a specially to enable both cases of restricting
  141. // numbers to telephone number-y numbers and accepting any arbitrary string,
  142. // which may be valid for SIP (jigasi) calls. If the dialOutAuthUrl is
  143. // defined, then it is assumed the call is to a telephone number and
  144. // some validation of the number is completed, with the + sign used as a way
  145. // for the UI to detect and enforce the usage of a country code. If the
  146. // dialOutAuthUrl is not defined, accept anything because this is assumed
  147. // to be the SIP (jigasi) case.
  148. if (dialOutEnabled && dialOutAuthUrl && isMaybeAPhoneNumber(text)) {
  149. let numberToVerify = text;
  150. // When the number to verify does not start with a +, we assume no
  151. // proper country code has been entered. In such a case, prepend 1 for
  152. // the country code. The service currently takes care of prepending the
  153. // +.
  154. if (!hasCountryCode && !text.startsWith('1')) {
  155. numberToVerify = `1${numberToVerify}`;
  156. }
  157. // The validation service works properly when the query is digits only
  158. // so ensure only digits get sent.
  159. numberToVerify = getDigitsOnly(numberToVerify);
  160. phoneNumberPromise = checkDialNumber(numberToVerify, dialOutAuthUrl);
  161. } else if (dialOutEnabled && !dialOutAuthUrl) {
  162. // fake having a country code to hide the country code reminder
  163. hasCountryCode = true;
  164. // With no auth url, let's say the text is a valid number
  165. phoneNumberPromise = Promise.resolve({
  166. allow: true,
  167. country: '',
  168. phone: text
  169. });
  170. } else {
  171. phoneNumberPromise = Promise.resolve({});
  172. }
  173. return Promise.all([ peopleSearchPromise, phoneNumberPromise ])
  174. .then(([ peopleResults, phoneResults ]) => {
  175. const results = [
  176. ...peopleResults
  177. ];
  178. /**
  179. * This check for phone results is for the day the call to searching
  180. * people might return phone results as well. When that day comes
  181. * this check will make it so the server checks are honored and the
  182. * local appending of the number is not done. The local appending of
  183. * the phone number can then be cleaned up when convenient.
  184. */
  185. const hasPhoneResult
  186. = peopleResults.find(result => result.type === 'phone');
  187. if (!hasPhoneResult && typeof phoneResults.allow === 'boolean') {
  188. results.push({
  189. allowed: phoneResults.allow,
  190. country: phoneResults.country,
  191. type: 'phone',
  192. number: phoneResults.phone,
  193. originalEntry: text,
  194. showCountryCodeReminder: !hasCountryCode
  195. });
  196. }
  197. return results;
  198. });
  199. }
  200. /**
  201. * Creates a message describing how to dial in to the conference.
  202. *
  203. * @returns {string}
  204. */
  205. export function getInviteText({
  206. _conferenceName,
  207. _localParticipantName,
  208. _inviteUrl,
  209. _locationUrl,
  210. _dialIn,
  211. _liveStreamViewURL,
  212. phoneNumber,
  213. t
  214. }: Object) {
  215. const inviteURL = _decodeRoomURI(_inviteUrl);
  216. let invite = _localParticipantName
  217. ? t('info.inviteURLFirstPartPersonal', { name: _localParticipantName })
  218. : t('info.inviteURLFirstPartGeneral');
  219. invite += t('info.inviteURLSecondPart', {
  220. url: inviteURL
  221. });
  222. if (_liveStreamViewURL) {
  223. const liveStream = t('info.inviteLiveStream', {
  224. url: _liveStreamViewURL
  225. });
  226. invite = `${invite}\n${liveStream}`;
  227. }
  228. if (shouldDisplayDialIn(_dialIn)) {
  229. const dial = t('info.invitePhone', {
  230. number: phoneNumber,
  231. conferenceID: _dialIn.conferenceID
  232. });
  233. const moreNumbers = t('info.invitePhoneAlternatives', {
  234. url: getDialInfoPageURL(
  235. _conferenceName,
  236. _locationUrl
  237. ),
  238. silentUrl: `${inviteURL}#config.startSilent=true`
  239. });
  240. invite = `${invite}\n${dial}\n${moreNumbers}`;
  241. }
  242. return invite;
  243. }
  244. /**
  245. * Helper for determining how many of each type of user is being invited. Used
  246. * for logging and sending analytics related to invites.
  247. *
  248. * @param {Array} inviteItems - An array with the invite items, as created in
  249. * {@link _parseQueryResults}.
  250. * @returns {Object} An object with keys as user types and values as the number
  251. * of invites for that type.
  252. */
  253. export function getInviteTypeCounts(inviteItems: Array<Object> = []) {
  254. const inviteTypeCounts = {};
  255. inviteItems.forEach(({ type }) => {
  256. if (!inviteTypeCounts[type]) {
  257. inviteTypeCounts[type] = 0;
  258. }
  259. inviteTypeCounts[type]++;
  260. });
  261. return inviteTypeCounts;
  262. }
  263. /**
  264. * Sends a post request to an invite service.
  265. *
  266. * @param {string} inviteServiceUrl - The invite service that generates the
  267. * invitation.
  268. * @param {string} inviteUrl - The url to the conference.
  269. * @param {string} jwt - The jwt token to pass to the search service.
  270. * @param {Immutable.List} inviteItems - The list of the "user" or "room" type
  271. * items to invite.
  272. * @returns {Promise} - The promise created by the request.
  273. */
  274. export function invitePeopleAndChatRooms( // eslint-disable-line max-params
  275. inviteServiceUrl: string,
  276. inviteUrl: string,
  277. jwt: string,
  278. inviteItems: Array<Object>
  279. ): Promise<void> {
  280. if (!inviteItems || inviteItems.length === 0) {
  281. return Promise.resolve();
  282. }
  283. return fetch(
  284. `${inviteServiceUrl}?token=${jwt}`,
  285. {
  286. body: JSON.stringify({
  287. 'invited': inviteItems,
  288. 'url': inviteUrl
  289. }),
  290. method: 'POST',
  291. headers: {
  292. 'Content-Type': 'application/json'
  293. }
  294. }
  295. );
  296. }
  297. /**
  298. * Determines if adding people is currently enabled.
  299. *
  300. * @param {boolean} state - Current state.
  301. * @returns {boolean} Indication of whether adding people is currently enabled.
  302. */
  303. export function isAddPeopleEnabled(state: Object): boolean {
  304. const { peopleSearchUrl } = state['features/base/config'];
  305. return state['features/base/jwt'].jwt && Boolean(peopleSearchUrl) && !isVpaasMeeting(state);
  306. }
  307. /**
  308. * Determines if dial out is currently enabled or not.
  309. *
  310. * @param {boolean} state - Current state.
  311. * @returns {boolean} Indication of whether dial out is currently enabled.
  312. */
  313. export function isDialOutEnabled(state: Object): boolean {
  314. const { conference } = state['features/base/conference'];
  315. return isLocalParticipantModerator(state)
  316. && conference && conference.isSIPCallingSupported();
  317. }
  318. /**
  319. * Checks whether a string looks like it could be for a phone number.
  320. *
  321. * @param {string} text - The text to check whether or not it could be a phone
  322. * number.
  323. * @private
  324. * @returns {boolean} True if the string looks like it could be a phone number.
  325. */
  326. function isMaybeAPhoneNumber(text: string): boolean {
  327. if (!isPhoneNumberRegex().test(text)) {
  328. return false;
  329. }
  330. const digits = getDigitsOnly(text);
  331. return Boolean(digits.length);
  332. }
  333. /**
  334. * RegExp to use to determine if some text might be a phone number.
  335. *
  336. * @returns {RegExp}
  337. */
  338. function isPhoneNumberRegex(): RegExp {
  339. let regexString = '^[0-9+()-\\s]*$';
  340. if (typeof interfaceConfig !== 'undefined') {
  341. regexString = interfaceConfig.PHONE_NUMBER_REGEX || regexString;
  342. }
  343. return new RegExp(regexString);
  344. }
  345. /**
  346. * Sends an ajax request to a directory service.
  347. *
  348. * @param {string} serviceUrl - The service to query.
  349. * @param {string} jwt - The jwt token to pass to the search service.
  350. * @param {string} text - Text to search.
  351. * @param {Array<string>} queryTypes - Array with the query types that will be
  352. * executed - "conferenceRooms" | "user" | "room".
  353. * @returns {Promise} - The promise created by the request.
  354. */
  355. export function searchDirectory( // eslint-disable-line max-params
  356. serviceUrl: string,
  357. jwt: string,
  358. text: string,
  359. queryTypes: Array<string> = [ 'conferenceRooms', 'user', 'room' ]
  360. ): Promise<Array<Object>> {
  361. const query = encodeURIComponent(text);
  362. const queryTypesString = encodeURIComponent(JSON.stringify(queryTypes));
  363. return fetch(`${serviceUrl}?query=${query}&queryTypes=${
  364. queryTypesString}&jwt=${jwt}`)
  365. .then(response => {
  366. const jsonify = response.json();
  367. if (response.ok) {
  368. return jsonify;
  369. }
  370. return jsonify
  371. .then(result => Promise.reject(result));
  372. })
  373. .catch(error => {
  374. logger.error(
  375. 'Error searching directory:', error);
  376. return Promise.reject(error);
  377. });
  378. }
  379. /**
  380. * Returns descriptive text that can be used to invite participants to a meeting
  381. * (share via mobile or use it for calendar event description).
  382. *
  383. * @param {Object} state - The current state.
  384. * @param {string} inviteUrl - The conference/location URL.
  385. * @param {boolean} useHtml - Whether to return html text.
  386. * @returns {Promise<string>} A {@code Promise} resolving with a
  387. * descriptive text that can be used to invite participants to a meeting.
  388. */
  389. export function getShareInfoText(
  390. state: Object, inviteUrl: string, useHtml: ?boolean): Promise<string> {
  391. let roomUrl = _decodeRoomURI(inviteUrl);
  392. const includeDialInfo = state['features/base/config'] !== undefined;
  393. if (useHtml) {
  394. roomUrl = `<a href="${roomUrl}">${roomUrl}</a>`;
  395. }
  396. let infoText = i18next.t('share.mainText', { roomUrl });
  397. if (includeDialInfo) {
  398. const { room } = parseURIString(inviteUrl);
  399. let numbersPromise;
  400. if (state['features/invite'].numbers
  401. && state['features/invite'].conferenceID) {
  402. numbersPromise = Promise.resolve(state['features/invite']);
  403. } else {
  404. // we are requesting numbers and conferenceId directly
  405. // not using updateDialInNumbers, because custom room
  406. // is specified and we do not want to store the data
  407. // in the state
  408. const { dialInConfCodeUrl, dialInNumbersUrl, hosts }
  409. = state['features/base/config'];
  410. const mucURL = hosts && hosts.muc;
  411. if (!dialInConfCodeUrl || !dialInNumbersUrl || !mucURL) {
  412. // URLs for fetching dial in numbers not defined
  413. return Promise.resolve(infoText);
  414. }
  415. numbersPromise = Promise.all([
  416. getDialInNumbers(dialInNumbersUrl, room, mucURL),
  417. getDialInConferenceID(dialInConfCodeUrl, room, mucURL)
  418. ]).then(([ numbers, {
  419. conference, id, message } ]) => {
  420. if (!conference || !id) {
  421. return Promise.reject(message);
  422. }
  423. return {
  424. numbers,
  425. conferenceID: id
  426. };
  427. });
  428. }
  429. return numbersPromise.then(
  430. ({ conferenceID, numbers }) => {
  431. const phoneNumber = _getDefaultPhoneNumber(numbers) || '';
  432. return `${
  433. i18next.t('info.dialInNumber')} ${
  434. phoneNumber} ${
  435. i18next.t('info.dialInConferenceID')} ${
  436. conferenceID}#\n\n`;
  437. })
  438. .catch(error =>
  439. logger.error('Error fetching numbers or conferenceID', error))
  440. .then(defaultDialInNumber => {
  441. let dialInfoPageUrl = getDialInfoPageURL(
  442. room,
  443. state['features/base/connection'].locationURL);
  444. if (useHtml) {
  445. dialInfoPageUrl
  446. = `<a href="${dialInfoPageUrl}">${dialInfoPageUrl}</a>`;
  447. }
  448. infoText += i18next.t('share.dialInfoText', {
  449. defaultDialInNumber,
  450. dialInfoPageUrl });
  451. return infoText;
  452. });
  453. }
  454. return Promise.resolve(infoText);
  455. }
  456. /**
  457. * Generates the URL for the static dial in info page.
  458. *
  459. * @param {string} conferenceName - The conference name.
  460. * @param {Object} locationURL - The current location URL, the object coming
  461. * from state ['features/base/connection'].locationURL.
  462. * @returns {string}
  463. */
  464. export function getDialInfoPageURL(
  465. conferenceName: string,
  466. locationURL: Object) {
  467. const origin = locationURL.origin;
  468. const pathParts = locationURL.pathname.split('/');
  469. pathParts.length = pathParts.length - 1;
  470. const newPath = pathParts.reduce((accumulator, currentValue) => {
  471. if (currentValue) {
  472. return `${accumulator}/${currentValue}`;
  473. }
  474. return accumulator;
  475. }, '');
  476. return `${origin}${newPath}/static/dialInInfo.html?room=${_decodeRoomURI(conferenceName)}`;
  477. }
  478. /**
  479. * Generates the URL for the static dial in info page.
  480. *
  481. * @param {string} uri - The conference URI string.
  482. * @returns {string}
  483. */
  484. export function getDialInfoPageURLForURIString(
  485. uri: ?string) {
  486. if (!uri) {
  487. return undefined;
  488. }
  489. const { protocol, host, contextRoot, room } = parseURIString(uri);
  490. return `${protocol}//${host}${contextRoot}static/dialInInfo.html?room=${room}`;
  491. }
  492. /**
  493. * Returns whether or not dial-in related UI should be displayed.
  494. *
  495. * @param {Object} dialIn - Dial in information.
  496. * @returns {boolean}
  497. */
  498. export function shouldDisplayDialIn(dialIn: Object) {
  499. const { conferenceID, numbers, numbersEnabled } = dialIn;
  500. const phoneNumber = _getDefaultPhoneNumber(numbers);
  501. return Boolean(
  502. conferenceID
  503. && numbers
  504. && numbersEnabled
  505. && phoneNumber);
  506. }
  507. /**
  508. * Sets the internal state of which dial-in number to display.
  509. *
  510. * @param {Array<string>|Object} dialInNumbers - The array or object of
  511. * numbers to choose a number from.
  512. * @private
  513. * @returns {string|null}
  514. */
  515. export function _getDefaultPhoneNumber(
  516. dialInNumbers: ?Object): ?string {
  517. if (!dialInNumbers) {
  518. return null;
  519. }
  520. if (Array.isArray(dialInNumbers)) {
  521. // new syntax follows
  522. // find the default country inside dialInNumbers, US one
  523. // or return the first one
  524. const defaultNumber = dialInNumbers.find(number => number.default);
  525. if (defaultNumber) {
  526. return defaultNumber.formattedNumber;
  527. }
  528. return dialInNumbers.length > 0
  529. ? dialInNumbers[0].formattedNumber : null;
  530. }
  531. const { numbers } = dialInNumbers;
  532. if (numbers && Object.keys(numbers).length > 0) {
  533. // deprecated and will be removed
  534. const firstRegion = Object.keys(numbers)[0];
  535. return firstRegion && numbers[firstRegion][0];
  536. }
  537. return null;
  538. }
  539. /**
  540. * Decodes URI only if doesn't contain a space(' ').
  541. *
  542. * @param {string} url - The string to decode.
  543. * @returns {string} - It the string contains space, encoded value is '%20' returns
  544. * same string, otherwise decoded one.
  545. * @private
  546. */
  547. export function _decodeRoomURI(url: string) {
  548. let roomUrl = url;
  549. // we want to decode urls when the do not contain space, ' ', which url encoded is %20
  550. if (roomUrl && !roomUrl.includes('%20')) {
  551. roomUrl = decodeURI(roomUrl);
  552. }
  553. // Handles a special case where the room name has % encoded, the decoded will have
  554. // % followed by a char (non-digit) which is not a valid URL and room name ... so we do not
  555. // want to show this decoded
  556. if (roomUrl.match(/.*%[^\d].*/)) {
  557. return url;
  558. }
  559. return roomUrl;
  560. }
  561. /**
  562. * Returns the stored conference id.
  563. *
  564. * @param {Object | Function} stateful - The Object or Function that can be
  565. * resolved to a Redux state object with the toState function.
  566. * @returns {string}
  567. */
  568. export function getConferenceId(stateful: Object | Function) {
  569. return toState(stateful)['features/invite'].conferenceID;
  570. }
  571. /**
  572. * Returns the default dial in number from the store.
  573. *
  574. * @param {Object | Function} stateful - The Object or Function that can be
  575. * resolved to a Redux state object with the toState function.
  576. * @returns {string | null}
  577. */
  578. export function getDefaultDialInNumber(stateful: Object | Function) {
  579. return _getDefaultPhoneNumber(toState(stateful)['features/invite'].numbers);
  580. }
  581. /**
  582. * Executes the dial out request.
  583. *
  584. * @param {string} url - The url for dialing out.
  585. * @param {Object} body - The body of the request.
  586. * @param {string} reqId - The unique request id.
  587. * @returns {Object}
  588. */
  589. export async function executeDialOutRequest(url: string, body: Object, reqId: string) {
  590. const res = await fetch(url, {
  591. method: 'POST',
  592. headers: {
  593. 'Content-Type': 'application/json',
  594. 'request-id': reqId
  595. },
  596. body: JSON.stringify(body)
  597. });
  598. const json = await res.json();
  599. return res.ok ? json : Promise.reject(json);
  600. }
  601. /**
  602. * Executes the dial out status request.
  603. *
  604. * @param {string} url - The url for dialing out.
  605. * @param {string} reqId - The unique request id used on the dial out request.
  606. * @returns {Object}
  607. */
  608. export async function executeDialOutStatusRequest(url: string, reqId: string) {
  609. const res = await fetch(url, {
  610. method: 'GET',
  611. headers: {
  612. 'Content-Type': 'application/json',
  613. 'request-id': reqId
  614. }
  615. });
  616. const json = await res.json();
  617. return res.ok ? json : Promise.reject(json);
  618. }