Skip to content

Commit 06a3c93

Browse files
Adds date validation
1 parent 634e97d commit 06a3c93

File tree

6 files changed

+154
-10
lines changed

6 files changed

+154
-10
lines changed

.pnp.cjs

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sources/nav-libre/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"start": "yarn server:dist"
2929
},
3030
"devDependencies": {
31+
"@types/async-retry": "^1",
3132
"@types/crypto-js": "^4",
3233
"@types/jest": "27.5.2",
3334
"@types/node": "16.18.119",
@@ -36,6 +37,7 @@
3637
},
3738
"dependencies": {
3839
"@chainlink/external-adapter-framework": "2.6.0",
40+
"async-retry": "^1.3.3",
3941
"crypto-js": "^4.2.0",
4042
"dayjs": "^1.11.13",
4143
"tslib": "2.4.1",

packages/sources/nav-libre/src/transport/authentication.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { v4 as uuidv4 } from 'uuid'
44
/**
55
* Generate the necessary headers for calling the NAV API with a 5-minute-valid signature.
66
*/
7-
export const getNavRequestHeaders = (
7+
export const getRequestHeaders = (
88
method: string,
99
path: string,
1010
body: string,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Requester } from '@chainlink/external-adapter-framework/util/requester'
2+
import { AdapterError } from '@chainlink/external-adapter-framework/validation/error'
3+
import { getRequestHeaders } from './authentication'
4+
interface Response {
5+
FundName: string
6+
GlobalFundID: number
7+
FundEndDate: string
8+
FundDailyAccountingStartDate: string
9+
FundDailyAccountingLastAvailableDate: string
10+
FundOfficialAccountingLastAvailableDate: string
11+
PortfolioLastAvailableDate: string
12+
}
13+
14+
export const getFund = async (
15+
globalFundID: number,
16+
url: string,
17+
apiKey: string,
18+
secret: string,
19+
requester: Requester,
20+
) => {
21+
const method = 'GET'
22+
const query = `globalFundID=${globalFundID}`
23+
const path = '/navapigateway/api/v1/FundAccountingData/GetAccountingDataDates'
24+
const requestConfig = {
25+
baseURL: url,
26+
url: path,
27+
method: method,
28+
headers: getRequestHeaders(method, path + '?' + query, '', apiKey, secret),
29+
}
30+
31+
const sourceResponse = await requester.request<Response[]>(
32+
JSON.stringify(requestConfig),
33+
requestConfig,
34+
)
35+
36+
if (sourceResponse.response.data.length == 0) {
37+
throw new AdapterError({
38+
statusCode: 400,
39+
message: `No fund found`,
40+
})
41+
}
42+
43+
const response = sourceResponse.response.data[0]
44+
console.log(response)
45+
46+
return [response.GlobalFundID.toString(), response.FundDailyAccountingLastAvailableDate + 'Z']
47+
}

packages/sources/nav-libre/src/transport/nav.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HttpTransport } from '@chainlink/external-adapter-framework/transports'
22
import dayjs from 'dayjs'
33
import { BaseEndpointTypes } from '../endpoint/nav'
4-
import { getNavRequestHeaders } from './authentication'
4+
import { getRequestHeaders } from './authentication'
55

66
export interface ResponseSchema {
77
Data: {
@@ -50,14 +50,23 @@ export const httpTransport = new HttpTransport<HttpTransportTypes>({
5050
throw new Error('toDate must be in MM-DD-YYYY format')
5151
}
5252

53+
const response = await getFund(
54+
getFund,
55+
param.globalFundID,
56+
config.API_ENDPOINT,
57+
config.API_KEY,
58+
config.SECRET_KEY,
59+
this.requestor,
60+
)
61+
5362
const method = 'GET'
5463
const path =
5564
'/navapigateway/api/v1/FundAccountingData/GetOfficialNAVAndPerformanceReturnsForFund'
5665
const query = `globalFundID=${param.globalFundID}&fromDate=${fromDate}&toDate=${toDate}`
5766
// Body is empy for GET
5867
const body = ''
5968

60-
const headers = getNavRequestHeaders(
69+
const headers = getRequestHeaders(
6170
method,
6271
path + '?' + query,
6372
body,
@@ -114,3 +123,33 @@ export const httpTransport = new HttpTransport<HttpTransportTypes>({
114123
}))
115124
},
116125
})
126+
127+
// async function callFunction<T extends unknown[], R>(
128+
// func: (...args: T) => Promise<R>,
129+
// maxRetry: number,
130+
// ...args: T
131+
// ): Promise<R> {
132+
// return retry(
133+
// async (bail, attempt) => {
134+
// try {
135+
// return await func(...args)
136+
// } catch (err) {
137+
// if (attempt >= maxRetry) {
138+
// // give up and bubble the error
139+
// bail(err)
140+
// return // unreachable, but satisfies TS
141+
// }
142+
// // otherwise throw to trigger another retry
143+
// throw err
144+
// }
145+
// },
146+
// {
147+
// retries: maxRetry,
148+
// minTimeout: 10000,
149+
// maxTimeout: 10000,
150+
// onRetry: (err, attempt) => {
151+
// logger.info(`${maxRetry - attempt} retries remaining, sleeping for 10000ms...`)
152+
// },
153+
// },
154+
// )
155+
// }

yarn.lock

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5000,9 +5000,11 @@ __metadata:
50005000
resolution: "@chainlink/nav-libre-adapter@workspace:packages/sources/nav-libre"
50015001
dependencies:
50025002
"@chainlink/external-adapter-framework": "npm:2.6.0"
5003+
"@types/async-retry": "npm:^1"
50035004
"@types/crypto-js": "npm:^4"
50045005
"@types/jest": "npm:27.5.2"
50055006
"@types/node": "npm:16.18.119"
5007+
async-retry: "npm:^1.3.3"
50065008
crypto-js: "npm:^4.2.0"
50075009
dayjs: "npm:^1.11.13"
50085010
nock: "npm:13.5.5"
@@ -12359,6 +12361,15 @@ __metadata:
1235912361
languageName: node
1236012362
linkType: hard
1236112363

12364+
"@types/async-retry@npm:^1":
12365+
version: 1.4.9
12366+
resolution: "@types/async-retry@npm:1.4.9"
12367+
dependencies:
12368+
"@types/retry": "npm:*"
12369+
checksum: 10/9cbfe8fb9a6c3559c7084b359edb7b6bae30e16e023eb959e58362b799fc5a9450961e77d994b86526c8de45815eed02c081a104712fb6f2f55ef4cba7263601
12370+
languageName: node
12371+
linkType: hard
12372+
1236212373
"@types/babel__core@npm:7.20.5, @types/babel__core@npm:^7.1.14":
1236312374
version: 7.20.5
1236412375
resolution: "@types/babel__core@npm:7.20.5"
@@ -13004,6 +13015,13 @@ __metadata:
1300413015
languageName: node
1300513016
linkType: hard
1300613017

13018+
"@types/retry@npm:*":
13019+
version: 0.12.5
13020+
resolution: "@types/retry@npm:0.12.5"
13021+
checksum: 10/3fb6bf91835ca0eb2987567d6977585235a7567f8aeb38b34a8bb7bbee57ac050ed6f04b9998cda29701b8c893f5dfe315869bc54ac17e536c9235637fe351a2
13022+
languageName: node
13023+
linkType: hard
13024+
1300713025
"@types/retry@npm:0.12.0":
1300813026
version: 0.12.0
1300913027
resolution: "@types/retry@npm:0.12.0"
@@ -14206,6 +14224,15 @@ __metadata:
1420614224
languageName: node
1420714225
linkType: hard
1420814226

14227+
"async-retry@npm:^1.3.3":
14228+
version: 1.3.3
14229+
resolution: "async-retry@npm:1.3.3"
14230+
dependencies:
14231+
retry: "npm:0.13.1"
14232+
checksum: 10/38a7152ff7265a9321ea214b9c69e8224ab1febbdec98efbbde6e562f17ff68405569b796b1c5271f354aef8783665d29953f051f68c1fc45306e61aec82fdc4
14233+
languageName: node
14234+
linkType: hard
14235+
1420914236
"async@npm:^3.2.2, async@npm:^3.2.3, async@npm:^3.2.4":
1421014237
version: 3.2.6
1421114238
resolution: "async@npm:3.2.6"
@@ -29177,20 +29204,20 @@ __metadata:
2917729204
languageName: node
2917829205
linkType: hard
2917929206

29207+
"retry@npm:0.13.1, retry@npm:^0.13.1":
29208+
version: 0.13.1
29209+
resolution: "retry@npm:0.13.1"
29210+
checksum: 10/6125ec2e06d6e47e9201539c887defba4e47f63471db304c59e4b82fc63c8e89ca06a77e9d34939a9a42a76f00774b2f46c0d4a4cbb3e287268bd018ed69426d
29211+
languageName: node
29212+
linkType: hard
29213+
2918029214
"retry@npm:^0.12.0":
2918129215
version: 0.12.0
2918229216
resolution: "retry@npm:0.12.0"
2918329217
checksum: 10/1f914879f97e7ee931ad05fe3afa629bd55270fc6cf1c1e589b6a99fab96d15daad0fa1a52a00c729ec0078045fe3e399bd4fd0c93bcc906957bdc17f89cb8e6
2918429218
languageName: node
2918529219
linkType: hard
2918629220

29187-
"retry@npm:^0.13.1":
29188-
version: 0.13.1
29189-
resolution: "retry@npm:0.13.1"
29190-
checksum: 10/6125ec2e06d6e47e9201539c887defba4e47f63471db304c59e4b82fc63c8e89ca06a77e9d34939a9a42a76f00774b2f46c0d4a4cbb3e287268bd018ed69426d
29191-
languageName: node
29192-
linkType: hard
29193-
2919429221
"reusify@npm:^1.0.4":
2919529222
version: 1.0.4
2919629223
resolution: "reusify@npm:1.0.4"

0 commit comments

Comments
 (0)