Skip to content

Commit de423d6

Browse files
authored
[advisor] Update @azure/arm-advisor to use snippets (#32415)
### Packages impacted by this PR - @azure/arm-advisor ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Adds snippets for the README which are type checked. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
1 parent e81ed7e commit de423d6

File tree

3 files changed

+50
-18
lines changed

3 files changed

+50
-18
lines changed

sdk/advisor/arm-advisor/README.md

+20-12
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,27 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica
4848

4949
For more information about how to create an Azure AD Application check out [this guide](https://learn.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal).
5050

51-
```javascript
52-
const { AdvisorManagementClient } = require("@azure/arm-advisor");
53-
const { DefaultAzureCredential } = require("@azure/identity");
54-
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.
51+
Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client.
52+
53+
```ts snippet:AdvisorManagementClientAuth_Node
54+
import { AdvisorManagementClient } from "@azure/arm-advisor";
55+
import { DefaultAzureCredential } from "@azure/identity";
5556

5657
const subscriptionId = "00000000-0000-0000-0000-000000000000";
5758
const client = new AdvisorManagementClient(new DefaultAzureCredential(), subscriptionId);
59+
```
60+
61+
For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate.
5862

59-
// For client-side applications running in the browser, use this code instead:
60-
// const credential = new InteractiveBrowserCredential({
61-
// tenantId: "<YOUR_TENANT_ID>",
62-
// clientId: "<YOUR_CLIENT_ID>"
63-
// });
64-
// const client = new AdvisorManagementClient(credential, subscriptionId);
63+
```ts snippet:AdvisorManagementClientAuth_Browser
64+
import { InteractiveBrowserCredential } from "@azure/identity";
65+
import { AdvisorManagementClient } from "@azure/arm-advisor";
66+
67+
const credential = new InteractiveBrowserCredential({
68+
tenantId: "<YOUR_TENANT_ID>",
69+
clientId: "<YOUR_CLIENT_ID>",
70+
});
71+
const client = new AdvisorManagementClient(credential, subscriptionId);
6572
```
6673

6774
### JavaScript Bundle
@@ -80,8 +87,9 @@ To use this client library in the browser, first you need to use a bundler. For
8087

8188
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
8289

83-
```javascript
84-
const { setLogLevel } = require("@azure/logger");
90+
```ts snippet:setLogLevel
91+
import { setLogLevel } from "@azure/logger";
92+
8593
setLogLevel("info");
8694
```
8795

sdk/advisor/arm-advisor/package.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"azure",
2020
"typescript",
2121
"browser",
22-
"isomorphic"
22+
"isomorphic",
23+
"cloud"
2324
],
2425
"license": "MIT",
2526
"main": "./dist/commonjs/index.js",
@@ -39,10 +40,7 @@
3940
"typescript": "~5.7.2",
4041
"vitest": "^2.1.8"
4142
},
42-
"repository": {
43-
"type": "git",
44-
"url": "https://github.com/Azure/azure-sdk-for-js.git"
45-
},
43+
"repository": "github:Azure/azure-sdk-for-js",
4644
"bugs": {
4745
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
4846
},
@@ -77,7 +75,7 @@
7775
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
7876
"unit-test:browser": "echo skipped",
7977
"unit-test:node": "dev-tool run test:vitest",
80-
"update-snippets": "echo skipped"
78+
"update-snippets": "dev-tool run update-snippets"
8179
},
8280
"sideEffects": false,
8381
"//metadata": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity";
5+
import { AdvisorManagementClient } from "@azure/arm-advisor";
6+
import { setLogLevel } from "@azure/logger";
7+
import { describe, it } from "vitest";
8+
9+
describe("snippets", function () {
10+
it("AdvisorManagementClientAuth_Node", async function () {
11+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
12+
const client = new AdvisorManagementClient(new DefaultAzureCredential(), subscriptionId);
13+
});
14+
15+
it("AdvisorManagementClientAuth_Browser", async function () {
16+
const credential = new InteractiveBrowserCredential({
17+
tenantId: "<YOUR_TENANT_ID>",
18+
clientId: "<YOUR_CLIENT_ID>",
19+
});
20+
const client = new AdvisorManagementClient(credential, subscriptionId);
21+
});
22+
23+
it("setLogLevel", async function () {
24+
setLogLevel("info");
25+
});
26+
});

0 commit comments

Comments
 (0)