From ce632aaa3832079ef86268a2774a907e9cf3eefb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Mon, 6 Nov 2023 14:42:23 +0100 Subject: [PATCH] fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../FetchApi/IdentityAuthInjectorFetchMiddleware.ts | 10 +++++++--- .../FetchApi/PluginProtocolResolverFetchMiddleware.ts | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/core-app-api/src/apis/implementations/FetchApi/IdentityAuthInjectorFetchMiddleware.ts b/packages/core-app-api/src/apis/implementations/FetchApi/IdentityAuthInjectorFetchMiddleware.ts index 810d9e76c1..6f9733cba1 100644 --- a/packages/core-app-api/src/apis/implementations/FetchApi/IdentityAuthInjectorFetchMiddleware.ts +++ b/packages/core-app-api/src/apis/implementations/FetchApi/IdentityAuthInjectorFetchMiddleware.ts @@ -55,8 +55,12 @@ export class IdentityAuthInjectorFetchMiddleware implements FetchMiddleware { apply(next: typeof fetch): typeof fetch { return async (input, init) => { // Skip this middleware if the header already exists, or if the URL - // doesn't match any of the allowlist items, or if there was no token - const request = new Request(input, init); + // doesn't match any of the allowlist items, or if there was no token. + // NOTE(freben): The "as any" casts here and below are because of subtle + // undici type differences that happened in a node types bump. Those are + // immaterial to the code at hand at runtime, as the global fetch and + // Request are always taken from the same place. + const request = new Request(input as any, init); const { token } = await this.identityApi.getCredentials(); if ( request.headers.get(this.headerName) || @@ -64,7 +68,7 @@ export class IdentityAuthInjectorFetchMiddleware implements FetchMiddleware { !token || !this.allowUrl(request.url) ) { - return next(input, init); + return next(input as any, init); } request.headers.set(this.headerName, this.headerValue(token)); diff --git a/packages/core-app-api/src/apis/implementations/FetchApi/PluginProtocolResolverFetchMiddleware.ts b/packages/core-app-api/src/apis/implementations/FetchApi/PluginProtocolResolverFetchMiddleware.ts index ff20b594b4..e0afaed614 100644 --- a/packages/core-app-api/src/apis/implementations/FetchApi/PluginProtocolResolverFetchMiddleware.ts +++ b/packages/core-app-api/src/apis/implementations/FetchApi/PluginProtocolResolverFetchMiddleware.ts @@ -34,11 +34,15 @@ export class PluginProtocolResolverFetchMiddleware implements FetchMiddleware { apply(next: typeof fetch): typeof fetch { return async (input, init) => { - const request = new Request(input, init); + // NOTE(freben): The "as any" casts here and below are because of subtle + // undici type differences that happened in a node types bump. Those are + // immaterial to the code at hand at runtime, as the global fetch and + // Request are always taken from the same place. + const request = new Request(input as any, init); const prefix = 'plugin://'; if (!request.url.startsWith(prefix)) { - return next(input, init); + return next(input as any, init); } // Switch to a known protocol, since browser URL parsing misbehaves wildly @@ -57,7 +61,7 @@ export class PluginProtocolResolverFetchMiddleware implements FetchMiddleware { const target = `${join(base, pathname)}${search}${hash}`; return next( target, - typeof input === 'string' || isUrl(input) ? init : input, + typeof input === 'string' || isUrl(input) ? init : (input as any), ); }; }