Files
2024-02-15 17:01:50 +00:00

57 lines
1.3 KiB
TypeScript

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;
}
}