@azure-rest/ai-translation-text
Advanced tools
Comparing version 1.0.0-alpha.20240327.1 to 1.0.0-alpha.20240411.1
@@ -6,2 +6,3 @@ # Release History | ||
### Features Added | ||
- Added support for AAD authentication. | ||
@@ -8,0 +9,0 @@ ### Breaking Changes |
@@ -5,2 +5,4 @@ // Copyright (c) Microsoft Corporation. | ||
const APIM_REGION_HEADER_NAME = "Ocp-Apim-Subscription-Region"; | ||
const APIM_RESOURCE_ID = "Ocp-Apim-ResourceId"; | ||
export const DEFAULT_SCOPE = "https://cognitiveservices.azure.com/.default"; | ||
export class TranslatorAuthenticationPolicy { | ||
@@ -27,2 +29,13 @@ constructor(credential) { | ||
} | ||
export class TranslatorTokenCredentialAuthenticationPolicy { | ||
constructor(credential) { | ||
this.name = "TranslatorTokenCredentialAuthenticationPolicy"; | ||
this.credential = credential; | ||
} | ||
sendRequest(request, next) { | ||
request.headers.set(APIM_REGION_HEADER_NAME, this.credential.region); | ||
request.headers.set(APIM_RESOURCE_ID, this.credential.azureResourceId); | ||
return next(request); | ||
} | ||
} | ||
//# sourceMappingURL=authentication.js.map |
@@ -6,4 +6,3 @@ // Copyright (c) Microsoft Corporation. | ||
import * as coreRestPipeline from "@azure/core-rest-pipeline"; | ||
import { TranslatorAuthenticationPolicy, TranslatorAzureKeyAuthenticationPolicy, } from "./authentication"; | ||
const DEFAULT_SCOPE = "https://cognitiveservices.azure.com/.default"; | ||
import { DEFAULT_SCOPE, TranslatorAuthenticationPolicy, TranslatorAzureKeyAuthenticationPolicy, TranslatorTokenCredentialAuthenticationPolicy, } from "./authentication"; | ||
const DEFAULT_ENPOINT = "https://api.cognitive.microsofttranslator.com"; | ||
@@ -18,2 +17,9 @@ const PLATFORM_HOST = "cognitiveservices"; | ||
} | ||
function isTokenCredential(credential) { | ||
return (credential === null || credential === void 0 ? void 0 : credential.getToken) !== undefined; | ||
} | ||
function isTranslatorTokenCredential(credential) { | ||
return ((credential === null || credential === void 0 ? void 0 : credential.tokenCredential) !== undefined && | ||
(credential === null || credential === void 0 ? void 0 : credential.azureResourceId) !== undefined); | ||
} | ||
/** | ||
@@ -57,3 +63,3 @@ * Initialize a new instance of `TextTranslationClient` | ||
} | ||
else if (credential) { | ||
else if (isTokenCredential(credential)) { | ||
client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({ | ||
@@ -64,4 +70,11 @@ credential: credential, | ||
} | ||
else if (isTranslatorTokenCredential(credential)) { | ||
client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({ | ||
credential: credential.tokenCredential, | ||
scopes: DEFAULT_SCOPE, | ||
})); | ||
client.pipeline.addPolicy(new TranslatorTokenCredentialAuthenticationPolicy(credential)); | ||
} | ||
return client; | ||
} | ||
//# sourceMappingURL=customClient.js.map |
@@ -36,2 +36,4 @@ 'use strict'; | ||
const APIM_REGION_HEADER_NAME = "Ocp-Apim-Subscription-Region"; | ||
const APIM_RESOURCE_ID = "Ocp-Apim-ResourceId"; | ||
const DEFAULT_SCOPE = "https://cognitiveservices.azure.com/.default"; | ||
class TranslatorAuthenticationPolicy { | ||
@@ -58,6 +60,16 @@ constructor(credential) { | ||
} | ||
class TranslatorTokenCredentialAuthenticationPolicy { | ||
constructor(credential) { | ||
this.name = "TranslatorTokenCredentialAuthenticationPolicy"; | ||
this.credential = credential; | ||
} | ||
sendRequest(request, next) { | ||
request.headers.set(APIM_REGION_HEADER_NAME, this.credential.region); | ||
request.headers.set(APIM_RESOURCE_ID, this.credential.azureResourceId); | ||
return next(request); | ||
} | ||
} | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
const DEFAULT_SCOPE = "https://cognitiveservices.azure.com/.default"; | ||
const DEFAULT_ENPOINT = "https://api.cognitive.microsofttranslator.com"; | ||
@@ -72,2 +84,9 @@ const PLATFORM_HOST = "cognitiveservices"; | ||
} | ||
function isTokenCredential(credential) { | ||
return (credential === null || credential === void 0 ? void 0 : credential.getToken) !== undefined; | ||
} | ||
function isTranslatorTokenCredential(credential) { | ||
return ((credential === null || credential === void 0 ? void 0 : credential.tokenCredential) !== undefined && | ||
(credential === null || credential === void 0 ? void 0 : credential.azureResourceId) !== undefined); | ||
} | ||
/** | ||
@@ -111,3 +130,3 @@ * Initialize a new instance of `TextTranslationClient` | ||
} | ||
else if (credential) { | ||
else if (isTokenCredential(credential)) { | ||
client.pipeline.addPolicy(coreRestPipeline__namespace.bearerTokenAuthenticationPolicy({ | ||
@@ -118,2 +137,9 @@ credential: credential, | ||
} | ||
else if (isTranslatorTokenCredential(credential)) { | ||
client.pipeline.addPolicy(coreRestPipeline__namespace.bearerTokenAuthenticationPolicy({ | ||
credential: credential.tokenCredential, | ||
scopes: DEFAULT_SCOPE, | ||
})); | ||
client.pipeline.addPolicy(new TranslatorTokenCredentialAuthenticationPolicy(credential)); | ||
} | ||
return client; | ||
@@ -120,0 +146,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Microsoft Corporation", | ||
"version": "1.0.0-alpha.20240327.1", | ||
"version": "1.0.0-alpha.20240411.1", | ||
"description": "An isomorphic client library for the Azure Cognitive Translator Service", | ||
@@ -8,0 +8,0 @@ "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/translation/ai-translation-text-rest/README.md", |
@@ -71,3 +71,3 @@ import { Client } from '@azure-rest/core-client'; | ||
*/ | ||
declare function createClient(endpoint: undefined | string, credential?: undefined | TranslatorCredential | KeyCredential | TokenCredential, options?: ClientOptions): TextTranslationClient; | ||
declare function createClient(endpoint: undefined | string, credential?: undefined | TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential, options?: ClientOptions): TextTranslationClient; | ||
export default createClient; | ||
@@ -755,2 +755,8 @@ | ||
export declare interface TranslatorTokenCredential { | ||
tokenCredential: TokenCredential; | ||
region: string; | ||
azureResourceId: string; | ||
} | ||
/** Script definition with list of script into which given script can be translitered. */ | ||
@@ -757,0 +763,0 @@ export declare interface TransliterableScriptOutput extends CommonScriptModelOutput { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
152910
1209
1