Skip to content

Commit 136b589

Browse files
[Communication] - phone-numbers - Azure Core V2 migration cleanup (Azure#20696)
1 parent 0555acb commit 136b589

File tree

9 files changed

+10
-137
lines changed

9 files changed

+10
-137
lines changed

sdk/communication/communication-phone-numbers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"@azure/core-auth": "^1.3.0",
6666
"@azure/core-client": "^1.3.0",
6767
"@azure/core-rest-pipeline": "^1.3.0",
68-
"@azure/core-lro": "^2.2.0",
68+
"@azure/core-lro": "^2.2.4",
6969
"@azure/core-paging": "^1.1.1",
7070
"@azure/core-tracing": "1.0.0-preview.13",
7171
"@azure/logger": "^1.0.0",

sdk/communication/communication-phone-numbers/src/generated/src/phoneNumbersClientContext.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/communication-phone-numbers/src/phoneNumbersClient.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ import {
3232
BeginSearchAvailablePhoneNumbersOptions,
3333
BeginUpdatePhoneNumberCapabilitiesOptions,
3434
} from "./lroModels";
35-
import {
36-
createPhoneNumbersPagingPolicy,
37-
phoneNumbersLroPolicy,
38-
} from "./utils/customPipelinePolicies";
35+
import { createPhoneNumbersPagingPolicy } from "./utils/customPipelinePolicies";
3936
import { CommonClientOptions } from "@azure/core-client";
4037

4138
/**
@@ -106,10 +103,9 @@ export class PhoneNumbersClient {
106103
const authPolicy = createCommunicationAuthPolicy(credential);
107104
this.client.pipeline.addPolicy(authPolicy);
108105

109-
// These policies are temporary workarounds to address compatibility issues with Azure Core V2.
106+
// This policy is temporary workarounds to address compatibility issues with Azure Core V2.
110107
const phoneNumbersPagingPolicy = createPhoneNumbersPagingPolicy(url);
111108
this.client.pipeline.addPolicy(phoneNumbersPagingPolicy);
112-
this.client.pipeline.addPolicy(phoneNumbersLroPolicy);
113109
}
114110

115111
/**

sdk/communication/communication-phone-numbers/src/utils/customPipelinePolicies.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,3 @@ export function createPhoneNumbersPagingPolicy(host: string): PipelinePolicy {
3434
},
3535
};
3636
}
37-
38-
/**
39-
* A `PipelinePolicy` that adds the `azure-asyncoperation` header to the request with the
40-
* same value as the `operation-location` header, if it exists.
41-
*
42-
* This is used because the phone-numbers API uses LROs with status monitors, but
43-
* the Core V2 LRO implementation only supports this pattern if the legacy
44-
* `azure-asyncoperation` header is present.
45-
*
46-
* For more information on the LRO guidelines, refer to: https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#long-running-operations-with-status-monitor
47-
*/
48-
export const phoneNumbersLroPolicy: PipelinePolicy = {
49-
name: "phoneNumbersLroPolicy",
50-
async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {
51-
const response = await next(request);
52-
53-
const operationLocation = response.headers?.get("operation-location");
54-
if (operationLocation) {
55-
response.headers.set("azure-asyncoperation", operationLocation);
56-
}
57-
58-
return response;
59-
},
60-
};

sdk/communication/communication-phone-numbers/swagger/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
## Configuration
66

77
```yaml
8-
package-name: azure-communication-phone-numbers
8+
package-name: "@azure/communication-phone-numbers"
99
description: Phone number configuration client
1010
package-version: 1.2.0-beta.2
1111
generate-metadata: false
@@ -23,7 +23,6 @@ azure-arm: false
2323
skip-enum-validation: true
2424
title: Phone Numbers Client
2525
v3: true
26-
use-core-v2: true
2726
```
2827
2928
## Customizations

sdk/communication/communication-phone-numbers/test/internal/customPipelinePolicies.spec.ts

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@
22
// Licensed under the MIT license.
33

44
import { FullOperationResponse } from "@azure/core-client";
5-
import {
6-
HttpHeaders,
7-
PipelineRequest,
8-
PipelineResponse,
9-
createHttpHeaders,
10-
} from "@azure/core-rest-pipeline";
5+
import { PipelineRequest, PipelineResponse, createHttpHeaders } from "@azure/core-rest-pipeline";
116
import { assert } from "chai";
12-
import {
13-
createPhoneNumbersPagingPolicy,
14-
phoneNumbersLroPolicy,
15-
} from "../../src/utils/customPipelinePolicies";
7+
import { createPhoneNumbersPagingPolicy } from "../../src/utils/customPipelinePolicies";
168

179
describe("phoneNumbersPagingPolicy", function () {
1810
const endpoint = "https://contoso.spool.azure.local";
@@ -79,39 +71,3 @@ describe("phoneNumbersPagingPolicy", function () {
7971
);
8072
});
8173
});
82-
83-
describe("phoneNumbersLroPolicy", function () {
84-
const request: PipelineRequest = {
85-
url: "https://contoso.spool.azure.local/availablePhoneNumbers/countries/{countryCode}/:search",
86-
method: "POST",
87-
headers: createHttpHeaders(),
88-
timeout: 0,
89-
withCredentials: false,
90-
requestId: "any-id",
91-
};
92-
93-
async function createMockResponse(headers: HttpHeaders) {
94-
return Promise.resolve({ headers }) as unknown as PipelineResponse;
95-
}
96-
97-
it("sets azure-asyncoperation header", async function () {
98-
const headers = createHttpHeaders();
99-
headers.set("operation-location", "/phoneNumbers/operations/search_12345");
100-
const response = await phoneNumbersLroPolicy.sendRequest(request, (_request) =>
101-
createMockResponse(headers)
102-
);
103-
assert.exists(response.headers.get("azure-asyncoperation"));
104-
assert.equal(
105-
response.headers.get("azure-asyncoperation"),
106-
"/phoneNumbers/operations/search_12345"
107-
);
108-
});
109-
110-
it("does not mutate headers without operation-location", async function () {
111-
const response = await phoneNumbersLroPolicy.sendRequest(request, (_request) =>
112-
createMockResponse(createHttpHeaders())
113-
);
114-
assert.isUndefined(response.headers.get("azure-asyncoperation"));
115-
assert.deepEqual(response.headers, createHttpHeaders());
116-
});
117-
});

sdk/communication/communication-phone-numbers/test/internal/headers.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("PhoneNumbersClient - headers", function () {
4444
const userAgentHeader = isNode ? "user-agent" : "x-ms-useragent";
4545
assert.match(
4646
request.headers.get(userAgentHeader) as string,
47-
new RegExp(`azsdk-js-azure-communication-phone-numbers/${SDK_VERSION}`, "g")
47+
new RegExp(`azsdk-js-communication-phone-numbers/${SDK_VERSION}`, "g")
4848
);
4949
});
5050

@@ -112,7 +112,7 @@ describe("PhoneNumbersClient - headers", function () {
112112
assert.match(
113113
request.headers.get(userAgentHeader) as string,
114114
new RegExp(
115-
`phonenumbersclient-headers-test azsdk-js-azure-communication-phone-numbers/${SDK_VERSION}`,
115+
`phonenumbersclient-headers-test azsdk-js-communication-phone-numbers/${SDK_VERSION}`,
116116
"g"
117117
)
118118
);

sdk/communication/communication-phone-numbers/test/internal/phoneNumbersClientPolicies.spec.ts

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,14 @@
33

44
import { AzureKeyCredential } from "@azure/core-auth";
55
import { assert } from "chai";
6-
import { SearchAvailablePhoneNumbersRequest } from "../../src/models";
76
import { PhoneNumbersClient } from "../../src/phoneNumbersClient";
8-
import {
9-
mockListPhoneNumbersHttpClient,
10-
mockSearchHttpClient,
11-
} from "../public/utils/mockHttpClients";
7+
import { mockListPhoneNumbersHttpClient } from "../public/utils/mockHttpClients";
128

139
describe("PhoneNumbersClient - custom policies ", function () {
1410
const endpoint = "https://contoso.spool.azure.local";
1511
const accessKey = "banana";
1612
let client: PhoneNumbersClient;
1713

18-
it("applies the phoneNumbersLroPolicy", async function () {
19-
client = new PhoneNumbersClient(endpoint, new AzureKeyCredential(accessKey), {
20-
httpClient: mockSearchHttpClient,
21-
});
22-
23-
const searchRequest: SearchAvailablePhoneNumbersRequest = {
24-
countryCode: "US",
25-
phoneNumberType: "tollFree",
26-
assignmentType: "application",
27-
capabilities: {
28-
sms: "none",
29-
calling: "outbound",
30-
},
31-
};
32-
33-
const poller = await client.beginSearchAvailablePhoneNumbers(searchRequest, {
34-
onResponse: (_response) => {
35-
assert.isDefined(_response.headers.get("azure-asyncoperation"));
36-
assert.equal(
37-
_response.headers.get("azure-asyncopearation"),
38-
_response.headers.get("opearation-location")
39-
);
40-
},
41-
});
42-
43-
// It is only required to poll once to check if the initial request contains the header
44-
await poller.poll();
45-
});
46-
4714
it("applies the phoneNumbersPagingPolicy", async function () {
4815
client = new PhoneNumbersClient(endpoint, new AzureKeyCredential(accessKey), {
4916
httpClient: mockListPhoneNumbersHttpClient,

sdk/communication/communication-phone-numbers/test/public/utils/mockHttpClients.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
HttpHeaders,
77
PipelineRequest,
88
PipelineResponse,
9-
createHttpHeaders,
109
} from "@azure/core-rest-pipeline";
1110
import { PurchasedPhoneNumber } from "../../../src";
1211
import { PurchasedPhoneNumbers } from "../../../src/generated/src/models";
@@ -49,26 +48,6 @@ export const getPhoneNumberHttpClient: HttpClient = createMockHttpClient<Purchas
4948
}
5049
);
5150

52-
function createMockSearchResponseHeaders(): HttpHeaders {
53-
const headers = createHttpHeaders();
54-
headers.set(
55-
"Operation-Location",
56-
"/phoneNumbers/operations/search_378ddf60-81be-452a-ba4f-613198ea6c28"
57-
);
58-
headers.set(
59-
"Location",
60-
"/availablePhoneNumbers/searchResults/378ddf60-81be-452a-ba4f-613198ea6c28"
61-
);
62-
headers.set("operation-id", "search_378ddf60-81be-452a-ba4f-613198ea6c28");
63-
headers.set("search-id", "378ddf60-81be-452a-ba4f-613198ea6c28");
64-
return headers;
65-
}
66-
export const mockSearchHttpClient = createMockHttpClient(
67-
202,
68-
null,
69-
createMockSearchResponseHeaders()
70-
);
71-
7251
export const mockListPhoneNumbersHttpClient = createMockHttpClient<PurchasedPhoneNumbers>(200, {
7352
phoneNumbers: [
7453
{

0 commit comments

Comments
 (0)