Skip to content

Commit 7277dd6

Browse files
committed
Few changes:
- Remove deprecated aliases: FetchWrapper and FetchMiddleware - Rename applyMiddleware to applyMiddlewares - Ignore lint errors because of `console` usage adding a warning to the JSDoc
1 parent a2eeca0 commit 7277dd6

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

src/client/middleware.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
2-
withOAuth,
3-
withLogging,
4-
applyMiddleware,
5-
createMiddleware,
2+
withOAuth,
3+
withLogging,
4+
applyMiddlewares,
5+
createMiddleware,
66
} from "./middleware.js";
77
import { OAuthClientProvider } from "./auth.js";
88
import { FetchLike } from "../shared/transport.js";
@@ -677,7 +677,7 @@ describe("applyMiddleware", () => {
677677
const response = new Response("success", { status: 200 });
678678
mockFetch.mockResolvedValue(response);
679679

680-
const composedFetch = applyMiddleware()(mockFetch);
680+
const composedFetch = applyMiddlewares()(mockFetch);
681681

682682
expect(composedFetch).toBe(mockFetch);
683683
});
@@ -694,7 +694,7 @@ describe("applyMiddleware", () => {
694694
return next(input, { ...init, headers });
695695
};
696696

697-
const composedFetch = applyMiddleware(middleware1)(mockFetch);
697+
const composedFetch = applyMiddlewares(middleware1)(mockFetch);
698698

699699
await composedFetch("https://api.example.com/data");
700700

@@ -736,7 +736,7 @@ describe("applyMiddleware", () => {
736736
return next(input, { ...init, headers });
737737
};
738738

739-
const composedFetch = applyMiddleware(
739+
const composedFetch = applyMiddlewares(
740740
middleware1,
741741
middleware2,
742742
middleware3,
@@ -765,7 +765,7 @@ describe("applyMiddleware", () => {
765765

766766
// Use custom logger to avoid console output
767767
const mockLogger = jest.fn();
768-
const composedFetch = applyMiddleware(
768+
const composedFetch = applyMiddlewares(
769769
oauthMiddleware,
770770
withLogging({ logger: mockLogger, statusLevel: 0 }),
771771
)(mockFetch);
@@ -803,7 +803,7 @@ describe("applyMiddleware", () => {
803803
const originalError = new Error("Network failure");
804804
mockFetch.mockRejectedValue(originalError);
805805

806-
const composedFetch = applyMiddleware(errorMiddleware)(mockFetch);
806+
const composedFetch = applyMiddlewares(errorMiddleware)(mockFetch);
807807

808808
await expect(composedFetch("https://api.example.com/data")).rejects.toThrow(
809809
"Middleware error: Network failure",
@@ -853,7 +853,7 @@ describe("Integration Tests", () => {
853853

854854
// Use custom logger to avoid console output
855855
const mockLogger = jest.fn();
856-
const enhancedFetch = applyMiddleware(
856+
const enhancedFetch = applyMiddlewares(
857857
withOAuth(
858858
mockProvider as OAuthClientProvider,
859859
"https://mcp-server.example.com",
@@ -903,7 +903,7 @@ describe("Integration Tests", () => {
903903

904904
// Use custom logger to avoid console output
905905
const mockLogger = jest.fn();
906-
const enhancedFetch = applyMiddleware(
906+
const enhancedFetch = applyMiddlewares(
907907
withOAuth(
908908
mockProvider as OAuthClientProvider,
909909
"https://streamable-server.example.com",
@@ -971,7 +971,7 @@ describe("Integration Tests", () => {
971971

972972
// Use custom logger to avoid console output
973973
const mockLogger = jest.fn();
974-
const enhancedFetch = applyMiddleware(
974+
const enhancedFetch = applyMiddlewares(
975975
withOAuth(
976976
mockProvider as OAuthClientProvider,
977977
"https://mcp-server.example.com",
@@ -1177,7 +1177,7 @@ describe("createMiddleware", () => {
11771177
});
11781178

11791179
// Compose with existing middleware
1180-
const enhancedFetch = applyMiddleware(
1180+
const enhancedFetch = applyMiddlewares(
11811181
customAuth,
11821182
customLogging,
11831183
withLogging({ statusLevel: 400 }),

src/client/middleware.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@ import { FetchLike } from "../shared/transport.js";
1212
*/
1313
export type Middleware = (next: FetchLike) => FetchLike;
1414

15-
/**
16-
* @deprecated Use Middleware instead
17-
*/
18-
export type FetchWrapper = Middleware;
19-
20-
/**
21-
* @deprecated Use Middleware instead
22-
*/
23-
export type FetchMiddleware = Middleware;
24-
2515
/**
2616
* Creates a fetch wrapper that handles OAuth authentication automatically.
2717
*
@@ -163,12 +153,15 @@ export type LoggingOptions = {
163153
* Creates a fetch middleware that logs HTTP requests and responses.
164154
*
165155
* When called without arguments `withLogging()`, it uses the default logger that:
166-
* - Logs successful requests (2xx) to console.log
167-
* - Logs error responses (4xx/5xx) and network errors to console.error
156+
* - Logs successful requests (2xx) to `console.log`
157+
* - Logs error responses (4xx/5xx) and network errors to `console.error`
168158
* - Logs all requests regardless of status (statusLevel: 0)
169159
* - Does not include request or response headers in logs
170160
* - Measures and displays request duration in milliseconds
171161
*
162+
* Important: the default logger uses both `console.log` and `console.error` so it should not be used with
163+
* `stdio` transports and applications.
164+
*
172165
* @param options - Logging configuration options
173166
* @returns A fetch middleware function
174167
*/
@@ -212,8 +205,10 @@ export const withLogging = (options: LoggingOptions = {}): Middleware => {
212205
}
213206

214207
if (error || status >= 400) {
208+
// eslint-disable-next-line no-console
215209
console.error(message);
216210
} else {
211+
// eslint-disable-next-line no-console
217212
console.log(message);
218213
}
219214
};
@@ -274,7 +269,7 @@ export const withLogging = (options: LoggingOptions = {}): Middleware => {
274269
* @example
275270
* ```typescript
276271
* // Create a middleware pipeline that handles both OAuth and logging
277-
* const enhancedFetch = applyMiddleware(
272+
* const enhancedFetch = applyMiddlewares(
278273
* withOAuth(oauthProvider, 'https://api.example.com'),
279274
* withLogging({ statusLevel: 400 })
280275
* )(fetch);
@@ -286,7 +281,7 @@ export const withLogging = (options: LoggingOptions = {}): Middleware => {
286281
* @param middleware - Array of fetch middleware to compose into a pipeline
287282
* @returns A single composed middleware function
288283
*/
289-
export const applyMiddleware = (
284+
export const applyMiddlewares = (
290285
...middleware: Middleware[]
291286
): Middleware => {
292287
return (next) => {

0 commit comments

Comments
 (0)