Skip to content

Instantly share code, notes, and snippets.

@BharatKalluri
Created September 28, 2021 08:36
Show Gist options
  • Save BharatKalluri/93c5c78082d46a3c8c2ed7969c726039 to your computer and use it in GitHub Desktop.
Save BharatKalluri/93c5c78082d46a3c8c2ed7969c726039 to your computer and use it in GitHub Desktop.
AA client
import {v4 as uuidV4} from 'uuid';
import rs from "jsrsasign";
const BASE_URL = 'https://aa-sandbox.setu.co'
class AccountAggregatorClient {
aa_id: string;
fiu_id: string;
client_api_key: string
constructor(
aa_id: string,
fiu_id: string,
client_api_key: string
) {
this.aa_id = aa_id
this.fiu_id = fiu_id
this.client_api_key = client_api_key
}
async requestConsent(context: {
onDate: Date,
phoneNumber: string,
}) {
const {onDate, phoneNumber} = context
const txnId: string = uuidV4()
const payload = {
"ver": "1.0",
"timestamp": `${onDate.toISOString()}`,
"txnid": `${txnId}`,
"ConsentDetail": {
"consentStart": "{{current_datetime}}",
"consentExpiry": "2021-12-31T11:39:57.153Z",
"consentMode": "VIEW",
"fetchType": "ONETIME",
"consentTypes": ["TRANSACTIONS", "PROFILE", "SUMMARY"],
"fiTypes": ["DEPOSIT", "BONDS", "INSURANCE_POLICIES", "PPF"],
"DataConsumer": {"id": `${this.fiu_id}`},
"Customer": {"id": `${phoneNumber}@${this.aa_id}`},
"Purpose": {
"code": "101",
"refUri": "https://api.rebit.org.in/aa/purpose/101.xml",
"text": "Wealth management service",
"Category": {
"type": "string"
}
},
"FIDataRange": {"from": "2019-04-11T11:39:57.153Z", "to": "2020-04-17T14:25:33.440Z"},
"DataLife": {"unit": "MONTH", "value": 0},
"Frequency": {"unit": "MONTH", "value": 3},
"DataFilter": [
{"type": "TRANSACTIONAMOUNT", "operator": ">=", "value": "10"}
]
}
}
const jwtToken: string = rs.KJUR.jws.JWS.sign(
null,
{"alg": "RS256"},
JSON.stringify(payload)
)
const response: Response = await fetch(`${BASE_URL}/Consent`, {
method: 'POST',
headers: {
'client_api_key': this.client_api_key,
'x-jws-signature': jwtToken,
}
})
}
}
{
"name": "aa-client",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"@types/jsrsasign": "^8.0.13",
"@types/uuid": "^8.3.1",
"axios": "^0.21.4",
"typescript": "^4.4.3"
},
"dependencies": {
"jsrsasign": "^10.4.0",
"jsrsasign-util": "^1.0.5",
"uuid": "^8.3.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment