Skip to content

v0.10.0

Compare
Choose a tag to compare
@github-actions github-actions released this 26 Nov 01:06

v0.10.0 is here! πŸŽ‰

Features

  • πŸ›‘οΈ Reject local unhandled requests (83e0126):

    Local HTTP interceptors are now capable of rejecting unhandled requests with action: 'reject'. This is useful when you want to ensure that unhandled requests cause a request error. For backward compatibility, the default behavior in local interceptors is still to bypass unhandled requests. Learn more.

  • πŸ’‘ Improved unhandled request API (e53cb89)

    To preserve the previous behavior, you can use action: 'bypass' for local interceptors and action: 'reject' for remote interceptors.

    Migration guide:
    • If you set an unhandled request strategy for a local interceptor, add action: 'bypass' to preserve the previous behavior.

      const interceptor = httpInterceptor.create<Schema>({
        type: 'local',
      - onUnhandledRequest: { log: false },
      + onUnhandledRequest: { action: 'bypass', log: false },
      });
      
      const interceptor = httpInterceptor.create<Schema>({
        type: 'local',
      - onUnhandledRequest: { log: true },
      + onUnhandledRequest: { action: 'bypass', log: true },
      });
    • If you set an unhandled request strategy for a remote interceptor, add action: 'reject' to preserve the previous behavior.

      const interceptor = httpInterceptor.create<Schema>({
        type: 'remote',
      - onUnhandledRequest: { log: false },
      + onUnhandledRequest: { action: 'reject', log: false },
      });
      
      const interceptor = httpInterceptor.create<Schema>({
        type: 'remote',
      - onUnhandledRequest: { log: true },
      + onUnhandledRequest: { action: 'reject', log: true },
      });
    • If you used an unhandled request strategy function, the context parameter was removed and await context.log() can be replaced with a return of the desired strategy.

      const interceptor = httpInterceptor.create<Schema>({
        type: 'local'
      - onUnhandledRequest: async (request, context) => {
      -   const url = new URL(request.url);
      -
      -   // Ignore only unhandled requests to /assets
      -   if (!url.pathname.startsWith('/assets')) {
      -     await context.log();
      -   }
      - },
      + onUnhandledRequest: async (request) => {
      +   const url = new URL(request.url);
      +
      +   // Ignore only unhandled requests to /assets
      +   return {
      +     action: 'bypass', // Use 'reject' for remote interceptors
      +     log: !url.pathname.startsWith('/assets'),
      +   }
      + },
      });
    • If you set a default unhandled request strategy, use httpInterceptor.default.local.onUnhandledRequest or httpInterceptor.default.remote.onUnhandledRequest.

      - httpInterceptor.default.onUnhandledRequest({ log: false });
      + httpInterceptor.default.local.onUnhandledRequest = { 
      +   action: 'bypass',
      +   log: false,
      + };
      + httpInterceptor.default.remote.onUnhandledRequest = { 
      +   action: 'reject',
      +   log: false,
      + };
      - httpInterceptor.default.onUnhandledRequest({ log: true });
      + httpInterceptor.default.local.onUnhandledRequest = {
      +   action: 'bypass',
      +   log: true,
      + };
      + httpInterceptor.default.remote.onUnhandledRequest = {
      +   action: 'reject',
      +   log: true,
      + };
    • If you used a default unhandled request strategy function, the context parameter was removed and await context.log() can be replaced with a return of the desired strategy.

      - httpInterceptor.default.onUnhandledRequest(async (request, context) => {
      -   const url = new URL(request.url);
      - 
      -   if (!url.pathname.startsWith('/assets')) {
      -     await context.log();
      -   }
      - });
      
      + httpInterceptor.default.local.onUnhandledRequest = async (request) => {
      +   const url = new URL(request.url);
      +
      +   return {
      +     action: 'bypass',
      +     log: !url.pathname.startsWith('/assets'),
      +   };
      + };
      + httpInterceptor.default.remote.onUnhandledRequest = async (request) => {
      +   const url = new URL(request.url);
      +
      +   return {
      +     action: 'reject',
      +     log: !url.pathname.startsWith('/assets'),
      +   };
      + };
    • The parameter onUnhandledRequest.log in the programmatic interceptor server API was changed to logUnhandledRequests to better reflect the CLI flag.

      const server = interceptorServer.create({
        hostname: 'localhost',
        port: 3000,
      - onUnhandledRequest: { log: false },
      + logUnhandledRequests: false,
      });
    • Setting httpInterceptor.default.onUnhandledRequest no longer affects interceptor servers in the programmatic API. To change the default logging behavior, use the parameter logUnhandledRequests in interceptorServer.create(options).

  • βš™οΈ Parsed unhandled requests (39fd1bb)

    Unhandled requests are now parsed by default, just like interceptor requests. request.body, request.searchParams, and request.pathParams are now available for unhandled requests. This makes it easier to manipulate them and improves the consistency of the API.

Deprecations

  • πŸ‘‹ Removed the types deprecated in v0.9

    Full list of removed types:
    Previous (now removed) Replaced by
    HttpServiceSchema HttpSchema
    HttpServiceMethodsSchema HttpMethodsSchema
    HttpServiceMethodsSchema HttpMethodsSchema
    HttpServiceMethodSchema HttpMethodSchema
    HttpServiceRequestSchema HttpRequestSchema
    HttpServiceResponseSchemaByStatusCode HttpResponseSchemaByStatusCode
    HttpServiceResponseSchema HttpResponseSchema
    HttpServiceResponseSchemaStatusCode HttpResponseSchemaStatusCode
    HttpServiceSchemaMethod HttpSchemaMethod
    HttpServiceSchemaPath HttpSchemaPath
    LiteralHttpServiceSchemaPath HttpSchemaPath.Literal
    NonLiteralHttpServiceSchemaPath HttpSchemaPath.NonLiteral
    PathParamsSchemaFromPath InferPathParams
    ExtractHttpInterceptorSchema InferHttpInterceptorSchema

Credits

Huge thanks to @diego-aquino for helping!

Full Changelog: v0.9.5...v0.10.0