1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import {
- addErrorMessage,
- addLoadingMessage,
- addSuccessMessage,
- } from 'sentry/actionCreators/indicator';
- import type {Client} from 'sentry/api';
- import {t} from 'sentry/locale';
- import type {NewInternalAppApiToken, SentryApp} from 'sentry/types';
- /**
- * Install a sentry application
- *
- * @param {Object} client ApiClient
- * @param {Object} app SentryApp
- */
- export async function addSentryAppToken(
- client: Client,
- app: SentryApp
- ): Promise<NewInternalAppApiToken> {
- addLoadingMessage();
- try {
- const token = await client.requestPromise(`/sentry-apps/${app.slug}/api-tokens/`, {
- method: 'POST',
- });
- addSuccessMessage(t('Token successfully added.'));
- return token;
- } catch (err) {
- addErrorMessage(t('Unable to create token'));
- throw err;
- }
- }
- /**
- * Uninstall a sentry application
- *
- * @param {Object} client ApiClient
- * @param {Object} app SentryApp
- * @param {String} tokenId Id of the token
- */
- export async function removeSentryAppToken(
- client: Client,
- app: SentryApp,
- tokenId: string
- ): Promise<void> {
- addLoadingMessage();
- try {
- await client.requestPromise(`/sentry-apps/${app.slug}/api-tokens/${tokenId}/`, {
- method: 'DELETE',
- });
- addSuccessMessage(t('Token successfully deleted.'));
- return;
- } catch (err) {
- addErrorMessage(t('Unable to delete token'));
- throw err;
- }
- }
|