api.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /** JSON-compatible cassette metadata value. */
  2. export type JsonValue =
  3. | null
  4. | boolean
  5. | number
  6. | string
  7. | ReadonlyArray<JsonValue>
  8. | { readonly [key: string]: JsonValue }
  9. /** Additional JSON metadata stored with a cassette. */
  10. export type CassetteMetadata = Readonly<Record<string, JsonValue>>
  11. /** The normalized HTTP request representation used for matching. */
  12. export interface RequestSnapshot {
  13. readonly method: string
  14. readonly url: string
  15. readonly headers: Record<string, string>
  16. readonly body: string
  17. }
  18. /** Returns whether an incoming HTTP request matches a recorded request. */
  19. export type RequestMatcher = (incoming: RequestSnapshot, recorded: RequestSnapshot) => boolean
  20. /** Additive redaction and header-preservation policy. */
  21. export interface RedactOptions {
  22. readonly headers?: ReadonlyArray<string>
  23. readonly allowRequestHeaders?: ReadonlyArray<string>
  24. readonly allowResponseHeaders?: ReadonlyArray<string>
  25. readonly queryParameters?: ReadonlyArray<string>
  26. readonly jsonFields?: ReadonlyArray<string>
  27. readonly url?: (url: string) => string
  28. readonly body?: (body: string) => string
  29. }
  30. /** Options shared by HTTP recorder layers. */
  31. export interface RecorderOptions {
  32. readonly directory?: string
  33. readonly metadata?: CassetteMetadata
  34. readonly redact?: RedactOptions
  35. readonly match?: RequestMatcher
  36. }
  37. /** Recorder configuration for Effect socket and WebSocket layers. */
  38. export type SocketRecorderOptions = Omit<RecorderOptions, "match">
  39. export * as Api from "./api.js"