Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/great-steaks-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@deeplx/cli": patch
"@deeplx/core": patch
---

feat: add `proxy` support with `node-fetch-native/proxy`
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@deeplx/core": "workspace:*",
"@octokit/request": "^9.2.3",
"@pkgr/rollup": "^6.0.3",
"@types/web": "^0.0.219",
"@vercel/node": "^5.1.14",
"@vitest/coverage-istanbul": "^3.1.1",
"eslint": "^9.24.0",
Expand All @@ -51,10 +50,13 @@
"typescript": "^5.8.3",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^3.1.1",
"yarn-berry-deduplicate": "^6.1.1"
"yarn-berry-deduplicate": "^6.1.3"
},
"resolutions": {
"prettier": "^3.5.3"
"node-fetch": "npm:node-fetch-native@^1.6.6",
"prettier": "^3.5.3",
"undici": "npm:undici@^7.8.0",
"undici-types": "npm:undici@^7.8.0"
},
"typeCoverage": {
"atLeast": 100,
Expand Down
2 changes: 1 addition & 1 deletion packages/@deeplx/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"dependencies": {
"@deeplx/core": "^0.1.1",
"commander": "^13.1.0",
"node-fetch": "^3.3.2"
"node-fetch-native": "^1.6.6"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 1 addition & 3 deletions packages/@deeplx/cli/src/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import fetch, { Headers } from 'node-fetch'
import fetch, { Headers } from 'node-fetch-native'

// @ts-expect-error -- incompatible types
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
globalThis.fetch ??= fetch

// @ts-expect-error -- incompatible types
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
globalThis.Headers ??= Headers
1 change: 1 addition & 0 deletions packages/@deeplx/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"translator"
],
"dependencies": {
"node-fetch-native": "^1.6.6",
"whatlang-node": "^0.1.0",
"x-fetch": "^0.2.6"
},
Expand Down
6 changes: 4 additions & 2 deletions packages/@deeplx/core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { HeadersInit } from 'undici'

import type { ValueOf } from './types.ts'

export const SUPPORTED_LANGUAGES = [
Expand Down Expand Up @@ -64,7 +66,7 @@ export const HTTP_STATUS_NOT_ALLOWED = 405
export const HTTP_STATUS_INTERNAL_ERROR = 500
export const HTTP_STATUS_SERVICE_UNAVAILABLE = 503

export const COMMON_HEADERS: HeadersInit = {
export const COMMON_HEADERS = {
'Content-Type': 'application/json',
'User-Agent': 'DeepL/1627620 CFNetwork/3826.500.62.2.1 Darwin/24.4.0',
Accept: '*/*',
Expand All @@ -77,4 +79,4 @@ export const COMMON_HEADERS: HeadersInit = {
'X-Product': 'translator',
'X-App-Build': '1627620',
'X-App-Version': '25.1',
}
} as const satisfies HeadersInit
8 changes: 5 additions & 3 deletions packages/@deeplx/core/src/translate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createProxy } from 'node-fetch-native/proxy'
import { detectLang } from 'whatlang-node'
import { fetchApi } from 'x-fetch'
import { xfetch } from 'x-fetch'

import {
API_URL,
Expand Down Expand Up @@ -29,15 +30,16 @@ import {
// makeRequest makes an HTTP request to DeepL API
const makeRequest = async (
postData: PostData,
_proxyUrl?: string, // unsupported yet
proxyUrl?: string,
dlSession?: string,
) => {
return fetchApi<TranslationResponse>(API_URL, {
return xfetch<TranslationResponse>(API_URL, {
method: 'POST',
body: formatPostString(postData),
headers: dlSession
? { ...COMMON_HEADERS, Cookie: `dl_session=${dlSession}` }
: COMMON_HEADERS,
...createProxy({ url: proxyUrl }),
})
}

Expand Down
Loading
Loading