-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Communication] - phone-numbers - Core V2 migration #20633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Communication] - phone-numbers - Core V2 migration #20633
Conversation
Replace usages of the old @azure/core-http package in favor of the Core V2 packages. Also, update the autorest/typescript version to the latest beta to support generating clients using the new implementation.
The phoneNumbers API uses relative URLs for the `nextLink` value, which causes issues with the Azure Core V2 library. To address this, a pipeline policy was implemented to transform any relative `nextLink` to absolute URLs.
The phoneNumbers API uses LROs with status monitors, as described in the following URL https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#long-running-operations-with-status-monitor. However, the current implementation of the @azure/core-lro library only supports this pattern if the legacy `azure-asyncoperation` header is present in the response of the operation. Thus, as a workaround to this limitation, a pipeline policy was implemented that adds this header to the responses of LROs, setting it with the same value as the `operation-location` header.
|
FYI, the following issue was created to track the LRO incompatibility: #20647 |
sdk/communication/communication-phone-numbers/src/utils/customPipelinePolicies.ts
Outdated
Show resolved
Hide resolved
| }, | ||
| }; | ||
|
|
||
| this.client = new PhoneNumbersGeneratedClient(url, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple lines above, the code to handle userAgentOptions should be removed. https://github.com/Azure/autorest.typescript/wiki/%60core-http%60-dependency-migration-to-%60core-client%60-%60core-rest-pipeline%60#remove-the-code-to-handle-useragentoptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I wasn't aware of that guide. I will update accordingly!
...rowsers/phonenumbersclient__get_phone_number/recording_can_get_a_purchased_phone_number.json
Show resolved
Hide resolved
...rsclient__lro__purchase_and_release_aad/recording_can_purchase_and_release_a_phone_number.js
Show resolved
Hide resolved
...nenumbersclient__lro__search/recording_can_search_for_1_available_phone_number_by_default.js
Show resolved
Hide resolved
...mbersclient__lro__search_aad/recording_can_search_for_1_available_phone_number_by_default.js
Show resolved
Hide resolved
...gs/node/phonenumbersclient__lro__update/recording_can_update_a_phone_numbers_capabilities.js
Show resolved
Hide resolved
sdk/communication/communication-phone-numbers/src/phoneNumbersClient.ts
Outdated
Show resolved
Hide resolved
sdk/communication/communication-phone-numbers/src/utils/customPipelinePolicies.ts
Outdated
Show resolved
Hide resolved
sdk/communication/communication-phone-numbers/test/internal/customPipelinePolicies.spec.ts
Show resolved
Hide resolved
|
@lucasrsant the phone number that is present in the recordings is actually the sanitized value. We even explicitly use it as a fake number in one of our tests: https://github.com/danielortega-msft/azure-sdk-for-js/blob/0b5233eec003cf06439612349d9023bf50fee51a/sdk/communication/communication-phone-numbers/test/public/get.spec.ts#L37. You can check in the recorded client configuration that the actual phone numbers are replaced with it. const replaceableVariables: { [k: string]: string } = {
COMMUNICATION_LIVETEST_STATIC_CONNECTION_STRING: "endpoint=https://endpoint/;accesskey=banana",
INCLUDE_PHONENUMBER_LIVE_TESTS: "false",
SKIP_UPDATE_CAPABILITIES_LIVE_TESTS: "false",
COMMUNICATION_ENDPOINT: "https://endpoint/",
AZURE_CLIENT_ID: "SomeClientId",
AZURE_CLIENT_SECRET: "azure_client_secret",
AZURE_TENANT_ID: "SomeTenantId",
AZURE_PHONE_NUMBER: "+14155550100",
COMMUNICATION_SKIP_INT_PHONENUMBERS_TESTS: "false",
}; |
Address the following feedback from the PR: - Remove the logic to generate the user agent - Specify the new major version of Azure Core used - Add integration tests between the PhoneNumbersClient and the custom policies implemented
|
@jeremymeng @Automagically @lucasrsant I updated the PR based on your comments, can you please do another review? |
The LRO bug has been fixed and I will make a release on Monday, 3/7. |
sdk/communication/communication-phone-numbers/test/internal/headers.spec.ts
Outdated
Show resolved
Hide resolved
|
API changes have been detected in API changes - export interface PhoneNumbersClientOptions extends PipelineOptions { }
+ export interface PhoneNumbersClientOptions extends CommonClientOptions { } |
jeremymeng
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I only have some minor comments.
| skip-enum-validation: true | ||
| title: Phone Numbers Client | ||
| v3: true | ||
| use-core-v2: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use-core-v2 is true now by default so this is not needed.
| * | ||
| * 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 | ||
| */ | ||
| export const phoneNumbersLroPolicy: PipelinePolicy = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe create a workitem to track removing this workaround when the LRO fix is available.
| requestContentType: "application/json; charset=utf-8" | ||
| }; | ||
|
|
||
| const packageDetails = `azsdk-js-azure-communication-phone-numbers/1.2.0-beta.2`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The azure after azsdk-js- is probably from the package-name in swagger/README.md. Could you please use @azure/communication-phone-numbers instead?
Thanks for the feedback @jeremymeng. I will merge this PR for now and, once the LRO fix is released, I will create a new one addressing your comments. |
* Migrate to Azure Core V2 Replace usages of the old @azure/core-http package in favor of the Core V2 packages. Also, update the autorest/typescript version to the latest beta to support generating clients using the new implementation. * Fix purchased phone numbers pagination The phoneNumbers API uses relative URLs for the `nextLink` value, which causes issues with the Azure Core V2 library. To address this, a pipeline policy was implemented to transform any relative `nextLink` to absolute URLs. * Workaround for LRO polling in phone-numbers sdk The phoneNumbers API uses LROs with status monitors, as described in the following URL https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#long-running-operations-with-status-monitor. However, the current implementation of the @azure/core-lro library only supports this pattern if the legacy `azure-asyncoperation` header is present in the response of the operation. Thus, as a workaround to this limitation, a pipeline policy was implemented that adds this header to the responses of LROs, setting it with the same value as the `operation-location` header. * Fix skip condition for update capabilities tests * Fix purchase and release tests, update recordings * Add changelog entry * Test integration of client and custom policies Address the following feedback from the PR: - Remove the logic to generate the user agent - Specify the new major version of Azure Core used - Add integration tests between the PhoneNumbersClient and the custom policies implemented * Run all tests * Add missing license header, lint code * Make `PhoneNumbersClientOptions` extend `CommonClientOptions` * Fix metadata paths
Packages impacted by this PR
@azure/communication-phone-numbersIssues associated with this PR
Describe the problem that is addressed by this PR
Migrate the HTTP pipeline to the new architecture in Azure Core V2. Refer to the following documentation for more details: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-rest-pipeline/documentation/core2.md
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?
For information on the Core V2 migration, refer to: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/core/core-rest-pipeline/documentation/core2.md
This migration introduced the following two compatibility issues:
nextLinkvalues in endpoints that support paging, which is not supported out-of-the-box in the new client. While the current REST API guidelines state that they should be absolute URLs, this was introduced after the initial release of the API (for more details, see the PR discussion that introduced the change).operation-locationheader; however, the@azure/core-lroimplementation expects it to be in the legacyazure-asyncoperationheader. While the current version of the guidelines discourage the later approach, they indicate that client code should look for both. For more details, refer to the Azure REST API guidelines.In order to solve both issues, custom pipeline policies were implemented to make the HTTP responses have the form expected by the Core V2 libraries. These policies are workarounds and should be cleaned up once the incompatibilities are addressed.
Are there test cases added in this PR? (If not, why?)
Yes, the test cases for the policies implemented as workarounds for compatibility issues.
Provide a list of related PRs (if any)
Checklists