Skip to content

v2.0.0

Latest

Choose a tag to compare

@github-actions github-actions released this 24 Nov 12:09

Upgrading from 1.x: see upgrading_to_v2.md for every breaking change
with before and after code.

Added

  • TranslationMemoryJobError, thrown by importTranslationMemoryFromFilepath()
    and exportTranslationMemoryToFilepath(). It extends DeepLError, holds the
    cause in error, the job ID in jobId once the job was created and the last
    job status the helper fetched in job, and copies
    httpStatusCode and shouldRetry from a DeepLError cause.
  • Cancellation: every DeepLClient and DeepLAdminClient method that sends a
    request accepts signal?: AbortSignal, through its options object or, for
    methods that had none, a new trailing options argument of the new type
    RequestOptions (which BaseRequestOptions, WaitOptions,
    TranslationMemorySegmentsOptions and GetLanguagesForResourceOptions now
    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 of translateDocument(),
    translateDocumentWaitUntilDone(), waitUntilTranslationMemoryJobDone() and
    the translation memory file helpers. The promise rejects with the signal's
    abort reason, unwrapped: not a DeepLError, and translateDocument() does
    not wrap it in a DocumentTranslationError. Code that relies on every
    rejection being a DeepLError must check signal.aborted first 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), as DeepLAdminClient.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's shouldRetry is [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
    ConnectionError whose shouldRetry is true, and is retried like a reset
    connection, except for the creates above. Before, it was never retried and
    shouldRetry was [secure]. Code that retried such errors itself can rely on
    the library's retries.
  • Breaking: Usage.anyLimitReached() is replaced by Usage.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.status is typed DocumentStatusCode | (string & {}) and
    TranslationMemoryJobResult.status TranslationMemoryJobStatus | (string & {}),
    so a status the library does not know yet is visible in the type. Exhaustive
    switch statements over these fields need a default branch.
  • Breaking: DocumentStatus.documentId is a required string. When the status response
    has no document ID, it is the ID of the handle passed to
    translateDocumentGetStatus(). Remove undefined checks.
  • Breaking: TranslationMemoryJob.creationTime, updatedTime, done() and ok() are
    required. The library always set them; a missing timestamp is an invalid
    Date. Code that builds TranslationMemoryJob objects itself must set them,
    and job.done?.() can become job.done().
  • Breaking: translateDocument() and translateDocumentUpload() reject with an
    ArgumentError before any request when the input file path does not exist
    (was a DocumentTranslationError, or the Node error for
    translateDocumentUpload()). An existing input file that cannot be read
    (e.g. EACCES, EISDIR) still rejects with a DocumentTranslationError
    from translateDocument() and the Node error from
    translateDocumentUpload(). translateDocument() rejects with a
    DocumentTranslationError for an existing output file or a missing or
    unwritable output directory (was the Node error); the Node error is in
    error. Catch ArgumentError and DocumentTranslationError instead of
    checking error.code.
  • Breaking: importTranslationMemoryFromFilepath() rejects with an
    ArgumentError for a missing input file (was the Node error ENOENT), and
    with the new TranslationMemoryJobError for every other failure: other read
    failures (was the Node error, e.g. EISDIR), a Buffer or stream without
    fileName or displayName (was ArgumentError) and failures of the job
    creation, upload and wait (were the DeepLError or its subclass).
    exportTranslationMemoryToFilepath() rejects with a
    TranslationMemoryJobError for every failure, including an existing output
    file, a missing or unwritable output directory and local write failures
    (were the Node error). The cause is in error; catch
    TranslationMemoryJobError instead of the DeepLError subclasses and read
    error.error for 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_instructions and the tag lists are sent as JSON
    arrays, booleans and numbers keep their JSON types, and the v3 glossary
    dictionaries are 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 of extraBodyParameters, is
    Record<string, unknown> (was Record<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 as true/[secure],
    numbers via String() 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 as Record<string, string> still compile as extra body
    parameters; only code that reads values from a RequestParameters as strings
    needs a cast or check.
  • Breaking: StyleRuleInfo.configuredRules is the configured_rules map as the API
    returns it (Record<string, Record<string, string>>, snake_case category
    and rule names), the same shape createStyleRule() 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.datesAndTimes with
    configuredRules.dates_and_times and configuredRules.styleAndTone with
    configuredRules.style_and_tone.
  • Breaking: rephraseText() takes a RephraseTextOptions object 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.node is >=18, was >=14.17),
    and the package is compiled to ES2022. Upgrade Node.js to 18 or later before
    upgrading the package.
  • Breaking: @types/node is 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/node to their own
    devDependencies.
  • Breaking: argument checks throw ArgumentError (a DeepLError
    subclass) instead of a plain DeepLError: an empty auth key in the
    DeepLClient constructor; empty texts, empty language codes, glossary
    with glossaryIds, more than 5 glossaryIds, a glossary, style rule, style
    profile or translation memory option without ID, translationMemoryThreshold
    without translationMemory or outside 0 to 100, a document glossary without
    sourceLang and a non-path document input without filename in
    translateText(), translateDocument(), translateDocumentUpload(),
    rephraseText() and correctText(); an empty name or entries in
    createGlossary() and createGlossaryWithCsv(); an empty or control
    character glossary or spoken term; an empty translation memory ID.
    deleteMultilingualGlossary() throws ArgumentError for an empty or missing
    glossary ID (was a plain Error, or a TypeError for null). Code that
    checks error.constructor === DeepLError must also accept ArgumentError.
  • Breaking: the multilingual glossary methods that take a glossary
    (getMultilingualGlossaryDictionaryEntries(),
    deleteMultilingualGlossaryDictionary(),
    replaceMultilingualGlossaryDictionary(),
    replaceMultilingualGlossaryDictionaryFromCsv(),
    updateMultilingualGlossary(), updateMultilingualGlossaryName(),
    updateMultilingualGlossaryDictionary() and
    updateMultilingualGlossaryDictionaryFromCsv()) throw ArgumentError before
    any request for an empty glossary ID or a MultilingualGlossaryInfo without
    one. Before, all but updateMultilingualGlossary() sent a request to
    /v3/glossaries/undefined for a MultilingualGlossaryInfo without ID (HTTP
    400 from the API), and updateMultilingualGlossaryName() sent one to
    /v3/glossaries/ for an empty ID (HTTP 404); the others already threw
    ArgumentError for an empty ID. createMultilingualGlossary() throws
    ArgumentError for an empty dictionary list, and it,
    replaceMultilingualGlossaryDictionary(),
    updateMultilingualGlossaryDictionary() and updateMultilingualGlossary()
    throw ArgumentError for a dictionary without entries. Catch ArgumentError
    where you handled the API's 400 or 404 for these calls.
  • Breaking: translateDocumentGetStatus() and
    translateDocumentWaitUntilDone() throw a DeepLError for HTTP 503 (was
    DocumentNotReadyError). Only translateDocumentDownload() throws
    DocumentNotReadyError. Check httpStatusCode === 503 or shouldRetry
    instead.
  • Breaking: downloadTranslationMemoryExport() throws a plain DeepLError
    with httpStatusCode for an error response from the pre-signed download URL,
    as uploadTranslationMemoryFile() does (was mapped like a DeepL API response:
    AuthorizationError for 403, NotFoundError for 404, QuotaExceededError
    for 456, DocumentNotReadyError for 503). It throws a DeepLError instead
    of an ArgumentError for a job without download URL, as the job state comes
    from the API. Check httpStatusCode instead of the DeepLError subclass.
  • Breaking: DeepLClient and DeepLAdminClient constructors throw an ArgumentError
    when serverUrl is not an absolute http or https URL, 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: DeepLClient and DeepLAdminClient constructors throw an
    ArgumentError when the proxy option is a URL string that is not http or
    https with 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 an http:// or https:// URL, or a ProxyConfig.
  • createTranslationMemoryExport() and exportTranslationMemoryToFilepath()
    send the export request without a Content-Type header, as it has no body
    (was application/x-www-form-urlencoded).
  • Breaking: a null value in extraBodyParameters was sent as the string
    "null" in form-encoded bodies; it is now sent as JSON null by the methods
    that switched to JSON bodies and removes the parameter in the document
    upload. Pass undefined to leave a parameter out.
  • Breaking: CustomInstruction.id is now string instead of
    string | undefined. CustomInstruction is only returned by the API, which
    always sets it; code that builds CustomInstruction objects must set id.
  • Breaking: rephraseText() and correctText() throw an ArgumentError
    for an empty targetLang instead of sending the request without a target
    language; pass null or omit targetLang to keep the language of the input
    text.
  • Breaking: createStyleProfile() and updateStyleProfile() send the
    translationMemoryIds elements as given, like glossaryIds and
    styleRuleIds, instead of throwing a DeepLError before the request for an
    empty ID or a TranslationMemoryInfo without ID; the API now rejects invalid
    IDs, e.g. an empty ID with HTTP 400. A catch of DeepLError still catches
    it; the error now comes from the API, after the request. Pass valid
    translation memory IDs.
  • Breaking: translateText(), translateDocument() and
    translateDocumentUpload() throw an ArgumentError for a null
    glossaryIds element, and getTranslationMemory(),
    listTranslationMemorySegments(), deleteTranslationMemory() and
    createTranslationMemoryExport() for a null translation memory, without
    sending a request. They threw a TypeError before.
    exportTranslationMemoryToFilepath() rejects with a
    TranslationMemoryJobError whose error is the ArgumentError. Catch
    ArgumentError instead of TypeError.
  • Breaking: createMultilingualGlossary(), updateMultilingualGlossary(),
    updateMultilingualGlossaryDictionary() and
    replaceMultilingualGlossaryDictionary() throw an ArgumentError for a
    dictionary with an empty sourceLangCode or targetLangCode;
    createSpokenTerms(), updateSpokenTerms() and replaceSpokenTermsList()
    for a term list with an empty lang; getSpokenTermsEntries() and
    deleteSpokenTermsList() for an empty lang. createStyleRule() throws an
    ArgumentError for a custom instruction with an empty source_language, and
    createStyleRuleCustomInstruction() and updateStyleRuleCustomInstruction()
    for an empty sourceLanguage; these two leave out a null sourceLanguage
    instead of sending JSON null. No request is sent; the API rejected these
    values with a DeepLError before. Catch ArgumentError where you handled
    that DeepLError.
  • translateText(), translateDocument() and translateDocumentUpload()
    treat an undefined sourceLang like null: the source language is
    auto-detected. They threw a DeepLError before.
  • 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 a ConnectionError whose
    shouldRetry was [secure] before; now that error comes after maxRetries
    retries and has shouldRetry true. The other methods that create a resource
    behave the same from this release on. Code that retries createDeveloperKey()
    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. A null, undefined or non-string key in
    the DeepLClient and DeepLAdminClient constructors, text in
    translateText(), rephraseText() and correctText(), language code,
    glossary name in createGlossary() and createGlossaryWithCsv(), or glossary
    or spoken term, a DeveloperKey whose keyId is not a string in
    deactivateDeveloperKey(), renameDeveloperKey() and
    setDeveloperKeyUsageLimits(), and a date that is neither a Date nor a
    string in getUsageAnalytics() and getCustomTagUsageAnalytics(): in
    1.29.0 these threw a plain DeepLError (DeepLClient constructor, texts,
    language codes, glossary names and terms) or an ArgumentError
    (DeepLAdminClient constructor, developer key methods, usage analytics
    dates). It now throws JavaScript's own TypeError, or, for a value without
    length such as a number, is sent as given. Empty values and invalid dates still throw
    ArgumentError. Code that catches ArgumentError for such values must pass
    values of the declared types.
  • Breaking: a non-2xx answer of the proxy to the CONNECT request, for
    example HTTP 407 (Proxy Authentication Required) or 502, now throws a
    ConnectionError with shouldRetry [secure] and no httpStatusCode, and is
    never retried. Before, it was handled as an API response: a DeepLError
    subclass for the proxy's status (for example NotFoundError for 404) with
    that status in httpStatusCode, retried for 429 and 5xx. Code that checks
    httpStatusCode 407 for proxy authentication must check for a
    ConnectionError instead; 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, TranslationMemoryJobApiResponse and
    LanguageResourceApiResponse are 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, and getMultilingualGlossaryDictionaryEntries() when the
    dictionary is missing, throw NotFoundError, which it extended. Replace
    GlossaryNotFoundError with NotFoundError.
  • Breaking: Usage.document and Usage.teamDocument. The API no longer returns
    document usage; remove reads of these fields. A response that still
    contains the document_* fields parses and the fields are ignored.
  • Breaking: The 'downloaded' member of TranslationMemoryJobStatus. The API does not
    report it for translation memory jobs; only 'completed' counts as done in
    done() and waitUntilTranslationMemoryJobDone(). Compare with
    'completed' instead.
  • Breaking: The ConfiguredRules type. Use Record<string, Record<string, string>>
    (or StyleRuleInfo['configuredRules']) instead.
  • Breaking: The Translator class and the TranslatorOptions type. DeepLClient no
    longer extends Translator and now holds all of its methods with the same
    signatures and behaviour. Replace new deepl.Translator(authKey, options)
    with new deepl.DeepLClient(authKey, options), TranslatorOptions with
    DeepLClientOptions, and instanceof Translator checks or Translator
    type annotations with DeepLClient.
  • 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
    the CreateStyleRuleRequestBody type: pass the name, language, configured
    rules and custom instructions, or the label, prompt and source language, as
    separate arguments.
  • Breaking: The __path option of TranslateTextOptions: translateText() always sends
    its request to /v2/translate.
  • Breaking: The 'on' and 'default' values of SentenceSplittingMode: 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() and downloadDocument(): use
    translateDocumentUpload(), translateDocumentGetStatus() and
    translateDocumentDownload(), which behave the same.
    isDocumentTranslationComplete(handle): use
    translateDocumentWaitUntilDone(handle), which resolves with the
    DocumentStatus instead of { handle, status }.
  • Breaking: Document minification: the enableDocumentMinification option of
    DocumentTranslateOptions, and DocumentMinificationError and
    DocumentDeminificationError. Remove the option; the DeepL API accepts
    larger documents, see the usage limits.
  • Breaking: The extraRequestParameters option of BaseRequestOptions and every options
    type: rename it to extraBodyParameters, which behaves the same.
  • Breaking: isTranslationMemoryJobComplete(): use waitUntilTranslationMemoryJobDone(),
    which takes the same arguments.
  • Breaking: the modules dist/translator, dist/documentMinifier and
    dist/fsHelper no longer exist, so deep imports such as
    deepl-node/dist/translator fail. Import from the package root.
  • Breaking: The package no longer depends on adm-zip. Projects that use
    adm-zip themselves add it to their own dependencies.
  • Breaking: The package no longer depends on form-data: document uploads use the
    FormData and Blob globals of Node.js 18 and send the same multipart
    fields, filename and content type. No code change is needed.
    Projects that use form-data themselves add it to their own dependencies.

Fixed

  • translateText(), translateDocument() and translateDocumentUpload()
    treat a null glossary, glossaryIds, styleRule, styleProfile or
    translationMemory option as unset, like undefined: the request is sent
    without it. They threw a TypeError before.
  • Requests through a proxy that accepts the connection but does not answer
    the CONNECT request, or closes the connection before answering, fail after
    the attempt's timeout (minTimeout) with a ConnectionError (error.code
    ECONNABORTED) and are retried like other timeouts. They never settled
    before.