Skip to content

Commit 5e386a1

Browse files
authored
[billing] Update billing projects to use snippets extraction (#32535)
### Packages impacted by this PR - @azure/arm-billing ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Updates the `billing` projects to use snippet extraction. ### 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 72238af commit 5e386a1

File tree

4 files changed

+74
-41
lines changed

4 files changed

+74
-41
lines changed

sdk/billing/arm-billing/README.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,28 @@ 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 { BillingManagementClient } = require("@azure/arm-billing");
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:ReadmeSampleCreateClient_Node
54+
import { BillingManagementClient } from "@azure/arm-billing";
55+
import { DefaultAzureCredential } from "@azure/identity";
5556

5657
const subscriptionId = "00000000-0000-0000-0000-000000000000";
5758
const client = new BillingManagementClient(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 BillingManagementClient(credential, subscriptionId);
63+
```ts snippet:ReadmeSampleCreateClient_Browser
64+
import { InteractiveBrowserCredential } from "@azure/identity";
65+
import { BillingManagementClient } from "@azure/arm-billing";
66+
67+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
68+
const credential = new InteractiveBrowserCredential({
69+
tenantId: "<YOUR_TENANT_ID>",
70+
clientId: "<YOUR_CLIENT_ID>",
71+
});
72+
const client = new BillingManagementClient(credential, subscriptionId);
6573
```
6674

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

8189
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`:
8290

83-
```javascript
84-
const { setLogLevel } = require("@azure/logger");
91+
```ts snippet:SetLogLevel
92+
import { setLogLevel } from "@azure/logger";
93+
8594
setLogLevel("info");
8695
```
8796

sdk/billing/arm-billing/package.json

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@
99
},
1010
"dependencies": {
1111
"@azure/abort-controller": "^2.1.2",
12-
"@azure/core-auth": "^1.6.0",
13-
"@azure/core-client": "^1.7.0",
14-
"@azure/core-lro": "^2.5.4",
15-
"@azure/core-paging": "^1.2.0",
16-
"@azure/core-rest-pipeline": "^1.14.0",
17-
"tslib": "^2.2.0"
12+
"@azure/core-auth": "^1.9.0",
13+
"@azure/core-client": "^1.9.2",
14+
"@azure/core-lro": "^2.7.2",
15+
"@azure/core-paging": "^1.6.2",
16+
"@azure/core-rest-pipeline": "^1.18.1",
17+
"tslib": "^2.8.1"
1818
},
1919
"keywords": [
2020
"node",
2121
"azure",
2222
"typescript",
2323
"browser",
24-
"isomorphic"
24+
"isomorphic",
25+
"cloud"
2526
],
2627
"license": "MIT",
2728
"main": "./dist/commonjs/index.js",
@@ -32,20 +33,17 @@
3233
"@azure-tools/test-recorder": "^4.1.0",
3334
"@azure-tools/test-utils-vitest": "^1.0.0",
3435
"@azure/dev-tool": "^1.0.0",
35-
"@azure/identity": "^4.2.1",
36+
"@azure/identity": "^4.5.0",
37+
"@azure/logger": "^1.1.4",
3638
"@types/node": "^18.0.0",
3739
"@vitest/browser": "^2.1.8",
3840
"@vitest/coverage-istanbul": "^2.1.8",
3941
"dotenv": "^16.0.0",
4042
"playwright": "^1.49.1",
41-
"tsx": "^4.7.1",
4243
"typescript": "~5.7.2",
4344
"vitest": "^2.1.8"
4445
},
45-
"repository": {
46-
"type": "git",
47-
"url": "https://github.com/Azure/azure-sdk-for-js.git"
48-
},
46+
"repository": "github:Azure/azure-sdk-for-js",
4947
"bugs": {
5048
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
5149
},
@@ -80,7 +78,7 @@
8078
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
8179
"unit-test:browser": "echo skipped",
8280
"unit-test:node": "dev-tool run test:vitest",
83-
"update-snippets": "echo skipped"
81+
"update-snippets": "dev-tool run update-snippets"
8482
},
8583
"sideEffects": false,
8684
"//metadata": {

sdk/billing/arm-billing/test/billing_operations_test.spec.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@
66
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
*/
88

9-
import {
10-
env,
11-
Recorder,
12-
RecorderStartOptions,
13-
isPlaybackMode,
14-
} from "@azure-tools/test-recorder";
9+
import type { RecorderStartOptions } from "@azure-tools/test-recorder";
10+
import { env, Recorder, isPlaybackMode } from "@azure-tools/test-recorder";
1511
import { createTestCredential } from "@azure-tools/test-credential";
1612
import { BillingManagementClient } from "../src/billingManagementClient.js";
1713
import { describe, it, assert, beforeEach, afterEach } from "vitest";
1814

1915
const replaceableVariables: Record<string, string> = {
20-
SUBSCRIPTION_ID: "88888888-8888-8888-8888-888888888888"
16+
SUBSCRIPTION_ID: "88888888-8888-8888-8888-888888888888",
2117
};
2218

2319
const recorderOptions: RecorderStartOptions = {
@@ -37,25 +33,28 @@ describe("Billing test", () => {
3733
let subscriptionId: string;
3834
let client: BillingManagementClient;
3935

40-
beforeEach(async function (ctx) {
36+
beforeEach(async (ctx) => {
4137
recorder = new Recorder(ctx);
4238
await recorder.start(recorderOptions);
43-
subscriptionId = env.SUBSCRIPTION_ID || '';
39+
subscriptionId = env.SUBSCRIPTION_ID || "";
4440
// This is an example of how the environment variables are used
4541
const credential = createTestCredential();
46-
client = new BillingManagementClient(credential, subscriptionId, recorder.configureClientOptions({}));
42+
client = new BillingManagementClient(
43+
credential,
44+
subscriptionId,
45+
recorder.configureClientOptions({}),
46+
);
4747
});
4848

49-
afterEach(async function () {
49+
afterEach(async () => {
5050
await recorder.stop();
5151
});
5252

53-
it("operations list test", async function () {
53+
it("operations list test", async () => {
5454
const resArray = new Array();
55-
for await (let item of client.operations.list()) {
55+
for await (const item of client.operations.list()) {
5656
resArray.push(item);
5757
}
5858
assert.notEqual(resArray.length, 0);
5959
});
60-
61-
})
60+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { BillingManagementClient } from "../src/index.js";
5+
import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity";
6+
import { setLogLevel } from "@azure/logger";
7+
import { describe, it } from "vitest";
8+
9+
describe("snippets", () => {
10+
it("ReadmeSampleCreateClient_Node", async () => {
11+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
12+
const client = new BillingManagementClient(new DefaultAzureCredential(), subscriptionId);
13+
});
14+
15+
it("ReadmeSampleCreateClient_Browser", async () => {
16+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
17+
const credential = new InteractiveBrowserCredential({
18+
tenantId: "<YOUR_TENANT_ID>",
19+
clientId: "<YOUR_CLIENT_ID>",
20+
});
21+
const client = new BillingManagementClient(credential, subscriptionId);
22+
});
23+
24+
it("SetLogLevel", async () => {
25+
setLogLevel("info");
26+
});
27+
});

0 commit comments

Comments
 (0)