Repository navigation
Upgrading from 1.x: see upgrading_to_v2.md for every breaking change
with before and after code.
Added
TranslationMemoryJobError, thrown byimportTranslationMemoryFromFilepath()
andexportTranslationMemoryToFilepath(). It extendsDeepLError, holds the
cause inerror, the job ID injobIdonce the job was created and the last
job status the helper fetched injob, and copies
httpStatusCodeandshouldRetryfrom aDeepLErrorcause.- Cancellation: every
DeepLClientandDeepLAdminClientmethod that sends a
request acceptssignal?: AbortSignal, through its options object or, for
methods that had none, a new trailingoptionsargument of the new type
RequestOptions(whichBaseRequestOptions,WaitOptions,
TranslationMemorySegmentsOptionsandGetLanguagesForResourceOptionsnow
extend). Aborting cancels the request in flight, the download of a response
body (an error response's included), pending retries and the wait between
status checks oftranslateDocument(),
translateDocumentWaitUntilDone(),waitUntilTranslationMemoryJobDone()and
the translation memory file helpers. The promise rejects with the signal's
abort reason, unwrapped: not aDeepLError, andtranslateDocument()does
not wrap it in aDocumentTranslationError. Code that relies on every
rejection being aDeepLErrormust checksignal.abortedfirst when it
passes a signal.
Changed
- Breaking: methods that create a resource are retried only when the
request was not sent (HTTP 429, DNS failures, refused connections,
unreachable hosts or networks, and timeouts or resets while connecting, TLS
handshake included), asDeepLAdminClient.createDeveloperKey()already was,
except for the TLS handshake:translateDocument(),
translateDocumentUpload(), the glossary, spoken terms, style rule, custom
instruction and style profile creates,createTranslationMemoryImport(),
createTranslationMemoryExport()and the translation memory file helpers.
A 5xx response or a connection reset after the request was sent is no
longer retried for them, and the error'sshouldRetryis [secure] for a 5xx,
as the API may have created the resource. Check for the resource before creating it again. - Breaking: a response body that is cut off mid-read now fails with a
ConnectionErrorwhoseshouldRetryis true, and is retried like a reset
connection, except for the creates above. Before, it was never retried and
shouldRetrywas [secure]. Code that retried such errors itself can rely on
the library's retries. - Breaking:
Usage.anyLimitReached()is replaced byUsage.anyCharacterLimitReached(),
which returns true if the account's character limit (character) or this
API key's character limit (apiKeyCharacter) is reached. An absent detail
counts as not reached; the speech minutes are not included. Rename calls to
anyCharacterLimitReached(); if you only want the account limit, call
usage.character?.limitReached(). - Breaking:
DocumentStatus.statusis typedDocumentStatusCode | (string & {})and
TranslationMemoryJobResult.statusTranslationMemoryJobStatus | (string & {}),
so a status the library does not know yet is visible in the type. Exhaustive
switchstatements over these fields need adefaultbranch. - Breaking:
DocumentStatus.documentIdis a requiredstring. When the status response
has no document ID, it is the ID of the handle passed to
translateDocumentGetStatus(). Removeundefinedchecks. - Breaking:
TranslationMemoryJob.creationTime,updatedTime,done()andok()are
required. The library always set them; a missing timestamp is an invalid
Date. Code that buildsTranslationMemoryJobobjects itself must set them,
andjob.done?.()can becomejob.done(). - Breaking:
translateDocument()andtranslateDocumentUpload()reject with an
ArgumentErrorbefore any request when the input file path does not exist
(was aDocumentTranslationError, or the Node error for
translateDocumentUpload()). An existing input file that cannot be read
(e.g.EACCES,EISDIR) still rejects with aDocumentTranslationError
fromtranslateDocument()and the Node error from
translateDocumentUpload().translateDocument()rejects with a
DocumentTranslationErrorfor an existing output file or a missing or
unwritable output directory (was the Node error); the Node error is in
error. CatchArgumentErrorandDocumentTranslationErrorinstead of
checkingerror.code. - Breaking:
importTranslationMemoryFromFilepath()rejects with an
ArgumentErrorfor a missing input file (was the Node errorENOENT), and
with the newTranslationMemoryJobErrorfor every other failure: other read
failures (was the Node error, e.g.EISDIR), aBufferor stream without
fileNameordisplayName(wasArgumentError) and failures of the job
creation, upload and wait (were theDeepLErroror its subclass).
exportTranslationMemoryToFilepath()rejects with a
TranslationMemoryJobErrorfor every failure, including an existing output
file, a missing or unwritable output directory and local write failures
(were the Node error). The cause is inerror; catch
TranslationMemoryJobErrorinstead of theDeepLErrorsubclasses and read
error.errorfor the cause.downloadTranslationMemoryExport()still rejects with the Node error (e.g.
EEXIST) for an existing or uncreatable output file and write failures. - Breaking:
translateText(),createGlossary(),createMultilingualGlossary(),
createMultilingualGlossaryFromCsv(),updateMultilingualGlossaryName(),
updateMultilingualGlossaryDictionary(),
updateMultilingualGlossaryDictionaryFromCsv(),rephraseText()and
correctText()send a JSON request body instead of a form-encoded one, as the
other glossary, style rule and translation memory methods already do.text,
glossary_ids,custom_instructionsand the tag lists are sent as JSON
arrays, booleans and numbers keep their JSON types, and the v3 glossary
dictionariesare a JSON array of objects. Document upload stays multipart.
Proxies and test doubles that read these request bodies must parse JSON. - Breaking:
RequestParameters, the type ofextraBodyParameters, is
Record<string, unknown>(wasRecord<string, string>). In JSON bodies each
value keeps its JSON type, so booleans, numbers and arrays can be passed
({ show_billed_characters: [secure] }). In the multipart document upload,
strings are sent as given, arrays comma-joined, booleans astrue/[secure],
numbers viaString()and other objects as JSON. The API does not convert strings, so a
string for a field it types as a boolean, number or array is now rejected,
e.g.{ outline_detection: '0' }: pass[secure]or use the matching option.
extraBodyParameters: { outline_detection: '0' }still compiles but fails at
runtime with HTTP 400 "Value for 'outline_detection' not supported"; write
extraBodyParameters: { outline_detection: [secure] }.
Objects typed asRecord<string, string>still compile as extra body
parameters; only code that reads values from aRequestParametersas strings
needs a cast or check. - Breaking:
StyleRuleInfo.configuredRulesis theconfigured_rulesmap as the API
returns it (Record<string, Record<string, string>>, snake_case category
and rule names), the same shapecreateStyleRule()and
updateStyleRuleConfiguredRules()take. Categories the library did not know
are no longer dropped. Replace the camelCase category properties with the
API's names, e.g.configuredRules.datesAndTimeswith
configuredRules.dates_and_timesandconfiguredRules.styleAndTonewith
configuredRules.style_and_tone. - Breaking:
rephraseText()takes aRephraseTextOptionsobject as its third argument
and has no fourth argument. Pass{ writingStyle, tone }instead of the
writing style and tone as the third and fourth arguments. JavaScript callers
that still pass the writing style or tone positionally get no error: the
value is ignored and the text is rephrased without it. - Breaking: Node.js 18 or later is required (
engines.nodeis>=18, was>=14.17),
and the package is compiled to ES2022. Upgrade Node.js to 18 or later before
upgrading the package. - Breaking:
@types/nodeis no longer a runtime dependency, so installing the package
no longer adds it to your project. TypeScript projects that relied on it
being installed transitively add@types/nodeto their own
devDependencies. - Breaking: argument checks throw
ArgumentError(aDeepLError
subclass) instead of a plainDeepLError: an empty auth key in the
DeepLClientconstructor; empty texts, empty language codes,glossary
withglossaryIds, more than 5glossaryIds, a glossary, style rule, style
profile or translation memory option without ID,translationMemoryThreshold
withouttranslationMemoryor outside 0 to 100, a document glossary without
sourceLangand a non-path document input withoutfilenamein
translateText(),translateDocument(),translateDocumentUpload(),
rephraseText()andcorrectText(); an empty name or entries in
createGlossary()andcreateGlossaryWithCsv(); an empty or control
character glossary or spoken term; an empty translation memory ID.
deleteMultilingualGlossary()throwsArgumentErrorfor an empty or missing
glossary ID (was a plainError, or aTypeErrorfornull). Code that
checkserror.constructor === DeepLErrormust also acceptArgumentError. - Breaking: the multilingual glossary methods that take a glossary
(getMultilingualGlossaryDictionaryEntries(),
deleteMultilingualGlossaryDictionary(),
replaceMultilingualGlossaryDictionary(),
replaceMultilingualGlossaryDictionaryFromCsv(),
updateMultilingualGlossary(),updateMultilingualGlossaryName(),
updateMultilingualGlossaryDictionary()and
updateMultilingualGlossaryDictionaryFromCsv()) throwArgumentErrorbefore
any request for an empty glossary ID or aMultilingualGlossaryInfowithout
one. Before, all butupdateMultilingualGlossary()sent a request to
/v3/glossaries/undefinedfor aMultilingualGlossaryInfowithout ID (HTTP
400 from the API), andupdateMultilingualGlossaryName()sent one to
/v3/glossaries/for an empty ID (HTTP 404); the others already threw
ArgumentErrorfor an empty ID.createMultilingualGlossary()throws
ArgumentErrorfor an empty dictionary list, and it,
replaceMultilingualGlossaryDictionary(),
updateMultilingualGlossaryDictionary()andupdateMultilingualGlossary()
throwArgumentErrorfor a dictionary without entries. CatchArgumentError
where you handled the API's 400 or 404 for these calls. - Breaking:
translateDocumentGetStatus()and
translateDocumentWaitUntilDone()throw aDeepLErrorfor HTTP 503 (was
DocumentNotReadyError). OnlytranslateDocumentDownload()throws
DocumentNotReadyError. CheckhttpStatusCode === 503orshouldRetry
instead. - Breaking:
downloadTranslationMemoryExport()throws a plainDeepLError
withhttpStatusCodefor an error response from the pre-signed download URL,
asuploadTranslationMemoryFile()does (was mapped like a DeepL API response:
AuthorizationErrorfor 403,NotFoundErrorfor 404,QuotaExceededError
for 456,DocumentNotReadyErrorfor 503). It throws aDeepLErrorinstead
of anArgumentErrorfor a job without download URL, as the job state comes
from the API. CheckhttpStatusCodeinstead of theDeepLErrorsubclass. - Breaking:
DeepLClientandDeepLAdminClientconstructors throw anArgumentError
whenserverUrlis not an absolutehttporhttpsURL, for example
'api.deepl.com'or'ftp://x', instead of failing on the first request.
Pass an absolute URL such as'https://api.deepl.com'. - Breaking:
DeepLClientandDeepLAdminClientconstructors throw an
ArgumentErrorwhen theproxyoption is a URL string that is nothttpor
httpswith a host, for example'proxy.example.com:3128'or
'socks5://127.0.0.1:1080'. Before, any parsable string was accepted and its
scheme was used as a plain HTTP proxy. The error message no longer contains
the proxy URL. Use anhttp://orhttps://URL, or aProxyConfig. createTranslationMemoryExport()andexportTranslationMemoryToFilepath()
send the export request without aContent-Typeheader, as it has no body
(wasapplication/x-www-form-urlencoded).- Breaking: a
nullvalue inextraBodyParameterswas sent as the string
"null"in form-encoded bodies; it is now sent as JSONnullby the methods
that switched to JSON bodies and removes the parameter in the document
upload. Passundefinedto leave a parameter out. - Breaking:
CustomInstruction.idis nowstringinstead of
string | undefined.CustomInstructionis only returned by the API, which
always sets it; code that buildsCustomInstructionobjects must setid. - Breaking:
rephraseText()andcorrectText()throw anArgumentError
for an emptytargetLanginstead of sending the request without a target
language; passnullor omittargetLangto keep the language of the input
text. - Breaking:
createStyleProfile()andupdateStyleProfile()send the
translationMemoryIdselements as given, likeglossaryIdsand
styleRuleIds, instead of throwing aDeepLErrorbefore the request for an
empty ID or aTranslationMemoryInfowithout ID; the API now rejects invalid
IDs, e.g. an empty ID with HTTP 400. AcatchofDeepLErrorstill catches
it; the error now comes from the API, after the request. Pass valid
translation memory IDs. - Breaking:
translateText(),translateDocument()and
translateDocumentUpload()throw anArgumentErrorfor anull
glossaryIdselement, andgetTranslationMemory(),
listTranslationMemorySegments(),deleteTranslationMemory()and
createTranslationMemoryExport()for anulltranslation memory, without
sending a request. They threw aTypeErrorbefore.
exportTranslationMemoryToFilepath()rejects with a
TranslationMemoryJobErrorwhoseerroris theArgumentError. Catch
ArgumentErrorinstead ofTypeError. - Breaking:
createMultilingualGlossary(),updateMultilingualGlossary(),
updateMultilingualGlossaryDictionary()and
replaceMultilingualGlossaryDictionary()throw anArgumentErrorfor a
dictionary with an emptysourceLangCodeortargetLangCode;
createSpokenTerms(),updateSpokenTerms()andreplaceSpokenTermsList()
for a term list with an emptylang;getSpokenTermsEntries()and
deleteSpokenTermsList()for an emptylang.createStyleRule()throws an
ArgumentErrorfor a custom instruction with an emptysource_language, and
createStyleRuleCustomInstruction()andupdateStyleRuleCustomInstruction()
for an emptysourceLanguage; these two leave out anullsourceLanguage
instead of sending JSONnull. No request is sent; the API rejected these
values with aDeepLErrorbefore. CatchArgumentErrorwhere you handled
thatDeepLError. translateText(),translateDocument()andtranslateDocumentUpload()
treat anundefinedsourceLanglikenull: the source language is
auto-detected. They threw aDeepLErrorbefore.- Breaking:
DeepLAdminClient.createDeveloperKey()is now also retried
after a timeout or connection reset during the TLS handshake, inside a proxy's
CONNECT tunnel too, before the request is written; a reset after the handshake
is still not retried. It rejected at once with aConnectionErrorwhose
shouldRetrywas [secure] before; now that error comes aftermaxRetries
retries and hasshouldRetrytrue. The other methods that create a resource
behave the same from this release on. Code that retriescreateDeveloperKey()
itself after such an error now sees the library's retries first. - Breaking: the library no longer checks argument types by hand; the
TypeScript types are the contract. Anull,undefinedor non-string key in
theDeepLClientandDeepLAdminClientconstructors, text in
translateText(),rephraseText()andcorrectText(), language code,
glossary name increateGlossary()andcreateGlossaryWithCsv(), or glossary
or spoken term, aDeveloperKeywhosekeyIdis not a string in
deactivateDeveloperKey(),renameDeveloperKey()and
setDeveloperKeyUsageLimits(), and a date that is neither aDatenor a
string ingetUsageAnalytics()andgetCustomTagUsageAnalytics(): in
1.29.0 these threw a plainDeepLError(DeepLClientconstructor, texts,
language codes, glossary names and terms) or anArgumentError
(DeepLAdminClientconstructor, developer key methods, usage analytics
dates). It now throws JavaScript's ownTypeError, or, for a value without
lengthsuch as a number, is sent as given. Empty values and invalid dates still throw
ArgumentError. Code that catchesArgumentErrorfor such values must pass
values of the declared types. - Breaking: a non-2xx answer of the
proxyto the CONNECT request, for
example HTTP 407 (Proxy Authentication Required) or 502, now throws a
ConnectionErrorwithshouldRetry[secure] and nohttpStatusCode, and is
never retried. Before, it was handled as an API response: aDeepLError
subclass for the proxy's status (for exampleNotFoundErrorfor 404) with
that status inhttpStatusCode, retried for 429 and 5xx. Code that checks
httpStatusCode407 for proxy authentication must check for a
ConnectionErrorinstead; its message contains the proxy's status.
Removed
- Breaking:
checkStatusCode()is no longer exported from the package root. It is
internal and has no replacement. - Breaking: The internal response types
MultilingualGlossaryDictionaryEntriesApiResponse,
MultilingualGlossaryDictionaryApiResponse,ListMultilingualGlossaryApiResponse,
StyleRuleInfoApiResponse,ListStyleRuleApiResponse,
TranslationMemoryInfoApiResponse,ListTranslationMemoryApiResponse,
TranslationMemorySegmentsApiResponse,TranslationMemoryImportApiResponse,
TranslationMemoryExportApiResponse,TranslationMemoryJobApiResponseand
LanguageResourceApiResponseare no longer exported. Use the parsed types
the methods return (MultilingualGlossaryInfo,StyleRuleInfo,
TranslationMemoryInfo,TranslationMemoryJob,LanguageResource, ...). - Breaking: the deprecated
GlossaryNotFoundError. Glossary requests that
answer HTTP 404, andgetMultilingualGlossaryDictionaryEntries()when the
dictionary is missing, throwNotFoundError, which it extended. Replace
GlossaryNotFoundErrorwithNotFoundError. - Breaking:
Usage.documentandUsage.teamDocument. The API no longer returns
document usage; remove reads of these fields. A response that still
contains thedocument_*fields parses and the fields are ignored. - Breaking: The
'downloaded'member ofTranslationMemoryJobStatus. The API does not
report it for translation memory jobs; only'completed'counts as done in
done()andwaitUntilTranslationMemoryJobDone(). Compare with
'completed'instead. - Breaking: The
ConfiguredRulestype. UseRecord<string, Record<string, string>>
(orStyleRuleInfo['configuredRules']) instead. - Breaking: The
Translatorclass and theTranslatorOptionstype.DeepLClientno
longer extendsTranslatorand now holds all of its methods with the same
signatures and behaviour. Replacenew deepl.Translator(authKey, options)
withnew deepl.DeepLClient(authKey, options),TranslatorOptionswith
DeepLClientOptions, andinstanceof Translatorchecks orTranslator
type annotations withDeepLClient. - Breaking:
createMultilingualGlossaryWithCsv(),
replaceMultilingualGlossaryDictionaryWithCsv()and
updateMultilingualGlossaryDictionaryWithCsv(): use
createMultilingualGlossaryFromCsv(),
replaceMultilingualGlossaryDictionaryFromCsv()and
updateMultilingualGlossaryDictionaryFromCsv(), which take the same arguments. - Breaking: The object forms of
createStyleRule(styleRule),
createStyleRuleCustomInstruction(styleRule, instruction)and
updateStyleRuleCustomInstruction(styleRule, instructionId, instruction), and
theCreateStyleRuleRequestBodytype: pass the name, language, configured
rules and custom instructions, or the label, prompt and source language, as
separate arguments. - Breaking: The
__pathoption ofTranslateTextOptions:translateText()always sends
its request to/v2/translate. - Breaking: The
'on'and'default'values ofSentenceSplittingMode: use'1'.
Any other string is still sent unchanged, so these values now reach the API
as given.splitSentences: 'on'still compiles but fails at runtime with
HTTP 400 "Value for 'split_sentences' not supported"; write
splitSentences: '1'. - Breaking:
uploadDocument(),getDocumentStatus()anddownloadDocument(): use
translateDocumentUpload(),translateDocumentGetStatus()and
translateDocumentDownload(), which behave the same.
isDocumentTranslationComplete(handle): use
translateDocumentWaitUntilDone(handle), which resolves with the
DocumentStatusinstead of{ handle, status }. - Breaking: Document minification: the
enableDocumentMinificationoption of
DocumentTranslateOptions, andDocumentMinificationErrorand
DocumentDeminificationError. Remove the option; the DeepL API accepts
larger documents, see the usage limits. - Breaking: The
extraRequestParametersoption ofBaseRequestOptionsand every options
type: rename it toextraBodyParameters, which behaves the same. - Breaking:
isTranslationMemoryJobComplete(): usewaitUntilTranslationMemoryJobDone(),
which takes the same arguments. - Breaking: the modules
dist/translator,dist/documentMinifierand
dist/fsHelperno longer exist, so deep imports such as
deepl-node/dist/translatorfail. Import from the package root. - Breaking: The package no longer depends on
adm-zip. Projects that use
adm-zipthemselves add it to their owndependencies. - Breaking: The package no longer depends on
form-data: document uploads use the
FormDataandBlobglobals of Node.js 18 and send the same multipart
fields, filename and content type. No code change is needed.
Projects that useform-datathemselves add it to their owndependencies.
Fixed
translateText(),translateDocument()andtranslateDocumentUpload()
treat anullglossary,glossaryIds,styleRule,styleProfileor
translationMemoryoption as unset, likeundefined: the request is sent
without it. They threw aTypeErrorbefore.- Requests through a
proxythat accepts the connection but does not answer
the CONNECT request, or closes the connection before answering, fail after
the attempt's timeout (minTimeout) with aConnectionError(error.code
ECONNABORTED) and are retried like other timeouts. They never settled
before.