Skip to content

Commit a436e37

Browse files
hive-botclaude
andcommitted
fix: use extraRequestParameters in RephraseTextOptions
RephraseTextOptions extends BaseRequestOptions, like the other option types, instead of defining its own extraBodyParameters field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0fe0332 commit a436e37

5 files changed

Lines changed: 14 additions & 20 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6161
- Added `translateDocumentWaitUntilDone()`, which polls a document translation
6262
until it is done and resolves with the final `DocumentStatus`, or rejects with
6363
a `DeepLError` if the translation fails.
64-
- Added the `RephraseTextOptions` type with `writingStyle`, `tone` and
65-
`extraBodyParameters`. `rephraseText()` accepts it as its third argument.
66-
`extraBodyParameters` are added to the request body and override parameters
67-
of the same name.
64+
- Added the `RephraseTextOptions` type with `writingStyle` and `tone`. It
65+
extends `BaseRequestOptions`, so it also accepts `extraRequestParameters`,
66+
which are added to the request body and override parameters of the same
67+
name. `rephraseText()` accepts it as its third argument.
6868

6969
### Changed
7070
- `getSourceLanguages()`, `getTargetLanguages()`, and `getGlossaryLanguagePairs()` now call the

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,10 +1129,10 @@ To rephrase text, call `rephraseText()`. The first argument is a string containi
11291129

11301130
The second argument is the target language code. Language codes are **case-insensitive** strings, for example, `'de'`, `'fr'`, `'en'`. The target language code can also be `null` to enable auto-detection of the target language.
11311131

1132-
The third argument is optional and is a `RephraseTextOptions` object with the following properties:
1132+
The third argument is optional and is a `RephraseTextOptions` object (it extends `BaseRequestOptions`) with the following properties:
11331133
- `writingStyle`: the writing style of the rephrased text. Possible values are defined in the `WritingStyle` enum.
11341134
- `tone`: the tone of the rephrased text. Possible values are defined in the `WritingTone` enum. The API accepts either `writingStyle` or `tone` in a request, not both.
1135-
- `extraBodyParameters`: extra parameters to add to the request body. They can override parameters set by the library.
1135+
- `extraRequestParameters`: extra parameters to add to the request body. They can override parameters set by the library.
11361136

11371137
Passing the writing style and tone as the third and fourth arguments, for example `rephraseText(text, 'en', WritingStyle.ACADEMIC)`, is deprecated and will be removed in the next major version.
11381138

‎src/deeplClient.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ export class DeepLClient extends Translator {
193193
tone?: string | null,
194194
): Promise<T extends string ? WriteResult : WriteResult[]> {
195195
let writingStyle: string | null | undefined;
196-
let extraBodyParameters: RequestParameters | undefined;
196+
let extraRequestParameters: RequestParameters | undefined;
197197
if (typeof writingStyleOrOptions === 'object' && writingStyleOrOptions !== null) {
198198
if (tone !== undefined && tone !== null) {
199199
throw new ArgumentError(
200200
'tone cannot be passed as a separate argument together with an options object',
201201
);
202202
}
203-
({ writingStyle, tone, extraBodyParameters } = writingStyleOrOptions);
203+
({ writingStyle, tone, extraRequestParameters } = writingStyleOrOptions);
204204
} else {
205205
writingStyle = writingStyleOrOptions;
206206
}
@@ -219,9 +219,9 @@ export class DeepLClient extends Translator {
219219
}
220220

221221
const singular = appendTextsAndReturnIsSingular(data, texts);
222-
if (extraBodyParameters !== undefined) {
223-
for (const paramName in extraBodyParameters) {
224-
data.set(paramName, extraBodyParameters[paramName]);
222+
if (extraRequestParameters !== undefined) {
223+
for (const paramName in extraRequestParameters) {
224+
data.set(paramName, extraRequestParameters[paramName]);
225225
}
226226
}
227227
const { statusCode, content } = await this.httpClient.sendRequestWithBackoff<string>(

‎src/types.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -790,17 +790,11 @@ export interface TextResult {
790790
/**
791791
* Options that can be specified when rephrasing text with `rephraseText()`.
792792
*/
793-
export interface RephraseTextOptions {
793+
export interface RephraseTextOptions extends BaseRequestOptions {
794794
/** Writing style of the rephrased text, see `WritingStyle`. Cannot be combined with `tone`. */
795795
writingStyle?: string;
796796
/** Tone of the rephrased text, see `WritingTone`. Cannot be combined with `writingStyle`. */
797797
tone?: string;
798-
/**
799-
* Extra parameters to be added to the request body.
800-
* Keys in this object will be added to the request body, and can override built-in parameters.
801-
* This is mostly used by DeepL employees to test functionality, or for beta programs.
802-
*/
803-
extraBodyParameters?: RequestParameters;
804798
}
805799

806800
/**

‎tests/offline/rephraseText.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('DeepLClient.rephraseText', () => {
6464
await makeDeeplClient().rephraseText('abc', 'en', {
6565
writingStyle: WritingStyle.BUSINESS,
6666
tone: WritingTone.CONFIDENT,
67-
extraBodyParameters: { extra: 'x' },
67+
extraRequestParameters: { extra: 'x' },
6868
});
6969
});
7070

@@ -74,7 +74,7 @@ describe('DeepLClient.rephraseText', () => {
7474
.reply(200, rephrased);
7575

7676
await makeDeeplClient().rephraseText('abc', 'en', {
77-
extraBodyParameters: { target_lang: 'fr' },
77+
extraRequestParameters: { target_lang: 'fr' },
7878
});
7979
});
8080

0 commit comments

Comments
 (0)