fix(core): update

This commit is contained in:
2022-02-15 23:50:37 +01:00
parent 09f470d2f8
commit 0ab5f2039c
3 changed files with 83 additions and 85 deletions

View File

@ -8,16 +8,22 @@ export class TinkAccount {
this.clientSecret = clientSecretArg;
}
public async getTinkHealthyBoolean (): Promise<boolean> {
const response = await plugins.smartrequest.request('https://api.tink.com/api/v1/monitoring/healthy', {
});
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) {
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.');
@ -25,37 +31,29 @@ export class TinkAccount {
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'
}
]);
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);
};
}
}
}