import ApiClient from './ApiClient'; import * as O from './types/OAuthCredentials'; import urls from './urls'; export const mapOAuthCredentialsResponse = ( res: O.OAuthCredentialsResponse, ): O.OAuthCredentials => ({ ...res }); export default class OAuthCredentialsClient { async getOAuthCredentials( this: ApiClient, applicationId: string, ): Promise { const data = await this.requestProtected< O.GetOAuthCredentialsRequest, O.OAuthCredentialsResponse >({ method: 'GET', url: urls.oauthCredentials(applicationId), }); return mapOAuthCredentialsResponse(data); } async createOAuthCredential( this: ApiClient, applicationId: string, params: O.CreateOAuthCredentialParams, ): Promise { const data = await this.requestProtected< O.CreateOAuthCredentialRequest, O.OAuthCredentialsResponse >({ method: 'POST', url: urls.oauthCredentials(applicationId), body: { prop_name: params.propName, credential_value: params.credentialValue, }, }); return mapOAuthCredentialsResponse(data); } async deleteOAuthCredential( this: ApiClient, applicationId: string, propName: string, ): Promise { await this.requestProtected< O.DeleteOAuthCredentialRequest, O.DeleteOAuthCredentialResponse >({ method: 'DELETE', url: urls.oauthCredential(applicationId, propName), }); } }