diff --git a/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/LICENSE.txt b/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/LICENSE.txt deleted file mode 100644 index ea8fb1516028..000000000000 --- a/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2020 Microsoft - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/README.md b/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/README.md index ca7dc10dc44b..ac7f163ef3a5 100644 --- a/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/README.md +++ b/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/README.md @@ -46,20 +46,28 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica 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). -```javascript -const { UsageManagementClient } = require("@azure/arm-commerce-profile-2020-09-01-hybrid"); -const { DefaultAzureCredential } = require("@azure/identity"); -// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details. +Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client. + +```ts snippet:ReadmeSampleCreateClient_Node +import { UsageManagementClient } from "@azure/arm-commerce-profile-2020-09-01-hybrid"; +import { DefaultAzureCredential } from "@azure/identity"; const subscriptionId = "00000000-0000-0000-0000-000000000000"; const client = new UsageManagementClient(new DefaultAzureCredential(), subscriptionId); +``` + +For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate. -// For client-side applications running in the browser, use this code instead: -// const credential = new InteractiveBrowserCredential({ -// tenantId: "", -// clientId: "" -// }); -// const client = new UsageManagementClient(credential, subscriptionId); +```ts snippet:ReadmeSampleCreateClient_Browser +import { InteractiveBrowserCredential } from "@azure/identity"; +import { UsageManagementClient } from "@azure/arm-commerce-profile-2020-09-01-hybrid"; + +const subscriptionId = "00000000-0000-0000-0000-000000000000"; +const credential = new InteractiveBrowserCredential({ + tenantId: "", + clientId: "", +}); +const client = new UsageManagementClient(credential, subscriptionId); ``` ### JavaScript Bundle @@ -78,8 +86,9 @@ To use this client library in the browser, first you need to use a bundler. For 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`: -```javascript -const { setLogLevel } = require("@azure/logger"); +```ts snippet:SetLogLevel +import { setLogLevel } from "@azure/logger"; + setLogLevel("info"); ``` diff --git a/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/package.json b/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/package.json index 470c8850dfba..aae4b6c14f0b 100644 --- a/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/package.json +++ b/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/package.json @@ -8,18 +8,19 @@ "node": ">=18.0.0" }, "dependencies": { - "@azure/core-auth": "^1.3.0", - "@azure/core-client": "^1.6.1", - "@azure/core-paging": "^1.2.0", - "@azure/core-rest-pipeline": "^1.8.0", - "tslib": "^2.2.0" + "@azure/core-auth": "^1.9.0", + "@azure/core-client": "^1.9.2", + "@azure/core-paging": "^1.6.2", + "@azure/core-rest-pipeline": "^1.18.2", + "tslib": "^2.8.1" }, "keywords": [ "node", "azure", "typescript", "browser", - "isomorphic" + "isomorphic", + "cloud" ], "license": "MIT", "main": "./dist/commonjs/index.js", @@ -30,7 +31,8 @@ "@azure-tools/test-recorder": "^4.1.0", "@azure-tools/test-utils-vitest": "^1.0.0", "@azure/dev-tool": "^1.0.0", - "@azure/identity": "^4.0.1", + "@azure/identity": "^4.5.0", + "@azure/logger": "^1.1.4", "@types/node": "^18.0.0", "@vitest/browser": "^2.1.8", "@vitest/coverage-istanbul": "^2.1.8", @@ -39,10 +41,7 @@ "typescript": "~5.7.2", "vitest": "^2.1.8" }, - "repository": { - "type": "git", - "url": "https://github.com/Azure/azure-sdk-for-js.git" - }, + "repository": "github:Azure/azure-sdk-for-js", "bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" }, @@ -77,7 +76,7 @@ "unit-test": "npm run unit-test:node && npm run unit-test:browser", "unit-test:browser": "echo skipped", "unit-test:node": "dev-tool run test:vitest", - "update-snippets": "echo skipped" + "update-snippets": "dev-tool run update-snippets" }, "sideEffects": false, "//metadata": { diff --git a/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/test/sampleTest.spec.ts b/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/test/sampleTest.spec.ts index e25d3db273e7..86a13f7a74a4 100644 --- a/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/test/sampleTest.spec.ts +++ b/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/test/sampleTest.spec.ts @@ -6,17 +6,15 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import { - Recorder, - RecorderStartOptions -} from "@azure-tools/test-recorder"; -import { afterEach, beforeEach, describe, it } from "vitest"; +import type { RecorderStartOptions } from "@azure-tools/test-recorder"; +import { Recorder } from "@azure-tools/test-recorder"; +import { afterEach, beforeEach, describe, it, assert } from "vitest"; const replaceableVariables: Record = { AZURE_CLIENT_ID: "azure_client_id", AZURE_CLIENT_SECRET: "azure_client_secret", AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888", - SUBSCRIPTION_ID: "azure_subscription_id" + SUBSCRIPTION_ID: "azure_subscription_id", }; const recorderOptions: RecorderStartOptions = { @@ -30,16 +28,16 @@ const recorderOptions: RecorderStartOptions = { describe("My test", () => { let recorder: Recorder; - beforeEach(async function (ctx) { + beforeEach(async (ctx) => { recorder = new Recorder(ctx); await recorder.start(recorderOptions); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); - it("sample test", async function () { - console.log("Hi, I'm a test!"); + it("sample test", async () => { + assert(true); }); }); diff --git a/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/test/snippets.spec.ts b/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/test/snippets.spec.ts new file mode 100644 index 000000000000..091b38f5ab43 --- /dev/null +++ b/sdk/commerce/arm-commerce-profile-2020-09-01-hybrid/test/snippets.spec.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { UsageManagementClient } from "../src/index.js"; +import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity"; +import { setLogLevel } from "@azure/logger"; +import { describe, it } from "vitest"; + +describe("snippets", () => { + it("ReadmeSampleCreateClient_Node", async () => { + const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const client = new UsageManagementClient(new DefaultAzureCredential(), subscriptionId); + }); + + it("ReadmeSampleCreateClient_Browser", async () => { + const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const credential = new InteractiveBrowserCredential({ + tenantId: "", + clientId: "", + }); + const client = new UsageManagementClient(credential, subscriptionId); + }); + + it("SetLogLevel", async () => { + setLogLevel("info"); + }); +}); diff --git a/sdk/commerce/arm-commerce/README.md b/sdk/commerce/arm-commerce/README.md index a613ddb40a1b..2bf73a913243 100644 --- a/sdk/commerce/arm-commerce/README.md +++ b/sdk/commerce/arm-commerce/README.md @@ -46,20 +46,28 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica 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). -```javascript -const { UsageManagementClient } = require("@azure/arm-commerce"); -const { DefaultAzureCredential } = require("@azure/identity"); -// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details. +Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client. + +```ts snippet:ReadmeSampleCreateClient_Node +import { UsageManagementClient } from "@azure/arm-commerce"; +import { DefaultAzureCredential } from "@azure/identity"; const subscriptionId = "00000000-0000-0000-0000-000000000000"; const client = new UsageManagementClient(new DefaultAzureCredential(), subscriptionId); +``` + +For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate. -// For client-side applications running in the browser, use this code instead: -// const credential = new InteractiveBrowserCredential({ -// tenantId: "", -// clientId: "" -// }); -// const client = new UsageManagementClient(credential, subscriptionId); +```ts snippet:ReadmeSampleCreateClient_Browser +import { InteractiveBrowserCredential } from "@azure/identity"; +import { UsageManagementClient } from "@azure/arm-commerce"; + +const subscriptionId = "00000000-0000-0000-0000-000000000000"; +const credential = new InteractiveBrowserCredential({ + tenantId: "", + clientId: "", +}); +const client = new UsageManagementClient(credential, subscriptionId); ``` ### JavaScript Bundle @@ -78,8 +86,9 @@ To use this client library in the browser, first you need to use a bundler. For 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`: -```javascript -const { setLogLevel } = require("@azure/logger"); +```ts snippet:SetLogLevel +import { setLogLevel } from "@azure/logger"; + setLogLevel("info"); ``` diff --git a/sdk/commerce/arm-commerce/package.json b/sdk/commerce/arm-commerce/package.json index cd5b5a96b1b4..37363ab0349f 100644 --- a/sdk/commerce/arm-commerce/package.json +++ b/sdk/commerce/arm-commerce/package.json @@ -8,18 +8,19 @@ "node": ">=18.0.0" }, "dependencies": { - "@azure/core-auth": "^1.3.0", - "@azure/core-client": "^1.6.1", - "@azure/core-paging": "^1.2.0", - "@azure/core-rest-pipeline": "^1.8.0", - "tslib": "^2.2.0" + "@azure/core-auth": "^1.9.0", + "@azure/core-client": "^1.9.2", + "@azure/core-paging": "^1.6.2", + "@azure/core-rest-pipeline": "^1.18.2", + "tslib": "^2.8.1" }, "keywords": [ "node", "azure", "typescript", "browser", - "isomorphic" + "isomorphic", + "cloud" ], "license": "MIT", "main": "./dist/commonjs/index.js", @@ -30,7 +31,8 @@ "@azure-tools/test-recorder": "^4.1.0", "@azure-tools/test-utils-vitest": "^1.0.0", "@azure/dev-tool": "^1.0.0", - "@azure/identity": "^4.0.1", + "@azure/identity": "^4.5.0", + "@azure/logger": "^1.1.4", "@types/node": "^18.0.0", "@vitest/browser": "^2.1.8", "@vitest/coverage-istanbul": "^2.1.8", @@ -39,10 +41,7 @@ "vitest": "^2.1.8" }, "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/commerce/arm-commerce", - "repository": { - "type": "git", - "url": "https://github.com/Azure/azure-sdk-for-js.git" - }, + "repository": "github:Azure/azure-sdk-for-js", "bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" }, @@ -77,7 +76,7 @@ "unit-test": "npm run unit-test:node && npm run unit-test:browser", "unit-test:browser": "echo skipped", "unit-test:node": "dev-tool run test:vitest", - "update-snippets": "echo skipped" + "update-snippets": "dev-tool run update-snippets" }, "sideEffects": false, "//metadata": { diff --git a/sdk/commerce/arm-commerce/test/commerce_examples.spec.ts b/sdk/commerce/arm-commerce/test/commerce_examples.spec.ts index 2d7db7bf20c5..1e7d7b02d443 100644 --- a/sdk/commerce/arm-commerce/test/commerce_examples.spec.ts +++ b/sdk/commerce/arm-commerce/test/commerce_examples.spec.ts @@ -6,12 +6,8 @@ * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ -import { - env, - Recorder, - RecorderStartOptions, - isPlaybackMode, -} from "@azure-tools/test-recorder"; +import type { RecorderStartOptions } from "@azure-tools/test-recorder"; +import { env, Recorder, isPlaybackMode } from "@azure-tools/test-recorder"; import { createTestCredential } from "@azure-tools/test-credential"; import { UsageManagementClient } from "../src/usageManagementClient.js"; import { afterEach, assert, beforeEach, describe, it } from "vitest"; @@ -20,7 +16,7 @@ const replaceableVariables: Record = { AZURE_CLIENT_ID: "azure_client_id", AZURE_CLIENT_SECRET: "azure_client_secret", AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888", - SUBSCRIPTION_ID: "azure_subscription_id" + SUBSCRIPTION_ID: "azure_subscription_id", }; const recorderOptions: RecorderStartOptions = { @@ -40,20 +36,24 @@ describe("Commerce test", () => { let subscriptionId: string; let client: UsageManagementClient; - beforeEach(async function (ctx) { + beforeEach(async (ctx) => { recorder = new Recorder(ctx); await recorder.start(recorderOptions); - subscriptionId = env.SUBSCRIPTION_ID || ''; + subscriptionId = env.SUBSCRIPTION_ID || ""; // This is an example of how the environment variables are used const credential = createTestCredential(); - client = new UsageManagementClient(credential, subscriptionId, recorder.configureClientOptions({})); + client = new UsageManagementClient( + credential, + subscriptionId, + recorder.configureClientOptions({}), + ); }); - afterEach(async function () { + afterEach(async () => { await recorder.stop(); }); - it.skip("rateCard get test", async function () { + it.skip("rateCard get test", async () => { const res = await client.rateCard.get("OfferDurableId eq 'MS-AZR-0062P' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US'"); assert.notEqual(res.meters?.length, 0); }); diff --git a/sdk/commerce/arm-commerce/test/snippets.spec.ts b/sdk/commerce/arm-commerce/test/snippets.spec.ts new file mode 100644 index 000000000000..091b38f5ab43 --- /dev/null +++ b/sdk/commerce/arm-commerce/test/snippets.spec.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { UsageManagementClient } from "../src/index.js"; +import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity"; +import { setLogLevel } from "@azure/logger"; +import { describe, it } from "vitest"; + +describe("snippets", () => { + it("ReadmeSampleCreateClient_Node", async () => { + const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const client = new UsageManagementClient(new DefaultAzureCredential(), subscriptionId); + }); + + it("ReadmeSampleCreateClient_Browser", async () => { + const subscriptionId = "00000000-0000-0000-0000-000000000000"; + const credential = new InteractiveBrowserCredential({ + tenantId: "", + clientId: "", + }); + const client = new UsageManagementClient(credential, subscriptionId); + }); + + it("SetLogLevel", async () => { + setLogLevel("info"); + }); +}); diff --git a/sdk/commerce/arm-commerce/tsconfig.vitest-temp.json b/sdk/commerce/arm-commerce/tsconfig.vitest-temp.json new file mode 100644 index 000000000000..c0db26cc50ac --- /dev/null +++ b/sdk/commerce/arm-commerce/tsconfig.vitest-temp.json @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "target": "ES2023", + "module": "NodeNext", + "lib": [], + "declaration": true, + "declarationMap": true, + "inlineSources": true, + "sourceMap": true, + "importHelpers": true, + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "moduleResolution": "NodeNext", + "esModuleInterop": true, + "composite": true, + "noEmit": true, + "skipLibCheck": true, + "emitDeclarationOnly": false, + "incremental": true, + "tsBuildInfoFile": "/Users/matthewp/git/azure-sdk-for-js-copy/common/temp/node_modules/.pnpm/vitest@2.1.8_@types+node@18.19.70_@vitest+browser@2.1.8_msw@2.7.0_@types+node@22.7.9_typescript@5.7.3_/node_modules/vitest/dist/chunks/tsconfig.tmp.tsbuildinfo" + }, + "include": [ + "/Users/matthewp/git/azure-sdk-for-js-copy/sdk/commerce/arm-commerce/test", + "/Users/matthewp/git/azure-sdk-for-js-copy/sdk/commerce/arm-commerce/src" + ], + "exclude": [ + "/Users/matthewp/git/azure-sdk-for-js-copy/sdk/commerce/arm-commerce/test/stress", + "/Users/matthewp/git/azure-sdk-for-js-copy/sdk/commerce/arm-commerce/test/snippets.spec.ts" + ] +} \ No newline at end of file