Compare commits

..

8 Commits
main ... v1.0.6

Author SHA1 Message Date
4c10678b17 1.0.6 2022-02-18 12:55:57 +01:00
eb61d1abbf fix(core): update 2022-02-18 12:55:56 +01:00
a0fa17fa1d 1.0.5 2022-02-17 11:54:44 +01:00
f5373c8c8d fix(core): update 2022-02-17 11:54:44 +01:00
ee60d6085c 1.0.4 2022-02-15 23:50:37 +01:00
0ab5f2039c fix(core): update 2022-02-15 23:50:37 +01:00
09f470d2f8 1.0.3 2022-02-15 16:51:16 +01:00
19699ada2a fix(core): update 2022-02-15 16:51:16 +01:00
9 changed files with 611 additions and 431 deletions

834
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@mojoio/tink",
"version": "1.0.2",
"version": "1.0.6",
"private": false,
"description": "an unofficial api abstraction for tink.com",
"main": "dist_ts/index.js",
@ -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.7",
"@types/node": "^17.0.18",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {},
"dependencies": {
"@pushrocks/smartrequest": "^1.1.56"
},
"browserslist": [
"last 1 chrome versions"
],

3
qenv.yml Normal file
View File

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

36
test/test.nonci.ts Normal file
View File

@ -0,0 +1,36 @@
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';
let tinkTestAccount: tink.TinkAccount;
tap.preTask('should delete existing users', async () => {
const preTinkAccount = tinkTestAccount = new tink.TinkAccount(
testQenv.getEnvVarOnDemand('TINK_CLIENT_ID'),
testQenv.getEnvVarOnDemand('TINK_CLIENT_SECRET')
);
expect(tinkTestAccount).toBeInstanceOf(tink.TinkAccount);
const tinkUser = new tink.TinkUser(preTinkAccount, null, 'user_1234_abc');
await tinkUser.delete();
})
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.createTinkUser("user_1234_abc");
})
tap.start();

View File

@ -1,8 +0,0 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as tink from '../ts/index';
tap.test('first test', async () => {
console.log(tink.standardExport);
});
tap.start();

View File

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

View File

@ -0,0 +1,82 @@
import * as plugins from './tink.plugins';
import { TinkUser } from './tink.classes.tinkuser'
export class TinkAccount {
private clientId: string;
private clientSecret: string;
private apiBaseUrl: string = 'https://api.tink.com';
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(optionsArg: {
urlArg: string,
methodArg: 'POST' | 'GET',
scopeArg: string,
payloadArg: any,
externalUserId: string
}) {
// check health
if (!(await this.getTinkHealthyBoolean())) {
throw new Error('TINK is not healthy right 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(
`${this.apiBaseUrl}/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: optionsArg.scopeArg,
},
]
);
if (response.statusCode !== 200) {
throw new Error('there was an error aquiring an access token.');
}
const accessToken = response.body.access_token;
const response2 = await plugins.smartrequest.request(`${this.apiBaseUrl}${optionsArg.urlArg}`, {
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
method: optionsArg.methodArg,
requestBody: JSON.stringify(optionsArg.payloadArg)
})
console.log(response2.statusCode);
return response2.body;
}
public async createTinkUser(externalUserIdArg: string) {
const tinkuser = await TinkUser.createNewTinkUser(this, externalUserIdArg);
}
}

View File

@ -0,0 +1,53 @@
import * as plugins from './tink.plugins';
import { TinkAccount } from './tink.classes.tinkaccount';
export class TinkUser {
// STATIC
public static async createNewTinkUser (tinkaccountArg: TinkAccount, externalUserIdArg: string) {
const response = await tinkaccountArg.request({
externalUserId: null,
urlArg: '/api/v1/user/create',
methodArg: 'POST',
scopeArg: 'user:create',
payloadArg: {
"external_user_id": externalUserIdArg,
"market": "GB",
"locale": "en_US"
}
});
console.log(response);
}
// INSTANCE
public tinkAccountRef: TinkAccount;
public tinkUserId: string;
public externalUserIdArg: string;
public authorizationToken: string
constructor(tinkAccountrefArg: TinkAccount, tinkUserIdArg: string, externalUserIdArg: string) {
this.tinkAccountRef = tinkAccountrefArg;
this.tinkUserId = tinkUserIdArg;
this.externalUserIdArg = externalUserIdArg;
}
public async authorize() {
}
/**
* deletes the user
*/
public async delete() {
const response = await this.tinkAccountRef.request({
externalUserId: this.externalUserIdArg,
methodArg: 'POST',
payloadArg: {},
scopeArg: 'user:delete',
urlArg: '/api/v1/user/delete'
});
console.log(response);
}
}

View File

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