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 accessToken = await tinkaccountArg.getClientAccessTokenForScope('user:create'); const response = await tinkaccountArg.request({ urlArg: '/api/v1/user/create', accessToken, methodArg: 'POST', payloadArg: { "external_user_id": externalUserIdArg, "market": "GB", "locale": "en_US" } }); const newTinkUser = new TinkUser (tinkaccountArg, response.user_id, response.external_user_id); return newTinkUser; } // 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; } /** * deletes the user */ public async delete() { const authorizationCode = await this.tinkAccountRef.getUserAuthorizationCode(this.externalUserIdArg, this.tinkAccountRef.clientId, 'user:delete'); const accessToken = await this.tinkAccountRef.getUserAccessToken(authorizationCode); const response = await this.tinkAccountRef.request({ methodArg: 'POST', accessToken, payloadArg: {}, urlArg: '/api/v1/user/delete' }); console.log(`successfully deleted user with externalId ${this.externalUserIdArg}`); } }