Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
switch to undici (cjs-compliant)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosahaj committed May 4, 2024
1 parent 0f8618c commit e8bfe65
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
},
"dependencies": {
"ky": "^1.2.4",
"undici": "^6.15.0",
"xml-js": "^1.6.11"
},
"devDependencies": {
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

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

21 changes: 8 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { js2xml } from 'xml-js'
import type { Options } from 'ky'

Check failure on line 2 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

'Options' is defined but never used
import ky from 'ky'

Check failure on line 3 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

'ky' is defined but never used
import { request } from 'undici'
import { SimpleFaxError } from './errors.js'
import type { EnvelopeOptions } from './types.js'
import template from './template.json'
Expand Down Expand Up @@ -30,26 +31,20 @@ export function createEnvelope(options: EnvelopeOptions): string {
* Throws a `SimpleFaxError` if the simple-fax.de server responds with an error
*
* @param options API options
* @param kyOptions Additional request options passed to ky
* @returns FaxId
*/
export async function sendFax(
options: EnvelopeOptions,
kyOptions?: Options,
): Promise<string> {
const envelope = createEnvelope(options)

const response = await ky
.post('http://longisland.simple-fax.de/soap/index.php', {
...kyOptions,
body: envelope,
headers: {
...kyOptions?.headers,
'Content-Type': 'text/xml;charset=UTF-8',
'SOAPAction': `"urn:soapservice#Service#sendfax"`,
},
})
.text()
const response = await request('http://longisland.simple-fax.de/soap/index.php', {
body: envelope,
headers: {
'Content-Type': 'text/xml;charset=UTF-8',
'SOAPAction': `"urn:soapservice#Service#sendfax"`,
},
}).then(({ body }) => body.text())

// Response format: "status;message."
const [status, message] = response.trim().replace(/\.$/, '').split(';')
Expand Down

0 comments on commit e8bfe65

Please sign in to comment.