sentryAppTokens.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {
  2. addErrorMessage,
  3. addLoadingMessage,
  4. addSuccessMessage,
  5. } from 'sentry/actionCreators/indicator';
  6. import {Client} from 'sentry/api';
  7. import {t} from 'sentry/locale';
  8. import {NewInternalAppApiToken, SentryApp} from 'sentry/types';
  9. /**
  10. * Install a sentry application
  11. *
  12. * @param {Object} client ApiClient
  13. * @param {Object} app SentryApp
  14. */
  15. export async function addSentryAppToken(
  16. client: Client,
  17. app: SentryApp
  18. ): Promise<NewInternalAppApiToken> {
  19. addLoadingMessage();
  20. try {
  21. const token = await client.requestPromise(`/sentry-apps/${app.slug}/api-tokens/`, {
  22. method: 'POST',
  23. });
  24. addSuccessMessage(t('Token successfully added.'));
  25. return token;
  26. } catch (err) {
  27. addErrorMessage(t('Unable to create token'));
  28. throw err;
  29. }
  30. }
  31. /**
  32. * Uninstall a sentry application
  33. *
  34. * @param {Object} client ApiClient
  35. * @param {Object} app SentryApp
  36. * @param {String} tokenId Id of the token
  37. */
  38. export async function removeSentryAppToken(
  39. client: Client,
  40. app: SentryApp,
  41. tokenId: string
  42. ): Promise<void> {
  43. addLoadingMessage();
  44. try {
  45. await client.requestPromise(`/sentry-apps/${app.slug}/api-tokens/${tokenId}/`, {
  46. method: 'DELETE',
  47. });
  48. addSuccessMessage(t('Token successfully deleted.'));
  49. return;
  50. } catch (err) {
  51. addErrorMessage(t('Unable to delete token'));
  52. throw err;
  53. }
  54. }