Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
4c10678b17 | |||
eb61d1abbf | |||
a0fa17fa1d | |||
f5373c8c8d |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/tink",
|
"name": "@mojoio/tink",
|
||||||
"version": "1.0.4",
|
"version": "1.0.6",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@mojoio/tink",
|
"name": "@mojoio/tink",
|
||||||
"version": "1.0.4",
|
"version": "1.0.6",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartrequest": "^1.1.56"
|
"@pushrocks/smartrequest": "^1.1.56"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/tink",
|
"name": "@mojoio/tink",
|
||||||
"version": "1.0.4",
|
"version": "1.0.6",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "an unofficial api abstraction for tink.com",
|
"description": "an unofficial api abstraction for tink.com",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -7,6 +7,16 @@ import * as tink from '../ts/index';
|
|||||||
|
|
||||||
let tinkTestAccount: tink.TinkAccount;
|
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 () => {
|
tap.test('should create a valid tink account', async () => {
|
||||||
tinkTestAccount = new tink.TinkAccount(
|
tinkTestAccount = new tink.TinkAccount(
|
||||||
testQenv.getEnvVarOnDemand('TINK_CLIENT_ID'),
|
testQenv.getEnvVarOnDemand('TINK_CLIENT_ID'),
|
||||||
@ -20,7 +30,7 @@ tap.test('should report tink as healthy', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a valid request', async () => {
|
tap.test('should create a valid request', async () => {
|
||||||
await tinkTestAccount.request('', 'POST', '', {});
|
await tinkTestAccount.createTinkUser("user_1234_abc");
|
||||||
})
|
})
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
@ -1 +1,2 @@
|
|||||||
export * from './tink.classes.tinkaccount';
|
export * from './tink.classes.tinkaccount';
|
||||||
|
export * from './tink.classes.tinkuser';
|
@ -1,8 +1,13 @@
|
|||||||
import * as plugins from './tink.plugins';
|
import * as plugins from './tink.plugins';
|
||||||
|
|
||||||
|
import { TinkUser } from './tink.classes.tinkuser'
|
||||||
|
|
||||||
export class TinkAccount {
|
export class TinkAccount {
|
||||||
private clientId: string;
|
private clientId: string;
|
||||||
private clientSecret: string;
|
private clientSecret: string;
|
||||||
|
|
||||||
|
private apiBaseUrl: string = 'https://api.tink.com';
|
||||||
|
|
||||||
constructor(clientIdArg: string, clientSecretArg: string) {
|
constructor(clientIdArg: string, clientSecretArg: string) {
|
||||||
this.clientId = clientIdArg;
|
this.clientId = clientIdArg;
|
||||||
this.clientSecret = clientSecretArg;
|
this.clientSecret = clientSecretArg;
|
||||||
@ -18,21 +23,22 @@ export class TinkAccount {
|
|||||||
|
|
||||||
// the request method for tink respecting platform specific stuff
|
// the request method for tink respecting platform specific stuff
|
||||||
// e.g. certain headers if needed
|
// e.g. certain headers if needed
|
||||||
public async request(
|
public async request(optionsArg: {
|
||||||
urlArg: string,
|
urlArg: string,
|
||||||
methodArg: 'POST' | 'GET',
|
methodArg: 'POST' | 'GET',
|
||||||
scopeArg: string,
|
scopeArg: string,
|
||||||
payloadArg: any
|
payloadArg: any,
|
||||||
) {
|
externalUserId: string
|
||||||
|
}) {
|
||||||
// check health
|
// check health
|
||||||
if (!(await this.getTinkHealthyBoolean())) {
|
if (!(await this.getTinkHealthyBoolean())) {
|
||||||
throw new Error('TINK is not healthy tight now. Please try again later.');
|
throw new Error('TINK is not healthy right now. Please try again later.');
|
||||||
} else {
|
} else {
|
||||||
console.log('tink is healthy, continuing...');
|
console.log('tink is healthy, continuing...');
|
||||||
}
|
}
|
||||||
// lets get an accessToken for the request
|
// lets get an accessToken for the request
|
||||||
const response = await plugins.smartrequest.postFormDataUrlEncoded(
|
const response = await plugins.smartrequest.postFormDataUrlEncoded(
|
||||||
'https://api.tink.com/api/v1/oauth/token',
|
`${this.apiBaseUrl}/api/v1/oauth/token`,
|
||||||
{},
|
{},
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@ -49,11 +55,28 @@ export class TinkAccount {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'scope',
|
key: 'scope',
|
||||||
content: 'user:read',
|
content: optionsArg.scopeArg,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
console.log(response.statusCode);
|
if (response.statusCode !== 200) {
|
||||||
console.log(response.body);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1,53 @@
|
|||||||
import * as plugins from './tink.plugins';
|
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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user