Skip to content

Commit

Permalink
use native fetch instead of got
Browse files Browse the repository at this point in the history
  • Loading branch information
pawel-id committed Dec 29, 2024
1 parent e4dd0db commit e6ec41c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
},
"dependencies": {
"entities": "^6.0.0",
"fast-xml-parser": "^4.3.2",
"got": "^11.8.6"
"fast-xml-parser": "^4.3.2"
},
"devDependencies": {
"@types/node": "^22.10.2",
Expand All @@ -54,6 +53,6 @@
"typescript": "^5.7.2"
},
"engines": {
"node": ">=16"
"node": ">=18"
}
}
18 changes: 11 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import got from 'got'

const url = {
prod: 'https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc',
test: 'https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc',
Expand All @@ -11,14 +9,20 @@ export type QueryOptions = {
}

export async function query(prod: boolean, options: QueryOptions) {
const { headers, ...rest } = options
// @ts-ignore
const { body } = await got.post(prod ? url.prod : url.test, {
const { headers, body } = options
const response = await fetch(prod ? url.prod : url.test, {
method: 'POST',
headers: {
'Content-Type': 'application/soap+xml',
...headers,
},
...rest,
body,
})
return body

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}

const responseBody = await response.text()
return responseBody
}

0 comments on commit e6ec41c

Please sign in to comment.