File tree Expand file tree Collapse file tree 8 files changed +51
-145
lines changed Expand file tree Collapse file tree 8 files changed +51
-145
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @deeplx/cli " : patch
3+ " @deeplx/core " : patch
4+ ---
5+
6+ feat: add ` proxy ` support with ` node-fetch-native/proxy `
Original file line number Diff line number Diff line change 3535 "@deeplx/core" : " workspace:*" ,
3636 "@octokit/request" : " ^9.2.3" ,
3737 "@pkgr/rollup" : " ^6.0.3" ,
38- "@types/web" : " ^0.0.219" ,
3938 "@vercel/node" : " ^5.1.14" ,
4039 "@vitest/coverage-istanbul" : " ^3.1.1" ,
4140 "eslint" : " ^9.24.0" ,
5150 "typescript" : " ^5.8.3" ,
5251 "vite-tsconfig-paths" : " ^5.1.4" ,
5352 "vitest" : " ^3.1.1" ,
54- "yarn-berry-deduplicate" : " ^6.1.1 "
53+ "yarn-berry-deduplicate" : " ^6.1.3 "
5554 },
5655 "resolutions" : {
57- "prettier" : " ^3.5.3"
56+ "node-fetch" : " npm:node-fetch-native@^1.6.6" ,
57+ "prettier" : " ^3.5.3" ,
58+ "undici" : " npm:undici@^7.8.0" ,
59+ "undici-types" : " npm:undici@^7.8.0"
5860 },
5961 "typeCoverage" : {
6062 "atLeast" : 100 ,
Original file line number Diff line number Diff line change 4040 "dependencies" : {
4141 "@deeplx/core" : " ^0.1.1" ,
4242 "commander" : " ^13.1.0" ,
43- "node-fetch" : " ^3.3.2 "
43+ "node-fetch-native " : " ^1.6.6 "
4444 },
4545 "publishConfig" : {
4646 "access" : " public"
Original file line number Diff line number Diff line change 1- import fetch , { Headers } from 'node-fetch'
1+ import fetch , { Headers } from 'node-fetch-native '
22
3- // @ts -expect-error -- incompatible types
43// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
54globalThis . fetch ??= fetch
65
7- // @ts -expect-error -- incompatible types
86// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
97globalThis . Headers ??= Headers
Original file line number Diff line number Diff line change 4848 " translator"
4949 ],
5050 "dependencies" : {
51+ "node-fetch-native" : " ^1.6.6" ,
5152 "whatlang-node" : " ^0.1.0" ,
5253 "x-fetch" : " ^0.2.6"
5354 },
Original file line number Diff line number Diff line change 1+ import type { HeadersInit } from 'undici'
2+
13import type { ValueOf } from './types.ts'
24
35export const SUPPORTED_LANGUAGES = [
@@ -64,7 +66,7 @@ export const HTTP_STATUS_NOT_ALLOWED = 405
6466export const HTTP_STATUS_INTERNAL_ERROR = 500
6567export const HTTP_STATUS_SERVICE_UNAVAILABLE = 503
6668
67- export const COMMON_HEADERS : HeadersInit = {
69+ export const COMMON_HEADERS = {
6870 'Content-Type' : 'application/json' ,
6971 'User-Agent' : 'DeepL/1627620 CFNetwork/3826.500.62.2.1 Darwin/24.4.0' ,
7072 Accept : '*/*' ,
@@ -77,4 +79,4 @@ export const COMMON_HEADERS: HeadersInit = {
7779 'X-Product' : 'translator' ,
7880 'X-App-Build' : '1627620' ,
7981 'X-App-Version' : '25.1' ,
80- }
82+ } as const satisfies HeadersInit
Original file line number Diff line number Diff line change 1+ import { createProxy } from 'node-fetch-native/proxy'
12import { detectLang } from 'whatlang-node'
2- import { fetchApi } from 'x-fetch'
3+ import { xfetch } from 'x-fetch'
34
45import {
56 API_URL ,
@@ -29,15 +30,16 @@ import {
2930// makeRequest makes an HTTP request to DeepL API
3031const makeRequest = async (
3132 postData : PostData ,
32- _proxyUrl ?: string , // unsupported yet
33+ proxyUrl ?: string ,
3334 dlSession ?: string ,
3435) => {
35- return fetchApi < TranslationResponse > ( API_URL , {
36+ return xfetch < TranslationResponse > ( API_URL , {
3637 method : 'POST' ,
3738 body : formatPostString ( postData ) ,
3839 headers : dlSession
3940 ? { ...COMMON_HEADERS , Cookie : `dl_session=${ dlSession } ` }
4041 : COMMON_HEADERS ,
42+ ...createProxy ( { url : proxyUrl } ) ,
4143 } )
4244}
4345
You can’t perform that action at this time.
0 commit comments