sentryAppTokens.tsx 1.4 KB

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