Skip to content

Commit

Permalink
[ts] allow passing got options to Bitrix constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhyde committed Oct 14, 2021
1 parent a230ada commit 8555802
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions source/bitrix.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ExtendOptions } from 'got'
import Client from './client'
import CompaniesService from './services/companies'
import ContactsService from './services/contacts'
Expand All @@ -11,9 +12,11 @@ import UsersService from './services/users'
* @param restURI REST endpoint, like a `https://hello.bitrix24.ua/rest` or an inbound webhook endpoint,
* like a `https://hello.bitrix24.ua/rest/1/WEBHOOK_TOKEN`.
* @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
* @param clientOptions an object that will overwrite underlying configuration for HTTP client,
* see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
*/
export default (restURI: string, accessToken?: string) => {
const { call, batch, list } = Client(restURI, accessToken)
export default (restURI: string, accessToken?: string, clientOptions?: ExtendOptions) => {
const { call, batch, list } = Client(restURI, accessToken, clientOptions)

return {
call,
Expand Down
9 changes: 6 additions & 3 deletions source/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import got from 'got'
import got, { ExtendOptions } from 'got'
import Queue from 'p-queue'
import addAccessToken from './hooks/addAccessToken'
import Batch from './methods/batch'
Expand All @@ -13,8 +13,10 @@ const BITRIX_API_RATE_INTERVAL = 1000 // 1 second
* @param restURI REST endpoint, like a `https://hello.bitrix24.ru/rest` or an inbound webhook endpoint,
* like a `https://hello.bitrix24.ru/rest/1/WEBHOOK_TOKEN`.
* @param accessToken Bitrix application Access Token. Do not specify in case inbound webhook endpoint used.
* @param options an object that will overwrite underlying configuration for HTTP client,
* see `https://github.com/sindresorhus/got/blob/main/documentation/2-options.md`.
*/
export default (restURI: string, accessToken?: string) => {
export default (restURI: string, accessToken?: string, options?: ExtendOptions) => {
const client = got.extend({
prefixUrl: restURI,
headers: {
Expand All @@ -25,7 +27,8 @@ export default (restURI: string, accessToken?: string) => {
beforeRequest: [
addAccessToken(accessToken)
]
}
},
...options
})

const queue = new Queue({
Expand Down

0 comments on commit 8555802

Please sign in to comment.