@zimic/interceptor 0.19.1-canary.4 → 0.19.1-canary.6

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/dist/http.d.ts CHANGED
@@ -617,475 +617,81 @@ interface HttpInterceptorRequestSaving {
617
617
  /** @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference} */
618
618
  safeLimit: number;
619
619
  }
620
- /**
621
- * An interceptor to handle HTTP requests and return mock responses. The methods, paths, status codes, parameters, and
622
- * responses are statically-typed based on the provided service schema.
623
- *
624
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference}
625
- */
620
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference} */
626
621
  interface HttpInterceptor<_Schema extends HttpSchema> {
627
- /**
628
- * The base URL used by the interceptor.
629
- *
630
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorbaseurl `interceptor.baseURL` API reference}
631
- */
622
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorbaseurl `interceptor.baseURL` API reference} */
632
623
  baseURL: string;
633
- /**
634
- * Configures if the intercepted requests are saved and how they are handled.
635
- *
636
- * @see {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `createHttpInterceptor` API reference}
637
- * @see {@link https://zimic.dev/docs/interceptor/guides/http/testing Testing}
638
- */
624
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorrequestsaving `interceptor.requestSaving` API reference} */
639
625
  requestSaving: HttpInterceptorRequestSaving;
640
- /**
641
- * The strategy to use for unhandled requests. If a request starts with the base URL of the interceptor, but no
642
- * matching handler exists, this strategy will be used. If a function is provided, it will be called with the
643
- * unhandled request.
644
- *
645
- * @see {@link https://zimic.dev/docs/interceptor/guides/http/unhandled-requests Unhandled requests}
646
- */
626
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptoronunhandledrequest `interceptor.onUnhandledRequest` API reference} */
647
627
  onUnhandledRequest?: UnhandledRequestStrategy;
648
628
  /**
649
- * The platform the interceptor is running on.
650
- *
651
629
  * @readonly
652
630
  * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorplatform `interceptor.platform` API reference}
653
631
  */
654
632
  get platform(): HttpInterceptorPlatform | null;
655
633
  /**
656
- * Whether the interceptor is currently running and ready to use.
657
- *
658
634
  * @readonly
659
635
  * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorisrunning `interceptor.isRunning` API reference}
660
636
  */
661
637
  get isRunning(): boolean;
662
- /**
663
- * Starts the interceptor, allowing it to intercept HTTP requests.
664
- *
665
- * When targeting a browser environment, make sure to run `npx zimic-interceptor browser init <publicDirectory>` on
666
- * your terminal before starting the worker. This initializes the mock service worker in your public directory.
667
- *
668
- * @throws {UnregisteredServiceWorkerError} When the worker is targeting a browser environment and the mock service
669
- * worker is not registered.
670
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()` API reference}
671
- */
638
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()` API reference} */
672
639
  start: () => Promise<void>;
673
- /**
674
- * Stops the interceptor, preventing it from intercepting HTTP requests. Stopped interceptors are automatically
675
- * cleared, exactly as if
676
- * {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorclear `interceptor.clear()`} had been
677
- * called.
678
- *
679
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstop `interceptor.stop()` API reference}
680
- */
640
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstop `interceptor.stop()` API reference} */
681
641
  stop: () => Promise<void>;
682
- /**
683
- * Checks if all handlers created by this interceptor have matched the number of requests declared with
684
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`}.
685
- *
686
- * If some handler has matched fewer or more requests than expected, this method will throw a `TimesCheckError` error,
687
- * including a stack trace to the
688
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes `handler.times()`} that was not
689
- * satisfied.
690
- *
691
- * This is useful in an `afterEach` hook (or equivalent) to make sure that all expected requests were made at the end
692
- * of each test.
693
- *
694
- * When {@link https://zimic.dev/docs/interceptor/api/create-http-interceptor `requestSaving.enabled`} is `true` in
695
- * your interceptor, the `TimesCheckError` errors will also list each unmatched request with diff of the expected and
696
- * received data. This is useful for debugging requests that did not match a handler with
697
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}.
698
- *
699
- * @throws {TimesCheckError} If some handler has matched less or more requests than the expected number of requests.
700
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()` API reference}
701
- * @see {@link https://zimic.dev/docs/interceptor/guides/http/testing Testing guide}
702
- */
642
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorchecktimes `interceptor.checkTimes()` API reference} */
703
643
  checkTimes: (() => void) | (() => Promise<void>);
704
- /**
705
- * Clears the interceptor and all of its
706
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} instances, including their
707
- * registered responses and intercepted requests. After calling this method, the interceptor will no longer intercept
708
- * any requests until new mock responses are registered.
709
- *
710
- * This method is useful to reset the interceptor mocks between tests.
711
- *
712
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
713
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorclear `interceptor.clear()` API reference}
714
- */
644
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorclear `interceptor.clear()` API reference} */
715
645
  clear: (() => void) | (() => Promise<void>);
716
646
  }
717
647
  /**
718
- * A local interceptor to handle HTTP requests and return mock responses. The methods, paths, status codes, parameters,
719
- * and responses are statically-typed based on the provided service schema.
720
- *
721
- * To intercept HTTP requests, the interceptor must have been started with
722
- * {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()`}.
723
- *
724
648
  * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference}
649
+ * @see {@link https://zimic.dev/docs/interceptor/guides/http/local-interceptors Using local interceptors}
725
650
  */
726
651
  interface LocalHttpInterceptor<Schema extends HttpSchema> extends HttpInterceptor<Schema> {
727
652
  /** @readonly */
728
653
  get type(): 'local';
729
654
  onUnhandledRequest?: UnhandledRequestStrategy.Local;
730
- /**
731
- * Creates a GET {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
732
- * The path and method must be declared in the interceptor schema.
733
- *
734
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
735
- * interceptor, and the method, path,
736
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
737
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
738
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
739
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
740
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
741
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
742
- * it is created **after** the generic one.
743
- *
744
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
745
- * to specify the original path as a type parameter to get type-inference and type-validation.
746
- * @returns A GET {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
747
- * provided path. The path and method must be declared in the interceptor schema.
748
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
749
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
750
- */
655
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorget `interceptor.get()` API reference} */
751
656
  get: SyncHttpInterceptorMethodHandler<Schema, 'GET'>;
752
- /**
753
- * Creates a POST {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
754
- * The path and method must be declared in the interceptor schema.
755
- *
756
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
757
- * interceptor, and the method, path,
758
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
759
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
760
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
761
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
762
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
763
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
764
- * it is created **after** the generic one.
765
- *
766
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
767
- * to specify the original path as a type parameter to get type-inference and type-validation.
768
- * @returns A POST {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
769
- * provided path. The path and method must be declared in the interceptor schema.
770
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
771
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
772
- */
657
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorpost `interceptor.post()` API reference} */
773
658
  post: SyncHttpInterceptorMethodHandler<Schema, 'POST'>;
774
- /**
775
- * Creates a PATCH {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
776
- * The path and method must be declared in the interceptor schema.
777
- *
778
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
779
- * interceptor, and the method, path,
780
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
781
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
782
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
783
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
784
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
785
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
786
- * it is created **after** the generic one.
787
- *
788
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
789
- * to specify the original path as a type parameter to get type-inference and type-validation.
790
- * @returns A PATCH {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
791
- * provided path. The path and method must be declared in the interceptor schema.
792
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
793
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
794
- */
659
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorpatch `interceptor.patch()` API reference} */
795
660
  patch: SyncHttpInterceptorMethodHandler<Schema, 'PATCH'>;
796
- /**
797
- * Creates a PUT {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
798
- * The path and method must be declared in the interceptor schema.
799
- *
800
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
801
- * interceptor, and the method, path,
802
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
803
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
804
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
805
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
806
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
807
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
808
- * it is created **after** the generic one.
809
- *
810
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
811
- * to specify the original path as a type parameter to get type-inference and type-validation.
812
- * @returns A PUT {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
813
- * provided path. The path and method must be declared in the interceptor schema.
814
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
815
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
816
- */
661
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorput `interceptor.put()` API reference} */
817
662
  put: SyncHttpInterceptorMethodHandler<Schema, 'PUT'>;
818
- /**
819
- * Creates a DELETE {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a
820
- * path. The path and method must be declared in the interceptor schema.
821
- *
822
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
823
- * interceptor, and the method, path,
824
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
825
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
826
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
827
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
828
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
829
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
830
- * it is created **after** the generic one.
831
- *
832
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
833
- * to specify the original path as a type parameter to get type-inference and type-validation.
834
- * @returns A DELETE {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
835
- * provided path. The path and method must be declared in the interceptor schema.
836
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
837
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
838
- */
663
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptordelete `interceptor.delete()` API reference} */
839
664
  delete: SyncHttpInterceptorMethodHandler<Schema, 'DELETE'>;
840
- /**
841
- * Creates a HEAD {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
842
- * The path and method must be declared in the interceptor schema.
843
- *
844
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
845
- * interceptor, and the method, path,
846
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
847
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
848
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
849
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
850
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
851
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
852
- * it is created **after** the generic one.
853
- *
854
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
855
- * to specify the original path as a type parameter to get type-inference and type-validation.
856
- * @returns A HEAD {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
857
- * provided path. The path and method must be declared in the interceptor schema.
858
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
859
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
860
- */
665
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorhead `interceptor.head()` API reference} */
861
666
  head: SyncHttpInterceptorMethodHandler<Schema, 'HEAD'>;
862
- /**
863
- * Creates an OPTIONS {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a
864
- * path. The path and method must be declared in the interceptor schema.
865
- *
866
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
867
- * interceptor, and the method, path,
868
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
869
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
870
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
871
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
872
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
873
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
874
- * it is created **after** the generic one.
875
- *
876
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
877
- * to specify the original path as a type parameter to get type-inference and type-validation.
878
- * @returns An OPTIONS {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
879
- * provided path. The path and method must be declared in the interceptor schema.
880
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
881
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
882
- */
667
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptoroptions `interceptor.options()` API reference} */
883
668
  options: SyncHttpInterceptorMethodHandler<Schema, 'OPTIONS'>;
884
669
  checkTimes: () => void;
885
670
  clear: () => void;
886
671
  }
887
672
  /**
888
- * A remote interceptor to handle HTTP requests and return mock responses. The methods, paths, status codes, parameters,
889
- * and responses are statically-typed based on the provided service schema.
890
- *
891
- * To intercept HTTP requests, the interceptor must have been started with
892
- * {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorstart `interceptor.start()`} and an
893
- * {@link https://zimic.dev/docs/interceptor/cli/server interceptor server} should be running.
894
- *
895
673
  * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor `HttpInterceptor` API reference}
674
+ * @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors Using remote interceptors}
896
675
  */
897
676
  interface RemoteHttpInterceptor<Schema extends HttpSchema> extends HttpInterceptor<Schema> {
898
677
  /** @readonly */
899
678
  get type(): 'remote';
900
- /**
901
- * Options to authenticate the interceptor when connecting to an interceptor server. This is required if the
902
- * interceptor server was started with the `--tokens-dir` option.
903
- *
904
- * @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors#interceptor-server-authentication Interceptor server authentication}
905
- */
906
- auth?: RemoteHttpInterceptorOptions['auth'];
907
679
  onUnhandledRequest?: UnhandledRequestStrategy.Remote;
908
- /**
909
- * Creates a GET {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
910
- * The path and method must be declared in the interceptor schema.
911
- *
912
- * When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
913
- * a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
914
- * apply them by awaiting the handler.
915
- *
916
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
917
- * interceptor, and the method, path,
918
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
919
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
920
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
921
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
922
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
923
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
924
- * it is created **after** the generic one.
925
- *
926
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
927
- * to specify the original path as a type parameter to get type-inference and type-validation.
928
- * @returns A GET {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
929
- * provided path. The path and method must be declared in the interceptor schema.
930
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
931
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
932
- */
680
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorauth `interceptor.auth` API reference} */
681
+ auth?: RemoteHttpInterceptorOptions['auth'];
682
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorget `interceptor.get()` API reference} */
933
683
  get: AsyncHttpInterceptorMethodHandler<Schema, 'GET'>;
934
- /**
935
- * Creates a POST {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
936
- * The path and method must be declared in the interceptor schema.
937
- *
938
- * When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
939
- * a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
940
- * apply them by awaiting the handler.
941
- *
942
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
943
- * interceptor, and the method, path,
944
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
945
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
946
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
947
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
948
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
949
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
950
- * it is created **after** the generic one.
951
- *
952
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
953
- * to specify the original path as a type parameter to get type-inference and type-validation.
954
- * @returns A POST {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
955
- * provided path. The path and method must be declared in the interceptor schema.
956
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
957
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
958
- */
684
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorpost `interceptor.post()` API reference} */
959
685
  post: AsyncHttpInterceptorMethodHandler<Schema, 'POST'>;
960
- /**
961
- * Creates a PATCH {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
962
- * The path and method must be declared in the interceptor schema.
963
- *
964
- * When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
965
- * a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
966
- * apply them by awaiting the handler.
967
- *
968
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
969
- * interceptor, and the method, path,
970
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
971
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
972
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
973
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
974
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
975
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
976
- * it is created **after** the generic one.
977
- *
978
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
979
- * to specify the original path as a type parameter to get type-inference and type-validation.
980
- * @returns A PATCH {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
981
- * provided path. The path and method must be declared in the interceptor schema.
982
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
983
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
984
- */
686
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorpatch `interceptor.patch()` API reference} */
985
687
  patch: AsyncHttpInterceptorMethodHandler<Schema, 'PATCH'>;
986
- /**
987
- * Creates a PUT {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
988
- * The path and method must be declared in the interceptor schema.
989
- *
990
- * When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
991
- * a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
992
- * apply them by awaiting the handler.
993
- *
994
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
995
- * interceptor, and the method, path,
996
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
997
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
998
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
999
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
1000
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
1001
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
1002
- * it is created **after** the generic one.
1003
- *
1004
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
1005
- * to specify the original path as a type parameter to get type-inference and type-validation.
1006
- * @returns A PUT {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
1007
- * provided path. The path and method must be declared in the interceptor schema.
1008
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
1009
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
1010
- */
688
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorput `interceptor.put()` API reference} */
1011
689
  put: AsyncHttpInterceptorMethodHandler<Schema, 'PUT'>;
1012
- /**
1013
- * Creates a DELETE {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a
1014
- * path. The path and method must be declared in the interceptor schema.
1015
- *
1016
- * When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
1017
- * a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
1018
- * apply them by awaiting the handler.
1019
- *
1020
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
1021
- * interceptor, and the method, path,
1022
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
1023
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
1024
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
1025
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
1026
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
1027
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
1028
- * it is created **after** the generic one.
1029
- *
1030
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
1031
- * to specify the original path as a type parameter to get type-inference and type-validation.
1032
- * @returns A DELETE {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
1033
- * provided path. The path and method must be declared in the interceptor schema.
1034
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
1035
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
1036
- */
690
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptordelete `interceptor.delete()` API reference} */
1037
691
  delete: AsyncHttpInterceptorMethodHandler<Schema, 'DELETE'>;
1038
- /**
1039
- * Creates a HEAD {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a path.
1040
- * The path and method must be declared in the interceptor schema.
1041
- *
1042
- * When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
1043
- * a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
1044
- * apply them by awaiting the handler.
1045
- *
1046
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
1047
- * interceptor, and the method, path,
1048
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
1049
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
1050
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
1051
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
1052
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
1053
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
1054
- * it is created **after** the generic one.
1055
- *
1056
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
1057
- * to specify the original path as a type parameter to get type-inference and type-validation.
1058
- * @returns A HEAD {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
1059
- * provided path. The path and method must be declared in the interceptor schema.
1060
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
1061
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
1062
- */
692
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptorhead `interceptor.head()` API reference} */
1063
693
  head: AsyncHttpInterceptorMethodHandler<Schema, 'HEAD'>;
1064
- /**
1065
- * Creates an OPTIONS {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for a
1066
- * path. The path and method must be declared in the interceptor schema.
1067
- *
1068
- * When using a {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptor}, creating
1069
- * a handler is an asynchronous operation, so you need to `await` it. You can also chain any number of operations and
1070
- * apply them by awaiting the handler.
1071
- *
1072
- * After a request is intercepted, Zimic tries to find a handler that matches it, considering the base URL of the
1073
- * interceptor, and the method, path,
1074
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlerwithrestriction restrictions}, and
1075
- * {@link https://zimic.dev/docs/interceptor/api/http-request-handler#handlertimes limits on the number of requests} of
1076
- * the handler. The handlers are checked from the **last** one created to the first one, so new handlers have
1077
- * preference over older ones. This allows you to declare generic and specific handlers based on their order of
1078
- * creation. For example, a generic handler for `GET /users` can return an empty list, while a specific handler in a
1079
- * test case can return a list with some users. In this case, the specific handler will be considered first as long as
1080
- * it is created **after** the generic one.
1081
- *
1082
- * @param path The path to intercept. Paths with dynamic parameters, such as `/users/:id`, are supported, but you need
1083
- * to specify the original path as a type parameter to get type-inference and type-validation.
1084
- * @returns An OPTIONS {@link https://zimic.dev/docs/interceptor/api/http-request-handler `HttpRequestHandler`} for the
1085
- * provided path. The path and method must be declared in the interceptor schema.
1086
- * @throws {NotRunningHttpInterceptorError} If the interceptor is not running.
1087
- * @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#declaring-request-handlers Declaring request handlers}
1088
- */
694
+ /** @see {@link https://zimic.dev/docs/interceptor/api/http-interceptor#interceptoroptions `interceptor.options()` API reference} */
1089
695
  options: AsyncHttpInterceptorMethodHandler<Schema, 'OPTIONS'>;
1090
696
  checkTimes: () => Promise<void>;
1091
697
  clear: () => Promise<void>;
package/dist/server.d.ts CHANGED
@@ -12,93 +12,36 @@ declare class NotRunningInterceptorServerError extends Error {
12
12
  constructor();
13
13
  }
14
14
 
15
- /**
16
- * The options to create an {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
17
- *
18
- * @see {@link https://zimic.dev/docs/interceptor/cli/server `zimic-interceptor server` API reference}
19
- */
15
+ /** @see {@link https://zimic.dev/docs/interceptor/api/create-interceptor-server `createInterceptorServer` API reference} */
20
16
  interface InterceptorServerOptions {
21
- /**
22
- * The hostname to start the server on.
23
- *
24
- * @default localhost
25
- */
17
+ /** @see {@link https://zimic.dev/docs/interceptor/api/create-interceptor-server `createInterceptorServer` API reference} */
26
18
  hostname?: string;
27
- /** The port to start the server on. If no port is provided, a random one is chosen. */
19
+ /** @see {@link https://zimic.dev/docs/interceptor/api/create-interceptor-server `createInterceptorServer` API reference} */
28
20
  port?: number;
29
- /**
30
- * Whether to log warnings about unhandled requests to the console.
31
- *
32
- * @default true
33
- */
21
+ /** @see {@link https://zimic.dev/docs/interceptor/api/create-interceptor-server `createInterceptorServer` API reference} */
34
22
  logUnhandledRequests?: boolean;
35
- /**
36
- * The directory where the authorized interceptor authentication tokens are saved. If provided, only remote
37
- * interceptors bearing a valid token will be accepted. This option is essential if you are exposing your interceptor
38
- * server publicly. For local development and testing, though, `--tokens-dir` is optional.
39
- *
40
- * @default undefined
41
- */
23
+ /** @see {@link https://zimic.dev/docs/interceptor/api/create-interceptor-server `createInterceptorServer` API reference} */
42
24
  tokensDirectory?: string;
43
25
  }
44
26
 
45
- /**
46
- * A server to intercept and handle requests. It is used in combination with
47
- * {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors remote interceptors}.
48
- *
49
- * @see {@link https://zimic.dev/docs/interceptor/cli/server `zimic-interceptor server` API reference}
50
- */
27
+ /** @see {@link https://zimic.dev/docs/interceptor/api/interceptor-server `InterceptorServer` API reference} */
51
28
  interface InterceptorServer {
52
- /**
53
- * The hostname of the server. It can be reassigned to a new value if the server is not running.
54
- *
55
- * @throws {RunningInterceptorServerError} When trying to reassign a new hostname with the server still running.
56
- * @see {@link https://zimic.dev/docs/interceptor/cli/server `zimic-interceptor server` API reference}
57
- */
29
+ /** @see {@link https://zimic.dev/docs/interceptor/api/interceptor-server `InterceptorServer` API reference} */
58
30
  hostname: string;
59
- /**
60
- * The port of the server. It can be reassigned to a new value if the server is not running.
61
- *
62
- * @throws {RunningInterceptorServerError} When trying to reassign a new port with the server still running.
63
- * @see {@link https://zimic.dev/docs/interceptor/cli/server `zimic-interceptor server` API reference}
64
- */
31
+ /** @see {@link https://zimic.dev/docs/interceptor/api/interceptor-server `InterceptorServer` API reference} */
65
32
  port: number | undefined;
66
- /**
67
- * Whether to log warnings about unhandled requests to the console.
68
- *
69
- * @default true
70
- * @see {@link https://zimic.dev/docs/interceptor/cli/server `zimic-interceptor server` API reference}
71
- */
33
+ /** @see {@link https://zimic.dev/docs/interceptor/api/interceptor-server `InterceptorServer` API reference} */
72
34
  logUnhandledRequests: boolean;
73
- /**
74
- * The directory where the authorized interceptor authentication tokens are saved. If provided, only remote
75
- * interceptors bearing a valid token will be accepted. This option is essential if you are exposing your interceptor
76
- * server publicly. For local development and testing, though, `--tokens-dir` is optional.
77
- *
78
- * @default undefined
79
- */
35
+ /** @see {@link https://zimic.dev/docs/interceptor/api/interceptor-server `InterceptorServer` API reference} */
80
36
  tokensDirectory?: string;
81
37
  /**
82
- * Whether the server is running.
83
- *
84
38
  * @readonly
85
- * @see {@link https://zimic.dev/docs/interceptor/cli/server `zimic-interceptor server` API reference}
39
+ * @see {@link https://zimic.dev/docs/interceptor/api/interceptor-server `InterceptorServer` API reference}
86
40
  */
87
41
  get isRunning(): boolean;
88
- /**
89
- * Starts the server.
90
- *
91
- * The server is automatically stopped if a process exit event is detected, such as SIGINT, SIGTERM, or an uncaught
92
- * exception.
93
- *
94
- * @see {@link https://zimic.dev/docs/interceptor/cli/server `zimic-interceptor server` API reference}
95
- */
42
+ /** @see {@link https://zimic.dev/docs/interceptor/api/interceptor-server `InterceptorServer` API reference} */
96
43
  start: () => Promise<void>;
97
- /**
98
- * Stops the server.
99
- *
100
- * @see {@link https://zimic.dev/docs/interceptor/cli/server `zimic-interceptor server` API reference}
101
- */
44
+ /** @see {@link https://zimic.dev/docs/interceptor/api/interceptor-server `InterceptorServer` API reference} */
102
45
  stop: () => Promise<void>;
103
46
  }
104
47
 
@@ -113,14 +56,7 @@ declare const DEFAULT_ACCESS_CONTROL_HEADERS: Readonly<{
113
56
  /** The default status code for the preflight request. */
114
57
  declare const DEFAULT_PREFLIGHT_STATUS_CODE = 204;
115
58
 
116
- /**
117
- * Creates an {@link https://zimic.dev/docs/interceptor/cli/server interceptor server}.
118
- *
119
- * @param options The options to create the server.
120
- * @returns The created server.
121
- * @see {@link https://zimic.dev/docs/interceptor/cli/server-programmatic-usage `zimic-interceptor server` programmatic usage}
122
- * @see {@link https://zimic.dev/docs/interceptor/guides/http/remote-interceptors Remote HTTP Interceptors} .
123
- */
59
+ /** @see {@link https://zimic.dev/docs/interceptor/api/create-interceptor-server `createInterceptorServer` API reference} */
124
60
  declare function createInterceptorServer(options?: InterceptorServerOptions): InterceptorServer;
125
61
 
126
62
  export { DEFAULT_ACCESS_CONTROL_HEADERS, DEFAULT_PREFLIGHT_STATUS_CODE, type InterceptorServer, type InterceptorServerOptions, NotRunningInterceptorServerError, RunningInterceptorServerError, createInterceptorServer };