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

Bump typescript to 4.9.5 and build target to es2020 #5750

Merged
merged 19 commits into from
Mar 10, 2023

Conversation

konstantin-msft
Copy link
Collaborator

@konstantin-msft konstantin-msft commented Mar 2, 2023

  • Bump typescript to 4.9.5.
  • Bump target/module versions to es2020 when applicable.
  • Replace calls to deprecated mocked() from ts-jest/utils with jest.spyOn().
  • Fix types' coercions to facilitate compatibility with the new ts version.
  • Make generic type extend ServerAuthorizationTokenResponse for NetworkManager.sendPostRequest() in msal-common to handle post processing properly.
  • Make serverTelemetryManager.cacheFailedRequest() accept any types of errors.

@konstantin-msft konstantin-msft changed the title Bump typescript to 4.9.5 and ecma build target to es2020. Bump typescript to 4.9.5 and ecma build target to es2020 Mar 2, 2023
@github-actions github-actions bot added msal-browser Related to msal-browser package msal-common Related to msal-common package msal-node Related to msal-node package msal-react Related to @azure/msal-react [email protected] Related to [email protected] (implicit flow) node-token-validation samples Related to the samples apps for the library. labels Mar 2, 2023
@konstantin-msft konstantin-msft changed the base branch from dev to msal-browser-v3 March 2, 2023 18:52
@konstantin-msft konstantin-msft force-pushed the 2069323_bump_ts_to_v4 branch from 5b23bd2 to c6c6ecb Compare March 2, 2023 18:53
@github-actions github-actions bot removed the samples Related to the samples apps for the library. label Mar 2, 2023
@@ -44,7 +44,7 @@ export class AuthToken {
const base64Decoded = crypto.base64Decode(base64TokenPayload);
return JSON.parse(base64Decoded) as TokenClaims;
} catch (err) {
throw ClientAuthError.createTokenParsingError(err);
throw ClientAuthError.createTokenParsingError(err as string);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Type coercions are prohibited in ts v4.

@@ -162,8 +162,8 @@ export abstract class ClientApplication {
} catch (e) {
if (e instanceof AuthError) {
e.setCorrelationId(validRequest.correlationId);
serverTelemetryManager.cacheFailedRequest(e);
Copy link
Collaborator Author

@konstantin-msft konstantin-msft Mar 2, 2023

Choose a reason for hiding this comment

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

serverTelemetryManager.cacheFailedRequest(e) expects an instance of AuthError. We can't pass an arbitrary error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If serverTelemetryManager.cacheFailedRequest() is able to accept any types of error, do these need to be reverted? (and below)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have already reverted it but forgot to resolve the comment. Sorry about that.

Copy link
Collaborator

@jo-arroyo jo-arroyo Mar 10, 2023

Choose a reason for hiding this comment

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

But cacheFailedRequest is still being called inside the if (e instanceof AuthError) block

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Completely forgot about msal-node module. Good catch, thank you. Fixed.

@@ -1,11 +1,11 @@
import { ClientAssertion } from "../../src/client/ClientAssertion";
import { TEST_CONSTANTS } from "../utils/TestConstants";
import { CryptoProvider } from "../../src/crypto/CryptoProvider";
import { sign } from "jsonwebtoken";
import { mocked } from "ts-jest/utils";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Deprecated

@@ -31,7 +32,7 @@ export class NetworkManager {
* @param tokenEndpoint
* @param options
*/
async sendPostRequest<T>(thumbprint: RequestThumbprint, tokenEndpoint: string, options: NetworkRequestOptions): Promise<NetworkResponse<T>> {
async sendPostRequest<T extends ServerAuthorizationTokenResponse>(thumbprint: RequestThumbprint, tokenEndpoint: string, options: NetworkRequestOptions): Promise<NetworkResponse<T>> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

T must extend ServerAuthorizationTokenResponse because ThrottlingUtils.postProcess() expects it as an input.

@github-actions github-actions bot removed the msal-react Related to @azure/msal-react label Mar 2, 2023
@codecov-commenter
Copy link

codecov-commenter commented Mar 2, 2023

Codecov Report

❗ No coverage uploaded for pull request base (msal-browser-v3@8b576a2). Click here to learn what that means.
The diff coverage is n/a.

Flag Coverage Δ *Carryforward flag
msal-common 85.32% <0.00%> (?)
msal-node-extensions 45.81% <0.00%> (?) Carriedforward from 185b755
msal-react 94.82% <0.00%> (?)
node-token-validation 87.28% <0.00%> (?)

*This pull request uses carry forward flags. Click here to find out more.

@konstantin-msft konstantin-msft force-pushed the 2069323_bump_ts_to_v4 branch from 99a26cf to eba9ef4 Compare March 3, 2023 02:12
@github-actions github-actions bot added the msal-react Related to @azure/msal-react label Mar 3, 2023
@@ -2,6 +2,7 @@
"include": ["src", "types", "test"],
"compilerOptions": {
"module": "esnext",
"target": "esnext",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Required for proper class transpiling.

Copy link
Contributor

@peterzenz peterzenz left a comment

Choose a reason for hiding this comment

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

I have the questions I mentioned in teams about the explicit type changes for TS4 and how those resolve. I'd also like some clarity on the ts-ignores as to what it would take to address those correctly. If we want this in though now to unblock I'm OK, but please track bugs/work items around these things if they are unresolved.

@@ -190,9 +191,9 @@ export class PopupClient extends StandardInteractionClient {

if (e instanceof AuthError) {
(e as AuthError).setCorrelationId(this.correlationId);
serverTelemetryManager.cacheFailedRequest(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a functional change and not a change related to the TS/ES intent of this PR. You mention type coercion changes are not supported in the new TS and I'm seeing this pattern throughout this change. What happened in the original code if we called .cacheFailedRequest(e) and it was not of type AuthError? Did the failure cascade out from cacheFailedRequest or was it able to coerce whatever error type that was thrown into something usable? If it's not of type AuthError we might still want to cache a failed response (failure is failure...). I just don't know what other types we might get in this flow.

Copy link
Member

Choose a reason for hiding this comment

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

Same comment, similar pattern below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a very good point. I have made serverTelemetryManager.cacheFailedRequest() to accept any types of errors to make sure we cache all of them.

*/
static getBrowserNetworkClient(): INetworkModule {
// @ts-ignore TS2774
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a comment on why we're adding the ts-ignore here? Is there a future fix we're holding off on just to unblock folks?

Copy link
Contributor

Choose a reason for hiding this comment

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

As I look at the other ts-ignores around window I'm thrown back to some earlier discussions on web workers not supporting window references. @sameerag or @tnorling I thought there were some alternates here that might be more friendly. I'll admit though I'm not up to speed on the new TS/ES changes that might impact here.

Copy link
Member

Choose a reason for hiding this comment

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

Reading this, I get that we are checking if window.fetch and window.headers are defined, what is the alternative here?

May be a try .. catch where if window.fetch isn't defined, we cannot call the fetchClient anyway. I am not sure if that actually throws though but worth a try.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately, try .. catch won't help here.
image

@@ -6,7 +6,33 @@
import sinon from "sinon";
import { PublicClientApplication } from "../../src/app/PublicClientApplication";
import { TEST_CONFIG, TEST_URIS, TEST_HASHES, TEST_TOKENS, TEST_DATA_CLIENT_INFO, TEST_TOKEN_LIFETIMES, RANDOM_TEST_GUID, DEFAULT_OPENID_CONFIG_RESPONSE, testNavUrl, TEST_STATE_VALUES, DEFAULT_TENANT_DISCOVERY_RESPONSE, testLogoutUrl, TEST_SSH_VALUES } from "../utils/StringConstants";
import { ServerError, Constants, AccountInfo, TokenClaims, AuthenticationResult, CommonAuthorizationCodeRequest, CommonAuthorizationUrlRequest, AuthToken, PersistentCacheKeys, AuthorizationCodeClient, ResponseMode, ProtocolUtils, AuthenticationScheme, Logger, ServerTelemetryEntity, LogLevel, NetworkResponse, ServerAuthorizationTokenResponse, CcsCredential, CcsCredentialType, CommonEndSessionRequest, ServerTelemetryManager, AccountEntity, ClientConfigurationError } from "@azure/msal-common";
import {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not as terse, but so much more readable. :)

Copy link
Member

Choose a reason for hiding this comment

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

At some point I had all files like this. Can we make this a standard?

{
"type": "minor",
"comment": "Bump typescript to 4.9.5 and target/module to es2020 #5750",
"packageName": "msal",
Copy link
Collaborator

Choose a reason for hiding this comment

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

If changes reverted, shouldn't this file be deleted?

extensions/msal-node-extensions/tsconfig.json Outdated Show resolved Hide resolved
Copy link
Collaborator

@jo-arroyo jo-arroyo left a comment

Choose a reason for hiding this comment

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

Thanks for addressing comments!

@konstantin-msft konstantin-msft merged commit 1e3e660 into msal-browser-v3 Mar 10, 2023
@konstantin-msft konstantin-msft deleted the 2069323_bump_ts_to_v4 branch March 10, 2023 23:32
konstantin-msft added a commit that referenced this pull request Mar 31, 2023
- Bump `typescript` to 4.9.5.
- Bump target/module versions to `es2020` when applicable.
- Replace calls to deprecated `mocked()` from `ts-jest/utils` with
`jest.spyOn()`.
- Fix types' coercions to facilitate compatibility with the new ts
version.
- Make generic type extend `ServerAuthorizationTokenResponse` for
`NetworkManager.sendPostRequest()` in `msal-common` to handle post
processing properly.
- Make `serverTelemetryManager.cacheFailedRequest()` accept any types of
errors.
hectormmg pushed a commit that referenced this pull request Apr 4, 2023
- Bump `typescript` to 4.9.5.
- Bump target/module versions to `es2020` when applicable.
- Replace calls to deprecated `mocked()` from `ts-jest/utils` with
`jest.spyOn()`.
- Fix types' coercions to facilitate compatibility with the new ts
version.
- Make generic type extend `ServerAuthorizationTokenResponse` for
`NetworkManager.sendPostRequest()` in `msal-common` to handle post
processing properly.
- Make `serverTelemetryManager.cacheFailedRequest()` accept any types of
errors.
@ghost
Copy link

ghost commented Jun 19, 2023

🎉@azure/[email protected] has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extensions Related to extensions for the base libraries msal-browser Related to msal-browser package msal-common Related to msal-common package msal-node Related to msal-node package msal-react Related to @azure/msal-react node-token-validation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants