61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
|
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<boolean> {
|
||
|
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.postFormData('https://api.tink.com/api/v1/oauth/token', {
|
||
|
headers: {
|
||
|
'content-type': 'multipart/form-data'
|
||
|
}
|
||
|
}, [
|
||
|
{
|
||
|
name: 'client_id',
|
||
|
type: 'string',
|
||
|
payload: this.clientId,
|
||
|
contentType: 'text/plain'
|
||
|
},
|
||
|
{
|
||
|
name: 'client_secret',
|
||
|
type: 'string',
|
||
|
payload: this.clientSecret,
|
||
|
contentType: 'text/plain'
|
||
|
},
|
||
|
{
|
||
|
name: 'grant_type',
|
||
|
type: 'string',
|
||
|
payload: 'client_credentials',
|
||
|
contentType: 'text/plain'
|
||
|
},
|
||
|
{
|
||
|
name: 'scope',
|
||
|
type: 'string',
|
||
|
payload: 'user:create',
|
||
|
contentType: 'text/plain'
|
||
|
}
|
||
|
]);
|
||
|
console.log(response.statusCode);
|
||
|
console.log(response.body);
|
||
|
};
|
||
|
}
|