Skip to content

Commit 00b4e35

Browse files
author
SDKAuto
committed
CodeGen from PR 14624 in Azure/azure-rest-api-specs
Merge a8ee67ca0997112125fd2869131e5936e95376db into d78816faeca788910b48ce0cfad89f85396260d6
1 parent 0868703 commit 00b4e35

File tree

9 files changed

+112
-151
lines changed

9 files changed

+112
-151
lines changed

sdk/cognitiveservices/cognitiveservices-textanalytics/LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2019 Microsoft
3+
Copyright (c) 2021 Microsoft
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
Lines changed: 76 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,112 @@
11
## An isomorphic javascript sdk for - TextAnalyticsClient
22

3-
This package contains an isomorphic SDK for TextAnalyticsClient.
3+
This package contains an isomorphic SDK (runs both in node.js and in browsers) for TextAnalyticsClient.
44

55
### Currently supported environments
66

7-
- Node.js version 6.x.x or higher
7+
- Node.js version 8.x.x or higher
88
- Browser JavaScript
99

10-
### How to Install
10+
### Prerequisites
1111

12+
You must have an [Azure subscription](https://azure.microsoft.com/free/).
13+
14+
### How to install
15+
16+
To use this SDK in your project, you will need to install two packages.
17+
- `@azure/cognitiveservices-textanalytics` that contains the client.
18+
- `@azure/identity` that provides different mechanisms for the client to authenticate your requests using Azure Active Directory.
19+
20+
Install both packages using the below command:
1221
```bash
13-
npm install @azure/cognitiveservices-textanalytics
22+
npm install --save @azure/cognitiveservices-textanalytics @azure/identity
1423
```
24+
> **Note**: You may have used either `@azure/ms-rest-nodeauth` or `@azure/ms-rest-browserauth` in the past. These packages are in maintenance mode receiving critical bug fixes, but no new features.
25+
If you are on a [Node.js that has LTS status](https://nodejs.org/about/releases/), or are writing a client side browser application, we strongly encourage you to upgrade to `@azure/identity` which uses the latest versions of Azure Active Directory and MSAL APIs and provides more authentication options.
1526

1627
### How to use
1728

18-
#### nodejs - Authentication, client creation and detectLanguage as an example written in TypeScript.
29+
- If you are writing a client side browser application,
30+
- Follow the instructions in the section on Authenticating client side browser applications in [Azure Identity examples](https://aka.ms/azsdk/js/identity/examples) to register your application in the Microsoft identity platform and set the right permissions.
31+
- Copy the client ID and tenant ID from the Overview section of your app registration in Azure portal and use it in the browser sample below.
32+
- If you are writing a server side application,
33+
- [Select a credential from `@azure/identity` based on the authentication method of your choice](https://aka.ms/azsdk/js/identity/examples)
34+
- Complete the set up steps required by the credential if any.
35+
- Use the credential you picked in the place of `DefaultAzureCredential` in the Node.js sample below.
1936

20-
##### Install @azure/ms-rest-azure-js
21-
22-
```bash
23-
npm install @azure/ms-rest-azure-js
24-
```
37+
In the below samples, we pass the credential and the Azure subscription id to instantiate the client.
38+
Once the client is created, explore the operations on it either in your favorite editor or in our [API reference documentation](https://docs.microsoft.com/javascript/api) to get started.
39+
#### nodejs - Authentication, client creation, and detectLanguage as an example written in JavaScript.
2540

2641
##### Sample code
27-
The following sample detects the langauge in the provided text. In addition, it provides data such as Characters count, transaction count, etc. To know more, refer to the [Azure Documentation on Text Analytics](https://docs.microsoft.com/azure/cognitive-services/text-analytics/overview)
2842

2943
```javascript
44+
const { DefaultAzureCredential } = require("@azure/identity");
3045
const { TextAnalyticsClient } = require("@azure/cognitiveservices-textanalytics");
31-
const { CognitiveServicesCredentials } = require("@azure/ms-rest-azure-js");
32-
33-
async function main() {
34-
const textAnalyticsKey =
35-
process.env["textAnalyticsKey"] || "<textAnalyticsKey>";
36-
const textAnalyticsEndPoint =
37-
process.env["textAnalyticsEndPoint"] || "<textAnalyticsEndPoint>";
38-
const cognitiveServiceCredentials = new CognitiveServicesCredentials(
39-
textAnalyticsKey
40-
);
41-
const client = new TextAnalyticsClient(
42-
cognitiveServiceCredentials,
43-
textAnalyticsEndPoint
44-
);
45-
const options = {
46-
showStats: true,
47-
languageBatchInput: {
48-
documents: [
49-
{
50-
id: "1",
51-
text: "Sample Text"
52-
},
53-
{
54-
id: "2",
55-
text: "Texto de ejemplo"
56-
}
57-
]
58-
}
59-
};
60-
client
61-
.detectLanguage(options)
62-
.then(result => {
63-
console.log("The result is:");
64-
result.documents.forEach(document => {
65-
console.log(`Id: ${document.id}`);
66-
console.log("Detected Languages:");
67-
document.detectedLanguages.forEach(dl => {
68-
console.log(dl.name);
69-
});
70-
console.log(
71-
`Characters Count: ${document.statistics.charactersCount}`
72-
);
73-
console.log(
74-
`Transactions Count: ${document.statistics.transactionsCount}`
75-
);
76-
});
77-
})
78-
.catch(err => {
79-
console.log("An error occurred:");
80-
console.error(err);
81-
});
82-
}
83-
84-
main();
85-
46+
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
47+
48+
// Use `DefaultAzureCredential` or any other credential of your choice based on https://aka.ms/azsdk/js/identity/examples
49+
// Please note that you can also use credentials from the `@azure/ms-rest-nodeauth` package instead.
50+
const creds = new DefaultAzureCredential();
51+
const client = new TextAnalyticsClient(creds, subscriptionId);
52+
const showStats = true;
53+
const languageBatchInput = {
54+
documents: [{
55+
countryHint: "testcountryHint",
56+
id: "testid",
57+
text: "testtext"
58+
}]
59+
};
60+
client.detectLanguage(showStats, languageBatchInput).then((result) => {
61+
console.log("The result is:");
62+
console.log(result);
63+
}).catch((err) => {
64+
console.log("An error occurred:");
65+
console.error(err);
66+
});
8667
```
8768

88-
#### browser - Authentication, client creation and detectLanguage as an example written in JavaScript.
69+
#### browser - Authentication, client creation, and detectLanguage as an example written in JavaScript.
70+
71+
In browser applications, we recommend using the `InteractiveBrowserCredential` that interactively authenticates using the default system browser.
72+
- See [Single-page application: App registration guide](https://docs.microsoft.com/azure/active-directory/develop/scenario-spa-app-registration) to configure your app registration for the browser.
73+
- Note down the client Id from the previous step and use it in the browser sample below.
8974

9075
##### Sample code
9176

9277
- index.html
78+
9379
```html
9480
<!DOCTYPE html>
9581
<html lang="en">
9682
<head>
9783
<title>@azure/cognitiveservices-textanalytics sample</title>
98-
<script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
9984
<script src="node_modules/@azure/cognitiveservices-textanalytics/dist/cognitiveservices-textanalytics.js"></script>
10085
<script type="text/javascript">
101-
const textAnalyticsKey = "<YOUR_TEXT_ANALYTICS_KEY>";
102-
const textAnalyticsEndPoint = "<YOUR_TEXT_ANALYTICS_ENDPOINT>";
103-
const cognitiveServiceCredentials = new msRest.ApiKeyCredentials({
104-
inHeader: {
105-
"Ocp-Apim-Subscription-Key": textAnalyticsKey
106-
}
86+
const subscriptionId = "<Subscription_Id>";
87+
// Create credentials using the `@azure/identity` package.
88+
// Please note that you can also use credentials from the `@azure/ms-rest-browserauth` package instead.
89+
const credential = new InteractiveBrowserCredential(
90+
{
91+
clientId: "<client id for your Azure AD app>",
92+
tenant: "<optional tenant for your organization>"
10793
});
108-
const client = new Azure.CognitiveservicesTextanalytics.TextAnalyticsClient(
109-
cognitiveServiceCredentials,
110-
textAnalyticsEndPoint
111-
);
112-
113-
const options = {
114-
showStats: true,
115-
languageBatchInput: {
116-
documents: [
117-
{
118-
id: "1",
119-
text: "Sample Text"
120-
},
121-
{
122-
id: "2",
123-
text: "Texto de ejemplo"
124-
}
125-
]
126-
}
94+
const client = new Azure.CognitiveservicesTextanalytics.TextAnalyticsClient(creds, subscriptionId);
95+
const showStats = true;
96+
const languageBatchInput = {
97+
documents: [{
98+
countryHint: "testcountryHint",
99+
id: "testid",
100+
text: "testtext"
101+
}]
127102
};
128-
129-
client
130-
.detectLanguage(options)
131-
.then(result => {
132-
console.log("The result is:");
133-
result.documents.forEach(document => {
134-
console.log(`Id: ${document.id}`);
135-
console.log("Detected Languages:");
136-
document.detectedLanguages.forEach(dl => {
137-
console.log(dl.name);
138-
});
139-
console.log(
140-
`Characters Count: ${document.statistics.charactersCount}`
141-
);
142-
console.log(
143-
`Transactions Count: ${document.statistics.transactionsCount}`
144-
);
145-
});
146-
})
147-
.catch(err => {
148-
console.log("An error occurred:");
149-
console.error(err);
150-
});
103+
client.detectLanguage(showStats, languageBatchInput).then((result) => {
104+
console.log("The result is:");
105+
console.log(result);
106+
}).catch((err) => {
107+
console.log("An error occurred:");
108+
console.error(err);
109+
});
151110
</script>
152111
</head>
153112
<body></body>
@@ -158,4 +117,4 @@ main();
158117

159118
- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)
160119

161-
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcognitiveservices%2Fcognitiveservices-textanalytics%2FREADME.png)
120+
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js/sdk/cognitiveservices/cognitiveservices-textanalytics/README.png)

sdk/cognitiveservices/cognitiveservices-textanalytics/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "TextAnalyticsClient Library with typescript type definitions for node.js and browser.",
55
"version": "4.0.0",
66
"dependencies": {
7-
"@azure/ms-rest-js": "^2.0.4",
7+
"@azure/ms-rest-js": "^2.2.0",
8+
"@azure/core-auth": "^1.1.4",
89
"tslib": "^1.10.0"
910
},
1011
"keywords": [
@@ -19,7 +20,7 @@
1920
"module": "./esm/textAnalyticsClient.js",
2021
"types": "./esm/textAnalyticsClient.d.ts",
2122
"devDependencies": {
22-
"typescript": "^3.5.3",
23+
"typescript": "^3.6.0",
2324
"rollup": "^1.18.0",
2425
"rollup-plugin-node-resolve": "^5.2.0",
2526
"rollup-plugin-sourcemaps": "^0.4.2",

sdk/cognitiveservices/cognitiveservices-textanalytics/rollup.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const config = {
2121
"@azure/ms-rest-azure-js": "msRestAzure"
2222
},
2323
banner: `/*
24-
* Copyright (c) Microsoft Corporation. All rights reserved.
25-
* Licensed under the MIT License. See License.txt in the project root for license information.
24+
* Copyright (c) Microsoft Corporation.
25+
* Licensed under the MIT License.
2626
*
2727
* Code generated by Microsoft (R) AutoRest Code Generator.
2828
* Changes may cause incorrect behavior and will be lost if the code is regenerated.

sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/index.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) Microsoft Corporation. All rights reserved.
3-
* Licensed under the MIT License. See License.txt in the project root for license information.
2+
* Copyright (c) Microsoft Corporation.
3+
* Licensed under the MIT License.
44
*
55
* Code generated by Microsoft (R) AutoRest Code Generator.
66
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
@@ -499,12 +499,7 @@ export type KeyPhrasesResponse = KeyPhraseBatchResult & {
499499
/**
500500
* Contains response data for the sentiment operation.
501501
*/
502-
export type SentimentResponse = {
503-
/**
504-
* The parsed response body.
505-
*/
506-
body: any;
507-
502+
export type SentimentResponse = SentimentBatchResult & {
508503
/**
509504
* The underlying HTTP response.
510505
*/
@@ -517,6 +512,6 @@ export type SentimentResponse = {
517512
/**
518513
* The response body as parsed JSON or XML
519514
*/
520-
parsedBody: any;
515+
parsedBody: SentimentBatchResult;
521516
};
522517
};

sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/mappers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) Microsoft Corporation. All rights reserved.
3-
* Licensed under the MIT License. See License.txt in the project root for license information.
2+
* Copyright (c) Microsoft Corporation.
3+
* Licensed under the MIT License.
44
*
55
* Code generated by Microsoft (R) AutoRest Code Generator.
66
* Changes may cause incorrect behavior and will be lost if the code is regenerated.

sdk/cognitiveservices/cognitiveservices-textanalytics/src/models/parameters.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
2-
* Copyright (c) Microsoft Corporation. All rights reserved.
3-
* Licensed under the MIT License. See License.txt in the project root for
4-
* license information.
2+
* Copyright (c) Microsoft Corporation.
3+
* Licensed under the MIT License.
54
*
65
* Code generated by Microsoft (R) AutoRest Code Generator.
76
* Changes may cause incorrect behavior and will be lost if the code is

sdk/cognitiveservices/cognitiveservices-textanalytics/src/textAnalyticsClient.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
2-
* Copyright (c) Microsoft Corporation. All rights reserved.
3-
* Licensed under the MIT License. See License.txt in the project root for
4-
* license information.
2+
* Copyright (c) Microsoft Corporation.
3+
* Licensed under the MIT License.
54
*
65
* Code generated by Microsoft (R) AutoRest Code Generator.
76
* Changes may cause incorrect behavior and will be lost if the code is
@@ -20,9 +19,14 @@ class TextAnalyticsClient extends TextAnalyticsClientContext {
2019
* @param endpoint Supported Cognitive Services endpoints (protocol and hostname, for example:
2120
* https://westus.api.cognitive.microsoft.com).
2221
* @param credentials Subscription credentials which uniquely identify client subscription.
22+
* Credentials implementing the TokenCredential interface from the @azure/identity package are
23+
* recommended. For more information about these credentials, see
24+
* {@link https://www.npmjs.com/package/@azure/identity}. Credentials implementing the
25+
* ServiceClientCredentials interface from the older packages @azure/ms-rest-nodeauth and
26+
* @azure/ms-rest-browserauth are also supported.
2327
* @param [options] The parameter options
2428
*/
25-
constructor(credentials: msRest.ServiceClientCredentials, endpoint: string, options?: msRest.ServiceClientOptions) {
29+
constructor(credentials: msRest.ServiceClientCredentials | TokenCredential, endpoint: string, options?: msRest.ServiceClientOptions) {
2630
super(credentials, endpoint, options);
2731
}
2832

@@ -122,13 +126,13 @@ class TextAnalyticsClient extends TextAnalyticsClientContext {
122126
/**
123127
* @param callback The callback
124128
*/
125-
sentiment(callback: msRest.ServiceCallback<any>): void;
129+
sentiment(callback: msRest.ServiceCallback<Models.SentimentBatchResult>): void;
126130
/**
127131
* @param options The optional parameters
128132
* @param callback The callback
129133
*/
130-
sentiment(options: Models.TextAnalyticsClientSentimentOptionalParams, callback: msRest.ServiceCallback<any>): void;
131-
sentiment(options?: Models.TextAnalyticsClientSentimentOptionalParams | msRest.ServiceCallback<any>, callback?: msRest.ServiceCallback<any>): Promise<Models.SentimentResponse> {
134+
sentiment(options: Models.TextAnalyticsClientSentimentOptionalParams, callback: msRest.ServiceCallback<Models.SentimentBatchResult>): void;
135+
sentiment(options?: Models.TextAnalyticsClientSentimentOptionalParams | msRest.ServiceCallback<Models.SentimentBatchResult>, callback?: msRest.ServiceCallback<Models.SentimentBatchResult>): Promise<Models.SentimentResponse> {
132136
return this.sendOperationRequest(
133137
{
134138
options
@@ -241,10 +245,9 @@ const sentimentOperationSpec: msRest.OperationSpec = {
241245
200: {
242246
bodyMapper: Mappers.SentimentBatchResult
243247
},
244-
500: {
248+
default: {
245249
bodyMapper: Mappers.ErrorResponse
246-
},
247-
default: {}
250+
}
248251
},
249252
serializer
250253
};

0 commit comments

Comments
 (0)