Use Node's built-in fetch instead of node-fetch (punycode DeprecationWarning, #219)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 54/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- node.js, typescript
- Ambito
- backend-api-design
Direzione di ricerca
Read index.ts and jws_verification.ts, then inspect the three test files that import Response from node-fetch and the OCSP fetch mock. Check how the protected makeFetchRequest return type is used by subclasses before changing it. Done means the library uses Node's global fetch APIs, preserves the documented request and response behavior, and passes the build and tests described in the issue.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
On Node 22 and later, loading the library can print:
(node:8) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
[email protected] depends on [email protected], which depends on [email protected]. whatwg-url/lib/url-state-machine.js and tr46/index.js both call require("punycode"), which loads Node's deprecated built-in module.
When the library runs straight from node_modules, Node does not print the warning, because it skips DEP0040 for code under node_modules. When it is bundled, for example by esbuild for AWS Lambda, those require calls end up in the bundle file. The bundle is outside node_modules, so the warning shows up on every cold start. Lambda logs stderr at ERROR level, so in our case this was the only ERROR line on the functions that use the library.
#219 reported the same warning and was closed because node-fetch 3 is ESM-only and the library is CommonJS. That reason still holds for node-fetch 3. This issue proposes a different route.
Proposal
The README lists Node 22+ as the requirement, and Node has shipped fetch, Headers, Response and AbortSignal.timeout as globals since Node 18. The library could use those and drop node-fetch and @types/node-fetch from its dependencies. It stays CommonJS.
I have a working branch. The library changes are small:
index.tsandjws_verification.tsstop importingnode-fetchand use the globalfetchandHeaders.- The
timeoutoption, which only exists in node-fetch, becomessignal: AbortSignal.timeout(...), with the same 30 s values. response.buffer()in the OCSP check becomesBuffer.from(await response.arrayBuffer()).response.headers.raw()inmakeRequestis replaced byheaders.forEach, withheaders.getSetCookie()forset-cookie.- The error body in
makeRequestis read asunknownand narrowed with a type guard (see point 4 below). - Three test files stop importing
Responsefromnode-fetch, and the OCSP mock spies onglobalThis.fetch.
With these changes tsc -p tsconfig.build.json passes and all 456 tests pass on Node 22, 24 and 26. I also ran the built library against a local HTTP server to check a request with a Buffer body, a 429 response with Retry-After, and the request timeout.
It also removes form-data from the dependency tree. It currently comes in through @types/node-fetch, and [email protected] has an open advisory (GHSA-hmw2-7cc7-3qxx).
Compatibility
This is why I am opening an issue before a PR.
makeFetchRequestis protected and can be overridden. Its return type changes from node-fetch'sResponseto the globalResponse. A subclass that builds a node-fetchResponsewould no longer type-check. Two of the test files do this today.APIException.headerschanges slightly. The Fetch standard trims leading and trailing whitespace from header values, so one test case (Retry-After: " ") now gets[""]. Over a real connection Node's HTTP parser already trims it, so the value is the same either way. A header sent more than once comes back as one comma-joined entry (["a, b"]rather than["a", "b"]), exceptset-cookie, which stays split.- A request that times out in
AppStoreServerAPIClientnow rejects with aTimeoutErrorDOMExceptionrather than node-fetch'sFetchError. InSignedDataVerifierit is still wrapped asRETRYABLE_VERIFICATION_FAILURE, as before. - Native
response.json()returnsPromise<unknown>where node-fetch returnedPromise<any>, so the error path inmakeRequestnow checks the body's types before building theAPIException.errorCodeis used only when it is a number anderrorMessageonly when it is a string; anything else becomesnull. The API always sends a numericerrorCode, so the visible difference is that a missingerrorMessageis nownullinstead ofundefined, which matches the declaredstring | nulltype.
If point 1 is a problem for a minor release, this could wait for the next major version.
Would you accept a PR along these lines? I can open it against main.
- Lingua principale
- TypeScript
- Stelle
- 388
- Fork
- 88
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apple/app-store-server-library-node
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
NotificationHistoryResponseValidator uses the response validator for history items and accepts malformed item fieldsForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Cloudflare Workers (nodejs_compat): SignedDataVerifier passes with online checks; two non-crypto blockers remainForse già presa @vishalhabib99 l’ha presa 4 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 32/100
apple/app-store-server-library-node#476 · 1 commento · 1 reazione ·
-
Abort OCSP requests when the response times outForse già presa @TorinAsakura l’ha presa 71 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
Subscription status response validators omit validation of data and nested lastTransactionsForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 84/100
Tutte le issue di apple/app-store-server-library-node
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Search input loses focus while typing on the Inventory, Reservations and Locations lists (view_configurations enabled)Forse già presa @medusa-os-bot l’ha presa oggi. Apertastatus: needs triaging type: bug version: 2.0
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
medusajs/medusa#17886 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
marimo-team/marimo#11949 ·
I maintainer di solito rispondono entro 1 giorno
-
bug server-time v2
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
modelcontextprotocol/servers#5559 ·
I maintainer di solito rispondono entro 1 giorno
-
D1 Time Travel restore help advertises 30 days without a plan qualifierForse già presa @akhil9tiet l’ha presa oggi. Apertabug package:wrangler product:d1
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
cloudflare/workers-sdk#17000 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno