2022-02-18 11:55:56 +00:00
|
|
|
import * as plugins from './tink.plugins';
|
|
|
|
|
|
|
|
import { TinkAccount } from './tink.classes.tinkaccount';
|
|
|
|
|
|
|
|
export class TinkUser {
|
|
|
|
// STATIC
|
2022-02-19 10:43:10 +00:00
|
|
|
public static async createNewTinkUser(tinkaccountArg: TinkAccount, externalUserIdArg: string) {
|
2022-02-19 00:34:07 +00:00
|
|
|
const accessToken = await tinkaccountArg.getClientAccessTokenForScope('user:create');
|
2022-02-18 11:55:56 +00:00
|
|
|
const response = await tinkaccountArg.request({
|
|
|
|
urlArg: '/api/v1/user/create',
|
2022-02-19 00:34:07 +00:00
|
|
|
accessToken,
|
2022-02-18 11:55:56 +00:00
|
|
|
methodArg: 'POST',
|
|
|
|
payloadArg: {
|
2022-02-19 10:43:10 +00:00
|
|
|
external_user_id: externalUserIdArg,
|
|
|
|
market: 'DE',
|
|
|
|
locale: 'en_US',
|
|
|
|
},
|
2022-02-18 11:55:56 +00:00
|
|
|
});
|
|
|
|
|
2022-02-19 10:43:10 +00:00
|
|
|
const newTinkUser = new TinkUser(tinkaccountArg, response.user_id, response.external_user_id);
|
2022-02-19 00:34:07 +00:00
|
|
|
return newTinkUser;
|
2022-02-18 11:55:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// INSTANCE
|
|
|
|
public tinkAccountRef: TinkAccount;
|
|
|
|
public tinkUserId: string;
|
|
|
|
public externalUserIdArg: string;
|
|
|
|
|
2022-02-19 10:43:10 +00:00
|
|
|
public authorizationToken: string;
|
2022-02-18 11:55:56 +00:00
|
|
|
|
|
|
|
constructor(tinkAccountrefArg: TinkAccount, tinkUserIdArg: string, externalUserIdArg: string) {
|
|
|
|
this.tinkAccountRef = tinkAccountrefArg;
|
|
|
|
this.tinkUserId = tinkUserIdArg;
|
|
|
|
this.externalUserIdArg = externalUserIdArg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* deletes the user
|
|
|
|
*/
|
|
|
|
public async delete() {
|
2022-02-19 10:43:10 +00:00
|
|
|
const authorizationCode = await this.tinkAccountRef.getUserAuthorizationCode(
|
|
|
|
this.externalUserIdArg,
|
|
|
|
this.tinkAccountRef.clientId,
|
|
|
|
'user:delete'
|
|
|
|
);
|
2022-02-19 00:34:07 +00:00
|
|
|
const accessToken = await this.tinkAccountRef.getUserAccessToken(authorizationCode);
|
2022-02-18 11:55:56 +00:00
|
|
|
const response = await this.tinkAccountRef.request({
|
|
|
|
methodArg: 'POST',
|
2022-02-19 00:34:07 +00:00
|
|
|
accessToken,
|
2022-02-18 11:55:56 +00:00
|
|
|
payloadArg: {},
|
2022-02-19 10:43:10 +00:00
|
|
|
urlArg: '/api/v1/user/delete',
|
2022-02-18 11:55:56 +00:00
|
|
|
});
|
2022-02-19 00:34:07 +00:00
|
|
|
console.log(`successfully deleted user with externalId ${this.externalUserIdArg}`);
|
2022-02-18 11:55:56 +00:00
|
|
|
}
|
2022-02-19 10:43:10 +00:00
|
|
|
|
|
|
|
public async getTinkLink(): Promise<string> {
|
|
|
|
const authorizationCode = await this.tinkAccountRef.getUserAuthorizationCode(
|
|
|
|
this.externalUserIdArg,
|
|
|
|
'df05e4b379934cd09963197cc855bfe9', // this is a hardcoded app id for tink link, as recommended by tink.com
|
|
|
|
'authorization:read,authorization:grant,credentials:refresh,credentials:read,credentials:write,providers:read,user:read'
|
|
|
|
);
|
|
|
|
const tinkLinkUrl = `https://link.tink.com/1.0/business-transactions/connect-accounts?client_id=${'teststate'}&redirect_uri=https://console.tink.com/callback&authorization_code=${authorizationCode}&market=DE`;
|
|
|
|
return tinkLinkUrl;
|
|
|
|
}
|
|
|
|
}
|