Skip to content

Commit

Permalink
feat: implement iframe mode
Browse files Browse the repository at this point in the history
  • Loading branch information
amarlankri committed Aug 5, 2021
1 parent c38e1aa commit 0faa939
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/algoan/dto/customer.enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export enum AggregationDetailsMode {
redirect = 'REDIRECT',
api = 'API',
iframe = 'IFRAME'
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/algoan/dto/customer.inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface AggregationDetailsUpdateInput {
token?: string;
redirectUrl?: string;
apiUrl?: string;
iframeUrl?: string;
userId?: string;
clientId?: string;
}
1 change: 1 addition & 0 deletions src/algoan/dto/customer.objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface AggregationDetails {
mode?: AggregationDetailsMode;
redirectUrl?: string;
apiUrl?: string;
iframeUrl?: string
userId?: string;
clientId?: string;
}
Expand Down
30 changes: 30 additions & 0 deletions src/hooks/services/hooks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { TINK_LINK_ACTOR_CLIENT_ID } from '../../tink/contstants/tink.constants'

import { bankDetailsRequiredMock } from '../dto/bank-details-required-payload.dto.mock';
import { mapTinkDataToAlgoanAnalysis } from '../mappers/analysis.mapper';
import { AggregationDetailsMode } from '../../algoan/dto/customer.enums'
import { HooksService } from './hooks.service';

describe('HookService', () => {
Expand Down Expand Up @@ -279,6 +280,35 @@ describe('HookService', () => {
},
});
});

it('should generate an iframe link and should update the customer with the new iframe URL', async () => {
getCustomerByIdSpy = jest.spyOn(algoanCustomerService, 'getCustomerById').mockResolvedValue({
...customerMock,
aggregationDetails: {
...customerMock.aggregationDetails,
mode: AggregationDetailsMode.iframe
},
});
await hookService.handleAggregatorLinkRequiredEvent(aggregatorLinkRequiredMock);
expect(getLinkSpy).toHaveBeenCalledWith({
client_id: serviceAccountConfigMock.clientId,
redirect_uri: customerMock.aggregationDetails.callbackUrl,
market: serviceAccountConfigMock.market,
locale: serviceAccountConfigMock.locale,
scope: 'accounts:read,transactions:read,credentials:read',
test: config.tink.test,
authorization_code: createAuthorizationObjectMock.code,
iframe: true
});

// update
expect(updateCustomerSpy).toHaveBeenCalledWith(aggregatorLinkRequiredMock.customerId, {
aggregationDetails: {
iframeUrl: 'MY_LINK_URL',
userId: createUserObject.user_id,
},
});
});
});

describe('handleBankDetailsRequiredEvent', () => {
Expand Down
34 changes: 21 additions & 13 deletions src/hooks/services/hooks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { AlgoanHttpService } from '../../algoan/services/algoan-http.service';
import { AggregatorLinkRequiredDTO } from '../dto/aggregator-link-required-payload.dto';
import { BankDetailsRequiredDTO } from '../dto/bank-details-required-payload.dto';
import { mapTinkDataToAlgoanAnalysis } from '../mappers/analysis.mapper';
import { AccountCheckArgs } from '../../tink/dto/account-check.args'

/**
* Hook service
Expand Down Expand Up @@ -129,24 +130,31 @@ export class HooksService {
*/
private generateLinkDataFromAggregationMode(mode: AggregationDetailsMode | undefined, data: { clientConfig: ClientConfig, callbackUrl: string, authorizationCode?: string}): CustomerUpdateInput["aggregationDetails"] {
const { clientConfig, callbackUrl, authorizationCode} = data
const sharedLinkParameters: AccountCheckArgs = {
client_id: clientConfig.clientId,
redirect_uri: callbackUrl,
market: clientConfig.market,
locale: clientConfig.locale,
test: this.config.tink.test ?? false,
scope: [
'accounts:read', // To list account: https://docs.tink.com/api#account-list-accounts-required-scopes-
'transactions:read', // To list transactions: https://docs.tink.com/api#search-query-transactions-required-scopes-
'credentials:read', // To list providers: https://docs.tink.com/api#provider-list-providers-required-scopes-
].join(','),
authorization_code: authorizationCode,
}


switch (mode) {
case AggregationDetailsMode.redirect:
const redirectUrl: string | undefined = this.tinkLinkService.getAuthorizeLink({
client_id: clientConfig.clientId,
redirect_uri: callbackUrl,
market: clientConfig.market,
locale: clientConfig.locale,
test: this.config.tink.test ?? false,
scope: [
'accounts:read', // To list account: https://docs.tink.com/api#account-list-accounts-required-scopes-
'transactions:read', // To list transactions: https://docs.tink.com/api#search-query-transactions-required-scopes-
'credentials:read', // To list providers: https://docs.tink.com/api#provider-list-providers-required-scopes-
].join(','),
authorization_code: authorizationCode,
});
const redirectUrl: string | undefined = this.tinkLinkService.getAuthorizeLink(sharedLinkParameters);

return { redirectUrl }
case AggregationDetailsMode.iframe:
const iframeUrl: string | undefined = this.tinkLinkService.getAuthorizeLink({...sharedLinkParameters, iframe: true});

return { iframeUrl }

default:
throw new Error(`Invalid bank connection mode ${mode}`);
}
Expand Down
1 change: 1 addition & 0 deletions src/tink/dto/account-check.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface AccountCheckArgs {
scope?: string;
test: boolean;
authorization_code?: string;
iframe?: boolean
}

0 comments on commit 0faa939

Please sign in to comment.