Skip to content

Commit 2d43231

Browse files
Refactors to use SubscribeTransport for multi HTTP requests
1 parent 0770c64 commit 2d43231

File tree

14 files changed

+263
-472
lines changed

14 files changed

+263
-472
lines changed

.pnp.cjs

Lines changed: 5 additions & 129 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

packages/sources/nav-libre/package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,16 @@
2828
"start": "yarn server:dist"
2929
},
3030
"devDependencies": {
31-
"@types/async-retry": "^1",
3231
"@types/crypto-js": "^4",
33-
"@types/jest": "27.5.2",
34-
"@types/node": "16.18.119",
35-
"nock": "13.5.5",
36-
"typescript": "5.6.3"
32+
"@types/jest": "^29.5.14",
33+
"@types/node": "22.14.1",
34+
"nock": "13.5.6",
35+
"typescript": "5.8.3"
3736
},
3837
"dependencies": {
3938
"@chainlink/external-adapter-framework": "2.6.0",
40-
"async-retry": "^1.3.3",
4139
"crypto-js": "^4.2.0",
42-
"dayjs": "^1.11.13",
40+
"date-fns": "^4.1.0",
4341
"tslib": "2.4.1",
4442
"uuid": "^11.1.0"
4543
}

packages/sources/nav-libre/src/config/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ export const config = new AdapterConfig({
1616
API_ENDPOINT: {
1717
description: 'An API endpoint for Data Provider',
1818
type: 'string',
19-
default: 'https://api.navfundservices.com/',
19+
default: 'https://api.navfundservices.com',
2020
},
2121
MAX_RETRIES: {
2222
description: 'Maximum attempts of sending a request',
2323
type: 'number',
2424
default: 3,
2525
},
26+
BACKGROUND_EXECUTE_MS: {
27+
description:
28+
'The amount of time the background execute should sleep before performing the next request',
29+
type: 'number',
30+
default: 120_000, // one call per two minute
31+
},
2632
})
Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { AdapterEndpoint } from '@chainlink/external-adapter-framework/adapter'
22
import { InputParameters } from '@chainlink/external-adapter-framework/validation'
3-
import dayjs from 'dayjs'
43
import { config } from '../config'
5-
import { httpTransport } from '../transport/nav'
4+
import { navLibreTransport } from '../transport/nav'
65

76
export const inputParameters = new InputParameters(
87
{
@@ -11,24 +10,10 @@ export const inputParameters = new InputParameters(
1110
type: 'number',
1211
description: 'The global fund ID for the Libre fund',
1312
},
14-
fromDate: {
15-
required: false,
16-
type: 'string',
17-
description: 'Start date in MM-DD-YYYY format (defaults to 7 days ago)',
18-
default: dayjs().subtract(7, 'day').format('MM-DD-YYYY'),
19-
},
20-
toDate: {
21-
required: false,
22-
type: 'string',
23-
description: 'End date in MM-DD-YYYY format (defaults to today)',
24-
default: dayjs().format('MM-DD-YYYY'),
25-
},
2613
},
2714
[
2815
{
2916
globalFundID: 139767,
30-
fromDate: '12-30-2024',
31-
toDate: '01-15-2025',
3217
},
3318
],
3419
)
@@ -47,7 +32,6 @@ export type BaseEndpointTypes = {
4732

4833
export const endpoint = new AdapterEndpoint({
4934
name: 'nav',
50-
aliases: [],
51-
transport: httpTransport,
35+
transport: navLibreTransport,
5236
inputParameters,
5337
})
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { differenceInBusinessDays, format, isValid, parse, subBusinessDays } from 'date-fns'
2+
3+
// Date format used by the NavLibre API
4+
export const DATE_FORMAT = 'MM-dd-yyyy'
5+
export const MAX_BUSINESS_DAYS = 7
6+
7+
/**
8+
* Parse a string in MM-DD-YYYY format.
9+
* Throws if the string is missing or malformed.
10+
*/
11+
export function parseDateString(dateStr: string): Date {
12+
const parsed = parse(dateStr, DATE_FORMAT, new Date())
13+
if (!isValid(parsed)) {
14+
throw new Error(`date must be in ${DATE_FORMAT} format: got "${dateStr}"`)
15+
}
16+
return parsed
17+
}
18+
19+
/** Ensure the window is <= N business days. Returns the (possibly adjusted) from-date. */
20+
export function clampToBusinessWindow(
21+
from: Date,
22+
to: Date,
23+
maxBusinessDays = MAX_BUSINESS_DAYS,
24+
): Date {
25+
const span = differenceInBusinessDays(to, from)
26+
return span > maxBusinessDays ? subBusinessDays(to, maxBusinessDays) : from
27+
}
28+
29+
/** Convenience formatter so every outbound string is consistent. */
30+
export function toDateString(d: Date): string {
31+
return format(d, DATE_FORMAT)
32+
}

0 commit comments

Comments
 (0)