Use Node's built-in fetch instead of node-fetch (punycode DeprecationWarning, #219)
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 54/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, typescript
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- TypeScript
- 星标
- 388
- 派生
- 88
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apple/app-store-server-library-node 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
NotificationHistoryResponseValidator uses the response validator for history items and accepts malformed item fields可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
-
Cloudflare Workers (nodejs_compat): SignedDataVerifier passes with online checks; two non-crypto blockers remain可能已有人在做 @vishalhabib99 于 4 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 32/100
apple/app-store-server-library-node#476 · 1 条评论 · 1 个 reaction ·
-
Abort OCSP requests when the response times out可能已有人在做 @TorinAsakura 于 71 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
-
Subscription status response validators omit validation of data and nested lastTransactions可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 3/5 1-2 天 新手友好度 84/100
查看 apple/app-store-server-library-node 的全部 Issue
相似的 Issue
-
bug priority: low role: BE stage: now
难度 2/5 1-3 小时 新手友好度 86/100
ahmadrosid/nakama#2594 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
milind-soni/OpenMausBot#6495 ·
维护者通常 1 天内回复
-
Navigating the session tree adds the branch's prompts to Up-arrow history again可能已有人在做 @acmerfight 今天认领。 未关闭untriaged
难度 2/5 1-3 小时 新手友好度 68/100
earendil-works/pi#12279 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
approved documentation
难度 1/5 1 小时以内 新手友好度 89/100
vitest-dev/vitest#12015 · 4 条评论 ·
维护者通常 1 天内回复