Skip to content

Commit

Permalink
fix(retry): fix got logic and add timeout. (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasMontone authored Sep 26, 2024
1 parent 0b52b0e commit dee5d5c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
9 changes: 7 additions & 2 deletions example/package-lock.json

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

3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"example:opportunities": "ts-node src/opportunities.ts",
"example:loans": "ts-node src/loans.ts",
"example:benefits": "ts-node src/benefits.ts",
"example:acquirers": "ts-node src/acquirers.ts"
"example:acquirers": "ts-node src/acquirers.ts",
"example:payment-recipient": "ts-node src/payment-recipient.ts"
},
"dependencies": {
"dotenv": "^16.0.3",
Expand Down
25 changes: 25 additions & 0 deletions example/src/payment-recipient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import dotenv from 'dotenv'
import { PluggyClient } from 'pluggy-sdk'

dotenv.config()

void (async function(): Promise<void> {
const { CLIENT_ID = '', CLIENT_SECRET = '' } = process.env

// Authenticate with API using clientId and secret. Valid for 2h.
const client = new PluggyClient({
clientId: CLIENT_ID,
clientSecret: CLIENT_SECRET,
})

try {
console.log('Creating payment recipient...')
await client.payments.createPaymentRecipient({
pixKey: '1234567890',
})

console.log('Succesfully connected to Pluggy, using ClientID and ClientSecret')
} catch (error) {
console.log(error)
}
})()
8 changes: 3 additions & 5 deletions src/baseApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
// eslint-disable-next-line @typescript-eslint/no-var-requires
} = require('../package.json')

const _60_SECONDS = 60 * 1000
const _30_SECONDS = 30 * 1000

type QueryParameters = { [key: string]: number | number[] | string | string[] | boolean }

Expand Down Expand Up @@ -55,13 +55,11 @@ export class BaseApi {
headers: this.defaultHeaders,
responseType: 'json',
parseJson: deserializeJSONWithDates,
timeout: _30_SECONDS,
retry: {
limit: 3,
limit: 2,
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
statusCodes: [429],
calculateDelay: ({ retryAfter }): number => {
return retryAfter ?? _60_SECONDS
},
},
})
}
Expand Down

0 comments on commit dee5d5c

Please sign in to comment.