-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
es2020
.es2020
5b23bd2
to
c6c6ecb
Compare
@@ -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); |
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.
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); |
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.
serverTelemetryManager.cacheFailedRequest(e)
expects an instance of AuthError
. We can't pass an arbitrary error.
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.
If serverTelemetryManager.cacheFailedRequest()
is able to accept any types of error, do these need to be reverted? (and below)
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.
I have already reverted it but forgot to resolve the comment. Sorry about that.
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.
But cacheFailedRequest
is still being called inside the if (e instanceof AuthError)
block
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.
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"; |
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.
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>> { |
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.
T
must extend ServerAuthorizationTokenResponse
because ThrottlingUtils.postProcess()
expects it as an input.
Codecov Report
*This pull request uses carry forward flags. Click here to find out more. |
99a26cf
to
eba9ef4
Compare
lib/msal-react/tsconfig.json
Outdated
@@ -2,6 +2,7 @@ | |||
"include": ["src", "types", "test"], | |||
"compilerOptions": { | |||
"module": "esnext", | |||
"target": "esnext", |
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.
Required for proper class transpiling.
415441b
to
288d07a
Compare
a71ef64
to
629d84d
Compare
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.
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); |
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.
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.
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.
Same comment, similar pattern below.
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.
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 |
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 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?
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.
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.
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.
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.
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.
@@ -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 { |
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.
Not as terse, but so much more readable. :)
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.
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", |
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.
If changes reverted, shouldn't this file be deleted?
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 for addressing comments!
- 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.
- 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.
🎉 Handy links: |
typescript
to 4.9.5.es2020
when applicable.mocked()
fromts-jest/utils
withjest.spyOn()
.ServerAuthorizationTokenResponse
forNetworkManager.sendPostRequest()
inmsal-common
to handle post processing properly.serverTelemetryManager.cacheFailedRequest()
accept any types of errors.