# Deprecation

> The deprecation helpers of @morevoice/sdk.

Helpers exported by `@morevoice/sdk` from `src/lib/deprecation.ts`.

## API

Exported from `@morevoice/sdk` (source: `packages/sdk-ts/src/lib/deprecation.ts`).

### `DeprecationNotice`

*interface*

```ts
interface DeprecationNotice {
	/** The request that got it first, e.g. `GET`. */
	method: string;
	/** Its URL path, e.g. `/v1/calls`. */
	path: string;
	/** When it was deprecated (RFC 9745 `Deprecation`), when the header carried a date. */
	deprecatedAt: Date | null;
	/** When it stops working (RFC 8594 `Sunset`). */
	sunset: Date | null;
	/** The migration guide (`Link: <…>; rel="deprecation"`, else `rel="sunset"`). */
	link: string | undefined;
	/** The `MoreVoice-Version` the response was rendered in. */
	apiVersion: string | undefined;
	/** A one-line, human-readable summary (what the default warning prints). */
	message: string;
	/** Identifies the notice: the same for every response of one deprecation. */
	key: string;
}
```

### `DeprecationHandler`

*type*

```ts
type DeprecationHandler = (notice: DeprecationNotice) => void;
```

### `parseDeprecationNotice()`

*function*

The notice a response carries, or null (no `Deprecation` and no `Sunset` header).

```ts
function parseDeprecationNotice(response: { headers: HeaderGetter }, request: { method: string; url: string }): DeprecationNotice | null;
```

### `resetDeprecationNotices()`

*function*

Forget the notices already reported (tests).

```ts
function resetDeprecationNotices(): void;
```

### `reportDeprecation()`

*function*

Report a notice once per process: through `handler` when it is a function, as a warning when it is undefined, not at
all when it is null. Never throws (a failing handler, or `--throw-deprecation`, must not fail the API call).
Returns true when this call reported it.

```ts
function reportDeprecation(notice: DeprecationNotice, handler: DeprecationHandler | null | undefined): boolean;
```

### `withDeprecationNotices()`

*function*

Wrap a fetch so every response is checked for a deprecation notice (the client does this for you).

```ts
function withDeprecationNotices(fetchFn: FetchLike, handler: DeprecationHandler | null | undefined): FetchLike;
```
