import * as plugins from './tink.plugins'; export class TinkAccount { private clientId: string; private clientSecret: string; constructor(clientIdArg: string, clientSecretArg: string) { this.clientId = clientIdArg; this.clientSecret = clientSecretArg; } public async getTinkHealthyBoolean(): Promise { const response = await plugins.smartrequest.request( 'https://api.tink.com/api/v1/monitoring/healthy', {} ); return response.body === 'ok'; } // the request method for tink respecting platform specific stuff // e.g. certain headers if needed public async request( urlArg: string, methodArg: 'POST' | 'GET', scopeArg: string, payloadArg: any ) { // check health if (!(await this.getTinkHealthyBoolean())) { throw new Error('TINK is not healthy tight now. Please try again later.'); } else { console.log('tink is healthy, continuing...'); } // lets get an accessToken for the request const response = await plugins.smartrequest.postFormDataUrlEncoded( 'https://api.tink.com/api/v1/oauth/token', {}, [ { key: 'client_id', content: this.clientId, }, { key: 'client_secret', content: this.clientSecret, }, { key: 'grant_type', content: 'client_credentials', }, { key: 'scope', content: 'user:read', }, ] ); console.log(response.statusCode); console.log(response.body); } }