Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7552f0c

Browse files
[communication] Move communication packages to snippets extraction (Azure#32572)
### Packages impacted by this PR - @azure/arm-communication - @azure-tools/communication-alpha-ids - @azure/communication-call-automation - @azure/communication-chat - @azure/communication-common - @azure/communication-email - @azure/communication-identity - @azure/communication-job-router - @azure-rest/communication-job-router - @azure-rest/communication-messages - @azure/communication-phone-numbers - @azure-tools/communication-recipient-verification - @azure/communication-rooms - @azure-tools/communication-short-codes - @azure/communication-sms - @azure-tools/communication-tiering - @azure-tools/communication-toll-free-verification ### Issues associated with this PR - Azure#32416 ### Describe the problem that is addressed by this PR Updates all projects under `communication` 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) --------- Co-authored-by: Dominik <[email protected]>
1 parent 5452442 commit 7552f0c

File tree

196 files changed

+5122
-2619
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+5122
-2619
lines changed

common/tools/dev-tool/src/commands/run/update-snippets.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,14 @@ async function findAllSnippetLocations(info: ProjectInfo): Promise<SnippetLocati
116116
openFence = undefined;
117117

118118
// We don't care about bash, text, etc. snippets. Only JS/TS in any incarnation.
119-
if (!["js", "ts", "javascript", "typescript"].includes(language)) continue;
119+
if (!["js", "ts", "javascript", "typescript"].includes(language)) {
120+
continue;
121+
}
122+
123+
// Ignore if it says snippet:ignore
124+
if (snippetName?.trim()?.startsWith("snippet:ignore")) {
125+
continue;
126+
}
120127

121128
if (!snippetName?.trim()?.startsWith("snippet:")) {
122129
log.error(

sdk/communication/arm-communication/README.md

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

5657
const subscriptionId = "00000000-0000-0000-0000-000000000000";
5758
const client = new CommunicationServiceManagementClient(
5859
new DefaultAzureCredential(),
5960
subscriptionId,
6061
);
62+
```
63+
64+
For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate.
6165

62-
// For client-side applications running in the browser, use this code instead:
63-
// const credential = new InteractiveBrowserCredential({
64-
// tenantId: "<YOUR_TENANT_ID>",
65-
// clientId: "<YOUR_CLIENT_ID>"
66-
// });
67-
// const client = new CommunicationServiceManagementClient(credential, subscriptionId);
66+
```ts snippet:ReadmeSampleCreateClient_Browser
67+
import { InteractiveBrowserCredential } from "@azure/identity";
68+
import { CommunicationServiceManagementClient } from "@azure/arm-communication";
69+
70+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
71+
const credential = new InteractiveBrowserCredential({
72+
tenantId: "<YOUR_TENANT_ID>",
73+
clientId: "<YOUR_CLIENT_ID>",
74+
});
75+
const client = new CommunicationServiceManagementClient(credential, subscriptionId);
6876
```
6977

7078
### JavaScript Bundle
@@ -83,8 +91,9 @@ To use this client library in the browser, first you need to use a bundler. For
8391

8492
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`:
8593

86-
```javascript
87-
const { setLogLevel } = require("@azure/logger");
94+
```ts snippet:SetLogLevel
95+
import { setLogLevel } from "@azure/logger";
96+
8897
setLogLevel("info");
8998
```
9099

sdk/communication/arm-communication/package.json

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88
"node": ">=18.0.0"
99
},
1010
"dependencies": {
11-
"@azure/abort-controller": "^1.0.0",
12-
"@azure/core-auth": "^1.6.0",
13-
"@azure/core-client": "^1.7.0",
14-
"@azure/core-lro": "^2.5.4",
11+
"@azure/abort-controller": "^2.1.2",
12+
"@azure/core-auth": "^1.9.0",
13+
"@azure/core-client": "^1.9.2",
14+
"@azure/core-lro": "^2.7.2",
1515
"@azure/core-paging": "^1.2.0",
16-
"@azure/core-rest-pipeline": "^1.14.0",
17-
"tslib": "^2.2.0"
16+
"@azure/core-rest-pipeline": "^1.18.2",
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,7 +33,8 @@
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.0.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",
@@ -41,10 +43,7 @@
4143
"typescript": "~5.7.2",
4244
"vitest": "^2.1.8"
4345
},
44-
"repository": {
45-
"type": "git",
46-
"url": "https://github.com/Azure/azure-sdk-for-js.git"
47-
},
46+
"repository": "github:Azure/azure-sdk-for-js",
4847
"bugs": {
4948
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
5049
},
@@ -79,7 +78,7 @@
7978
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
8079
"unit-test:browser": "echo skipped",
8180
"unit-test:node": "dev-tool run test:vitest",
82-
"update-snippets": "echo skipped"
81+
"update-snippets": "dev-tool run update-snippets"
8382
},
8483
"sideEffects": false,
8584
"//metadata": {

sdk/communication/arm-communication/samples-dev/communicationServicesCheckNameAvailabilitySample.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
// Copyright (c) Microsoft Corporation.
1010
// Licensed under the MIT License.
11-
import {
12-
NameAvailabilityParameters,
13-
CommunicationServiceManagementClient,
14-
} from "@azure/arm-communication";
11+
import type { NameAvailabilityParameters } from "@azure/arm-communication";
12+
import { CommunicationServiceManagementClient } from "@azure/arm-communication";
1513
import { DefaultAzureCredential } from "@azure/identity";
1614
import "dotenv/config";
1715

@@ -23,17 +21,13 @@ import "dotenv/config";
2321
*/
2422
async function checkNameAvailabilityAvailable(): Promise<void> {
2523
const subscriptionId =
26-
process.env["COMMUNICATION_SUBSCRIPTION_ID"] ||
27-
"11112222-3333-4444-5555-666677778888";
24+
process.env["COMMUNICATION_SUBSCRIPTION_ID"] || "11112222-3333-4444-5555-666677778888";
2825
const nameAvailabilityParameters: NameAvailabilityParameters = {
2926
name: "MyCommunicationService",
3027
type: "Microsoft.Communication/CommunicationServices",
3128
};
3229
const credential = new DefaultAzureCredential();
33-
const client = new CommunicationServiceManagementClient(
34-
credential,
35-
subscriptionId,
36-
);
30+
const client = new CommunicationServiceManagementClient(credential, subscriptionId);
3731
const result = await client.communicationServices.checkNameAvailability(
3832
nameAvailabilityParameters,
3933
);
@@ -48,26 +42,22 @@ async function checkNameAvailabilityAvailable(): Promise<void> {
4842
*/
4943
async function checkNameAvailabilityUnavailable(): Promise<void> {
5044
const subscriptionId =
51-
process.env["COMMUNICATION_SUBSCRIPTION_ID"] ||
52-
"11112222-3333-4444-5555-666677778888";
45+
process.env["COMMUNICATION_SUBSCRIPTION_ID"] || "11112222-3333-4444-5555-666677778888";
5346
const nameAvailabilityParameters: NameAvailabilityParameters = {
5447
name: "MyCommunicationService",
5548
type: "Microsoft.Communication/CommunicationServices",
5649
};
5750
const credential = new DefaultAzureCredential();
58-
const client = new CommunicationServiceManagementClient(
59-
credential,
60-
subscriptionId,
61-
);
51+
const client = new CommunicationServiceManagementClient(credential, subscriptionId);
6252
const result = await client.communicationServices.checkNameAvailability(
6353
nameAvailabilityParameters,
6454
);
6555
console.log(result);
6656
}
6757

6858
async function main(): Promise<void> {
69-
checkNameAvailabilityAvailable();
70-
checkNameAvailabilityUnavailable();
59+
await checkNameAvailabilityAvailable();
60+
await checkNameAvailabilityUnavailable();
7161
}
7262

7363
main().catch(console.error);

sdk/communication/arm-communication/samples-dev/communicationServicesCreateOrUpdateSample.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
// Copyright (c) Microsoft Corporation.
1010
// Licensed under the MIT License.
11-
import {
12-
CommunicationServiceResource,
13-
CommunicationServiceManagementClient,
14-
} from "@azure/arm-communication";
11+
import type { CommunicationServiceResource } from "@azure/arm-communication";
12+
import { CommunicationServiceManagementClient } from "@azure/arm-communication";
1513
import { DefaultAzureCredential } from "@azure/identity";
1614
import "dotenv/config";
1715

@@ -23,20 +21,15 @@ import "dotenv/config";
2321
*/
2422
async function createOrUpdateResource(): Promise<void> {
2523
const subscriptionId =
26-
process.env["COMMUNICATION_SUBSCRIPTION_ID"] ||
27-
"11112222-3333-4444-5555-666677778888";
28-
const resourceGroupName =
29-
process.env["COMMUNICATION_RESOURCE_GROUP"] || "MyResourceGroup";
24+
process.env["COMMUNICATION_SUBSCRIPTION_ID"] || "11112222-3333-4444-5555-666677778888";
25+
const resourceGroupName = process.env["COMMUNICATION_RESOURCE_GROUP"] || "MyResourceGroup";
3026
const communicationServiceName = "MyCommunicationResource";
3127
const parameters: CommunicationServiceResource = {
3228
dataLocation: "United States",
3329
location: "Global",
3430
};
3531
const credential = new DefaultAzureCredential();
36-
const client = new CommunicationServiceManagementClient(
37-
credential,
38-
subscriptionId,
39-
);
32+
const client = new CommunicationServiceManagementClient(credential, subscriptionId);
4033
const result = await client.communicationServices.beginCreateOrUpdateAndWait(
4134
resourceGroupName,
4235
communicationServiceName,
@@ -53,21 +46,16 @@ async function createOrUpdateResource(): Promise<void> {
5346
*/
5447
async function createOrUpdateResourceWithManagedIdentity(): Promise<void> {
5548
const subscriptionId =
56-
process.env["COMMUNICATION_SUBSCRIPTION_ID"] ||
57-
"11112222-3333-4444-5555-666677778888";
58-
const resourceGroupName =
59-
process.env["COMMUNICATION_RESOURCE_GROUP"] || "MyResourceGroup";
49+
process.env["COMMUNICATION_SUBSCRIPTION_ID"] || "11112222-3333-4444-5555-666677778888";
50+
const resourceGroupName = process.env["COMMUNICATION_RESOURCE_GROUP"] || "MyResourceGroup";
6051
const communicationServiceName = "MyCommunicationResource";
6152
const parameters: CommunicationServiceResource = {
6253
dataLocation: "United States",
6354
identity: { type: "SystemAssigned" },
6455
location: "Global",
6556
};
6657
const credential = new DefaultAzureCredential();
67-
const client = new CommunicationServiceManagementClient(
68-
credential,
69-
subscriptionId,
70-
);
58+
const client = new CommunicationServiceManagementClient(credential, subscriptionId);
7159
const result = await client.communicationServices.beginCreateOrUpdateAndWait(
7260
resourceGroupName,
7361
communicationServiceName,
@@ -77,8 +65,8 @@ async function createOrUpdateResourceWithManagedIdentity(): Promise<void> {
7765
}
7866

7967
async function main(): Promise<void> {
80-
createOrUpdateResource();
81-
createOrUpdateResourceWithManagedIdentity();
68+
await createOrUpdateResource();
69+
await createOrUpdateResourceWithManagedIdentity();
8270
}
8371

8472
main().catch(console.error);

sdk/communication/arm-communication/samples-dev/communicationServicesDeleteSample.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,11 @@ import "dotenv/config";
2020
*/
2121
async function deleteResource(): Promise<void> {
2222
const subscriptionId =
23-
process.env["COMMUNICATION_SUBSCRIPTION_ID"] ||
24-
"11112222-3333-4444-5555-666677778888";
25-
const resourceGroupName =
26-
process.env["COMMUNICATION_RESOURCE_GROUP"] || "MyResourceGroup";
23+
process.env["COMMUNICATION_SUBSCRIPTION_ID"] || "11112222-3333-4444-5555-666677778888";
24+
const resourceGroupName = process.env["COMMUNICATION_RESOURCE_GROUP"] || "MyResourceGroup";
2725
const communicationServiceName = "MyCommunicationResource";
2826
const credential = new DefaultAzureCredential();
29-
const client = new CommunicationServiceManagementClient(
30-
credential,
31-
subscriptionId,
32-
);
27+
const client = new CommunicationServiceManagementClient(credential, subscriptionId);
3328
const result = await client.communicationServices.beginDeleteAndWait(
3429
resourceGroupName,
3530
communicationServiceName,
@@ -38,7 +33,7 @@ async function deleteResource(): Promise<void> {
3833
}
3934

4035
async function main(): Promise<void> {
41-
deleteResource();
36+
await deleteResource();
4237
}
4338

4439
main().catch(console.error);

sdk/communication/arm-communication/samples-dev/communicationServicesGetSample.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,11 @@ import "dotenv/config";
2020
*/
2121
async function getResource(): Promise<void> {
2222
const subscriptionId =
23-
process.env["COMMUNICATION_SUBSCRIPTION_ID"] ||
24-
"11112222-3333-4444-5555-666677778888";
25-
const resourceGroupName =
26-
process.env["COMMUNICATION_RESOURCE_GROUP"] || "MyResourceGroup";
23+
process.env["COMMUNICATION_SUBSCRIPTION_ID"] || "11112222-3333-4444-5555-666677778888";
24+
const resourceGroupName = process.env["COMMUNICATION_RESOURCE_GROUP"] || "MyResourceGroup";
2725
const communicationServiceName = "MyCommunicationResource";
2826
const credential = new DefaultAzureCredential();
29-
const client = new CommunicationServiceManagementClient(
30-
credential,
31-
subscriptionId,
32-
);
27+
const client = new CommunicationServiceManagementClient(credential, subscriptionId);
3328
const result = await client.communicationServices.get(
3429
resourceGroupName,
3530
communicationServiceName,
@@ -38,7 +33,7 @@ async function getResource(): Promise<void> {
3833
}
3934

4035
async function main(): Promise<void> {
41-
getResource();
36+
await getResource();
4237
}
4338

4439
main().catch(console.error);

sdk/communication/arm-communication/samples-dev/communicationServicesLinkNotificationHubSample.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
// Copyright (c) Microsoft Corporation.
1010
// Licensed under the MIT License.
11-
import {
11+
import type {
1212
LinkNotificationHubParameters,
1313
CommunicationServicesLinkNotificationHubOptionalParams,
14-
CommunicationServiceManagementClient,
1514
} from "@azure/arm-communication";
15+
import { CommunicationServiceManagementClient } from "@azure/arm-communication";
1616
import { DefaultAzureCredential } from "@azure/identity";
1717
import "dotenv/config";
1818

@@ -24,25 +24,19 @@ import "dotenv/config";
2424
*/
2525
async function linkNotificationHub(): Promise<void> {
2626
const subscriptionId =
27-
process.env["COMMUNICATION_SUBSCRIPTION_ID"] ||
28-
"11112222-3333-4444-5555-666677778888";
29-
const resourceGroupName =
30-
process.env["COMMUNICATION_RESOURCE_GROUP"] || "MyResourceGroup";
27+
process.env["COMMUNICATION_SUBSCRIPTION_ID"] || "11112222-3333-4444-5555-666677778888";
28+
const resourceGroupName = process.env["COMMUNICATION_RESOURCE_GROUP"] || "MyResourceGroup";
3129
const communicationServiceName = "MyCommunicationResource";
3230
const linkNotificationHubParameters: LinkNotificationHubParameters = {
33-
connectionString:
34-
"Endpoint=sb://MyNamespace.servicebus.windows.net/;SharedAccessKey=abcd1234",
31+
connectionString: "Endpoint=sb://MyNamespace.servicebus.windows.net/;SharedAccessKey=abcd1234",
3532
resourceId:
3633
"/subscriptions/11112222-3333-4444-5555-666677778888/resourceGroups/MyOtherResourceGroup/providers/Microsoft.NotificationHubs/namespaces/MyNamespace/notificationHubs/MyHub",
3734
};
3835
const options: CommunicationServicesLinkNotificationHubOptionalParams = {
3936
linkNotificationHubParameters,
4037
};
4138
const credential = new DefaultAzureCredential();
42-
const client = new CommunicationServiceManagementClient(
43-
credential,
44-
subscriptionId,
45-
);
39+
const client = new CommunicationServiceManagementClient(credential, subscriptionId);
4640
const result = await client.communicationServices.linkNotificationHub(
4741
resourceGroupName,
4842
communicationServiceName,
@@ -52,7 +46,7 @@ async function linkNotificationHub(): Promise<void> {
5246
}
5347

5448
async function main(): Promise<void> {
55-
linkNotificationHub();
49+
await linkNotificationHub();
5650
}
5751

5852
main().catch(console.error);

0 commit comments

Comments
 (0)