Use Node's built-in fetch instead of node-fetch (punycode DeprecationWarning, #219)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 54/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 388
- Fork
- 88
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apple/app-store-server-library-node
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
NotificationHistoryResponseValidator uses the response validator for history items and accepts malformed item fieldsCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Cloudflare Workers (nodejs_compat): SignedDataVerifier passes with online checks; two non-crypto blockers remainCó thể đã có người làm @vishalhabib99 đã nhận 4 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 32/100
apple/app-store-server-library-node#476 · 1 bình luận · 1 reaction ·
-
Abort OCSP requests when the response times outCó thể đã có người làm @TorinAsakura đã nhận 71 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
-
Subscription status response validators omit validation of data and nested lastTransactionsCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 84/100
Tất cả issue của apple/app-store-server-library-node
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Search input loses focus while typing on the Inventory, Reservations and Locations lists (view_configurations enabled)Có thể đã có người làm @medusa-os-bot đã nhận hôm nay. Đang mởstatus: needs triaging type: bug version: 2.0
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
medusajs/medusa#17886 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
marimo-team/marimo#11949 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug server-time v2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
modelcontextprotocol/servers#5559 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
D1 Time Travel restore help advertises 30 days without a plan qualifierCó thể đã có người làm @akhil9tiet đã nhận hôm nay. Đang mởbug package:wrangler product:d1
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
cloudflare/workers-sdk#17000 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày