Skip to content

Commit

Permalink
v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Nov 9, 2023
1 parent 1e630e2 commit 7b70292
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 19 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ $ npm install @seneca/bud-provider @seneca/env

* ["sys":"entity","base":"bud","cmd":"list","name":"account","zone":"provider"](#-sysentitybasebudcmdlistnameaccountzoneprovider-)
* ["sys":"entity","base":"bud","cmd":"list","name":"obp","zone":"provider"](#-sysentitybasebudcmdlistnameobpzoneprovider-)
* ["sys":"entity","base":"bud","cmd":"list","name":"transaction","zone":"provider"](#-sysentitybasebudcmdlistnametransactionzoneprovider-)
* ["sys":"entity","base":"bud","cmd":"load","name":"account","zone":"provider"](#-sysentitybasebudcmdloadnameaccountzoneprovider-)
* ["sys":"entity","base":"bud","cmd":"load","name":"connection","zone":"provider"](#-sysentitybasebudcmdloadnameconnectionzoneprovider-)
* ["sys":"entity","base":"bud","cmd":"load","name":"customer","zone":"provider"](#-sysentitybasebudcmdloadnamecustomerzoneprovider-)
Expand Down Expand Up @@ -110,6 +111,13 @@ No description provided.



----------
### « `"sys":"entity","base":"bud","cmd":"list","name":"transaction","zone":"provider"` »

No description provided.



----------
### « `"sys":"entity","base":"bud","cmd":"load","name":"account","zone":"provider"` »

Expand Down
57 changes: 53 additions & 4 deletions dist/bud-provider.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/bud-provider.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@seneca/bud-provider",
"version": "0.3.0",
"version": "0.4.0",
"main": "dist/bud-provider.js",
"type": "commonjs",
"types": "dist/bud-provider.d.ts",
Expand Down Expand Up @@ -46,18 +46,18 @@
},
"peerDependencies": {
"@seneca/env": ">=0.2",
"@seneca/provider": ">=1",
"@seneca/provider": ">=2",
"seneca": ">=3",
"seneca-entity": ">=24",
"seneca-entity": ">=25",
"seneca-promisify": ">=3"
},
"devDependencies": {
"@seneca/doc": "^5.0.1",
"@seneca/maintain": "^0.1.0",
"@seneca/user": "^6.3.0",
"@types/jest": "^29.5.5",
"@types/node": "^20.8.2",
"esbuild": "^0.19.4",
"@types/jest": "^29.5.8",
"@types/node": "^20.9.0",
"esbuild": "^0.19.5",
"esbuild-jest": "^0.5.0",
"jest": "^29.7.0",
"node-fetch": "^2",
Expand Down
71 changes: 67 additions & 4 deletions src/bud-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function BudProvider(this: any, options: BudProviderOptions) {
})


console.log('makeUtils', 'get', get)
// console.log('makeUtils', 'get', get)

seneca.message('sys:provider,provider:bud,get:info', get_info)

Expand All @@ -66,6 +66,9 @@ function BudProvider(this: any, options: BudProviderOptions) {
customer: { cmd: { load: {}, save: {} } },
connection: { cmd: { load: {} } },
account: { cmd: { load: {}, list: {} } },
transaction: { cmd: { list: {} } },

// Open Banking Providers (banks and other institutions)
obp: { cmd: { list: {} } },
}

Expand Down Expand Up @@ -219,7 +222,66 @@ function BudProvider(this: any, options: BudProviderOptions) {
return list
}
catch (e: any) {
console.log('LIST ACCOUNT ERR', e)
// console.log('LIST ACCOUNT ERR', e)
let res = e.provider?.response

if (404 === res?.status) {
return null
}

throw e
}
}



entity.transaction.cmd.list.action =
async function(this: any, entize: any, msg: any) {
let q = msg.q || {}
let customerid = q.customerid
let customersecret = q.customersecret

delete q.customerid
delete q.customersecret

try {
let headers = {
'X-Customer-Id': customerid,
'X-Customer-Secret': customersecret,
}

let listdata: any[] = []
let paging = true
let pI = 0
let nextPageToken: string | null | undefined = null
const maxPages = 1111

while (paging && pI < maxPages) {
let json = await get(makeUrl('financial/v2/transactions', q), {
headers
})

// console.log('LIST TX JSON', pI, json.data.length, json.data[0])
listdata = listdata.concat(json.data)

pI++

nextPageToken = json.metadata?.next_page_token

if (null == nextPageToken) {
paging = false
}
}

let list = listdata.map((entry: any) => {
let ent = entize(entry)
ent.id = ent.account_id
return ent
})
return list
}
catch (e: any) {
console.log('LIST TX ERR', e)
let res = e.provider?.response

if (404 === res?.status) {
Expand Down Expand Up @@ -307,7 +369,8 @@ function BudProvider(this: any, options: BudProviderOptions) {
let refreshResult =
await origFetcher(options.url + 'v1/oauth/token', refreshConfig)

// console.log('REFRESH RES', refreshConfig, refreshResult)
options.debug &&
console.log('REFRESH RESULT', refreshConfig, refreshResult)

let refreshJSON = await refreshResult.json()
// console.log('REFRESH JSON', refreshJSON)
Expand Down Expand Up @@ -365,7 +428,7 @@ function BudProvider(this: any, options: BudProviderOptions) {
}
}
catch (e) {
console.log('RETRY', e)
// console.log('RETRY', e)
throw e
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/bud-provider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ async function makeSeneca() {
},
})
.use(BudProvider,{
// debug: true,
url: 'https://api-sandbox.thisisbud.com/',
entity: {
customer: {
save: {
Expand Down
21 changes: 17 additions & 4 deletions test/live.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,22 @@ Seneca({ legacy: false })

console.log(await seneca.post('sys:provider,provider:bud,get:info'))

const list = await seneca.entity('provider/bud/account').list$({
customerid: 'b75fb418-173b-4509-aafa-29a33bf8bd33',
customersecret: 'c02893aa205e04ac32346eaaa143e385a26f6ca3d2e3e5bf11c7dcd95c8be7b6',
const customerid = 'b75fb418-173b-4509-aafa-29a33bf8bd33'
const customersecret = 'c02893aa205e04ac32346eaaa143e385a26f6ca3d2e3e5bf11c7dcd95c8be7b6'

const aclist = await seneca.entity('provider/bud/account').list$({
customerid,
customersecret,
})
console.dir(aclist,{depth:null})

let ac0 = aclist[0]

const txlist0 = await seneca.entity('provider/bud/transaction').list$({
customerid,
customersecret,
})
console.dir(list,{depth:null})
console.dir(txlist0.slice(0,3),{depth:null})


})

0 comments on commit 7b70292

Please sign in to comment.