fix(core): update

This commit is contained in:
Philipp Kunz 2022-02-15 16:51:16 +01:00
parent ee9fd1f1f9
commit 19699ada2a
8 changed files with 493 additions and 397 deletions

778
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,13 +14,16 @@
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsbundle": "^1.0.78",
"@gitzone/tstest": "^1.0.44",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.11.2",
"@gitzone/tstest": "^1.0.64",
"@pushrocks/qenv": "^4.0.10",
"@pushrocks/tapbundle": "^4.0.3",
"@types/node": "^17.0.18",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {},
"dependencies": {
"@pushrocks/smartrequest": "^1.1.52"
},
"browserslist": [
"last 1 chrome versions"
],

3
qenv.yml Normal file
View File

@ -0,0 +1,3 @@
required:
- TINK_CLIENT_ID
- TINK_CLIENT_SECRET

View File

@ -1,8 +1,26 @@
import { expect, tap } from '@pushrocks/tapbundle';
import { expect, expectAsync, tap } from '@pushrocks/tapbundle';
import * as qenv from '@pushrocks/qenv';
const testQenv = new qenv.Qenv('./', './.nogit/');
import * as tink from '../ts/index';
tap.test('first test', async () => {
console.log(tink.standardExport);
let tinkTestAccount: tink.TinkAccount;
tap.test('should create a valid tink account', async () => {
tinkTestAccount = new tink.TinkAccount(
testQenv.getEnvVarOnDemand('TINK_CLIENT_ID'),
testQenv.getEnvVarOnDemand('TINK_CLIENT_SECRET')
);
expect(tinkTestAccount).toBeInstanceOf(tink.TinkAccount);
});
tap.test('should report tink as healthy', async () => {
await expectAsync(tinkTestAccount.getTinkHealthyBoolean()).toBeTrue();
});
tap.test('should create a valid request', async () => {
await tinkTestAccount.request('', 'POST', '', {});
})
tap.start();

View File

@ -1,3 +1 @@
import * as plugins from './tink.plugins';
export let standardExport = 'Hi there! :) This is an exported string';
export * from './tink.classes.tinkaccount';

View File

@ -0,0 +1,61 @@
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);
};
}

View File

@ -0,0 +1 @@
import * as plugins from './tink.plugins';

View File

@ -1,2 +1,6 @@
const removeme = {};
export { removeme };
// @pushrocks scope
import * as smartrequest from '@pushrocks/smartrequest';
export {
smartrequest
}