Repository navigation
ConvertApi.auth: accept the host as a URL, keep the JSDoc in dist/*.d.ts - #35
Merged
Merged
Conversation
ConvertApi.auth('api-token', 'https://eu-v2.convertapi.com/') requested
https://https://eu-v2.convertapi.com//convert/... and failed with "fetch
failed" (ENOTFOUND https). The README showed that form from 2023-07-04
until #34, and
https://www.convertapi.com/llms.txt still does. The constructor now
removes a leading https:// or http:// and trailing slashes and stores
the bare host in this.host, which createParams() and the upload URLs
use too. Requests always use https.
The auth() JSDoc described the retired secret or apiKey and token
object; it now describes the API token and the host name. The build
also removed every JSDoc comment from dist/*.d.ts (removeComments), so
editors never showed any of them. It now emits the declarations a
second time with their comments; the JavaScript keeps none, as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the host normalization and declaration documentation changes.
No open issues 🎉
What changed in this PR
This PR lets the JavaScript client accept URL-form API hosts and preserves JSDoc in published type declarations so editors can display it.
Changes:
- Normalize hosts by removing HTTP(S) prefixes and trailing slashes while keeping requests on HTTPS.
- Update authentication documentation and emit declarations with comments without changing JavaScript comment removal.
- Add regression tests for host normalization, upload and conversion URLs, and declaration JSDoc.
| File | Description |
|---|---|
tsconfig.json |
Explain the separate comment settings for JavaScript and declarations. |
test/convertapi.test.js |
Test URL-form hosts, request destinations, and preserved JSDoc. |
src/convertapi.ts |
Normalize hosts in the constructor and clarify authentication documentation. |
package.json |
Add a declaration-only build pass that preserves comments. |
CHANGELOG.md |
Document host normalization and declaration documentation improvements. |
Review effort: Balanced
The previous commit makes dist/*.d.ts keep their JSDoc, so this comment now shows in editors. It said "conversion duration seconds", but the getter returns ConversionCost, which the API spec describes as the amount deducted from the balance after the conversion. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #34, which changes README.md only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ConvertApi.auth()also takes the host as a URL. A leadinghttps://orhttp://and trailing slashes are removed, soConvertApi.auth('api-token', 'https://eu-v2.convertapi.com/')sends requests tohttps://eu-v2.convertapi.com/convert/.... The bare host goes intothis.host, socreateParams()and the uploadURLs in
src/file-param.tsuse it too. Requests always use https.auth()JSDoc describes the API token and the host name. It described the retiredsecretorapiKeyandtokenobject.dist/*.d.tskeep their JSDoc, so editors show it. Until now the build removed it (see below).Result.duration's JSDoc says it returns the conversion cost (ConversionCost), not a duration in seconds. Thatcomment now ships too (second commit).
fixes its example.
Why
From 2023-07-04 until #34, the README's "Alternative domain"
example passed
'https://eu-v2.convertapi.com/'. The library buildshttps://${host}/..., so it requestedhttps://https://eu-v2.convertapi.com//convert/..., and fetch failed (ENOTFOUND, hosthttps) before any requestreached ConvertAPI. https://www.convertapi.com/llms.txt still shows that form, and code copied or generated from it
fails the same way. With this change, that code works.
JSDoc in the type declarations
tsconfig.jsonhas hadremoveComments: truesince 2020, and TypeScript applies it to the declarations too. Nopublished version has had any JSDoc in
dist/*.d.ts(checked 1.1.9 and 1.1.11 on unpkg), so fixing theauth()textalone would change nothing users see.
npm run buildnow runstsc, thentsc --emitDeclarationOnly --removeComments false:dist/has no comments, as before. Onlydist/convertapi.jschanges, for the host fix; the othersix files are byte-identical with a build of
main.dist/*.d.tsgrow from 3,856 to 7,600 bytes in all.build.ymlandpublish.ymlboth build withnpm run build, so releases get it too.removeComments: false) would have grown the JavaScript from 7,962 to 11,400 bytes.I read the other comments that now ship. The
Params.addlink https://www.convertapi.com/conversions redirects tohttps://www.convertapi.com/api (200).
Result.durationsaid "conversion duration seconds", but it returnsConversionCost, which the API spec describes as "This amount will be deducted from your balance after theconversion." The second commit fixes that comment.
This part is separate from the host fix and can be dropped. It consists of the
package.jsonandtsconfig.jsonlines,the last test, the second CHANGELOG bullet and the second commit.
Tests
npm ci && npm teston Node 24.20.0: 12 pass. The 3 live tests are skipped without a token. Three of the unit testsare new:
https://,HTTPS://,http://, one or two trailing slashes, a bare host,http://localhost:8080/(the port stays), andnew ConvertApi();'https://example.test/', the file upload, the URL upload and the conversion all go tohttps://example.test/...;dist/convertapi.d.tscontains theauth()JSDoc.Against a build of
main, those three fail and the other nine pass.node --test test/live.test.jswith a staging token passes 3 of 3 withCONVERT_API_HOST=stag-v2.convertapi.com,and 3 of 3 with
CONVERT_API_HOST=https://stag-v2.convertapi.com/. With a build ofmain, the URL form fails withfetch failed(ENOTFOUND https).Not in this PR
release with this change is out, that line works with it.
src/worker.tsuploads tohttps://v2.convertapi.comwhatever host is set. It is not exported from the packageentry, so it is left alone.
🤖 Generated with Claude Code