wrangler 0.0.0-e928f94 → 0.0.0-e9a1820

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/user.tsx CHANGED
@@ -578,19 +578,16 @@ export async function getAuthURL(scopes?: string[]): Promise<string> {
578
578
  * Refresh an access token from the remote service.
579
579
  */
580
580
  async function exchangeRefreshTokenForAccessToken(): Promise<AccessContext> {
581
- const { refreshToken } = LocalState;
582
-
583
- if (!refreshToken) {
581
+ if (!LocalState.refreshToken) {
584
582
  console.warn("No refresh token is present.");
585
583
  }
586
584
 
587
- const url = TOKEN_URL;
588
585
  const body =
589
586
  `grant_type=refresh_token&` +
590
- `refresh_token=${refreshToken?.value}&` +
587
+ `refresh_token=${LocalState.refreshToken?.value}&` +
591
588
  `client_id=${CLIENT_ID}`;
592
589
 
593
- const response = await fetch(url, {
590
+ const response = await fetch(TOKEN_URL, {
594
591
  method: "POST",
595
592
  body,
596
593
  headers: {
@@ -617,10 +614,9 @@ async function exchangeRefreshTokenForAccessToken(): Promise<AccessContext> {
617
614
  LocalState.accessToken = accessToken;
618
615
 
619
616
  if (refresh_token) {
620
- const refreshToken: RefreshToken = {
617
+ LocalState.refreshToken = {
621
618
  value: refresh_token,
622
619
  };
623
- LocalState.refreshToken = refreshToken;
624
620
  }
625
621
 
626
622
  if (scope) {
@@ -666,7 +662,6 @@ async function exchangeAuthCodeForAccessToken(): Promise<AccessContext> {
666
662
  console.warn("No authorization grant code is being passed.");
667
663
  }
668
664
 
669
- const url = TOKEN_URL;
670
665
  const body =
671
666
  `grant_type=authorization_code&` +
672
667
  `code=${encodeURIComponent(authorizationCode || "")}&` +
@@ -674,7 +669,7 @@ async function exchangeAuthCodeForAccessToken(): Promise<AccessContext> {
674
669
  `client_id=${encodeURIComponent(CLIENT_ID)}&` +
675
670
  `code_verifier=${codeVerifier}`;
676
671
 
677
- const response = await fetch(url, {
672
+ const response = await fetch(TOKEN_URL, {
678
673
  method: "POST",
679
674
  body,
680
675
  headers: {
@@ -709,10 +704,9 @@ async function exchangeAuthCodeForAccessToken(): Promise<AccessContext> {
709
704
  LocalState.accessToken = accessToken;
710
705
 
711
706
  if (refresh_token) {
712
- const refreshToken: RefreshToken = {
707
+ LocalState.refreshToken = {
713
708
  value: refresh_token,
714
709
  };
715
- LocalState.refreshToken = refreshToken;
716
710
  }
717
711
 
718
712
  if (scope) {
@@ -816,7 +810,7 @@ export async function loginOrRefreshIfRequired(): Promise<boolean> {
816
810
 
817
811
  export async function login(props?: LoginProps): Promise<boolean> {
818
812
  const urlToOpen = await getAuthURL(props?.scopes);
819
- open(urlToOpen);
813
+ await open(urlToOpen);
820
814
  // TODO: log url only if on system where it's unreliable/unavailable
821
815
  // console.log(`💁 Opened ${urlToOpen}`);
822
816
  let server;
@@ -921,15 +915,14 @@ export async function refreshToken(): Promise<boolean> {
921
915
 
922
916
  export async function logout(): Promise<void> {
923
917
  throwIfNotInitialised();
924
- const { refreshToken } = LocalState;
925
- if (!refreshToken) {
918
+ if (!LocalState.refreshToken) {
926
919
  console.log("Not logged in, exiting...");
927
920
  return;
928
921
  }
929
922
  const body =
930
923
  `client_id=${encodeURIComponent(CLIENT_ID)}&` +
931
924
  `token_type_hint=refresh_token&` +
932
- `token=${encodeURIComponent(refreshToken?.value || "")}`;
925
+ `token=${encodeURIComponent(LocalState.refreshToken?.value || "")}`;
933
926
 
934
927
  const response = await fetch(REVOKE_URL, {
935
928
  method: "POST",