deepgram / deepgram-js-sdk

Official JavaScript SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
127 stars 45 forks source link

Last url segment is removed from custom global url values #294

Open lox opened 1 month ago

lox commented 1 month ago

What is the current behavior?

The last path segment gets trimmed from custom api endpoint urls.

If setting global: { url: 'https://example.com/test/url/is/long/' }, the url that is fetched for prerecorded transcribe is https://example.com/test/url/is/v1/listen (note the last segment removed).

This was unexpected!

For context, I am building a mock endpoint for our test suites.

Steps to reproduce

import { createClient } from '@deepgram/sdk'
import fs from 'fs'

const client = createClient('nope', {
  global: { url: 'https://example.com/test/url/is/long/' },
  _experimentalCustomFetch: (url, init) => {
    return Response.json({
      url: url.href,
    })
  },
})

const { result, error } = await client.listen.prerecorded.transcribeFile(
  fs.createReadStream('./testdata/polar-bear.webm'),
  {
    model: 'nova',
  }
)

console.log(result)
console.log(error)

Output is:

{
  url: 'https://example.com/test/url/is/v1/listen?model=nova'
}

Expected behavior

I would expect the last segment of the url to be preserved.

Please tell us about your environment

@deepgram/sdk 3.3.2

Other information

Looks like the trailing slash is trimmed in Interested in a PR that preserves the trailing slash here? https://github.com/deepgram/deepgram-js-sdk/blob/bd51da7ce06c59b3dea55e4a915e802bd43a3754/src/packages/AbstractClient.ts#L81.

A hacky workaround is to add a double slash at the end.