@authup/errors 1.0.0-beta.40 → 1.0.0-beta.42

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.
Files changed (45) hide show
  1. package/dist/built-in/auth-header.d.ts +7 -0
  2. package/dist/built-in/auth-header.d.ts.map +1 -0
  3. package/dist/built-in/bad-request.d.ts +7 -0
  4. package/dist/built-in/bad-request.d.ts.map +1 -0
  5. package/dist/built-in/bearer-token.d.ts +6 -0
  6. package/dist/built-in/bearer-token.d.ts.map +1 -0
  7. package/dist/built-in/check.d.ts +19 -0
  8. package/dist/built-in/check.d.ts.map +1 -0
  9. package/dist/built-in/entity-conflict.d.ts +7 -0
  10. package/dist/built-in/entity-conflict.d.ts.map +1 -0
  11. package/dist/built-in/entity-credentials-invalid.d.ts +7 -0
  12. package/dist/built-in/entity-credentials-invalid.d.ts.map +1 -0
  13. package/dist/built-in/entity-inactive.d.ts +7 -0
  14. package/dist/built-in/entity-inactive.d.ts.map +1 -0
  15. package/dist/built-in/entity-not-found.d.ts +7 -0
  16. package/dist/built-in/entity-not-found.d.ts.map +1 -0
  17. package/dist/built-in/index.d.ts +10 -1
  18. package/dist/built-in/index.d.ts.map +1 -1
  19. package/dist/built-in/internal.d.ts +7 -0
  20. package/dist/built-in/internal.d.ts.map +1 -0
  21. package/dist/built-in/unauthorized.d.ts +7 -0
  22. package/dist/built-in/unauthorized.d.ts.map +1 -0
  23. package/dist/check.d.ts +24 -0
  24. package/dist/check.d.ts.map +1 -0
  25. package/dist/constants.d.ts +11 -0
  26. package/dist/constants.d.ts.map +1 -1
  27. package/dist/index.d.mts +178 -842
  28. package/dist/index.d.mts.map +1 -1
  29. package/dist/index.d.ts +6 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.mjs +323 -10
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/module.d.ts +14 -4
  34. package/dist/module.d.ts.map +1 -1
  35. package/dist/normalize.d.ts +11 -0
  36. package/dist/normalize.d.ts.map +1 -0
  37. package/dist/serialize.d.ts +15 -0
  38. package/dist/serialize.d.ts.map +1 -0
  39. package/dist/status.d.ts +32 -0
  40. package/dist/status.d.ts.map +1 -0
  41. package/dist/types.d.ts +8 -4
  42. package/dist/types.d.ts.map +1 -1
  43. package/package.json +2 -2
  44. package/dist/built-in/http.d.ts +0 -6
  45. package/dist/built-in/http.d.ts.map +0 -1
package/dist/index.d.mts CHANGED
@@ -1,19 +1,139 @@
1
- /// <reference types="node" />
2
- import { BadRequestError, Input, Options as Options$1 } from "@ebec/http";
3
- import { URL as URL$1, URLSearchParams } from "node:url";
4
- import { Duplex, Readable, Writable } from "node:stream";
5
- import { EventEmitter } from "node:events";
6
- import { Blob, File } from "node:buffer";
7
- import { ConnectionOptions, TLSSocket } from "node:tls";
8
- import { IpcNetConnectOpts, Socket, TcpNetConnectOpts } from "node:net";
1
+ import { BASE_ERROR_INSTANCE, BaseError, ErrorOptions, INSTANCEOF_PROPERTY, hasInstanceof, markInstanceof } from "@ebec/core";
9
2
  import { Issue } from "validup";
10
3
 
4
+ //#region src/types.d.ts
5
+ type AuthupErrorOptions = ErrorOptions & {
6
+ data?: Record<string, any>;
7
+ };
8
+ type AuthupErrorInput = string | AuthupErrorOptions;
9
+ type AuthupEntityErrorOptions = AuthupErrorOptions & {
10
+ entity?: string;
11
+ };
12
+ type AuthupEntityErrorInput = string | AuthupEntityErrorOptions;
13
+ //#endregion
14
+ //#region src/module.d.ts
15
+ declare const AUTHUP_ERROR_INSTANCE: unique symbol;
16
+ declare class AuthupError extends BaseError {
17
+ readonly issues: Issue[];
18
+ readonly data?: Record<string, any>;
19
+ constructor(input?: AuthupErrorInput);
20
+ toJSON(): {
21
+ issues: Issue[];
22
+ name: string;
23
+ message: string;
24
+ code: string;
25
+ cause?: unknown;
26
+ errors?: unknown[];
27
+ };
28
+ }
29
+ //#endregion
30
+ //#region src/built-in/unauthorized.d.ts
31
+ declare const UNAUTHORIZED_ERROR_INSTANCE: unique symbol;
32
+ declare class UnauthorizedError extends AuthupError {
33
+ constructor(input?: string | AuthupErrorOptions);
34
+ }
35
+ //#endregion
36
+ //#region src/built-in/auth-header.d.ts
37
+ declare const AUTH_HEADER_ERROR_INSTANCE: unique symbol;
38
+ declare class AuthHeaderError extends UnauthorizedError {
39
+ constructor(message: string);
40
+ static unsupportedType(type: string): AuthHeaderError;
41
+ }
42
+ //#endregion
43
+ //#region src/built-in/bad-request.d.ts
44
+ declare const BAD_REQUEST_ERROR_INSTANCE: unique symbol;
45
+ declare class BadRequestError extends AuthupError {
46
+ constructor(input?: string | AuthupErrorOptions);
47
+ }
48
+ //#endregion
49
+ //#region src/built-in/bearer-token.d.ts
50
+ declare const BEARER_TOKEN_MALFORMED_ERROR_INSTANCE: unique symbol;
51
+ declare class BearerTokenMalformedError extends UnauthorizedError {
52
+ constructor(message?: string);
53
+ }
54
+ //#endregion
55
+ //#region src/built-in/entity-conflict.d.ts
56
+ declare const ENTITY_CONFLICT_ERROR_INSTANCE: unique symbol;
57
+ declare class EntityConflictError extends AuthupError {
58
+ constructor(input?: string | AuthupEntityErrorOptions);
59
+ }
60
+ //#endregion
61
+ //#region src/built-in/entity-credentials-invalid.d.ts
62
+ declare const ENTITY_CREDENTIALS_INVALID_ERROR_INSTANCE: unique symbol;
63
+ declare class EntityCredentialsInvalidError extends AuthupError {
64
+ constructor(input?: string | AuthupEntityErrorOptions);
65
+ }
66
+ //#endregion
67
+ //#region src/built-in/entity-inactive.d.ts
68
+ declare const ENTITY_INACTIVE_ERROR_INSTANCE: unique symbol;
69
+ declare class EntityInactiveError extends AuthupError {
70
+ constructor(input?: string | AuthupEntityErrorOptions);
71
+ }
72
+ //#endregion
73
+ //#region src/built-in/entity-not-found.d.ts
74
+ declare const ENTITY_NOT_FOUND_ERROR_INSTANCE: unique symbol;
75
+ declare class EntityNotFoundError extends AuthupError {
76
+ constructor(input?: string | AuthupEntityErrorOptions);
77
+ }
78
+ //#endregion
79
+ //#region src/built-in/internal.d.ts
80
+ declare const INTERNAL_ERROR_INSTANCE: unique symbol;
81
+ declare class InternalError extends AuthupError {
82
+ constructor(input?: string | AuthupErrorOptions);
83
+ }
84
+ //#endregion
85
+ //#region src/built-in/check.d.ts
86
+ declare function isAuthHeaderError(input: unknown): input is AuthHeaderError;
87
+ declare function isBearerTokenMalformedError(input: unknown): input is BearerTokenMalformedError;
88
+ declare function isBadRequestError(input: unknown): input is BadRequestError;
89
+ declare function isUnauthorizedError(input: unknown): input is UnauthorizedError;
90
+ declare function isEntityNotFoundError(input: unknown): input is EntityNotFoundError;
91
+ declare function isEntityConflictError(input: unknown): input is EntityConflictError;
92
+ declare function isEntityInactiveError(input: unknown): input is EntityInactiveError;
93
+ declare function isEntityCredentialsInvalidError(input: unknown): input is EntityCredentialsInvalidError;
94
+ declare function isInternalError(input: unknown): input is InternalError;
95
+ //#endregion
96
+ //#region src/check.d.ts
97
+ /**
98
+ * Duck-type guard for `Error`.
99
+ *
100
+ * Re-exports `@ebec/core`'s shape-based check: `input` matches when it
101
+ * carries the standard `name` / `message` / `stack` triplet, regardless
102
+ * of which realm or class hierarchy produced it. Use this instead of
103
+ * `instanceof Error` for cross-realm boundaries (worker threads,
104
+ * duplicate-module copies) where `instanceof` can yield false negatives.
105
+ */
106
+ declare function isError(input: unknown): input is Error;
107
+ /**
108
+ * Duck-type guard for AuthupError.
109
+ *
110
+ * Fast path: input has the AuthupError marker in its `@instanceof` chain.
111
+ * Subclass instances also accumulate this marker, so this guard matches any
112
+ * AuthupError subclass (`OAuth2Error`, `JWTError`, etc.).
113
+ *
114
+ * Slow path: input is shape-compatible with AuthupError (BaseError + has
115
+ * `issues: Issue[]`). Catches cases where the marker is missing — plain
116
+ * objects rehydrated from JSON, older builds without the marker.
117
+ */
118
+ declare function isAuthupError(input: unknown): input is AuthupError;
119
+ //#endregion
11
120
  //#region src/constants.d.ts
12
121
  declare enum ErrorCode {
122
+ BAD_REQUEST = "bad_request",
123
+ INTERNAL_ERROR = "internal_error",
13
124
  HTTP_HEADER_AUTH_TYPE_UNSUPPORTED = "unsupported_auth_header_type",
125
+ HTTP_BEARER_TOKEN_MALFORMED = "bearer_token_malformed",
126
+ IDENTITY_UNAUTHORIZED = "identity_unauthorized",
14
127
  ENTITY_CREDENTIALS_INVALID = "invalid_credentials",
15
128
  ENTITY_INACTIVE = "entity_inactive",
16
129
  ENTITY_NOT_FOUND = "entity_not_found",
130
+ ENTITY_CONFLICT = "entity_conflict",
131
+ ENTITY_RELATION_INVALID = "entity_relation_invalid",
132
+ REGISTRATION_DISABLED = "registration_disabled",
133
+ PASSWORD_RECOVERY_DISABLED = "password_recovery_disabled",
134
+ EMAIL_VERIFICATION_REQUIRED = "email_verification_required",
135
+ RESET_TOKEN_EXPIRED = "reset_token_expired",
136
+ STORAGE_INSUFFICIENT = "storage_insufficient",
17
137
  JWK_INVALID = "jwk_invalid",
18
138
  JWK_NOT_FOUND = "jwk_not_found",
19
139
  JWT_INVALID = "invalid_token",
@@ -35,849 +155,65 @@ declare enum ErrorCode {
35
155
  POLICY_EVALUATOR_CONTEXT_INVALID = "policy_evaluator_context_invalid"
36
156
  }
37
157
  //#endregion
38
- //#region ../../node_modules/undici/types/utility.d.ts
39
- type AutocompletePrimitiveBaseType<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : never;
40
- type Autocomplete<T> = T | (AutocompletePrimitiveBaseType<T> & Record<never, never>);
41
- //#endregion
42
- //#region ../../node_modules/undici/types/header.d.ts
158
+ //#region src/normalize.d.ts
43
159
  /**
44
- * The header type declaration of `undici`.
160
+ * Normalize an arbitrary thrown value into an `Error` instance.
161
+ *
162
+ * Useful at error-pipeline boundaries (catch blocks, error middleware,
163
+ * fallbacks) where TypeScript hands you `unknown` but downstream code
164
+ * wants a real `Error` to inspect or rethrow. Duck-typed: any value
165
+ * passing `isError` is returned as-is. Strings become `new Error(str)`;
166
+ * any other value is stringified.
45
167
  */
46
- type IncomingHttpHeaders = Record<string, string | string[] | undefined>;
47
- type HeaderNames = Autocomplete<'Accept' | 'Accept-CH' | 'Accept-Charset' | 'Accept-Encoding' | 'Accept-Language' | 'Accept-Patch' | 'Accept-Post' | 'Accept-Ranges' | 'Access-Control-Allow-Credentials' | 'Access-Control-Allow-Headers' | 'Access-Control-Allow-Methods' | 'Access-Control-Allow-Origin' | 'Access-Control-Expose-Headers' | 'Access-Control-Max-Age' | 'Access-Control-Request-Headers' | 'Access-Control-Request-Method' | 'Age' | 'Allow' | 'Alt-Svc' | 'Alt-Used' | 'Authorization' | 'Cache-Control' | 'Clear-Site-Data' | 'Connection' | 'Content-Disposition' | 'Content-Encoding' | 'Content-Language' | 'Content-Length' | 'Content-Location' | 'Content-Range' | 'Content-Security-Policy' | 'Content-Security-Policy-Report-Only' | 'Content-Type' | 'Cookie' | 'Cross-Origin-Embedder-Policy' | 'Cross-Origin-Opener-Policy' | 'Cross-Origin-Resource-Policy' | 'Date' | 'Device-Memory' | 'ETag' | 'Expect' | 'Expect-CT' | 'Expires' | 'Forwarded' | 'From' | 'Host' | 'If-Match' | 'If-Modified-Since' | 'If-None-Match' | 'If-Range' | 'If-Unmodified-Since' | 'Keep-Alive' | 'Last-Modified' | 'Link' | 'Location' | 'Max-Forwards' | 'Origin' | 'Permissions-Policy' | 'Priority' | 'Proxy-Authenticate' | 'Proxy-Authorization' | 'Range' | 'Referer' | 'Referrer-Policy' | 'Retry-After' | 'Sec-Fetch-Dest' | 'Sec-Fetch-Mode' | 'Sec-Fetch-Site' | 'Sec-Fetch-User' | 'Sec-Purpose' | 'Sec-WebSocket-Accept' | 'Server' | 'Server-Timing' | 'Service-Worker-Navigation-Preload' | 'Set-Cookie' | 'SourceMap' | 'Strict-Transport-Security' | 'TE' | 'Timing-Allow-Origin' | 'Trailer' | 'Transfer-Encoding' | 'Upgrade' | 'Upgrade-Insecure-Requests' | 'User-Agent' | 'Vary' | 'Via' | 'WWW-Authenticate' | 'X-Content-Type-Options' | 'X-Frame-Options'>;
48
- type IANARegisteredMimeType = Autocomplete<'audio/aac' | 'video/x-msvideo' | 'image/avif' | 'video/av1' | 'application/octet-stream' | 'image/bmp' | 'text/css' | 'text/csv' | 'application/vnd.ms-fontobject' | 'application/epub+zip' | 'image/gif' | 'application/gzip' | 'text/html' | 'image/x-icon' | 'text/calendar' | 'image/jpeg' | 'text/javascript' | 'application/json' | 'application/ld+json' | 'audio/x-midi' | 'audio/mpeg' | 'video/mp4' | 'video/mpeg' | 'audio/ogg' | 'video/ogg' | 'application/ogg' | 'audio/opus' | 'font/otf' | 'application/pdf' | 'image/png' | 'application/rtf' | 'image/svg+xml' | 'image/tiff' | 'video/mp2t' | 'font/ttf' | 'text/plain' | 'application/wasm' | 'video/webm' | 'audio/webm' | 'image/webp' | 'font/woff' | 'font/woff2' | 'application/xhtml+xml' | 'application/xml' | 'application/zip' | 'video/3gpp' | 'video/3gpp2' | 'model/gltf+json' | 'model/gltf-binary'>;
49
- type KnownHeaderValues = {
50
- 'content-type': IANARegisteredMimeType;
51
- };
52
- type HeaderRecord = { [K in HeaderNames | Lowercase<HeaderNames>]?: Lowercase<K> extends keyof KnownHeaderValues ? KnownHeaderValues[Lowercase<K>] : string };
53
- //#endregion
54
- //#region ../../node_modules/undici/types/readable.d.ts
55
- declare class BodyReadable extends Readable {
56
- constructor(opts: {
57
- resume: (this: Readable, size: number) => void | null;
58
- abort: () => void | null;
59
- contentType?: string;
60
- contentLength?: number;
61
- highWaterMark?: number;
62
- });
63
- /** Consumes and returns the body as a string
64
- * https://fetch.spec.whatwg.org/#dom-body-text
65
- */
66
- text(): Promise<string>;
67
- /** Consumes and returns the body as a JavaScript Object
68
- * https://fetch.spec.whatwg.org/#dom-body-json
69
- */
70
- json(): Promise<unknown>;
71
- /** Consumes and returns the body as a Blob
72
- * https://fetch.spec.whatwg.org/#dom-body-blob
73
- */
74
- blob(): Promise<Blob>;
75
- /** Consumes and returns the body as an Uint8Array
76
- * https://fetch.spec.whatwg.org/#dom-body-bytes
77
- */
78
- bytes(): Promise<Uint8Array>;
79
- /** Consumes and returns the body as an ArrayBuffer
80
- * https://fetch.spec.whatwg.org/#dom-body-arraybuffer
81
- */
82
- arrayBuffer(): Promise<ArrayBuffer>;
83
- /** Not implemented
84
- *
85
- * https://fetch.spec.whatwg.org/#dom-body-formdata
86
- */
87
- formData(): Promise<never>;
88
- /** Returns true if the body is not null and the body has been consumed
89
- *
90
- * Otherwise, returns false
91
- *
92
- * https://fetch.spec.whatwg.org/#dom-body-bodyused
93
- */
94
- readonly bodyUsed: boolean;
95
- /**
96
- * If body is null, it should return null as the body
97
- *
98
- * If body is not null, should return the body as a ReadableStream
99
- *
100
- * https://fetch.spec.whatwg.org/#dom-body-body
101
- */
102
- readonly body: never | undefined;
103
- /** Dumps the response body by reading `limit` number of bytes.
104
- * @param opts.limit Number of bytes to read (optional) - Default: 131072
105
- * @param opts.signal AbortSignal to cancel the operation (optional)
106
- */
107
- dump(opts?: {
108
- limit: number;
109
- signal?: AbortSignal;
110
- }): Promise<void>;
111
- }
168
+ declare function normalizeError(input: unknown): Error;
112
169
  //#endregion
113
- //#region ../../node_modules/undici/types/fetch.d.ts
114
- type BodyInit = ArrayBuffer | AsyncIterable<Uint8Array> | Blob | FormData | Iterable<Uint8Array> | NodeJS.ArrayBufferView | URLSearchParams | null | string;
115
- interface SpecIterator<T, TReturn = any, TNext = undefined> {
116
- next(...args: [] | [TNext]): IteratorResult<T, TReturn>;
117
- }
118
- interface SpecIteratorObject<T, TReturn = undefined, TNext = unknown> extends SpecIterator<T, TReturn, TNext> {
119
- [Symbol.iterator](): SpecIteratorObject<T, TReturn, TNext>;
120
- map<U>(callbackfn: (value: T, index: number) => U): SpecIteratorObject<U>;
121
- filter<S extends T>(predicate: (value: T, index: number) => value is S): SpecIteratorObject<S>;
122
- filter(predicate: (value: T, index: number) => unknown): SpecIteratorObject<T>;
123
- take(limit: number): SpecIteratorObject<T>;
124
- drop(count: number): SpecIteratorObject<T>;
125
- flatMap<U>(callbackfn: (value: T, index: number) => Iterator<U> | Iterable<U>): SpecIteratorObject<U>;
126
- reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number) => T): T;
127
- reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number) => T, initialValue: T): T;
128
- reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number) => U, initialValue: U): U;
129
- toArray(): T[];
130
- forEach(callbackfn: (value: T, index: number) => void): void;
131
- some(predicate: (value: T, index: number) => unknown): boolean;
132
- every(predicate: (value: T, index: number) => unknown): boolean;
133
- find<S extends T>(predicate: (value: T, index: number) => value is S): S | undefined;
134
- find(predicate: (value: T, index: number) => unknown): T | undefined;
135
- readonly [Symbol.toStringTag]: string;
136
- }
137
- interface SpecIterableIterator<T> extends SpecIteratorObject<T> {
138
- [Symbol.iterator](): SpecIterableIterator<T>;
139
- }
140
- interface SpecIterable<T> {
141
- [Symbol.iterator](): SpecIterableIterator<T>;
142
- }
143
- type HeadersInit$1 = [string, string][] | HeaderRecord | Headers$1;
144
- declare class Headers$1 implements SpecIterable<[string, string]> {
145
- constructor(init?: HeadersInit$1);
146
- readonly append: (name: string, value: string) => void;
147
- readonly delete: (name: string) => void;
148
- readonly get: (name: string) => string | null;
149
- readonly has: (name: string) => boolean;
150
- readonly set: (name: string, value: string) => void;
151
- readonly getSetCookie: () => string[];
152
- readonly forEach: (callbackfn: (value: string, key: string, iterable: Headers$1) => void, thisArg?: unknown) => void;
153
- readonly keys: () => SpecIterableIterator<string>;
154
- readonly values: () => SpecIterableIterator<string>;
155
- readonly entries: () => SpecIterableIterator<[string, string]>;
156
- readonly [Symbol.iterator]: () => SpecIterableIterator<[string, string]>;
157
- }
170
+ //#region src/serialize.d.ts
171
+ /**
172
+ * Convert an `Error` (or any value with a `toJSON()` method) into a
173
+ * plain object suitable for embedding in a JSON response body.
174
+ *
175
+ * Calls `input.toJSON()` if present — preserves every attribute the
176
+ * error chose to surface (`code`, `cause`, `errors`, `issues`, `data`,
177
+ * AuthupError sub-class fields, ...). Falls back to spreading the
178
+ * Error's enumerable own properties alongside the standard
179
+ * `name` / `message` pair, so caller-attached fields survive.
180
+ *
181
+ * Pair with `normalizeError` to handle arbitrary thrown values:
182
+ * `serializeError(normalizeError(e))`.
183
+ */
184
+ declare function serializeError(input: Error): Record<string, any>;
158
185
  //#endregion
159
- //#region ../../node_modules/undici/types/formdata.d.ts
160
- declare module 'node:buffer' {
161
- interface File {
162
- readonly [Symbol.toStringTag]: string;
163
- }
164
- }
186
+ //#region src/status.d.ts
165
187
  /**
166
- * A `string` or `File` that represents a single value from a set of `FormData` key-value pairs.
188
+ * Default mapping from `ErrorCode` to HTTP status. Adapters apply this and
189
+ * may layer their own overrides on top. Codes not listed here fall back
190
+ * to 400 (Bad Request) — which is the right default for "validation /
191
+ * malformed-request" style errors.
192
+ *
193
+ * The mapping mirrors the HTTP statuses produced by the pre-refactor
194
+ * `@ebec/http`-coupled error classes, with one intentional change:
195
+ *
196
+ * - `OAUTH_CLIENT_INVALID`: 400 → **401**, per RFC 6749 §5.2 (`invalid_client`
197
+ * responses should use 401). Surfaces as a behavior change in HTTP-level
198
+ * tests asserting `status: 400, code: OAUTH_CLIENT_INVALID`.
167
199
  */
168
- declare type FormDataEntryValue = string | File;
200
+ declare const ERROR_CODE_TO_STATUS: Readonly<Partial<Record<`${ErrorCode}`, number>>>;
169
201
  /**
170
- * Provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using fetch().
202
+ * Resolve an HTTP status for a given error code. Unknown codes fall back
203
+ * to `fallback` (default 400).
171
204
  */
172
- declare class FormData {
173
- /**
174
- * Appends a new value onto an existing key inside a FormData object,
175
- * or adds the key if it does not already exist.
176
- *
177
- * The difference between `set()` and `append()` is that if the specified key already exists, `set()` will overwrite all existing values with the new one, whereas `append()` will append the new value onto the end of the existing set of values.
178
- *
179
- * @param name The name of the field whose data is contained in `value`.
180
- * @param value The field's value. This can be [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
181
- or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
182
- * @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
183
- */
184
- append(name: string, value: unknown, fileName?: string): void;
185
- /**
186
- * Set a new value for an existing key inside FormData,
187
- * or add the new field if it does not already exist.
188
- *
189
- * @param name The name of the field whose data is contained in `value`.
190
- * @param value The field's value. This can be [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
191
- or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
192
- * @param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.
193
- *
194
- */
195
- set(name: string, value: unknown, fileName?: string): void;
196
- /**
197
- * Returns the first value associated with a given key from within a `FormData` object.
198
- * If you expect multiple values and want all of them, use the `getAll()` method instead.
199
- *
200
- * @param {string} name A name of the value you want to retrieve.
201
- *
202
- * @returns A `FormDataEntryValue` containing the value. If the key doesn't exist, the method returns null.
203
- */
204
- get(name: string): FormDataEntryValue | null;
205
- /**
206
- * Returns all the values associated with a given key from within a `FormData` object.
207
- *
208
- * @param {string} name A name of the value you want to retrieve.
209
- *
210
- * @returns An array of `FormDataEntryValue` whose key matches the value passed in the `name` parameter. If the key doesn't exist, the method returns an empty list.
211
- */
212
- getAll(name: string): FormDataEntryValue[];
213
- /**
214
- * Returns a boolean stating whether a `FormData` object contains a certain key.
215
- *
216
- * @param name A string representing the name of the key you want to test for.
217
- *
218
- * @return A boolean value.
219
- */
220
- has(name: string): boolean;
221
- /**
222
- * Deletes a key and its value(s) from a `FormData` object.
223
- *
224
- * @param name The name of the key you want to delete.
225
- */
226
- delete(name: string): void;
227
- /**
228
- * Executes given callback function for each field of the FormData instance
229
- */
230
- forEach: (callbackfn: (value: FormDataEntryValue, key: string, iterable: FormData) => void, thisArg?: unknown) => void;
231
- /**
232
- * Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through all keys contained in this `FormData` object.
233
- * Each key is a `string`.
234
- */
235
- keys: () => SpecIterableIterator<string>;
236
- /**
237
- * Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through all values contained in this object `FormData` object.
238
- * Each value is a [`FormDataValue`](https://developer.mozilla.org/en-US/docs/Web/API/FormDataEntryValue).
239
- */
240
- values: () => SpecIterableIterator<FormDataEntryValue>;
241
- /**
242
- * Returns an [`iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) allowing to go through the `FormData` key/value pairs.
243
- * The key of each pair is a string; the value is a [`FormDataValue`](https://developer.mozilla.org/en-US/docs/Web/API/FormDataEntryValue).
244
- */
245
- entries: () => SpecIterableIterator<[string, FormDataEntryValue]>;
246
- /**
247
- * An alias for FormData#entries()
248
- */
249
- [Symbol.iterator]: () => SpecIterableIterator<[string, FormDataEntryValue]>;
250
- readonly [Symbol.toStringTag]: string;
251
- }
252
- //#endregion
253
- //#region ../../node_modules/undici/types/connector.d.ts
254
- declare function buildConnector(options?: buildConnector.BuildOptions): buildConnector.connector;
255
- declare namespace buildConnector {
256
- export type BuildOptions = (ConnectionOptions | TcpNetConnectOpts | IpcNetConnectOpts) & {
257
- allowH2?: boolean;
258
- maxCachedSessions?: number | null;
259
- socketPath?: string | null;
260
- timeout?: number | null;
261
- port?: number;
262
- keepAlive?: boolean | null;
263
- keepAliveInitialDelay?: number | null;
264
- typeOfService?: number | null;
265
- };
266
- export interface Options {
267
- hostname: string;
268
- host?: string;
269
- protocol: string;
270
- port: string;
271
- servername?: string;
272
- localAddress?: string | null;
273
- socketPath?: string | null;
274
- httpSocket?: Socket;
275
- }
276
- export type Callback = (...args: CallbackArgs) => void;
277
- type CallbackArgs = [null, Socket | TLSSocket] | [Error, null];
278
- export interface connector {
279
- (options: buildConnector.Options, callback: buildConnector.Callback): void;
280
- }
281
- }
282
- //#endregion
283
- //#region ../../node_modules/undici/types/client-stats.d.ts
284
- declare class ClientStats {
285
- constructor(pool: Client);
286
- /** If socket has open connection. */
287
- connected: boolean;
288
- /** Number of open socket connections in this client that do not have an active request. */
289
- pending: number;
290
- /** Number of currently active requests of this client. */
291
- running: number;
292
- /** Number of active, pending, or queued requests of this client. */
293
- size: number;
294
- }
295
- //#endregion
296
- //#region ../../node_modules/undici/types/client.d.ts
297
- type ClientConnectOptions = Omit<Dispatcher.ConnectOptions, 'origin'>;
205
+ declare function httpStatusFromCode(code: string, fallback?: number): number;
298
206
  /**
299
- * A basic HTTP/1.1 client, mapped on top a single TCP/TLS connection. Pipelining is disabled by default.
207
+ * Resolve a semantic `ErrorCode` for a foreign HTTP status. Used at the
208
+ * boundary where a non-AuthupError (e.g. `@ebec/http` HTTPError thrown by
209
+ * the framework, or a foreign service response) enters our system and
210
+ * needs to be normalized into an `AuthupError` with an authup-vocabulary
211
+ * code. Status is the only stable handshake across the two vocabularies.
212
+ *
213
+ * Default mapping covers the common HTTP statuses. Anything 5xx
214
+ * collapses to `INTERNAL_ERROR`; unknown 4xx collapses to `BAD_REQUEST`.
300
215
  */
301
- declare class Client extends Dispatcher {
302
- constructor(url: string | URL$1, options?: Client.Options);
303
- /** Property to get and set the pipelining factor. */
304
- pipelining: number;
305
- /** `true` after `client.close()` has been called. */
306
- closed: boolean;
307
- /** `true` after `client.destroyed()` has been called or `client.close()` has been called and the client shutdown has completed. */
308
- destroyed: boolean;
309
- /** Aggregate stats for a Client. */
310
- readonly stats: ClientStats; // Override dispatcher APIs.
311
- override connect(options: ClientConnectOptions): Promise<Dispatcher.ConnectData>;
312
- override connect(options: ClientConnectOptions, callback: (err: Error | null, data: Dispatcher.ConnectData) => void): void;
313
- }
314
- declare namespace Client {
315
- export interface OptionsInterceptors {
316
- Client: readonly Dispatcher.DispatchInterceptor[];
317
- }
318
- export interface Options {
319
- /** TODO */
320
- interceptors?: OptionsInterceptors;
321
- /** The maximum length of request headers in bytes. Default: Node.js' `--max-http-header-size` or `16384` (16KiB). */
322
- maxHeaderSize?: number;
323
- /** The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers (Node 14 and above only). Default: `300e3` milliseconds (300s). */
324
- headersTimeout?: number;
325
- /** @deprecated unsupported socketTimeout, use headersTimeout & bodyTimeout instead */
326
- socketTimeout?: never;
327
- /** @deprecated unsupported requestTimeout, use headersTimeout & bodyTimeout instead */
328
- requestTimeout?: never;
329
- /** TODO */
330
- connectTimeout?: number;
331
- /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Default: `300e3` milliseconds (300s). */
332
- bodyTimeout?: number;
333
- /** @deprecated unsupported idleTimeout, use keepAliveTimeout instead */
334
- idleTimeout?: never;
335
- /** @deprecated unsupported keepAlive, use pipelining=0 instead */
336
- keepAlive?: never;
337
- /** the timeout, in milliseconds, after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. Default: `4e3` milliseconds (4s). */
338
- keepAliveTimeout?: number;
339
- /** @deprecated unsupported maxKeepAliveTimeout, use keepAliveMaxTimeout instead */
340
- maxKeepAliveTimeout?: never;
341
- /** the maximum allowed `idleTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Default: `600e3` milliseconds (10min). */
342
- keepAliveMaxTimeout?: number;
343
- /** A number of milliseconds subtracted from server *keep-alive* hints when overriding `idleTimeout` to account for timing inaccuracies caused by e.g. transport latency. Default: `1e3` milliseconds (1s). */
344
- keepAliveTimeoutThreshold?: number;
345
- /** TODO */
346
- socketPath?: string;
347
- /** The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Default: `1`. */
348
- pipelining?: number;
349
- /** @deprecated use the connect option instead */
350
- tls?: never;
351
- /** If `true`, an error is thrown when the request content-length header doesn't match the length of the request body. Default: `true`. */
352
- strictContentLength?: boolean;
353
- /** TODO */
354
- maxCachedSessions?: number;
355
- /** TODO */
356
- connect?: Partial<buildConnector.BuildOptions> | buildConnector.connector;
357
- /** TODO */
358
- maxRequestsPerClient?: number;
359
- /** TODO */
360
- localAddress?: string;
361
- /** Max response body size in bytes, -1 is disabled */
362
- maxResponseSize?: number;
363
- /** Enables a family autodetection algorithm that loosely implements section 5 of RFC 8305. */
364
- autoSelectFamily?: boolean;
365
- /** The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. */
366
- autoSelectFamilyAttemptTimeout?: number;
367
- /**
368
- * @description Enables support for H2 if the server has assigned bigger priority to it through ALPN negotiation.
369
- * @default false
370
- */
371
- allowH2?: boolean;
372
- /**
373
- * @description Dictates the maximum number of concurrent streams for a single H2 session. It can be overridden by a SETTINGS remote frame.
374
- * @default 100
375
- */
376
- maxConcurrentStreams?: number;
377
- /**
378
- * @description Sets the HTTP/2 stream-level flow-control window size (SETTINGS_INITIAL_WINDOW_SIZE).
379
- * @default 262144
380
- */
381
- initialWindowSize?: number;
382
- /**
383
- * @description Sets the HTTP/2 connection-level flow-control window size (ClientHttp2Session.setLocalWindowSize).
384
- * @default 524288
385
- */
386
- connectionWindowSize?: number;
387
- /**
388
- * @description Time interval between PING frames dispatch
389
- * @default 60000
390
- */
391
- pingInterval?: number;
392
- }
393
- export interface SocketInfo {
394
- localAddress?: string;
395
- localPort?: number;
396
- remoteAddress?: string;
397
- remotePort?: number;
398
- remoteFamily?: string;
399
- timeout?: number;
400
- bytesWritten?: number;
401
- bytesRead?: number;
402
- }
403
- }
404
- //#endregion
405
- //#region ../../node_modules/undici/types/errors.d.ts
406
- declare namespace Errors {
407
- export class UndiciError extends Error {
408
- name: string;
409
- code: string;
410
- }
411
- /** Connect timeout error. */
412
- export class ConnectTimeoutError extends UndiciError {
413
- name: 'ConnectTimeoutError';
414
- code: 'UND_ERR_CONNECT_TIMEOUT';
415
- }
416
- /** A header exceeds the `headersTimeout` option. */
417
- export class HeadersTimeoutError extends UndiciError {
418
- name: 'HeadersTimeoutError';
419
- code: 'UND_ERR_HEADERS_TIMEOUT';
420
- }
421
- /** Headers overflow error. */
422
- export class HeadersOverflowError extends UndiciError {
423
- name: 'HeadersOverflowError';
424
- code: 'UND_ERR_HEADERS_OVERFLOW';
425
- }
426
- /** A body exceeds the `bodyTimeout` option. */
427
- export class BodyTimeoutError extends UndiciError {
428
- name: 'BodyTimeoutError';
429
- code: 'UND_ERR_BODY_TIMEOUT';
430
- }
431
- export class ResponseError extends UndiciError {
432
- constructor(message: string, code: number, options: {
433
- headers?: IncomingHttpHeaders | string[] | null;
434
- body?: null | Record<string, any> | string;
435
- });
436
- name: 'ResponseError';
437
- code: 'UND_ERR_RESPONSE';
438
- statusCode: number;
439
- body: null | Record<string, any> | string;
440
- headers: IncomingHttpHeaders | string[] | null;
441
- }
442
- /** Passed an invalid argument. */
443
- export class InvalidArgumentError extends UndiciError {
444
- name: 'InvalidArgumentError';
445
- code: 'UND_ERR_INVALID_ARG';
446
- }
447
- /** Returned an invalid value. */
448
- export class InvalidReturnValueError extends UndiciError {
449
- name: 'InvalidReturnValueError';
450
- code: 'UND_ERR_INVALID_RETURN_VALUE';
451
- }
452
- /** The request has been aborted by the user. */
453
- export class RequestAbortedError extends UndiciError {
454
- name: 'AbortError';
455
- code: 'UND_ERR_ABORTED';
456
- }
457
- /** Expected error with reason. */
458
- export class InformationalError extends UndiciError {
459
- name: 'InformationalError';
460
- code: 'UND_ERR_INFO';
461
- }
462
- /** Request body length does not match content-length header. */
463
- export class RequestContentLengthMismatchError extends UndiciError {
464
- name: 'RequestContentLengthMismatchError';
465
- code: 'UND_ERR_REQ_CONTENT_LENGTH_MISMATCH';
466
- }
467
- /** Response body length does not match content-length header. */
468
- export class ResponseContentLengthMismatchError extends UndiciError {
469
- name: 'ResponseContentLengthMismatchError';
470
- code: 'UND_ERR_RES_CONTENT_LENGTH_MISMATCH';
471
- }
472
- /** Trying to use a destroyed client. */
473
- export class ClientDestroyedError extends UndiciError {
474
- name: 'ClientDestroyedError';
475
- code: 'UND_ERR_DESTROYED';
476
- }
477
- /** Trying to use a closed client. */
478
- export class ClientClosedError extends UndiciError {
479
- name: 'ClientClosedError';
480
- code: 'UND_ERR_CLOSED';
481
- }
482
- /** There is an error with the socket. */
483
- export class SocketError extends UndiciError {
484
- name: 'SocketError';
485
- code: 'UND_ERR_SOCKET';
486
- socket: Client.SocketInfo | null;
487
- }
488
- /** Encountered unsupported functionality. */
489
- export class NotSupportedError extends UndiciError {
490
- name: 'NotSupportedError';
491
- code: 'UND_ERR_NOT_SUPPORTED';
492
- }
493
- /** No upstream has been added to the BalancedPool. */
494
- export class BalancedPoolMissingUpstreamError extends UndiciError {
495
- name: 'MissingUpstreamError';
496
- code: 'UND_ERR_BPL_MISSING_UPSTREAM';
497
- }
498
- export class HTTPParserError extends UndiciError {
499
- name: 'HTTPParserError';
500
- code: string;
501
- }
502
- /** The response exceed the length allowed. */
503
- export class ResponseExceededMaxSizeError extends UndiciError {
504
- name: 'ResponseExceededMaxSizeError';
505
- code: 'UND_ERR_RES_EXCEEDED_MAX_SIZE';
506
- }
507
- export class RequestRetryError extends UndiciError {
508
- constructor(message: string, statusCode: number, headers?: IncomingHttpHeaders | string[] | null, body?: null | Record<string, any> | string);
509
- name: 'RequestRetryError';
510
- code: 'UND_ERR_REQ_RETRY';
511
- statusCode: number;
512
- data: {
513
- count: number;
514
- };
515
- headers: Record<string, string | string[]>;
516
- }
517
- export class SecureProxyConnectionError extends UndiciError {
518
- constructor(cause?: Error, message?: string, options?: Record<any, any>);
519
- name: 'SecureProxyConnectionError';
520
- code: 'UND_ERR_PRX_TLS';
521
- }
522
- export class MaxOriginsReachedError extends UndiciError {
523
- name: 'MaxOriginsReachedError';
524
- code: 'UND_ERR_MAX_ORIGINS_REACHED';
525
- }
526
- /** SOCKS5 proxy related error. */
527
- export class Socks5ProxyError extends UndiciError {
528
- constructor(message?: string, code?: string);
529
- name: 'Socks5ProxyError';
530
- code: string;
531
- }
532
- /** WebSocket decompressed message exceeded maximum size. */
533
- export class MessageSizeExceededError extends UndiciError {
534
- name: 'MessageSizeExceededError';
535
- code: 'UND_ERR_WS_MESSAGE_SIZE_EXCEEDED';
536
- }
537
- }
538
- //#endregion
539
- //#region ../../node_modules/undici/types/dispatcher.d.ts
540
- type AbortSignal$1 = unknown;
541
- type UndiciHeaders = Record<string, string | string[]> | IncomingHttpHeaders | string[] | Iterable<[string, string | string[] | undefined]> | null;
542
- /** Dispatcher is the core API used to dispatch requests. */
543
- declare class Dispatcher extends EventEmitter {
544
- /** Dispatches a request. This API is expected to evolve through semver-major versions and is less stable than the preceding higher level APIs. It is primarily intended for library developers who implement higher level APIs on top of this. */
545
- dispatch(options: Dispatcher.DispatchOptions, handler: Dispatcher.DispatchHandler): boolean;
546
- /** Starts two-way communications with the requested resource. */
547
- connect<TOpaque = null>(options: Dispatcher.ConnectOptions<TOpaque>, callback: (err: Error | null, data: Dispatcher.ConnectData<TOpaque>) => void): void;
548
- connect<TOpaque = null>(options: Dispatcher.ConnectOptions<TOpaque>): Promise<Dispatcher.ConnectData<TOpaque>>;
549
- /** Compose a chain of dispatchers */
550
- compose(dispatchers: Dispatcher.DispatcherComposeInterceptor[]): Dispatcher.ComposedDispatcher;
551
- compose(...dispatchers: Dispatcher.DispatcherComposeInterceptor[]): Dispatcher.ComposedDispatcher;
552
- /** Performs an HTTP request. */
553
- request<TOpaque = null>(options: Dispatcher.RequestOptions<TOpaque>, callback: (err: Error | null, data: Dispatcher.ResponseData<TOpaque>) => void): void;
554
- request<TOpaque = null>(options: Dispatcher.RequestOptions<TOpaque>): Promise<Dispatcher.ResponseData<TOpaque>>;
555
- /** For easy use with `stream.pipeline`. */
556
- pipeline<TOpaque = null>(options: Dispatcher.PipelineOptions<TOpaque>, handler: Dispatcher.PipelineHandler<TOpaque>): Duplex;
557
- /** A faster version of `Dispatcher.request`. */
558
- stream<TOpaque = null>(options: Dispatcher.RequestOptions<TOpaque>, factory: Dispatcher.StreamFactory<TOpaque>, callback: (err: Error | null, data: Dispatcher.StreamData<TOpaque>) => void): void;
559
- stream<TOpaque = null>(options: Dispatcher.RequestOptions<TOpaque>, factory: Dispatcher.StreamFactory<TOpaque>): Promise<Dispatcher.StreamData<TOpaque>>;
560
- /** Upgrade to a different protocol. */
561
- upgrade(options: Dispatcher.UpgradeOptions, callback: (err: Error | null, data: Dispatcher.UpgradeData) => void): void;
562
- upgrade(options: Dispatcher.UpgradeOptions): Promise<Dispatcher.UpgradeData>;
563
- /** Closes the client and gracefully waits for enqueued requests to complete before invoking the callback (or returning a promise if no callback is provided). */
564
- close(callback: () => void): void;
565
- close(): Promise<void>;
566
- /** Destroy the client abruptly with the given err. All the pending and running requests will be asynchronously aborted and error. Waits until socket is closed before invoking the callback (or returning a promise if no callback is provided). Since this operation is asynchronously dispatched there might still be some progress on dispatched requests. */
567
- destroy(err: Error | null, callback: () => void): void;
568
- destroy(callback: () => void): void;
569
- destroy(err: Error | null): Promise<void>;
570
- destroy(): Promise<void>;
571
- on(eventName: 'connect', callback: (origin: URL$1, targets: readonly Dispatcher[]) => void): this;
572
- on(eventName: 'disconnect', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
573
- on(eventName: 'connectionError', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
574
- on(eventName: 'drain', callback: (origin: URL$1) => void): this;
575
- once(eventName: 'connect', callback: (origin: URL$1, targets: readonly Dispatcher[]) => void): this;
576
- once(eventName: 'disconnect', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
577
- once(eventName: 'connectionError', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
578
- once(eventName: 'drain', callback: (origin: URL$1) => void): this;
579
- off(eventName: 'connect', callback: (origin: URL$1, targets: readonly Dispatcher[]) => void): this;
580
- off(eventName: 'disconnect', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
581
- off(eventName: 'connectionError', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
582
- off(eventName: 'drain', callback: (origin: URL$1) => void): this;
583
- addListener(eventName: 'connect', callback: (origin: URL$1, targets: readonly Dispatcher[]) => void): this;
584
- addListener(eventName: 'disconnect', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
585
- addListener(eventName: 'connectionError', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
586
- addListener(eventName: 'drain', callback: (origin: URL$1) => void): this;
587
- removeListener(eventName: 'connect', callback: (origin: URL$1, targets: readonly Dispatcher[]) => void): this;
588
- removeListener(eventName: 'disconnect', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
589
- removeListener(eventName: 'connectionError', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
590
- removeListener(eventName: 'drain', callback: (origin: URL$1) => void): this;
591
- prependListener(eventName: 'connect', callback: (origin: URL$1, targets: readonly Dispatcher[]) => void): this;
592
- prependListener(eventName: 'disconnect', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
593
- prependListener(eventName: 'connectionError', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
594
- prependListener(eventName: 'drain', callback: (origin: URL$1) => void): this;
595
- prependOnceListener(eventName: 'connect', callback: (origin: URL$1, targets: readonly Dispatcher[]) => void): this;
596
- prependOnceListener(eventName: 'disconnect', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
597
- prependOnceListener(eventName: 'connectionError', callback: (origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void): this;
598
- prependOnceListener(eventName: 'drain', callback: (origin: URL$1) => void): this;
599
- listeners(eventName: 'connect'): ((origin: URL$1, targets: readonly Dispatcher[]) => void)[];
600
- listeners(eventName: 'disconnect'): ((origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
601
- listeners(eventName: 'connectionError'): ((origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
602
- listeners(eventName: 'drain'): ((origin: URL$1) => void)[];
603
- rawListeners(eventName: 'connect'): ((origin: URL$1, targets: readonly Dispatcher[]) => void)[];
604
- rawListeners(eventName: 'disconnect'): ((origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
605
- rawListeners(eventName: 'connectionError'): ((origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError) => void)[];
606
- rawListeners(eventName: 'drain'): ((origin: URL$1) => void)[];
607
- emit(eventName: 'connect', origin: URL$1, targets: readonly Dispatcher[]): boolean;
608
- emit(eventName: 'disconnect', origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError): boolean;
609
- emit(eventName: 'connectionError', origin: URL$1, targets: readonly Dispatcher[], error: Errors.UndiciError): boolean;
610
- emit(eventName: 'drain', origin: URL$1): boolean;
611
- }
612
- declare namespace Dispatcher {
613
- export interface ComposedDispatcher extends Dispatcher {}
614
- export type Dispatch = Dispatcher['dispatch'];
615
- export type DispatcherComposeInterceptor = (dispatch: Dispatch) => Dispatch;
616
- export interface DispatchOptions {
617
- origin?: string | URL$1;
618
- path: string;
619
- method: HttpMethod;
620
- /** Default: `null` */
621
- body?: string | Buffer | Uint8Array | Readable | null | FormData;
622
- /** Default: `null` */
623
- headers?: UndiciHeaders;
624
- /** Query string params to be embedded in the request URL. Default: `null` */
625
- query?: Record<string, any>;
626
- /** Whether the requests can be safely retried or not. If `false` the request won't be sent until all preceding requests in the pipeline have completed. Default: `true` if `method` is `HEAD` or `GET`. */
627
- idempotent?: boolean;
628
- /** Whether the response is expected to take a long time and would end up blocking the pipeline. When this is set to `true` further pipelining will be avoided on the same connection until headers have been received. Defaults to `method !== 'HEAD'`. */
629
- blocking?: boolean;
630
- /** The IP Type of Service (ToS) value for the request socket. Must be an integer between 0 and 255. Default: `0` */
631
- typeOfService?: number | null;
632
- /** Upgrade the request. Should be used to specify the kind of upgrade i.e. `'Websocket'`. Default: `method === 'CONNECT' || null`. */
633
- upgrade?: boolean | string | null;
634
- /** The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers. Defaults to 300 seconds. */
635
- headersTimeout?: number | null;
636
- /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use 0 to disable it entirely. Defaults to 300 seconds. */
637
- bodyTimeout?: number | null;
638
- /** Whether the request should stablish a keep-alive or not. Default `false` */
639
- reset?: boolean;
640
- /** Whether Undici should throw an error upon receiving a 4xx or 5xx response from the server. Defaults to false */
641
- throwOnError?: boolean;
642
- /** For H2, it appends the expect: 100-continue header, and halts the request body until a 100-continue is received from the remote server */
643
- expectContinue?: boolean;
644
- }
645
- export interface ConnectOptions<TOpaque = null> {
646
- origin: string | URL$1;
647
- path: string;
648
- /** Default: `null` */
649
- headers?: UndiciHeaders;
650
- /** Default: `null` */
651
- signal?: AbortSignal$1 | EventEmitter | null;
652
- /** This argument parameter is passed through to `ConnectData` */
653
- opaque?: TOpaque;
654
- /** Default: `null` */
655
- responseHeaders?: 'raw' | null;
656
- }
657
- export interface RequestOptions<TOpaque = null> extends DispatchOptions {
658
- /** Default: `null` */
659
- opaque?: TOpaque;
660
- /** Default: `null` */
661
- signal?: AbortSignal$1 | EventEmitter | null;
662
- /** Default: `null` */
663
- onInfo?: (info: {
664
- statusCode: number;
665
- headers: Record<string, string | string[]>;
666
- }) => void;
667
- /** Default: `null` */
668
- responseHeaders?: 'raw' | null;
669
- /** Default: `64 KiB` */
670
- highWaterMark?: number;
671
- }
672
- export interface PipelineOptions<TOpaque = null> extends RequestOptions<TOpaque> {
673
- /** `true` if the `handler` will return an object stream. Default: `false` */
674
- objectMode?: boolean;
675
- }
676
- export interface UpgradeOptions {
677
- path: string;
678
- /** Default: `'GET'` */
679
- method?: string;
680
- /** Default: `null` */
681
- headers?: UndiciHeaders;
682
- /** A string of comma separated protocols, in descending preference order. Default: `'Websocket'` */
683
- protocol?: string;
684
- /** Default: `null` */
685
- signal?: AbortSignal$1 | EventEmitter | null;
686
- /** Default: `null` */
687
- responseHeaders?: 'raw' | null;
688
- }
689
- export interface ConnectData<TOpaque = null> {
690
- statusCode: number;
691
- headers: IncomingHttpHeaders;
692
- socket: Duplex;
693
- opaque: TOpaque;
694
- }
695
- export interface ResponseData<TOpaque = null> {
696
- statusCode: number;
697
- statusText: string;
698
- headers: IncomingHttpHeaders;
699
- body: BodyReadable & BodyMixin;
700
- trailers: Record<string, string>;
701
- opaque: TOpaque;
702
- context: object;
703
- }
704
- export interface PipelineHandlerData<TOpaque = null> {
705
- statusCode: number;
706
- headers: IncomingHttpHeaders;
707
- opaque: TOpaque;
708
- body: BodyReadable;
709
- context: object;
710
- }
711
- export interface StreamData<TOpaque = null> {
712
- opaque: TOpaque;
713
- trailers: Record<string, string>;
714
- }
715
- export interface UpgradeData<TOpaque = null> {
716
- headers: IncomingHttpHeaders;
717
- socket: Duplex;
718
- opaque: TOpaque;
719
- }
720
- export interface StreamFactoryData<TOpaque = null> {
721
- statusCode: number;
722
- headers: IncomingHttpHeaders;
723
- opaque: TOpaque;
724
- context: object;
725
- }
726
- export type StreamFactory<TOpaque = null> = (data: StreamFactoryData<TOpaque>) => Writable;
727
- export interface DispatchController {
728
- get aborted(): boolean;
729
- get paused(): boolean;
730
- get reason(): Error | null;
731
- abort(reason: Error): void;
732
- pause(): void;
733
- resume(): void;
734
- }
735
- export interface DispatchHandler {
736
- onRequestStart?(controller: DispatchController, context: any): void;
737
- onRequestUpgrade?(controller: DispatchController, statusCode: number, headers: IncomingHttpHeaders, socket: Duplex): void;
738
- onResponseStart?(controller: DispatchController, statusCode: number, headers: IncomingHttpHeaders, statusMessage?: string): void;
739
- onResponseData?(controller: DispatchController, chunk: Buffer): void;
740
- onResponseEnd?(controller: DispatchController, trailers: IncomingHttpHeaders): void;
741
- onResponseError?(controller: DispatchController, error: Error): void;
742
- /** Invoked before request is dispatched on socket. May be invoked multiple times when a request is retried when the request at the head of the pipeline fails. */
743
- /** @deprecated */
744
- onConnect?(abort: (err?: Error) => void): void;
745
- /** Invoked when an error has occurred. */
746
- /** @deprecated */
747
- onError?(err: Error): void;
748
- /** Invoked when request is upgraded either due to a `Upgrade` header or `CONNECT` method. */
749
- /** @deprecated */
750
- onUpgrade?(statusCode: number, headers: Buffer[] | string[] | null, socket: Duplex): void;
751
- /** Invoked when response is received, before headers have been read. **/
752
- /** @deprecated */
753
- onResponseStarted?(): void;
754
- /** Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. */
755
- /** @deprecated */
756
- onHeaders?(statusCode: number, headers: Buffer[], resume: () => void, statusText: string): boolean;
757
- /** Invoked when response payload data is received. */
758
- /** @deprecated */
759
- onData?(chunk: Buffer): boolean;
760
- /** Invoked when response payload and trailers have been received and the request has completed. */
761
- /** @deprecated */
762
- onComplete?(trailers: string[] | null): void;
763
- /** Invoked when a body chunk is sent to the server. May be invoked multiple times for chunked requests */
764
- /** @deprecated */
765
- onBodySent?(chunkSize: number, totalBytesSent: number): void;
766
- }
767
- export type PipelineHandler<TOpaque = null> = (data: PipelineHandlerData<TOpaque>) => Readable;
768
- export type HttpMethod = Autocomplete<'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH'>;
769
- /**
770
- * @link https://fetch.spec.whatwg.org/#body-mixin
771
- */
772
- interface BodyMixin {
773
- readonly body?: never;
774
- readonly bodyUsed: boolean;
775
- arrayBuffer(): Promise<ArrayBuffer>;
776
- blob(): Promise<Blob>;
777
- bytes(): Promise<Uint8Array>;
778
- formData(): Promise<never>;
779
- json(): Promise<unknown>;
780
- text(): Promise<string>;
781
- }
782
- export interface DispatchInterceptor {
783
- (dispatch: Dispatch): Dispatch;
784
- }
785
- }
786
- //#endregion
787
- //#region ../../node_modules/undici/types/mock-interceptor.d.ts
788
- /** The scope associated with a mock dispatch. */
789
- declare class MockScope<TData extends object = object> {
790
- constructor(mockDispatch: MockInterceptor.MockDispatch<TData>);
791
- /** Delay a reply by a set amount of time in ms. */
792
- delay(waitInMs: number): MockScope<TData>;
793
- /** Persist the defined mock data for the associated reply. It will return the defined mock data indefinitely. */
794
- persist(): MockScope<TData>;
795
- /** Define a reply for a set amount of matching requests. */
796
- times(repeatTimes: number): MockScope<TData>;
797
- }
798
- /** The interceptor for a Mock. */
799
- declare class MockInterceptor {
800
- constructor(options: MockInterceptor.Options, mockDispatches: MockInterceptor.MockDispatch[]);
801
- /** Mock an undici request with the defined reply. */
802
- reply<TData extends object = object>(replyOptionsCallback: MockInterceptor.MockReplyOptionsCallback<TData>): MockScope<TData>;
803
- reply<TData extends object = object>(statusCode: number, data?: TData | Buffer | string | MockInterceptor.MockResponseDataHandler<TData>, responseOptions?: MockInterceptor.MockResponseOptions): MockScope<TData>;
804
- /** Mock an undici request by throwing the defined reply error. */
805
- replyWithError<TError extends Error = Error>(error: TError): MockScope;
806
- /** Set default reply headers on the interceptor for subsequent mocked replies. */
807
- defaultReplyHeaders(headers: IncomingHttpHeaders): MockInterceptor;
808
- /** Set default reply trailers on the interceptor for subsequent mocked replies. */
809
- defaultReplyTrailers(trailers: Record<string, string>): MockInterceptor;
810
- /** Set automatically calculated content-length header on subsequent mocked replies. */
811
- replyContentLength(): MockInterceptor;
812
- }
813
- declare namespace MockInterceptor {
814
- /** MockInterceptor options. */
815
- export interface Options {
816
- /** Path to intercept on. */
817
- path: string | RegExp | ((path: string) => boolean);
818
- /** Method to intercept on. Defaults to GET. */
819
- method?: string | RegExp | ((method: string) => boolean);
820
- /** Body to intercept on. */
821
- body?: string | RegExp | ((body: string) => boolean);
822
- /** Headers to intercept on. */
823
- headers?: Record<string, string | RegExp | ((body: string) => boolean)> | ((headers: Record<string, string>) => boolean);
824
- /** Query params to intercept on */
825
- query?: Record<string, any>;
826
- }
827
- export interface MockDispatch<TData extends object = object, TError extends Error = Error> extends Options {
828
- times: number | null;
829
- persist: boolean;
830
- consumed: boolean;
831
- data: MockDispatchData<TData, TError>;
832
- }
833
- export interface MockDispatchData<TData extends object = object, TError extends Error = Error> extends MockResponseOptions {
834
- error: TError | null;
835
- statusCode?: number;
836
- data?: TData | string;
837
- }
838
- export interface MockResponseOptions {
839
- headers?: IncomingHttpHeaders;
840
- trailers?: Record<string, string>;
841
- }
842
- export interface MockResponseCallbackOptions {
843
- path: string;
844
- method: string;
845
- headers?: Headers$1 | Record<string, string>;
846
- origin?: string;
847
- body?: BodyInit | Dispatcher.DispatchOptions['body'] | null;
848
- }
849
- export type MockResponseDataHandler<TData extends object = object> = (opts: MockResponseCallbackOptions) => TData | Buffer | string;
850
- export type MockReplyOptionsCallback<TData extends object = object> = (opts: MockResponseCallbackOptions) => {
851
- statusCode: number;
852
- data?: TData | Buffer | string;
853
- responseOptions?: MockResponseOptions;
854
- };
855
- }
856
- //#endregion
857
- //#region ../../node_modules/hapic/dist/header/authorization/constants.d.ts
858
- declare enum AuthorizationHeaderType {
859
- BEARER = "Bearer",
860
- BASIC = "Basic",
861
- X_API_KEY = "X-API-Key",
862
- API_KEY = "API-Key"
863
- }
864
- //#endregion
865
- //#region src/module.d.ts
866
- declare class AuthupError extends BadRequestError {
867
- readonly issues: Issue[];
868
- constructor(...input: Input[]);
869
- }
870
- //#endregion
871
- //#region src/built-in/http.d.ts
872
- declare class HTTPError extends AuthupError {
873
- static unsupportedHeaderType(type: `${AuthorizationHeaderType}`): HTTPError;
874
- }
875
- //#endregion
876
- //#region src/types.d.ts
877
- type AuthupErrorOptions = Options$1 & {
878
- codePrefix?: string;
879
- };
880
- type AuthupErrorOptionsInput = AuthupErrorOptions | string | Error;
216
+ declare function codeFromHttpStatus(status: number): ErrorCode;
881
217
  //#endregion
882
- export { AuthupError, AuthupErrorOptions, AuthupErrorOptionsInput, ErrorCode, HTTPError };
218
+ export { AUTHUP_ERROR_INSTANCE, AUTH_HEADER_ERROR_INSTANCE, AuthHeaderError, AuthupEntityErrorInput, AuthupEntityErrorOptions, AuthupError, AuthupErrorInput, AuthupErrorOptions, BAD_REQUEST_ERROR_INSTANCE, BASE_ERROR_INSTANCE, BEARER_TOKEN_MALFORMED_ERROR_INSTANCE, BadRequestError, BearerTokenMalformedError, ENTITY_CONFLICT_ERROR_INSTANCE, ENTITY_CREDENTIALS_INVALID_ERROR_INSTANCE, ENTITY_INACTIVE_ERROR_INSTANCE, ENTITY_NOT_FOUND_ERROR_INSTANCE, ERROR_CODE_TO_STATUS, EntityConflictError, EntityCredentialsInvalidError, EntityInactiveError, EntityNotFoundError, ErrorCode, INSTANCEOF_PROPERTY, INTERNAL_ERROR_INSTANCE, InternalError, UNAUTHORIZED_ERROR_INSTANCE, UnauthorizedError, codeFromHttpStatus, hasInstanceof, httpStatusFromCode, isAuthHeaderError, isAuthupError, isBadRequestError, isBearerTokenMalformedError, isEntityConflictError, isEntityCredentialsInvalidError, isEntityInactiveError, isEntityNotFoundError, isError, isInternalError, isUnauthorizedError, markInstanceof, normalizeError, serializeError };
883
219
  //# sourceMappingURL=index.d.mts.map