Skip to content
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-short-codes] Migrate to Core v2 #19043

Merged
merged 37 commits into from
Mar 15, 2022

Conversation

AlonsoMondal
Copy link
Member

@AlonsoMondal AlonsoMondal commented Dec 8, 2021

Updating the version of the autorest.typescript extension to the code generator to 6.0.0-beta.15

Main change is updating the dependencies from @azure/core-http to @azure/core-client/@azure/core-rest-pipeline packages, the client for rest http calls

Issue: #18688

Mainly following this wiki guide: https://github.com/Azure/autorest.typescript/wiki/%60core-http%60-dependency-migration-to-%60core-client%60-%60core-rest-pipeline%60

Also aiding myself with other PRs in communication that have done this, e.g. #17045

@check-enforcer
Copy link

check-enforcer bot commented Dec 8, 2021

This pull request is protected by Check Enforcer.

What is Check Enforcer?

Check Enforcer helps ensure all pull requests are covered by at least one check-run (typically an Azure Pipeline). When all check-runs associated with this pull request pass then Check Enforcer itself will pass.

Why am I getting this message?

You are getting this message because Check Enforcer did not detect any check-runs being associated with this pull request within five minutes. This may indicate that your pull request is not covered by any pipelines and so Check Enforcer is correctly blocking the pull request being merged.

What should I do now?

If the check-enforcer check-run is not passing and all other check-runs associated with this PR are passing (excluding license-cla) then you could try telling Check Enforcer to evaluate your pull request again. You can do this by adding a comment to this pull request as follows:
/check-enforcer evaluate
Typically evaulation only takes a few seconds. If you know that your pull request is not covered by a pipeline and this is expected you can override Check Enforcer using the following command:
/check-enforcer override
Note that using the override command triggers alerts so that follow-up investigations can occur (PRs still need to be approved as normal).

What if I am onboarding a new service?

Often, new services do not have validation pipelines associated with them, in order to bootstrap pipelines for a new service, you can issue the following command as a pull request comment:
/azp run prepare-pipelines
This will run a pipeline that analyzes the source tree and creates the pipelines necessary to build and validate your pull request. Once the pipeline has been created you can trigger the pipeline using the following comment:
/azp run js - [service] - ci

@AlonsoMondal
Copy link
Member Author

/azp run js - shortcodes - ci

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@AlonsoMondal
Copy link
Member Author

/azp run js - communication-short-codes - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@AlonsoMondal
Copy link
Member Author

/azp run js - communication-short-codes - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@AlonsoMondal
Copy link
Member Author

/azp run js - communication-short-codes - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@azure-sdk
Copy link
Collaborator

API changes have been detected in @azure-tools/communication-short-codes. You can review API changes here

@AlonsoMondal
Copy link
Member Author

/azp run js - communication-short-codes - tests

@azure-pipelines
Copy link

Pull request contains merge conflicts.

@AlonsoMondal
Copy link
Member Author

/azp run js - communication-short-codes - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@AlonsoMondal
Copy link
Member Author

/azp run js - communication-short-codes - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@AlonsoMondal
Copy link
Member Author

Hello @ramya-rao-a ! With the changes made up to now the node tests are passing with v2 http client, but all browser tests fail. Main message from error:
TypeError: Cannot read properties of undefined (reading 'createHash') at shaHash$1 (src/utils/cryptoUtils.ts:12:45 <- dist-test/index.browser.js:34861:48) at signRequest (src/utils/communicationAccessKeyCredentialPolicy.ts:58:29 <- dist-test/index.browser.js:34905:32)

I see that communication-common uses 2 cryptoUtils files, one called cryptoUtils.browser.ts, which in my mind would fix this issue, but how can I tell the browser tests to use this other cryptoUtils?

I have also tried debugging the browser tests but it seems it never goes through the actual cryptoUtils nor communicationAccessKeyCredentialPolicy ...
Anything you might notice?

@joheredi
Copy link
Member

Hello @ramya-rao-a ! With the changes made up to now the node tests are passing with v2 http client, but all browser tests fail. Main message from error: TypeError: Cannot read properties of undefined (reading 'createHash') at shaHash$1 (src/utils/cryptoUtils.ts:12:45 <- dist-test/index.browser.js:34861:48) at signRequest (src/utils/communicationAccessKeyCredentialPolicy.ts:58:29 <- dist-test/index.browser.js:34905:32)

I see that communication-common uses 2 cryptoUtils files, one called cryptoUtils.browser.ts, which in my mind would fix this issue, but how can I tell the browser tests to use this other cryptoUtils?

I have also tried debugging the browser tests but it seems it never goes through the actual cryptoUtils nor communicationAccessKeyCredentialPolicy ... Anything you might notice?

@AlonsoMondal, usually this node->browser mapping is set in the package.json, something like this under "browser"

{
"name": "@azure/communication-sms",
  "version": "1.1.0",
  "description": "SDK for Azure Communication SMS service which facilitates the sending of SMS messages.",
  "sdk-type": "client",
  "main": "dist/index.js",
  "module": "dist-esm/src/index.js",
  "browser": {
    "stream": "./node_modules/stream-browserify/index.js",
    "./dist-esm/src/credentials/cryptoUtils.js": "./dist-esm/src/credentials/cryptoUtils.browser.js"
  },
 ...
}

Where the key is the transpiled node/default version (see that it is pointing to the dist-esm folder and to the .js file) and the value is the transpiled browser version.

Browser bundlers would read this mapping and whenever they would use"./dist-esm/src/credentials/cryptoUtils.js" instead they would take the file set on the right side of the mapping.

This should help you with the browser tests. When setting the mappings make sure the file paths match the actual files in your dist-esm folder after building your project

@AlonsoMondal AlonsoMondal marked this pull request as ready for review December 20, 2021 23:54
@AlonsoMondal
Copy link
Member Author

/azp run js - communication-short-codes - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@danielortega-msft danielortega-msft requested review from petrsvihlik and removed request for ramya-rao-a March 10, 2022 23:21
@danielortega-msft
Copy link
Member

@petrsvihlik this PR is now updated to address your comments. Can you please review again?

CC: @rtrevino89

- Add versioning metadata to package.json
- Update changelog wording
- Import `isNode` from `@azure/test-utils`
- Restore tokenCredential explicit typing
@danielortega-msft
Copy link
Member

@petrsvihlik just pushed some changes addressing your comments. Thanks for the thorough review!

isPlaybackMode,
record,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind filing an issue to track migrating tests to the new recorder?
https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/test-utils/recorder/MIGRATION.md

Copy link
Member

@joheredi joheredi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good! Please file an issue for migrating tests to the new recorder

@danielortega-msft danielortega-msft merged commit ca2ff18 into Azure:main Mar 15, 2022
@danielortega-msft
Copy link
Member

Thanks for the reviews! I created the issue to track the test recorder migration, you can see it here: #20871.

WeiJun428 pushed a commit to WeiJun428/azure-sdk-for-js that referenced this pull request Mar 20, 2022
* changes to migrate http client

* shortcodes-http

* formatting changes

* fixing from pulling

* formatting

* credential changes for http client v2 migration

* adding browser specific utils for auth

* adding linter fixes

* fixing mocked client

* updating policy and sdk version constant

* formatting....

* re-recording node tests

* fixes needed for browser tests

* re-recording tests

* fixing unsupported ES2020 'OptionalChain' syntax

* formatting

* fixing unsupported ES2020 'OptionalChain' syntax on pending sample

* fixing unsupported ES2020 'OptionalChain' syntax

* fixed typo for shortcodes description

* retaking http migration work

* removing unnecessary file

* removing http-core library

* resolving comments

* adding re recorded tests

* resolving comments and re-recording tests

* removing unsupported chainings in samples

* fixing samples for ES2020 unsupported syntax

* formatting

* fixing samples and rerecording tests

* fixing tests to include azure on user agent.

prepared for second beta release.

* fixing error from sms. formatting.

* Update communication-common dependency to 2.0.0

Fix package-name property in autorest configuration

* Reuse auth pipelines from communication-common

Inject XHR client to fix browser tests

* Cleanup no longer needed dependencies

* Lint and format

* Expect `preferredVanityNumbers` in program briefs

* Address PR comments

- Add versioning metadata to package.json
- Update changelog wording
- Import `isNode` from `@azure/test-utils`
- Restore tokenCredential explicit typing

Co-authored-by: Daniel Ortega <[email protected]>
WeiJun428 pushed a commit to WeiJun428/azure-sdk-for-js that referenced this pull request Mar 20, 2022
* changes to migrate http client

* shortcodes-http

* formatting changes

* fixing from pulling

* formatting

* credential changes for http client v2 migration

* adding browser specific utils for auth

* adding linter fixes

* fixing mocked client

* updating policy and sdk version constant

* formatting....

* re-recording node tests

* fixes needed for browser tests

* re-recording tests

* fixing unsupported ES2020 'OptionalChain' syntax

* formatting

* fixing unsupported ES2020 'OptionalChain' syntax on pending sample

* fixing unsupported ES2020 'OptionalChain' syntax

* fixed typo for shortcodes description

* retaking http migration work

* removing unnecessary file

* removing http-core library

* resolving comments

* adding re recorded tests

* resolving comments and re-recording tests

* removing unsupported chainings in samples

* fixing samples for ES2020 unsupported syntax

* formatting

* fixing samples and rerecording tests

* fixing tests to include azure on user agent.

prepared for second beta release.

* fixing error from sms. formatting.

* Update communication-common dependency to 2.0.0

Fix package-name property in autorest configuration

* Reuse auth pipelines from communication-common

Inject XHR client to fix browser tests

* Cleanup no longer needed dependencies

* Lint and format

* Expect `preferredVanityNumbers` in program briefs

* Address PR comments

- Add versioning metadata to package.json
- Update changelog wording
- Import `isNode` from `@azure/test-utils`
- Restore tokenCredential explicit typing

Co-authored-by: Daniel Ortega <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants