Skip to content

Commit 3352cfc

Browse files
authored
[identity] Migrate rest of identity projects to use snippets extraction (#33201)
### Packages impacted by this PR - @azure/identity-cache-persistence - @azure/identity-vscode ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Updates all remaining projects under `identity` to use snippets 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 fabbcb1 commit 3352cfc

24 files changed

+213
-116
lines changed

common/config/rush/pnpm-lock.yaml

+10-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/identity/identity-cache-persistence/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ If this is your first time using `@azure/identity` or Microsoft Entra ID, we rec
3131

3232
As of `@azure/identity` version 2.0.0, the Identity client library for JavaScript includes a plugin API. This package (`@azure/identity-cache-persistence`) exports a plugin object that you must pass as an argument to the top-level `useIdentityPlugin` function from the `@azure/identity` package. Enable token cache persistence in your program as follows:
3333

34-
```ts snippet:getting_started
34+
```ts snippet:ReadmeSampleUsePlugin
3535
import { useIdentityPlugin } from "@azure/identity";
3636
import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
3737

@@ -44,7 +44,7 @@ After calling `useIdentityPlugin`, the persistent token cache plugin is register
4444

4545
Once the plugin is registered, you can enable token cache persistence by passing `tokenCachePersistenceOptions` with an `enabled` property set to `true` to a credential constructor. In the following example, we use the `DeviceCodeCredential`, since persistent caching of its tokens allows you to skip the interactive device-code authentication flow if a cached token is available.
4646

47-
```ts snippet:device_code_credential_example
47+
```ts snippet:ReadmeSampleDeviceCodeCredential
4848
import { DeviceCodeCredential } from "@azure/identity";
4949

5050
const credential = new DeviceCodeCredential({
@@ -66,7 +66,7 @@ console.log((await credential.getToken(scope)).token.substring(0, 10), "...");
6666

6767
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`:
6868

69-
```ts snippet:logging
69+
```ts snippet:SetLogLevel
7070
import { setLogLevel } from "@azure/logger";
7171

7272
setLogLevel("info");

sdk/identity/identity-cache-persistence/package.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
2828
"unit-test:browser": "echo skipped",
2929
"unit-test:node": "echo skipped",
30-
"update-snippets": "echo skipped"
30+
"update-snippets": "dev-tool run update-snippets"
3131
},
3232
"files": [
3333
"dist/",
@@ -71,16 +71,17 @@
7171
"@azure/eslint-plugin-azure-sdk": "^3.0.0",
7272
"@azure/logger": "^1.1.4",
7373
"@types/node": "^18.0.0",
74-
"@vitest/browser": "^3.0.3",
75-
"@vitest/coverage-istanbul": "^3.0.3",
74+
"@vitest/browser": "^3.0.6",
75+
"@vitest/coverage-istanbul": "^3.0.6",
7676
"dotenv": "^16.0.0",
7777
"eslint": "^9.9.0",
78-
"playwright": "^1.49.0",
78+
"playwright": "^1.50.1",
7979
"typescript": "~5.7.2",
80-
"vitest": "^3.0.3"
80+
"vitest": "^3.0.6"
8181
},
8282
"type": "module",
8383
"tshy": {
84+
"project": "./tsconfig.src.json",
8485
"exports": {
8586
"./package.json": "./package.json",
8687
".": "./src/index.ts"
@@ -93,8 +94,7 @@
9394
"browser",
9495
"react-native"
9596
],
96-
"selfLink": false,
97-
"project": "./tsconfig.src.json"
97+
"selfLink": false
9898
},
9999
"browser": "./dist/browser/index.js",
100100
"exports": {
@@ -117,5 +117,6 @@
117117
"default": "./dist/commonjs/index.js"
118118
}
119119
}
120-
}
120+
},
121+
"react-native": "./dist/react-native/index.js"
121122
}

sdk/identity/identity-cache-persistence/samples-dev/extension.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ import { useIdentityPlugin, DeviceCodeCredential } from "@azure/identity";
2020
import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
2121
useIdentityPlugin(cachePersistencePlugin);
2222

23-
import dotenv from "dotenv";
24-
dotenv.config();
23+
import "dotenv/config";
2524

26-
async function main() {
25+
async function main(): Promise<void> {
2726
const credential = new DeviceCodeCredential({
2827
// This property must be provided, with `enabled` set to true to enable
2928
// persistent token caching.

sdk/identity/identity-cache-persistence/samples-dev/persistentCachingInteractiveBrowserCredential.ts

+6-11
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,14 @@
44
/**
55
* @summary Authenticates using persistent token caching with Interactive Browser Credential
66
*/
7-
import {
8-
InteractiveBrowserCredential,
9-
useIdentityPlugin,
10-
AuthenticationRecord,
11-
} from "@azure/identity";
7+
import type { AuthenticationRecord } from "@azure/identity";
8+
import { InteractiveBrowserCredential, useIdentityPlugin } from "@azure/identity";
129
import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
13-
import path from "path";
14-
import fs from "fs";
15-
import dotenv from "dotenv";
10+
import path from "node:path";
11+
import fs from "node:fs";
12+
import "dotenv/config";
1613

1714
useIdentityPlugin(cachePersistencePlugin);
18-
19-
dotenv.config();
2015
// The app registration client ID in the Microsoft Entra tenant
2116
const clientId = "APP-REGISTRATION-CLIENT-ID";
2217
// The tenant ID in Microsoft Entra ID
@@ -26,7 +21,7 @@ const loginHint = `EMAIL-ADDRESS`;
2621
// The file path to save the authentication record
2722
const authenticationRecordFilePath = path.resolve(__dirname, "authenticationRecord.json");
2823

29-
async function main() {
24+
async function main(): Promise<void> {
3025
try {
3126
const fileContents = await fs.promises.readFile(authenticationRecordFilePath, "utf8");
3227
const authenticationRecord = JSON.parse(fileContents);

sdk/identity/identity-cache-persistence/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ interface AzurePluginContext {
3737
*
3838
* Example:
3939
*
40-
* ```ts snippet:device_code_credential_example
40+
* ```ts snippet:ReadmeSampleDeviceCodeCredential
4141
* import { DeviceCodeCredential } from "@azure/identity";
4242
*
4343
* const credential = new DeviceCodeCredential({

sdk/identity/identity-cache-persistence/test/internal/node/clientCertificateCredential.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe("ClientCertificateCredential (internal)", () => {
3535
);
3636
});
3737

38-
afterEach(async function () {
38+
afterEach(async () => {
3939
await cleanup();
4040
});
4141

sdk/identity/identity-cache-persistence/test/internal/node/clientSecretCredential.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe("ClientSecretCredential (internal)", () => {
3232
"acquireTokenByClientCredential",
3333
);
3434
});
35-
afterEach(async function () {
35+
afterEach(async () => {
3636
await cleanup();
3737
});
3838

sdk/identity/identity-cache-persistence/test/internal/node/deviceCodeCredential.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("DeviceCodeCredential (internal)", () => {
2929
doGetTokenSpy = vi.spyOn(PublicClientApplication.prototype, "acquireTokenByDeviceCode");
3030
});
3131

32-
afterEach(async function () {
32+
afterEach(async () => {
3333
await cleanup();
3434
});
3535

sdk/identity/identity-cache-persistence/test/internal/node/usernamePasswordCredential.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("UsernamePasswordCredential (internal)", () => {
2929
doGetTokenSpy = vi.spyOn(PublicClientApplication.prototype, "acquireTokenByUsernamePassword");
3030
});
3131

32-
afterEach(async function () {
32+
afterEach(async () => {
3333
await cleanup();
3434
});
3535

sdk/identity/identity-cache-persistence/test/snippets.spec.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import { DeviceCodeCredential, useIdentityPlugin } from "@azure/identity";
55
import { cachePersistencePlugin } from "@azure/identity-cache-persistence";
66
import { setLogLevel } from "@azure/logger";
7-
import { describe, it, assert } from "vitest";
7+
import { describe, it } from "vitest";
88

99
describe("snippets", () => {
10-
it("getting_started", () => {
10+
it("ReadmeSampleUsePlugin", () => {
1111
useIdentityPlugin(cachePersistencePlugin);
1212
});
1313

14-
it("device_code_credential_example", async () => {
14+
it("ReadmeSampleDeviceCodeCredential", async () => {
1515
const credential = new DeviceCodeCredential({
1616
tokenCachePersistenceOptions: {
1717
enabled: true,
@@ -25,7 +25,7 @@ describe("snippets", () => {
2525
console.log((await credential.getToken(scope)).token.substring(0, 10), "...");
2626
});
2727

28-
it("logging", async () => {
28+
it("SetLogLevel", async () => {
2929
setLogLevel("info");
3030
});
3131
});
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
22
"references": [
3-
{ "path": "./tsconfig.src.json" },
4-
{ "path": "./tsconfig.samples.json" },
5-
{ "path": "./tsconfig.test.json" }
6-
],
7-
"compilerOptions": {
8-
"esModuleInterop": true
9-
}
3+
{
4+
"path": "./tsconfig.src.json"
5+
},
6+
{
7+
"path": "./tsconfig.samples.json"
8+
},
9+
{
10+
"path": "./tsconfig.test.json"
11+
}
12+
]
1013
}

sdk/identity/identity-cache-persistence/vitest.browser.config.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ export default mergeConfig(
99
viteConfig,
1010
defineConfig({
1111
test: {
12-
include: [
13-
"dist-test/browser/test/**/*.spec.js",
14-
],
12+
include: ["dist-test/browser/test/**/*.spec.js",],
13+
testTimeout: 1200000,
14+
hookTimeout: 1200000,
1515
},
1616
}),
1717
);
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
12
// Copyright (c) Microsoft Corporation.
23
// Licensed under the MIT License.
34

5+
import { defineConfig, mergeConfig } from "vitest/config";
46
import viteConfig from "../../../vitest.shared.config.ts";
57

6-
export default viteConfig;
8+
export default mergeConfig(
9+
viteConfig,
10+
defineConfig({
11+
test: {
12+
testTimeout: 1200000,
13+
hookTimeout: 1200000,
14+
},
15+
}),
16+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
// Copyright (c) Microsoft Corporation.
3+
// Licensed under the MIT License.
4+
5+
import { mergeConfig } from "vitest/config";
6+
import vitestConfig from "./vitest.config.ts";
7+
import vitestEsmConfig from "../../../vitest.esm.shared.config.ts";
8+
9+
export default mergeConfig(
10+
vitestConfig,
11+
vitestEsmConfig
12+
);

0 commit comments

Comments
 (0)