@azure-rest/ai-translation-text 1.0.2-alpha.20250620.1 → 1.0.2-alpha.20250721.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/authenticationCustomized.js +6 -3
- package/dist/browser/authenticationCustomized.js.map +1 -1
- package/dist/browser/customClient.js +17 -14
- package/dist/browser/customClient.js.map +1 -1
- package/dist/browser/isUnexpected.js +4 -5
- package/dist/browser/isUnexpected.js.map +1 -1
- package/dist/browser/textTranslationClient.js +10 -9
- package/dist/browser/textTranslationClient.js.map +1 -1
- package/dist/commonjs/authenticationCustomized.js +6 -3
- package/dist/commonjs/authenticationCustomized.js.map +1 -1
- package/dist/commonjs/customClient.js +17 -14
- package/dist/commonjs/customClient.js.map +1 -1
- package/dist/commonjs/isUnexpected.js +4 -5
- package/dist/commonjs/isUnexpected.js.map +1 -1
- package/dist/commonjs/textTranslationClient.js +10 -9
- package/dist/commonjs/textTranslationClient.js.map +1 -1
- package/dist/commonjs/tsdoc-metadata.json +11 -11
- package/dist/esm/authenticationCustomized.js +6 -3
- package/dist/esm/authenticationCustomized.js.map +1 -1
- package/dist/esm/customClient.js +17 -14
- package/dist/esm/customClient.js.map +1 -1
- package/dist/esm/isUnexpected.js +4 -5
- package/dist/esm/isUnexpected.js.map +1 -1
- package/dist/esm/textTranslationClient.js +10 -9
- package/dist/esm/textTranslationClient.js.map +1 -1
- package/dist/react-native/authenticationCustomized.js +6 -3
- package/dist/react-native/authenticationCustomized.js.map +1 -1
- package/dist/react-native/customClient.js +17 -14
- package/dist/react-native/customClient.js.map +1 -1
- package/dist/react-native/isUnexpected.js +4 -5
- package/dist/react-native/isUnexpected.js.map +1 -1
- package/dist/react-native/textTranslationClient.js +10 -9
- package/dist/react-native/textTranslationClient.js.map +1 -1
- package/package.json +2 -2
- /package/review/{ai-translation-text.api.md → ai-translation-text-node.api.md} +0 -0
|
@@ -5,8 +5,9 @@ const APIM_REGION_HEADER_NAME = "Ocp-Apim-Subscription-Region";
|
|
|
5
5
|
const APIM_RESOURCE_ID = "Ocp-Apim-ResourceId";
|
|
6
6
|
export const DEFAULT_SCOPE = "https://cognitiveservices.azure.com/.default";
|
|
7
7
|
export class TranslatorAuthenticationPolicy {
|
|
8
|
+
name = "TranslatorAuthenticationPolicy";
|
|
9
|
+
credential;
|
|
8
10
|
constructor(credential) {
|
|
9
|
-
this.name = "TranslatorAuthenticationPolicy";
|
|
10
11
|
this.credential = credential;
|
|
11
12
|
}
|
|
12
13
|
sendRequest(request, next) {
|
|
@@ -16,8 +17,9 @@ export class TranslatorAuthenticationPolicy {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
export class TranslatorAzureKeyAuthenticationPolicy {
|
|
20
|
+
name = "TranslatorAzureKeyAuthenticationPolicy";
|
|
21
|
+
credential;
|
|
19
22
|
constructor(credential) {
|
|
20
|
-
this.name = "TranslatorAzureKeyAuthenticationPolicy";
|
|
21
23
|
this.credential = credential;
|
|
22
24
|
}
|
|
23
25
|
sendRequest(request, next) {
|
|
@@ -26,8 +28,9 @@ export class TranslatorAzureKeyAuthenticationPolicy {
|
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
export class TranslatorTokenCredentialAuthenticationPolicy {
|
|
31
|
+
name = "TranslatorTokenCredentialAuthenticationPolicy";
|
|
32
|
+
credential;
|
|
29
33
|
constructor(credential) {
|
|
30
|
-
this.name = "TranslatorTokenCredentialAuthenticationPolicy";
|
|
31
34
|
this.credential = credential;
|
|
32
35
|
}
|
|
33
36
|
sendRequest(request, next) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticationCustomized.js","sourceRoot":"","sources":["../../src/authenticationCustomized.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;AACzD,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AAC/D,MAAM,gBAAgB,GAAG,qBA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+C,CAAC;IAC/D,UAAU,CAA4B;IAEtC,YAAY,UAAqC;QAC/C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,WAAW,CAAC,OAAwB,EAAE,IAAiB;QACrD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACrE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;QAEvE,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AzureKeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport type {\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\n\nconst APIM_KEY_HEADER_NAME = \"Ocp-Apim-Subscription-Key\";\nconst APIM_REGION_HEADER_NAME = \"Ocp-Apim-Subscription-Region\";\nconst APIM_RESOURCE_ID = \"Ocp-Apim-ResourceId\";\nexport const DEFAULT_SCOPE = \"https://cognitiveservices.azure.com/.default\";\n\nexport interface TranslatorCredential {\n key: string;\n region: string;\n}\n\nexport interface TranslatorTokenCredential {\n tokenCredential: TokenCredential;\n region: string;\n azureResourceId: string;\n}\n\nexport class TranslatorAuthenticationPolicy implements PipelinePolicy {\n name: string = \"TranslatorAuthenticationPolicy\";\n credential: TranslatorCredential;\n\n constructor(credential: TranslatorCredential) {\n this.credential = credential;\n }\n\n sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.headers.set(APIM_KEY_HEADER_NAME, this.credential.key);\n request.headers.set(APIM_REGION_HEADER_NAME, this.credential.region);\n\n return next(request);\n }\n}\n\nexport class TranslatorAzureKeyAuthenticationPolicy implements PipelinePolicy {\n name: string = \"TranslatorAzureKeyAuthenticationPolicy\";\n credential: AzureKeyCredential;\n\n constructor(credential: AzureKeyCredential) {\n this.credential = credential;\n }\n\n sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.headers.set(APIM_KEY_HEADER_NAME, this.credential.key);\n\n return next(request);\n }\n}\n\nexport class TranslatorTokenCredentialAuthenticationPolicy implements PipelinePolicy {\n name: string = \"TranslatorTokenCredentialAuthenticationPolicy\";\n credential: TranslatorTokenCredential;\n\n constructor(credential: TranslatorTokenCredential) {\n this.credential = credential;\n }\n\n sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.headers.set(APIM_REGION_HEADER_NAME, this.credential.region);\n request.headers.set(APIM_RESOURCE_ID, this.credential.azureResourceId);\n\n return next(request);\n }\n}\n"]}
|
|
@@ -8,17 +8,17 @@ const DEFAULT_ENPOINT = "https://api.cognitive.microsofttranslator.com";
|
|
|
8
8
|
const PLATFORM_HOST = "cognitiveservices";
|
|
9
9
|
const PLATFORM_PATH = "/translator/text/v3.0";
|
|
10
10
|
function isKeyCredential(credential) {
|
|
11
|
-
return
|
|
11
|
+
return credential?.key !== undefined;
|
|
12
12
|
}
|
|
13
13
|
function isTranslatorKeyCredential(credential) {
|
|
14
|
-
return
|
|
14
|
+
return credential?.key !== undefined;
|
|
15
15
|
}
|
|
16
16
|
function isTokenCredential(credential) {
|
|
17
|
-
return
|
|
17
|
+
return credential?.getToken !== undefined;
|
|
18
18
|
}
|
|
19
19
|
function isTranslatorTokenCredential(credential) {
|
|
20
|
-
return (
|
|
21
|
-
|
|
20
|
+
return (credential?.tokenCredential !== undefined &&
|
|
21
|
+
credential?.azureResourceId !== undefined);
|
|
22
22
|
}
|
|
23
23
|
function isCredentials(credential) {
|
|
24
24
|
return (isKeyCredential(credential) ||
|
|
@@ -28,7 +28,6 @@ function isCredentials(credential) {
|
|
|
28
28
|
}
|
|
29
29
|
// Implementation
|
|
30
30
|
export default function createClient(arg1, arg2, arg3) {
|
|
31
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
32
31
|
let serviceEndpoint;
|
|
33
32
|
let endpoint;
|
|
34
33
|
let options;
|
|
@@ -47,7 +46,7 @@ export default function createClient(arg1, arg2, arg3) {
|
|
|
47
46
|
if (!options) {
|
|
48
47
|
options = {};
|
|
49
48
|
}
|
|
50
|
-
options.apiVersion =
|
|
49
|
+
options.apiVersion = options.apiVersion ?? "3.0";
|
|
51
50
|
if (!endpoint) {
|
|
52
51
|
serviceEndpoint = DEFAULT_ENPOINT;
|
|
53
52
|
}
|
|
@@ -57,16 +56,20 @@ export default function createClient(arg1, arg2, arg3) {
|
|
|
57
56
|
else {
|
|
58
57
|
serviceEndpoint = endpoint;
|
|
59
58
|
}
|
|
60
|
-
const baseUrl =
|
|
59
|
+
const baseUrl = options.baseUrl ?? `${serviceEndpoint}`;
|
|
61
60
|
const userAgentInfo = `azsdk-js-ai-translation-text-rest/1.0.2`;
|
|
62
61
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
63
62
|
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
64
63
|
: `${userAgentInfo}`;
|
|
65
|
-
options =
|
|
64
|
+
options = {
|
|
65
|
+
...options,
|
|
66
|
+
userAgentOptions: {
|
|
66
67
|
userAgentPrefix,
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
},
|
|
69
|
+
loggingOptions: {
|
|
70
|
+
logger: options.loggingOptions?.logger ?? logger.info,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
70
73
|
const client = getClient(baseUrl, options);
|
|
71
74
|
if (isTranslatorKeyCredential(credential)) {
|
|
72
75
|
const mtAuthneticationPolicy = new TranslatorAuthenticationPolicy(credential);
|
|
@@ -79,13 +82,13 @@ export default function createClient(arg1, arg2, arg3) {
|
|
|
79
82
|
else if (isTokenCredential(credential)) {
|
|
80
83
|
client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
81
84
|
credential: credential,
|
|
82
|
-
scopes:
|
|
85
|
+
scopes: options?.credentials?.scopes ?? DEFAULT_SCOPE,
|
|
83
86
|
}));
|
|
84
87
|
}
|
|
85
88
|
else if (isTranslatorTokenCredential(credential)) {
|
|
86
89
|
client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
87
90
|
credential: credential.tokenCredential,
|
|
88
|
-
scopes:
|
|
91
|
+
scopes: options?.credentials?.scopes ?? DEFAULT_SCOPE,
|
|
89
92
|
}));
|
|
90
93
|
client.pipeline.addPolicy(new TranslatorTokenCredentialAuthenticationPolicy(credential));
|
|
91
94
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customClient.js","sourceRoot":"","sources":["../../src/customClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,gBAAgB,MAAM,2BAA2B,CAAC;AAM9D,OAAO,EACL,aAAa,EACb,8BAA8B,EAC9B,sCAAsC,EACtC,6CAA6C,GAC9C,MAAM,+BAA+B,CAAC;AAGvC,MAAM,eAAe,GAAG,+CAA+C,CAAC;AACxE,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAC1C,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAE9C,SAAS,eAAe,CAAC,UAAe;IACtC,OAAO,CAAC,UAA4B,aAA5B,UAAU,uBAAV,UAAU,CAAoB,GAAG,MAAK,SAAS,CAAC;AAC1D,CAAC;AAED,SAAS,yBAAyB,CAAC,UAAe;IAChD,OAAO,CAAC,UAAmC,aAAnC,UAAU,uBAAV,UAAU,CAA2B,GAAG,MAAK,SAAS,CAAC;AACjE,CAAC;AAED,SAAS,iBAAiB,CAAC,UAAe;IACxC,OAAO,CAAC,UAA8B,aAA9B,UAAU,uBAAV,UAAU,CAAsB,QAAQ,MAAK,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,SAAS,CACvB,gBAAgB,CAAC,+BAA+B,CAAC;YAC/C,UAAU,EAAE,UAA6B;YACzC,MAAM,EAAE,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,0CAAE,MAAM,mCAAI,aAAa;SACtD,CAAC,CACH,CAAC;IACJ,CAAC;SAAM,IAAI,2BAA2B,CAAC,UAAU,CAAC,EAAE,CAAC;QACnD,MAAM,CAAC,QAAQ,CAAC,SAAS,CACvB,gBAAgB,CAAC,+BAA+B,CAAC;YAC/C,UAAU,EAAG,UAAwC,CAAC,eAAe;YACrE,MAAM,EAAE,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,0CAAE,MAAM,mCAAI,aAAa;SACtD,CAAC,CACH,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,SAAS,CACvB,IAAI,6CAA6C,CAAC,UAAuC,CAAC,CAC3F,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ClientOptions } from \"@azure-rest/core-client\";\nimport { getClient } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger.js\";\nimport * as coreRestPipeline from \"@azure/core-rest-pipeline\";\nimport type { TextTranslationClient } from \"./clientDefinitions.js\";\nimport type {\n TranslatorCredential,\n TranslatorTokenCredential,\n} from \"./authenticationCustomized.js\";\nimport {\n DEFAULT_SCOPE,\n TranslatorAuthenticationPolicy,\n TranslatorAzureKeyAuthenticationPolicy,\n TranslatorTokenCredentialAuthenticationPolicy,\n} from \"./authenticationCustomized.js\";\nimport type { AzureKeyCredential, KeyCredential, TokenCredential } from \"@azure/core-auth\";\n\nconst DEFAULT_ENPOINT = \"https://api.cognitive.microsofttranslator.com\";\nconst PLATFORM_HOST = \"cognitiveservices\";\nconst PLATFORM_PATH = \"/translator/text/v3.0\";\n\nfunction isKeyCredential(credential: any): credential is KeyCredential {\n return (credential as KeyCredential)?.key !== undefined;\n}\n\nfunction isTranslatorKeyCredential(credential: any): credential is TranslatorCredential {\n return (credential as TranslatorCredential)?.key !== undefined;\n}\n\nfunction isTokenCredential(credential: any): credential is TokenCredential {\n return (credential as TokenCredential)?.getToken !== undefined;\n}\n\nfunction isTranslatorTokenCredential(credential: any): credential is TranslatorTokenCredential {\n return (\n (credential as TranslatorTokenCredential)?.tokenCredential !== undefined &&\n (credential as TranslatorTokenCredential)?.azureResourceId !== undefined\n );\n}\n\nfunction isCredentials(credential: any): boolean {\n return (\n isKeyCredential(credential) ||\n isTranslatorKeyCredential(credential) ||\n isTokenCredential(credential) ||\n isTranslatorTokenCredential(credential)\n );\n}\n\n/**\n * Initialize a new instance of `TextTranslationClient`\n * @param credential - type: TranslatorCredential | TranslatorTokenCredential | KeyCredential |TokenCredential, credentials\n * used to authenticate the service with.\n * @param options - type: ClientOptions, the parameter for all optional parameters\n */\nexport default function createClient(\n credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential,\n options?: ClientOptions,\n): TextTranslationClient;\n\n/**\n * Initialize a new instance of `TextTranslationClient`\n * @param endpoint - type: string, Supported Text Translation endpoints (protocol and hostname, for example:\n * https://api.cognitive.microsofttranslator.com).\n * @param options - type: ClientOptions, the parameter for all optional parameters\n */\nexport default function createClient(\n endpoint: string,\n options?: ClientOptions,\n): TextTranslationClient;\n\n/**\n * Initialize a new instance of `TextTranslationClient`\n * @param endpoint - type: string, Supported Text Translation endpoints (protocol and hostname, for example:\n * https://api.cognitive.microsofttranslator.com).\n * @param credential - type: TranslatorCredential | TranslatorTokenCredential | KeyCredential |TokenCredential, credentials\n * used to authenticate the service with.\n * @param options - type: ClientOptions, the parameter for all optional parameters\n */\nexport default function createClient(\n endpoint: string,\n credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential,\n options?: ClientOptions,\n): TextTranslationClient;\n\n// Implementation\nexport default function createClient(\n arg1?:\n | string\n | (TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential),\n arg2?:\n | (TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential)\n | ClientOptions,\n arg3?: ClientOptions,\n): TextTranslationClient {\n let serviceEndpoint: string;\n\n let endpoint: string | undefined;\n let options: ClientOptions | undefined;\n let credential:\n | TranslatorCredential\n | TranslatorTokenCredential\n | KeyCredential\n | TokenCredential\n | undefined;\n\n if (typeof arg1 === \"string\") {\n endpoint = arg1;\n }\n\n if (typeof arg1 !== \"string\" && isCredentials(arg1)) {\n credential = arg1;\n options = arg2 as ClientOptions;\n } else if (isCredentials(arg2)) {\n credential = arg2 as\n | TranslatorCredential\n | TranslatorTokenCredential\n | KeyCredential\n | TokenCredential;\n options = arg3;\n }\n\n if (!options) {\n options = {};\n }\n\n options.apiVersion = options.apiVersion ?? \"3.0\";\n\n if (!endpoint) {\n serviceEndpoint = DEFAULT_ENPOINT;\n } else if (endpoint.toLowerCase().indexOf(PLATFORM_HOST) !== -1) {\n serviceEndpoint = `${endpoint}${PLATFORM_PATH}`;\n } else {\n serviceEndpoint = endpoint;\n }\n\n const baseUrl = options.baseUrl ?? `${serviceEndpoint}`;\n\n const userAgentInfo = `azsdk-js-ai-translation-text-rest/1.0.2`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n };\n\n const client = getClient(baseUrl, options) as TextTranslationClient;\n\n if (isTranslatorKeyCredential(credential)) {\n const mtAuthneticationPolicy = new TranslatorAuthenticationPolicy(\n credential as TranslatorCredential,\n );\n client.pipeline.addPolicy(mtAuthneticationPolicy);\n } else if (isKeyCredential(credential)) {\n const mtKeyAuthenticationPolicy = new TranslatorAzureKeyAuthenticationPolicy(\n credential as AzureKeyCredential,\n );\n client.pipeline.addPolicy(mtKeyAuthenticationPolicy);\n } else if (isTokenCredential(credential)) {\n client.pipeline.addPolicy(\n coreRestPipeline.bearerTokenAuthenticationPolicy({\n credential: credential as TokenCredential,\n scopes: options?.credentials?.scopes ?? DEFAULT_SCOPE,\n }),\n );\n } else if (isTranslatorTokenCredential(credential)) {\n client.pipeline.addPolicy(\n coreRestPipeline.bearerTokenAuthenticationPolicy({\n credential: (credential as TranslatorTokenCredential).tokenCredential,\n scopes: options?.credentials?.scopes ?? DEFAULT_SCOPE,\n }),\n );\n client.pipeline.addPolicy(\n new TranslatorTokenCredentialAuthenticationPolicy(credential as TranslatorTokenCredential),\n );\n }\n\n return client;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"customClient.js","sourceRoot":"","sources":["../../src/customClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,KAAK,gBAAgB,MAAM,2BAA2B,CAAC;AAM9D,OAAO,EACL,aAAa,EACb,8BAA8B,EAC9B,sCAAsC,EACtC,6CAA6C,GAC9C,MAAM,+BAA+B,CAAC;AAGvC,MAAM,eAAe,GAAG,+CAA+C,CAAC;AACxE,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAC1C,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAE9C,SAAS,eAAe,CAAC,UAAe;IACtC,OAAQ,UAA4B,EAAE,GAAG,KAAK,SAAS,CAAC;AAC1D,CAAC;AAED,SAAS,yBAAyB,CAAC,UAAe;IAChD,OAAQ,UAAmC,EAAE,GAAG,KAAK,SAAS,CAAC;AACjE,CAAC;AAED,SAAS,iBAAiB,CAAC,UAAe;IACxC,OAAQ,UAA8B,EAAE,QAAQ,KAAK,SAAS,CAAC;AACjE,CAAC;AAED,SAAS,2BAA2B,CAAC,UAAe;IAClD,OAAO,CACJ,UAAwC,EAAE,eA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,2BAA2B,CAAC,UAAU,CAAC,EAAE,CAAC;QACnD,MAAM,CAAC,QAAQ,CAAC,SAAS,CACvB,gBAAgB,CAAC,+BAA+B,CAAC;YAC/C,UAAU,EAAG,UAAwC,CAAC,eAAe;YACrE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,aAAa;SACtD,CAAC,CACH,CAAC;QACF,MAAM,CAAC,QAAQ,CAAC,SAAS,CACvB,IAAI,6CAA6C,CAAC,UAAuC,CAAC,CAC3F,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ClientOptions } from \"@azure-rest/core-client\";\nimport { getClient } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger.js\";\nimport * as coreRestPipeline from \"@azure/core-rest-pipeline\";\nimport type { TextTranslationClient } from \"./clientDefinitions.js\";\nimport type {\n TranslatorCredential,\n TranslatorTokenCredential,\n} from \"./authenticationCustomized.js\";\nimport {\n DEFAULT_SCOPE,\n TranslatorAuthenticationPolicy,\n TranslatorAzureKeyAuthenticationPolicy,\n TranslatorTokenCredentialAuthenticationPolicy,\n} from \"./authenticationCustomized.js\";\nimport type { AzureKeyCredential, KeyCredential, TokenCredential } from \"@azure/core-auth\";\n\nconst DEFAULT_ENPOINT = \"https://api.cognitive.microsofttranslator.com\";\nconst PLATFORM_HOST = \"cognitiveservices\";\nconst PLATFORM_PATH = \"/translator/text/v3.0\";\n\nfunction isKeyCredential(credential: any): credential is KeyCredential {\n return (credential as KeyCredential)?.key !== undefined;\n}\n\nfunction isTranslatorKeyCredential(credential: any): credential is TranslatorCredential {\n return (credential as TranslatorCredential)?.key !== undefined;\n}\n\nfunction isTokenCredential(credential: any): credential is TokenCredential {\n return (credential as TokenCredential)?.getToken !== undefined;\n}\n\nfunction isTranslatorTokenCredential(credential: any): credential is TranslatorTokenCredential {\n return (\n (credential as TranslatorTokenCredential)?.tokenCredential !== undefined &&\n (credential as TranslatorTokenCredential)?.azureResourceId !== undefined\n );\n}\n\nfunction isCredentials(credential: any): boolean {\n return (\n isKeyCredential(credential) ||\n isTranslatorKeyCredential(credential) ||\n isTokenCredential(credential) ||\n isTranslatorTokenCredential(credential)\n );\n}\n\n/**\n * Initialize a new instance of `TextTranslationClient`\n * @param credential - type: TranslatorCredential | TranslatorTokenCredential | KeyCredential |TokenCredential, credentials\n * used to authenticate the service with.\n * @param options - type: ClientOptions, the parameter for all optional parameters\n */\nexport default function createClient(\n credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential,\n options?: ClientOptions,\n): TextTranslationClient;\n\n/**\n * Initialize a new instance of `TextTranslationClient`\n * @param endpoint - type: string, Supported Text Translation endpoints (protocol and hostname, for example:\n * https://api.cognitive.microsofttranslator.com).\n * @param options - type: ClientOptions, the parameter for all optional parameters\n */\nexport default function createClient(\n endpoint: string,\n options?: ClientOptions,\n): TextTranslationClient;\n\n/**\n * Initialize a new instance of `TextTranslationClient`\n * @param endpoint - type: string, Supported Text Translation endpoints (protocol and hostname, for example:\n * https://api.cognitive.microsofttranslator.com).\n * @param credential - type: TranslatorCredential | TranslatorTokenCredential | KeyCredential |TokenCredential, credentials\n * used to authenticate the service with.\n * @param options - type: ClientOptions, the parameter for all optional parameters\n */\nexport default function createClient(\n endpoint: string,\n credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential,\n options?: ClientOptions,\n): TextTranslationClient;\n\n// Implementation\nexport default function createClient(\n arg1?:\n | string\n | (TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential),\n arg2?:\n | (TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential)\n | ClientOptions,\n arg3?: ClientOptions,\n): TextTranslationClient {\n let serviceEndpoint: string;\n\n let endpoint: string | undefined;\n let options: ClientOptions | undefined;\n let credential:\n | TranslatorCredential\n | TranslatorTokenCredential\n | KeyCredential\n | TokenCredential\n | undefined;\n\n if (typeof arg1 === \"string\") {\n endpoint = arg1;\n }\n\n if (typeof arg1 !== \"string\" && isCredentials(arg1)) {\n credential = arg1;\n options = arg2 as ClientOptions;\n } else if (isCredentials(arg2)) {\n credential = arg2 as\n | TranslatorCredential\n | TranslatorTokenCredential\n | KeyCredential\n | TokenCredential;\n options = arg3;\n }\n\n if (!options) {\n options = {};\n }\n\n options.apiVersion = options.apiVersion ?? \"3.0\";\n\n if (!endpoint) {\n serviceEndpoint = DEFAULT_ENPOINT;\n } else if (endpoint.toLowerCase().indexOf(PLATFORM_HOST) !== -1) {\n serviceEndpoint = `${endpoint}${PLATFORM_PATH}`;\n } else {\n serviceEndpoint = endpoint;\n }\n\n const baseUrl = options.baseUrl ?? `${serviceEndpoint}`;\n\n const userAgentInfo = `azsdk-js-ai-translation-text-rest/1.0.2`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n };\n\n const client = getClient(baseUrl, options) as TextTranslationClient;\n\n if (isTranslatorKeyCredential(credential)) {\n const mtAuthneticationPolicy = new TranslatorAuthenticationPolicy(\n credential as TranslatorCredential,\n );\n client.pipeline.addPolicy(mtAuthneticationPolicy);\n } else if (isKeyCredential(credential)) {\n const mtKeyAuthenticationPolicy = new TranslatorAzureKeyAuthenticationPolicy(\n credential as AzureKeyCredential,\n );\n client.pipeline.addPolicy(mtKeyAuthenticationPolicy);\n } else if (isTokenCredential(credential)) {\n client.pipeline.addPolicy(\n coreRestPipeline.bearerTokenAuthenticationPolicy({\n credential: credential as TokenCredential,\n scopes: options?.credentials?.scopes ?? DEFAULT_SCOPE,\n }),\n );\n } else if (isTranslatorTokenCredential(credential)) {\n client.pipeline.addPolicy(\n coreRestPipeline.bearerTokenAuthenticationPolicy({\n credential: (credential as TranslatorTokenCredential).tokenCredential,\n scopes: options?.credentials?.scopes ?? DEFAULT_SCOPE,\n }),\n );\n client.pipeline.addPolicy(\n new TranslatorTokenCredentialAuthenticationPolicy(credential as TranslatorTokenCredential),\n );\n }\n\n return client;\n}\n"]}
|
|
@@ -10,7 +10,7 @@ const responseMap = {
|
|
|
10
10
|
};
|
|
11
11
|
export function isUnexpected(response) {
|
|
12
12
|
const lroOriginal = response.headers["x-ms-original-url"];
|
|
13
|
-
const url = new URL(lroOriginal
|
|
13
|
+
const url = new URL(lroOriginal ?? response.request.url);
|
|
14
14
|
const method = response.request.method;
|
|
15
15
|
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
16
16
|
if (!pathDetails) {
|
|
@@ -19,7 +19,6 @@ export function isUnexpected(response) {
|
|
|
19
19
|
return !pathDetails.includes(response.status);
|
|
20
20
|
}
|
|
21
21
|
function getParametrizedPathSuccess(method, path) {
|
|
22
|
-
var _a, _b, _c, _d;
|
|
23
22
|
const pathParts = path.split("/");
|
|
24
23
|
// Traverse list to match the longest candidate
|
|
25
24
|
// matchedLen: the length of candidate path
|
|
@@ -38,13 +37,13 @@ function getParametrizedPathSuccess(method, path) {
|
|
|
38
37
|
// track if we have found a match to return the values found.
|
|
39
38
|
let found = true;
|
|
40
39
|
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
|
41
|
-
if (
|
|
42
|
-
const start = candidateParts[i].indexOf("}") + 1, end =
|
|
40
|
+
if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) {
|
|
41
|
+
const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]?.length;
|
|
43
42
|
// If the current part of the candidate is a "template" part
|
|
44
43
|
// Try to use the suffix of pattern to match the path
|
|
45
44
|
// {guid} ==> $
|
|
46
45
|
// {guid}:export ==> :export$
|
|
47
|
-
const isMatched = new RegExp(`${
|
|
46
|
+
const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(pathParts[j] || "");
|
|
48
47
|
if (!isMatched) {
|
|
49
48
|
found = false;
|
|
50
49
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,MAAM,WAAW,GAA6B;IAC5C,gBAAgB,EAAE,CAAC,KAAK,CAAC;IACzB,iBAAiB,EAAE,CAAC,KAAK,CAAC;IAC1B,qBAAqB,EAAE,CAAC,KAAK,CAAC;IAC9B,qBAAqB,EAAE,CAAC,KAAK,CAAC;IAC9B,yBAAyB,EAAE,CAAC,KAAK,CAAC;IAClC,2BAA2B,EAAE,CAAC,KAAK,CAAC;CACrC,CAAC;AAoBF,MAAM,UAAU,YAAY,CAC1B,QAY2C;IAQ3C,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,
|
|
1
|
+
{"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC,MAAM,WAAW,GAA6B;IAC5C,gBAAgB,EAAE,CAAC,KAAK,CAAC;IACzB,iBAAiB,EAAE,CAAC,KAAK,CAAC;IAC1B,qBAAqB,EAAE,CAAC,KAAK,CAAC;IAC9B,qBAAqB,EAAE,CAAC,KAAK,CAAC;IAC9B,yBAAyB,EAAE,CAAC,KAAK,CAAC;IAClC,2BAA2B,EAAE,CAAC,KAAK,CAAC;CACrC,CAAC;AAoBF,MAAM,UAAU,YAAY,CAC1B,QAY2C;IAQ3C,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,WAAW,IAAI,QAAQ,CAAC,OAAO,CAAC,G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,SAAS,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n GetSupportedLanguages200Response,\n GetSupportedLanguagesDefaultResponse,\n Translate200Response,\n TranslateDefaultResponse,\n Transliterate200Response,\n TransliterateDefaultResponse,\n FindSentenceBoundaries200Response,\n FindSentenceBoundariesDefaultResponse,\n LookupDictionaryEntries200Response,\n LookupDictionaryEntriesDefaultResponse,\n LookupDictionaryExamples200Response,\n LookupDictionaryExamplesDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /languages\": [\"200\"],\n \"POST /translate\": [\"200\"],\n \"POST /transliterate\": [\"200\"],\n \"POST /breaksentence\": [\"200\"],\n \"POST /dictionary/lookup\": [\"200\"],\n \"POST /dictionary/examples\": [\"200\"],\n};\n\nexport function isUnexpected(\n response: GetSupportedLanguages200Response | GetSupportedLanguagesDefaultResponse,\n): response is GetSupportedLanguagesDefaultResponse;\nexport function isUnexpected(\n response: Translate200Response | TranslateDefaultResponse,\n): response is TranslateDefaultResponse;\nexport function isUnexpected(\n response: Transliterate200Response | TransliterateDefaultResponse,\n): response is TransliterateDefaultResponse;\nexport function isUnexpected(\n response: FindSentenceBoundaries200Response | FindSentenceBoundariesDefaultResponse,\n): response is FindSentenceBoundariesDefaultResponse;\nexport function isUnexpected(\n response: LookupDictionaryEntries200Response | LookupDictionaryEntriesDefaultResponse,\n): response is LookupDictionaryEntriesDefaultResponse;\nexport function isUnexpected(\n response: LookupDictionaryExamples200Response | LookupDictionaryExamplesDefaultResponse,\n): response is LookupDictionaryExamplesDefaultResponse;\nexport function isUnexpected(\n response:\n | GetSupportedLanguages200Response\n | GetSupportedLanguagesDefaultResponse\n | Translate200Response\n | TranslateDefaultResponse\n | Transliterate200Response\n | TransliterateDefaultResponse\n | FindSentenceBoundaries200Response\n | FindSentenceBoundariesDefaultResponse\n | LookupDictionaryEntries200Response\n | LookupDictionaryEntriesDefaultResponse\n | LookupDictionaryExamples200Response\n | LookupDictionaryExamplesDefaultResponse,\n): response is\n | GetSupportedLanguagesDefaultResponse\n | TranslateDefaultResponse\n | TransliterateDefaultResponse\n | FindSentenceBoundariesDefaultResponse\n | LookupDictionaryEntriesDefaultResponse\n | LookupDictionaryExamplesDefaultResponse {\n const lroOriginal = response.headers[\"x-ms-original-url\"];\n const url = new URL(lroOriginal ?? response.request.url);\n const method = response.request.method;\n let pathDetails = responseMap[`${method} ${url.pathname}`];\n if (!pathDetails) {\n pathDetails = getParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction getParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Traverse list to match the longest candidate\n // matchedLen: the length of candidate path\n // matchedValue: the matched status code array\n let matchedLen = -1,\n matchedValue: string[] = [];\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(responseMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // track if we have found a match to return the values found.\n let found = true;\n for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {\n if (candidateParts[i]?.startsWith(\"{\") && candidateParts[i]?.indexOf(\"}\") !== -1) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(\n pathParts[j] || \"\",\n );\n\n if (!isMatched) {\n found = false;\n break;\n }\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
|
-
import { __rest } from "tslib";
|
|
4
3
|
import { getClient } from "@azure-rest/core-client";
|
|
5
4
|
import { logger } from "./logger.js";
|
|
6
5
|
/**
|
|
@@ -9,19 +8,21 @@ import { logger } from "./logger.js";
|
|
|
9
8
|
* https://api.cognitive.microsofttranslator.com).
|
|
10
9
|
* @param options - the parameter for all optional parameters
|
|
11
10
|
*/
|
|
12
|
-
export default function createClient(endpointParam,
|
|
13
|
-
|
|
14
|
-
var { apiVersion = "3.0" } = _a, options = __rest(_a, ["apiVersion"]);
|
|
15
|
-
const endpointUrl = (_c = (_b = options.endpoint) !== null && _b !== void 0 ? _b : options.baseUrl) !== null && _c !== void 0 ? _c : `${endpointParam}`;
|
|
11
|
+
export default function createClient(endpointParam, { apiVersion = "3.0", ...options } = {}) {
|
|
12
|
+
const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`;
|
|
16
13
|
const userAgentInfo = `azsdk-js-ai-translation-text-rest/1.0.0-beta.1`;
|
|
17
14
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
18
15
|
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
19
16
|
: `${userAgentInfo}`;
|
|
20
|
-
options =
|
|
17
|
+
options = {
|
|
18
|
+
...options,
|
|
19
|
+
userAgentOptions: {
|
|
21
20
|
userAgentPrefix,
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
},
|
|
22
|
+
loggingOptions: {
|
|
23
|
+
logger: options.loggingOptions?.logger ?? logger.info,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
25
26
|
const client = getClient(endpointUrl, options);
|
|
26
27
|
client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
|
|
27
28
|
client.pipeline.addPolicy({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textTranslationClient.js","sourceRoot":"","sources":["../../src/textTranslationClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC
|
|
1
|
+
{"version":3,"file":"textTranslationClient.js","sourceRoot":"","sources":["../../src/textTranslationClient.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AASrC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,aAAqB,EACrB,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,OAAO,KAAmC,EAAE;IAErE,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,OAAO,IAAI,GAAG,aAAa,EAAE,CAAC;IAC9E,MAAM,aAAa,GAAG,gDAAgD,CAAC;IACvE,MAAM,eAAe,GACnB,OAAO,CAAC,gBAAgB,IAAI,OAAO,CAAC,gBAAgB,CAAC,eAAe;QAClE,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,eAAe,IAAI,aAAa,EAAE;QAChE,CAAC,CAAC,GAAG,aAAa,EAAE,CAAC;IACzB,OAAO,GAAG;QACR,GAAG,OAAO;QACV,gBAAgB,EAAE;YAChB,eAAe;SAChB;QACD,cAAc,EAAE;YACd,MAAM,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,IAAI,MAAM,CAAC,IAAI;SACtD;KACF,CAAC;IACF,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,EAAE,OAAO,CAA0B,CAAC;IAExE,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAC3D,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;QACxB,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YACzB,qDAAqD;YACrD,yEAAyE;YACzE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,UAAU,EAAE,CAAC;gBACvD,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,GAClB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GACzD,eAAe,UAAU,EAAE,CAAC;YAC9B,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ClientOptions } from \"@azure-rest/core-client\";\nimport { getClient } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger.js\";\nimport type { TextTranslationClient } from \"./clientDefinitions.js\";\n\n/** The optional parameters for the client */\nexport interface TextTranslationClientOptions extends ClientOptions {\n /** The api version option of the client */\n apiVersion?: string;\n}\n\n/**\n * Initialize a new instance of `TextTranslationClient`\n * @param endpointParam - Supported Text Translation endpoints (protocol and hostname, for example:\n * https://api.cognitive.microsofttranslator.com).\n * @param options - the parameter for all optional parameters\n */\nexport default function createClient(\n endpointParam: string,\n { apiVersion = \"3.0\", ...options }: TextTranslationClientOptions = {},\n): TextTranslationClient {\n const endpointUrl = options.endpoint ?? options.baseUrl ?? `${endpointParam}`;\n const userAgentInfo = `azsdk-js-ai-translation-text-rest/1.0.0-beta.1`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n };\n const client = getClient(endpointUrl, options) as TextTranslationClient;\n\n client.pipeline.removePolicy({ name: \"ApiVersionPolicy\" });\n client.pipeline.addPolicy({\n name: \"ClientApiVersionPolicy\",\n sendRequest: (req, next) => {\n // Use the apiVersion defined in request url directly\n // Append one if there is no apiVersion and we have one at client options\n const url = new URL(req.url);\n if (!url.searchParams.get(\"api-version\") && apiVersion) {\n req.url = `${req.url}${\n Array.from(url.searchParams.keys()).length > 0 ? \"&\" : \"?\"\n }api-version=${apiVersion}`;\n }\n\n return next(req);\n },\n });\n\n return client;\n}\n"]}
|
|
@@ -8,8 +8,9 @@ const APIM_REGION_HEADER_NAME = "Ocp-Apim-Subscription-Region";
|
|
|
8
8
|
const APIM_RESOURCE_ID = "Ocp-Apim-ResourceId";
|
|
9
9
|
exports.DEFAULT_SCOPE = "https://cognitiveservices.azure.com/.default";
|
|
10
10
|
class TranslatorAuthenticationPolicy {
|
|
11
|
+
name = "TranslatorAuthenticationPolicy";
|
|
12
|
+
credential;
|
|
11
13
|
constructor(credential) {
|
|
12
|
-
this.name = "TranslatorAuthenticationPolicy";
|
|
13
14
|
this.credential = credential;
|
|
14
15
|
}
|
|
15
16
|
sendRequest(request, next) {
|
|
@@ -20,8 +21,9 @@ class TranslatorAuthenticationPolicy {
|
|
|
20
21
|
}
|
|
21
22
|
exports.TranslatorAuthenticationPolicy = TranslatorAuthenticationPolicy;
|
|
22
23
|
class TranslatorAzureKeyAuthenticationPolicy {
|
|
24
|
+
name = "TranslatorAzureKeyAuthenticationPolicy";
|
|
25
|
+
credential;
|
|
23
26
|
constructor(credential) {
|
|
24
|
-
this.name = "TranslatorAzureKeyAuthenticationPolicy";
|
|
25
27
|
this.credential = credential;
|
|
26
28
|
}
|
|
27
29
|
sendRequest(request, next) {
|
|
@@ -31,8 +33,9 @@ class TranslatorAzureKeyAuthenticationPolicy {
|
|
|
31
33
|
}
|
|
32
34
|
exports.TranslatorAzureKeyAuthenticationPolicy = TranslatorAzureKeyAuthenticationPolicy;
|
|
33
35
|
class TranslatorTokenCredentialAuthenticationPolicy {
|
|
36
|
+
name = "TranslatorTokenCredentialAuthenticationPolicy";
|
|
37
|
+
credential;
|
|
34
38
|
constructor(credential) {
|
|
35
|
-
this.name = "TranslatorTokenCredentialAuthenticationPolicy";
|
|
36
39
|
this.credential = credential;
|
|
37
40
|
}
|
|
38
41
|
sendRequest(request, next) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticationCustomized.js","sourceRoot":"","sources":["../../src/authenticationCustomized.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAUlC,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;AACzD,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AAC/D,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAClC,QAAA,aAAa,GAAG,8CAA8C,CAAC;AAa5E,MAAa,8BAA8B;
|
|
1
|
+
{"version":3,"file":"authenticationCustomized.js","sourceRoot":"","sources":["../../src/authenticationCustomized.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAUlC,MAAM,oBAAoB,GAAG,2BAA2B,CAAC;AACzD,MAAM,uBAAuB,GAAG,8BAA8B,CAAC;AAC/D,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAClC,QAAA,aAAa,GAAG,8CAA8C,CAAC;AAa5E,MAAa,8BAA8B;IACzC,IAAI,GAAW,gCAAgC,CAAC;IAChD,UAAU,CAAuB;IAEjC,YAAY,UAAgC;QAC1C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,WAAW,CAAC,OAAwB,EAAE,IAAiB;QACrD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC/D,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAErE,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;CACF;AAdD,wEAcC;AAED,MAAa,sCAAsC;IACjD,IAAI,GAAW,wCAAwC,CAAC;IACxD,UAAU,CAAqB;IAE/B,YAAY,UAA8B;QACxC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,WAAW,CAAC,OAAwB,EAAE,IAAiB;QACrD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAE/D,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;CACF;AAbD,wFAaC;AAED,MAAa,6CAA6C;IACxD,IAAI,GAAW,+CAA+C,CAAC;IAC/D,UAAU,CAA4B;IAEtC,YAAY,UAAqC;QAC/C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,WAAW,CAAC,OAAwB,EAAE,IAAiB;QACrD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACrE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;QAEvE,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;CACF;AAdD,sGAcC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AzureKeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport type {\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\n\nconst APIM_KEY_HEADER_NAME = \"Ocp-Apim-Subscription-Key\";\nconst APIM_REGION_HEADER_NAME = \"Ocp-Apim-Subscription-Region\";\nconst APIM_RESOURCE_ID = \"Ocp-Apim-ResourceId\";\nexport const DEFAULT_SCOPE = \"https://cognitiveservices.azure.com/.default\";\n\nexport interface TranslatorCredential {\n key: string;\n region: string;\n}\n\nexport interface TranslatorTokenCredential {\n tokenCredential: TokenCredential;\n region: string;\n azureResourceId: string;\n}\n\nexport class TranslatorAuthenticationPolicy implements PipelinePolicy {\n name: string = \"TranslatorAuthenticationPolicy\";\n credential: TranslatorCredential;\n\n constructor(credential: TranslatorCredential) {\n this.credential = credential;\n }\n\n sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.headers.set(APIM_KEY_HEADER_NAME, this.credential.key);\n request.headers.set(APIM_REGION_HEADER_NAME, this.credential.region);\n\n return next(request);\n }\n}\n\nexport class TranslatorAzureKeyAuthenticationPolicy implements PipelinePolicy {\n name: string = \"TranslatorAzureKeyAuthenticationPolicy\";\n credential: AzureKeyCredential;\n\n constructor(credential: AzureKeyCredential) {\n this.credential = credential;\n }\n\n sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.headers.set(APIM_KEY_HEADER_NAME, this.credential.key);\n\n return next(request);\n }\n}\n\nexport class TranslatorTokenCredentialAuthenticationPolicy implements PipelinePolicy {\n name: string = \"TranslatorTokenCredentialAuthenticationPolicy\";\n credential: TranslatorTokenCredential;\n\n constructor(credential: TranslatorTokenCredential) {\n this.credential = credential;\n }\n\n sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.headers.set(APIM_REGION_HEADER_NAME, this.credential.region);\n request.headers.set(APIM_RESOURCE_ID, this.credential.azureResourceId);\n\n return next(request);\n }\n}\n"]}
|
|
@@ -12,17 +12,17 @@ const DEFAULT_ENPOINT = "https://api.cognitive.microsofttranslator.com";
|
|
|
12
12
|
const PLATFORM_HOST = "cognitiveservices";
|
|
13
13
|
const PLATFORM_PATH = "/translator/text/v3.0";
|
|
14
14
|
function isKeyCredential(credential) {
|
|
15
|
-
return
|
|
15
|
+
return credential?.key !== undefined;
|
|
16
16
|
}
|
|
17
17
|
function isTranslatorKeyCredential(credential) {
|
|
18
|
-
return
|
|
18
|
+
return credential?.key !== undefined;
|
|
19
19
|
}
|
|
20
20
|
function isTokenCredential(credential) {
|
|
21
|
-
return
|
|
21
|
+
return credential?.getToken !== undefined;
|
|
22
22
|
}
|
|
23
23
|
function isTranslatorTokenCredential(credential) {
|
|
24
|
-
return (
|
|
25
|
-
|
|
24
|
+
return (credential?.tokenCredential !== undefined &&
|
|
25
|
+
credential?.azureResourceId !== undefined);
|
|
26
26
|
}
|
|
27
27
|
function isCredentials(credential) {
|
|
28
28
|
return (isKeyCredential(credential) ||
|
|
@@ -32,7 +32,6 @@ function isCredentials(credential) {
|
|
|
32
32
|
}
|
|
33
33
|
// Implementation
|
|
34
34
|
function createClient(arg1, arg2, arg3) {
|
|
35
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
36
35
|
let serviceEndpoint;
|
|
37
36
|
let endpoint;
|
|
38
37
|
let options;
|
|
@@ -51,7 +50,7 @@ function createClient(arg1, arg2, arg3) {
|
|
|
51
50
|
if (!options) {
|
|
52
51
|
options = {};
|
|
53
52
|
}
|
|
54
|
-
options.apiVersion =
|
|
53
|
+
options.apiVersion = options.apiVersion ?? "3.0";
|
|
55
54
|
if (!endpoint) {
|
|
56
55
|
serviceEndpoint = DEFAULT_ENPOINT;
|
|
57
56
|
}
|
|
@@ -61,16 +60,20 @@ function createClient(arg1, arg2, arg3) {
|
|
|
61
60
|
else {
|
|
62
61
|
serviceEndpoint = endpoint;
|
|
63
62
|
}
|
|
64
|
-
const baseUrl =
|
|
63
|
+
const baseUrl = options.baseUrl ?? `${serviceEndpoint}`;
|
|
65
64
|
const userAgentInfo = `azsdk-js-ai-translation-text-rest/1.0.2`;
|
|
66
65
|
const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
|
|
67
66
|
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
|
|
68
67
|
: `${userAgentInfo}`;
|
|
69
|
-
options =
|
|
68
|
+
options = {
|
|
69
|
+
...options,
|
|
70
|
+
userAgentOptions: {
|
|
70
71
|
userAgentPrefix,
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
},
|
|
73
|
+
loggingOptions: {
|
|
74
|
+
logger: options.loggingOptions?.logger ?? logger_js_1.logger.info,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
74
77
|
const client = (0, core_client_1.getClient)(baseUrl, options);
|
|
75
78
|
if (isTranslatorKeyCredential(credential)) {
|
|
76
79
|
const mtAuthneticationPolicy = new authenticationCustomized_js_1.TranslatorAuthenticationPolicy(credential);
|
|
@@ -83,13 +86,13 @@ function createClient(arg1, arg2, arg3) {
|
|
|
83
86
|
else if (isTokenCredential(credential)) {
|
|
84
87
|
client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
85
88
|
credential: credential,
|
|
86
|
-
scopes:
|
|
89
|
+
scopes: options?.credentials?.scopes ?? authenticationCustomized_js_1.DEFAULT_SCOPE,
|
|
87
90
|
}));
|
|
88
91
|
}
|
|
89
92
|
else if (isTranslatorTokenCredential(credential)) {
|
|
90
93
|
client.pipeline.addPolicy(coreRestPipeline.bearerTokenAuthenticationPolicy({
|
|
91
94
|
credential: credential.tokenCredential,
|
|
92
|
-
scopes:
|
|
95
|
+
scopes: options?.credentials?.scopes ?? authenticationCustomized_js_1.DEFAULT_SCOPE,
|
|
93
96
|
}));
|
|
94
97
|
client.pipeline.addPolicy(new authenticationCustomized_js_1.TranslatorTokenCredentialAuthenticationPolicy(credential));
|
|
95
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customClient.js","sourceRoot":"","sources":["../../src/customClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAwFlC,+BAmGC;;AAxLD,yDAAoD;AACpD,2CAAqC;AACrC,oFAA8D;AAM9D,+EAKuC;AAGvC,MAAM,eAAe,GAAG,+CAA+C,CAAC;AACxE,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAC1C,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAE9C,SAAS,eAAe,CAAC,UAAe;IACtC,
|
|
1
|
+
{"version":3,"file":"customClient.js","sourceRoot":"","sources":["../../src/customClient.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAwFlC,+BAmGC;;AAxLD,yDAAoD;AACpD,2CAAqC;AACrC,oFAA8D;AAM9D,+EAKuC;AAGvC,MAAM,eAAe,GAAG,+CAA+C,CAAC;AACxE,MAAM,aAAa,GAAG,mBAAmB,CAAC;AAC1C,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAE9C,SAAS,eAAe,CAAC,UAAe;IACtC,OAAQ,UAA4B,EAAE,GAAG,KAAK,SAAS,CAAC;AAC1D,CAAC;AAED,SAAS,yBAAyB,CAAC,UAAe;IAChD,OAAQ,UAAmC,EAAE,GAAG,KAAK,SAAS,CAAC;AACjE,CAAC;AAED,SAAS,iBAAiB,CAAC,UAAe;IACxC,OAAQ,UAA8B,EAAE,QAAQ,KAAK,SAAS,CAAC;AACjE,CAAC;AAED,SAAS,2BAA2B,CAAC,UAAe;IAClD,OAAO,CACJ,UAAwC,EAAE,eAAe,KAAK,SAAS;QACvE,UAAwC,EAAE,eAAe,KAAK,SAAS,CACzE,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,UAAe;IACpC,OAAO,CACL,eAAe,CAAC,UAAU,CAAC;QAC3B,yBAAyB,CAAC,UAAU,CAAC;QACrC,iBAAiB,CAAC,UAAU,CAAC;QAC7B,2BAA2B,CAAC,UAAU,CAAC,CACxC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CAAC,SAAS,CACvB,IAAI,2EAA6C,CAAC,UAAuC,CAAC,CAC3F,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ClientOptions } from \"@azure-rest/core-client\";\nimport { getClient } from \"@azure-rest/core-client\";\nimport { logger } from \"./logger.js\";\nimport * as coreRestPipeline from \"@azure/core-rest-pipeline\";\nimport type { TextTranslationClient } from \"./clientDefinitions.js\";\nimport type {\n TranslatorCredential,\n TranslatorTokenCredential,\n} from \"./authenticationCustomized.js\";\nimport {\n DEFAULT_SCOPE,\n TranslatorAuthenticationPolicy,\n TranslatorAzureKeyAuthenticationPolicy,\n TranslatorTokenCredentialAuthenticationPolicy,\n} from \"./authenticationCustomized.js\";\nimport type { AzureKeyCredential, KeyCredential, TokenCredential } from \"@azure/core-auth\";\n\nconst DEFAULT_ENPOINT = \"https://api.cognitive.microsofttranslator.com\";\nconst PLATFORM_HOST = \"cognitiveservices\";\nconst PLATFORM_PATH = \"/translator/text/v3.0\";\n\nfunction isKeyCredential(credential: any): credential is KeyCredential {\n return (credential as KeyCredential)?.key !== undefined;\n}\n\nfunction isTranslatorKeyCredential(credential: any): credential is TranslatorCredential {\n return (credential as TranslatorCredential)?.key !== undefined;\n}\n\nfunction isTokenCredential(credential: any): credential is TokenCredential {\n return (credential as TokenCredential)?.getToken !== undefined;\n}\n\nfunction isTranslatorTokenCredential(credential: any): credential is TranslatorTokenCredential {\n return (\n (credential as TranslatorTokenCredential)?.tokenCredential !== undefined &&\n (credential as TranslatorTokenCredential)?.azureResourceId !== undefined\n );\n}\n\nfunction isCredentials(credential: any): boolean {\n return (\n isKeyCredential(credential) ||\n isTranslatorKeyCredential(credential) ||\n isTokenCredential(credential) ||\n isTranslatorTokenCredential(credential)\n );\n}\n\n/**\n * Initialize a new instance of `TextTranslationClient`\n * @param credential - type: TranslatorCredential | TranslatorTokenCredential | KeyCredential |TokenCredential, credentials\n * used to authenticate the service with.\n * @param options - type: ClientOptions, the parameter for all optional parameters\n */\nexport default function createClient(\n credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential,\n options?: ClientOptions,\n): TextTranslationClient;\n\n/**\n * Initialize a new instance of `TextTranslationClient`\n * @param endpoint - type: string, Supported Text Translation endpoints (protocol and hostname, for example:\n * https://api.cognitive.microsofttranslator.com).\n * @param options - type: ClientOptions, the parameter for all optional parameters\n */\nexport default function createClient(\n endpoint: string,\n options?: ClientOptions,\n): TextTranslationClient;\n\n/**\n * Initialize a new instance of `TextTranslationClient`\n * @param endpoint - type: string, Supported Text Translation endpoints (protocol and hostname, for example:\n * https://api.cognitive.microsofttranslator.com).\n * @param credential - type: TranslatorCredential | TranslatorTokenCredential | KeyCredential |TokenCredential, credentials\n * used to authenticate the service with.\n * @param options - type: ClientOptions, the parameter for all optional parameters\n */\nexport default function createClient(\n endpoint: string,\n credential: TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential,\n options?: ClientOptions,\n): TextTranslationClient;\n\n// Implementation\nexport default function createClient(\n arg1?:\n | string\n | (TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential),\n arg2?:\n | (TranslatorCredential | TranslatorTokenCredential | KeyCredential | TokenCredential)\n | ClientOptions,\n arg3?: ClientOptions,\n): TextTranslationClient {\n let serviceEndpoint: string;\n\n let endpoint: string | undefined;\n let options: ClientOptions | undefined;\n let credential:\n | TranslatorCredential\n | TranslatorTokenCredential\n | KeyCredential\n | TokenCredential\n | undefined;\n\n if (typeof arg1 === \"string\") {\n endpoint = arg1;\n }\n\n if (typeof arg1 !== \"string\" && isCredentials(arg1)) {\n credential = arg1;\n options = arg2 as ClientOptions;\n } else if (isCredentials(arg2)) {\n credential = arg2 as\n | TranslatorCredential\n | TranslatorTokenCredential\n | KeyCredential\n | TokenCredential;\n options = arg3;\n }\n\n if (!options) {\n options = {};\n }\n\n options.apiVersion = options.apiVersion ?? \"3.0\";\n\n if (!endpoint) {\n serviceEndpoint = DEFAULT_ENPOINT;\n } else if (endpoint.toLowerCase().indexOf(PLATFORM_HOST) !== -1) {\n serviceEndpoint = `${endpoint}${PLATFORM_PATH}`;\n } else {\n serviceEndpoint = endpoint;\n }\n\n const baseUrl = options.baseUrl ?? `${serviceEndpoint}`;\n\n const userAgentInfo = `azsdk-js-ai-translation-text-rest/1.0.2`;\n const userAgentPrefix =\n options.userAgentOptions && options.userAgentOptions.userAgentPrefix\n ? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`\n : `${userAgentInfo}`;\n options = {\n ...options,\n userAgentOptions: {\n userAgentPrefix,\n },\n loggingOptions: {\n logger: options.loggingOptions?.logger ?? logger.info,\n },\n };\n\n const client = getClient(baseUrl, options) as TextTranslationClient;\n\n if (isTranslatorKeyCredential(credential)) {\n const mtAuthneticationPolicy = new TranslatorAuthenticationPolicy(\n credential as TranslatorCredential,\n );\n client.pipeline.addPolicy(mtAuthneticationPolicy);\n } else if (isKeyCredential(credential)) {\n const mtKeyAuthenticationPolicy = new TranslatorAzureKeyAuthenticationPolicy(\n credential as AzureKeyCredential,\n );\n client.pipeline.addPolicy(mtKeyAuthenticationPolicy);\n } else if (isTokenCredential(credential)) {\n client.pipeline.addPolicy(\n coreRestPipeline.bearerTokenAuthenticationPolicy({\n credential: credential as TokenCredential,\n scopes: options?.credentials?.scopes ?? DEFAULT_SCOPE,\n }),\n );\n } else if (isTranslatorTokenCredential(credential)) {\n client.pipeline.addPolicy(\n coreRestPipeline.bearerTokenAuthenticationPolicy({\n credential: (credential as TranslatorTokenCredential).tokenCredential,\n scopes: options?.credentials?.scopes ?? DEFAULT_SCOPE,\n }),\n );\n client.pipeline.addPolicy(\n new TranslatorTokenCredentialAuthenticationPolicy(credential as TranslatorTokenCredential),\n );\n }\n\n return client;\n}\n"]}
|
|
@@ -13,7 +13,7 @@ const responseMap = {
|
|
|
13
13
|
};
|
|
14
14
|
function isUnexpected(response) {
|
|
15
15
|
const lroOriginal = response.headers["x-ms-original-url"];
|
|
16
|
-
const url = new URL(lroOriginal
|
|
16
|
+
const url = new URL(lroOriginal ?? response.request.url);
|
|
17
17
|
const method = response.request.method;
|
|
18
18
|
let pathDetails = responseMap[`${method} ${url.pathname}`];
|
|
19
19
|
if (!pathDetails) {
|
|
@@ -22,7 +22,6 @@ function isUnexpected(response) {
|
|
|
22
22
|
return !pathDetails.includes(response.status);
|
|
23
23
|
}
|
|
24
24
|
function getParametrizedPathSuccess(method, path) {
|
|
25
|
-
var _a, _b, _c, _d;
|
|
26
25
|
const pathParts = path.split("/");
|
|
27
26
|
// Traverse list to match the longest candidate
|
|
28
27
|
// matchedLen: the length of candidate path
|
|
@@ -41,13 +40,13 @@ function getParametrizedPathSuccess(method, path) {
|
|
|
41
40
|
// track if we have found a match to return the values found.
|
|
42
41
|
let found = true;
|
|
43
42
|
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
|
|
44
|
-
if (
|
|
45
|
-
const start = candidateParts[i].indexOf("}") + 1, end =
|
|
43
|
+
if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) {
|
|
44
|
+
const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]?.length;
|
|
46
45
|
// If the current part of the candidate is a "template" part
|
|
47
46
|
// Try to use the suffix of pattern to match the path
|
|
48
47
|
// {guid} ==> $
|
|
49
48
|
// {guid}:export ==> :export$
|
|
50
|
-
const isMatched = new RegExp(`${
|
|
49
|
+
const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(pathParts[j] || "");
|
|
51
50
|
if (!isMatched) {
|
|
52
51
|
found = false;
|
|
53
52
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isUnexpected.js","sourceRoot":"","sources":["../../src/isUnexpected.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AA4ClC,oCA6BC;AAxDD,MAAM,WAAW,GAA6B;I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,CAAC,GAAG,CAAC,EAC/C,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;gBAClC,4DAA4D;gBAC5D,qDAAqD;gBACrD,eAAe;gBACf,6BAA6B;gBAC7B,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAC1E,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,CACnB,CAAC;gBAEF,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,KAAK,GAAG,KAAK,CAAC;oBACd,MAAM;gBACR,CAAC;gBACD,SAAS;YACX,CAAC;YAED,8CAA8C;YAC9C,wDAAwD;YACxD,2CAA2C;YAC3C,IAAI,cAAc,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvC,KAAK,GAAG,KAAK,CAAC;gBACd,MAAM;YACR,CAAC;QACH,CAAC;QAED,qDAAqD;QACrD,sEAAsE;QACtE,IAAI,KAAK,IAAI,aAAa,CAAC,MAAM,GAAG,UAAU,EAAE,CAAC;YAC/C,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC;YAClC,YAAY,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAc;IACvC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n GetSupportedLanguages200Response,\n GetSupportedLanguagesDefaultResponse,\n Translate200Response,\n TranslateDefaultResponse,\n Transliterate200Response,\n TransliterateDefaultResponse,\n FindSentenceBoundaries200Response,\n FindSentenceBoundariesDefaultResponse,\n LookupDictionaryEntries200Response,\n LookupDictionaryEntriesDefaultResponse,\n LookupDictionaryExamples200Response,\n LookupDictionaryExamplesDefaultResponse,\n} from \"./responses.js\";\n\nconst responseMap: Record<string, string[]> = {\n \"GET /languages\": [\"200\"],\n \"POST /translate\": [\"200\"],\n \"POST /transliterate\": [\"200\"],\n \"POST /breaksentence\": [\"200\"],\n \"POST /dictionary/lookup\": [\"200\"],\n \"POST /dictionary/examples\": [\"200\"],\n};\n\nexport function isUnexpected(\n response: GetSupportedLanguages200Response | GetSupportedLanguagesDefaultResponse,\n): response is GetSupportedLanguagesDefaultResponse;\nexport function isUnexpected(\n response: Translate200Response | TranslateDefaultResponse,\n): response is TranslateDefaultResponse;\nexport function isUnexpected(\n response: Transliterate200Response | TransliterateDefaultResponse,\n): response is TransliterateDefaultResponse;\nexport function isUnexpected(\n response: FindSentenceBoundaries200Response | FindSentenceBoundariesDefaultResponse,\n): response is FindSentenceBoundariesDefaultResponse;\nexport function isUnexpected(\n response: LookupDictionaryEntries200Response | LookupDictionaryEntriesDefaultResponse,\n): response is LookupDictionaryEntriesDefaultResponse;\nexport function isUnexpected(\n response: LookupDictionaryExamples200Response | LookupDictionaryExamplesDefaultResponse,\n): response is LookupDictionaryExamplesDefaultResponse;\nexport function isUnexpected(\n response:\n | GetSupportedLanguages200Response\n | GetSupportedLanguagesDefaultResponse\n | Translate200Response\n | TranslateDefaultResponse\n | Transliterate200Response\n | TransliterateDefaultResponse\n | FindSentenceBoundaries200Response\n | FindSentenceBoundariesDefaultResponse\n | LookupDictionaryEntries200Response\n | LookupDictionaryEntriesDefaultResponse\n | LookupDictionaryExamples200Response\n | LookupDictionaryExamplesDefaultResponse,\n): response is\n | GetSupportedLanguagesDefaultResponse\n | TranslateDefaultResponse\n | TransliterateDefaultResponse\n | FindSentenceBoundariesDefaultResponse\n | LookupDictionaryEntriesDefaultResponse\n | LookupDictionaryExamplesDefaultResponse {\n const lroOriginal = response.headers[\"x-ms-original-url\"];\n const url = new URL(lroOriginal ?? response.request.url);\n const method = response.request.method;\n let pathDetails = responseMap[`${method} ${url.pathname}`];\n if (!pathDetails) {\n pathDetails = getParametrizedPathSuccess(method, url.pathname);\n }\n return !pathDetails.includes(response.status);\n}\n\nfunction getParametrizedPathSuccess(method: string, path: string): string[] {\n const pathParts = path.split(\"/\");\n\n // Traverse list to match the longest candidate\n // matchedLen: the length of candidate path\n // matchedValue: the matched status code array\n let matchedLen = -1,\n matchedValue: string[] = [];\n\n // Iterate the responseMap to find a match\n for (const [key, value] of Object.entries(responseMap)) {\n // Extracting the path from the map key which is in format\n // GET /path/foo\n if (!key.startsWith(method)) {\n continue;\n }\n const candidatePath = getPathFromMapKey(key);\n // Get each part of the url path\n const candidateParts = candidatePath.split(\"/\");\n\n // track if we have found a match to return the values found.\n let found = true;\n for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {\n if (candidateParts[i]?.startsWith(\"{\") && candidateParts[i]?.indexOf(\"}\") !== -1) {\n const start = candidateParts[i]!.indexOf(\"}\") + 1,\n end = candidateParts[i]?.length;\n // If the current part of the candidate is a \"template\" part\n // Try to use the suffix of pattern to match the path\n // {guid} ==> $\n // {guid}:export ==> :export$\n const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(\n pathParts[j] || \"\",\n );\n\n if (!isMatched) {\n found = false;\n break;\n }\n continue;\n }\n\n // If the candidate part is not a template and\n // the parts don't match mark the candidate as not found\n // to move on with the next candidate path.\n if (candidateParts[i] !== pathParts[j]) {\n found = false;\n break;\n }\n }\n\n // We finished evaluating the current candidate parts\n // Update the matched value if and only if we found the longer pattern\n if (found && candidatePath.length > matchedLen) {\n matchedLen = candidatePath.length;\n matchedValue = value;\n }\n }\n\n return matchedValue;\n}\n\nfunction getPathFromMapKey(mapKey: string): string {\n const pathStart = mapKey.indexOf(\"/\");\n return mapKey.slice(pathStart);\n}\n"]}
|