UNPKG

226 kBTypeScriptView Raw
1/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
2 + +
3 + +
4 + +
5 + WARNING: BACKWARDS INCOMPATIBLE +
6 + +
7 + +
8 + +
9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
10
11/// <reference types='node' />
12
13import * as Boom from "boom";
14import * as http from "http";
15import * as https from "https";
16import * as Shot from "shot";
17import * as stream from "stream";
18import * as url from "url";
19import * as zlib from "zlib";
20
21import { SealOptions, SealOptionsSub } from "iron";
22import { Schema, SchemaMap, ValidationOptions } from "joi";
23import { MimosOptions } from "mimos";
24import Podium = require("podium");
25import {
26 ClientApi,
27 ClientOptions,
28 EnginePrototype,
29 EnginePrototypeOrObject,
30 Policy,
31 PolicyOptions,
32 PolicyOptionVariants,
33} from "catbox";
34
35/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
36 + +
37 + +
38 + +
39 + Plugin +
40 + +
41 + +
42 + +
43 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
44
45/**
46 * one of
47 * a single plugin name string.
48 * an array of plugin name strings.
49 * an object where each key is a plugin name and each matching value is a
50 * {@link https://www.npmjs.com/package/semver version range string} which must match the registered
51 * plugin version.
52 */
53export type Dependencies = string | string[] | {
54 [key: string]: string;
55};
56
57/**
58 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverregistrations)
59 */
60
61/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
62export interface PluginsListRegistered {
63}
64
65/**
66 * An object of the currently registered plugins where each key is a registered plugin name and the value is an
67 * object containing:
68 * * version - the plugin version.
69 * * name - the plugin name.
70 * * options - (optional) options passed to the plugin during registration.
71 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverregistrations)
72 */
73export interface PluginRegistered {
74 /**
75 * the plugin version.
76 */
77 version: string;
78
79 /**
80 * the plugin name.
81 */
82 name: string;
83
84 /**
85 * options used to register the plugin.
86 */
87 options: object;
88}
89
90/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
91export interface PluginsStates {
92}
93
94/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
95export interface PluginSpecificConfiguration {
96}
97
98export interface PluginNameVersion {
99 /**
100 * (required) the plugin name string. The name is used as a unique key. Published plugins (e.g. published in the npm
101 * registry) should use the same name as the name field in their 'package.json' file. Names must be
102 * unique within each application.
103 */
104 name: string;
105
106 /**
107 * optional plugin version. The version is only used informatively to enable other plugins to find out the versions loaded. The version should be the same as the one specified in the plugin's
108 * 'package.json' file.
109 */
110 version?: string | undefined;
111}
112
113export interface PluginPackage {
114 /**
115 * Alternatively, the name and version can be included via the pkg property containing the 'package.json' file for the module which already has the name and version included
116 */
117 pkg: any;
118}
119
120/**
121 * Plugins provide a way to organize application code by splitting the server logic into smaller components. Each
122 * plugin can manipulate the server through the standard server interface, but with the added ability to sandbox
123 * certain properties. For example, setting a file path in one plugin doesn't affect the file path set
124 * in another plugin.
125 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#plugins)
126 *
127 * The type T is the type of the plugin options.
128 */
129export interface PluginBase<T> {
130 /**
131 * (required) the registration function with the signature async function(server, options) where:
132 * * server - the server object with a plugin-specific server.realm.
133 * * options - any options passed to the plugin during registration via server.register().
134 */
135 register: (server: Server, options: T) => void | Promise<void>;
136
137 /** (optional) if true, allows the plugin to be registered multiple times with the same server. Defaults to false. */
138 multiple?: boolean | undefined;
139
140 /** (optional) a string or an array of strings indicating a plugin dependency. Same as setting dependencies via server.dependency(). */
141 dependencies?: Dependencies | undefined;
142
143 /**
144 * Allows defining semver requirements for node and hapi.
145 * @default Allows all.
146 */
147 requirements?: {
148 node?: string | undefined;
149 hapi?: string | undefined;
150 } | undefined;
151
152 /** once - (optional) if true, will only register the plugin once per server. If set, overrides the once option passed to server.register(). Defaults to no override. */
153 once?: boolean | undefined;
154}
155
156export type Plugin<T> = PluginBase<T> & (PluginNameVersion | PluginPackage);
157
158/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
159 + +
160 + +
161 + +
162 + Request +
163 + +
164 + +
165 + +
166 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
167
168/**
169 * User extensible types user credentials.
170 */
171// eslint-disable-next-line @typescript-eslint/no-empty-interface
172export interface UserCredentials {
173}
174
175/**
176 * User extensible types app credentials.
177 */
178// eslint-disable-next-line @typescript-eslint/no-empty-interface
179export interface AppCredentials {
180}
181
182/**
183 * User-extensible type for request.auth credentials.
184 */
185export interface AuthCredentials {
186 /**
187 * The application scopes to be granted.
188 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccessscope)
189 */
190 scope?: string[] | undefined;
191 /**
192 * If set, will only work with routes that set `access.entity` to `user`.
193 */
194 user?: UserCredentials | undefined;
195
196 /**
197 * If set, will only work with routes that set `access.entity` to `app`.
198 */
199 app?: AppCredentials | undefined;
200}
201
202/**
203 * Authentication information:
204 * * artifacts - an artifact object received from the authentication strategy and used in authentication-related actions.
205 * * credentials - the credential object received during the authentication process. The presence of an object does not mean successful authentication.
206 * * error - the authentication error is failed and mode set to 'try'.
207 * * isAuthenticated - true if the request has been successfully authenticated, otherwise false.
208 * * isAuthorized - true is the request has been successfully authorized against the route authentication access configuration. If the route has not access rules defined or if the request failed
209 * authorization, set to false.
210 * * mode - the route authentication mode.
211 * * strategy - the name of the strategy used.
212 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestauth)
213 */
214export interface RequestAuth {
215 /** an artifact object received from the authentication strategy and used in authentication-related actions. */
216 artifacts: object;
217 /** the credential object received during the authentication process. The presence of an object does not mean successful authentication. */
218 credentials: AuthCredentials;
219 /** the authentication error is failed and mode set to 'try'. */
220 error: Error;
221 /** true if the request has been successfully authenticated, otherwise false. */
222 isAuthenticated: boolean;
223 /**
224 * true is the request has been successfully authorized against the route authentication access configuration. If the route has not access rules defined or if the request failed authorization,
225 * set to false.
226 */
227 isAuthorized: boolean;
228 /** the route authentication mode. */
229 mode: string;
230 /** the name of the strategy used. */
231 strategy: string;
232}
233
234/**
235 * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
236 * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
237 * 'disconnect' - emitted when a request errors or aborts unexpectedly.
238 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
239 */
240export type RequestEventType = "peek" | "finish" | "disconnect";
241
242/**
243 * Access: read only and the public podium interface.
244 * The request.events supports the following events:
245 * * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
246 * * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
247 * * 'disconnect' - emitted when a request errors or aborts unexpectedly.
248 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
249 */
250export interface RequestEvents extends Podium {
251 /**
252 * Access: read only and the public podium interface.
253 * The request.events supports the following events:
254 * * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
255 * * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
256 * * 'disconnect' - emitted when a request errors or aborts unexpectedly.
257 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
258 */
259 on(criteria: "peek", listener: PeekListener): void;
260
261 on(criteria: "finish" | "disconnect", listener: (data: undefined) => void): void;
262
263 /**
264 * Access: read only and the public podium interface.
265 * The request.events supports the following events:
266 * * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
267 * * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
268 * * 'disconnect' - emitted when a request errors or aborts unexpectedly.
269 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
270 */
271 once(criteria: "peek", listener: PeekListener): void;
272
273 once(criteria: "finish" | "disconnect", listener: (data: undefined) => void): void;
274}
275
276/**
277 * Request information:
278 * * acceptEncoding - the request preferred encoding.
279 * * cors - if CORS is enabled for the route, contains the following:
280 * * isOriginMatch - true if the request 'Origin' header matches the configured CORS restrictions. Set to false if no 'Origin' header is found or if it does not match. Note that this is only
281 * available after the 'onRequest' extension point as CORS is configured per-route and no routing decisions are made at that point in the request lifecycle.
282 * * host - content of the HTTP 'Host' header (e.g. 'example.com:8080').
283 * * hostname - the hostname part of the 'Host' header (e.g. 'example.com').
284 * * id - a unique request identifier (using the format '{now}:{connection.info.id}:{5 digits counter}').
285 * * received - request reception timestamp.
286 * * referrer - content of the HTTP 'Referrer' (or 'Referer') header.
287 * * remoteAddress - remote client IP address.
288 * * remotePort - remote client port.
289 * * responded - request response timestamp (0 is not responded yet).
290 * Note that the request.info object is not meant to be modified.
291 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestinfo)
292 */
293export interface RequestInfo {
294 /** the request preferred encoding. */
295 acceptEncoding: string;
296 /** if CORS is enabled for the route, contains the following: */
297 cors: {
298 /**
299 * true if the request 'Origin' header matches the configured CORS restrictions. Set to false if no 'Origin' header is found or if it does not match. Note that this is only available after
300 * the 'onRequest' extension point as CORS is configured per-route and no routing decisions are made at that point in the request lifecycle.
301 */
302 isOriginMatch?: boolean | undefined;
303 };
304 /** content of the HTTP 'Host' header (e.g. 'example.com:8080'). */
305 host: string;
306 /** the hostname part of the 'Host' header (e.g. 'example.com'). */
307 hostname: string;
308 /** a unique request identifier (using the format '{now}:{connection.info.id}:{5 digits counter}') */
309 id: string;
310 /** request reception timestamp. */
311 received: number;
312 /** content of the HTTP 'Referrer' (or 'Referer') header. */
313 referrer: string;
314 /** remote client IP address. */
315 remoteAddress: string;
316 /** remote client port. */
317 remotePort: string;
318 /** request response timestamp (0 is not responded yet). */
319 responded: number;
320 /** request processing completion timestamp (0 is still processing). */
321 completed: number;
322}
323
324/**
325 * The request route information object, where:
326 * * method - the route HTTP method.
327 * * path - the route path.
328 * * vhost - the route vhost option if configured.
329 * * realm - the active realm associated with the route.
330 * * settings - the route options object with all defaults applied.
331 * * fingerprint - the route internal normalized string representing the normalized path.
332 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestroute)
333 */
334export interface RequestRoute {
335 /** the route HTTP method. */
336 method: Util.HTTP_METHODS_PARTIAL;
337
338 /** the route path. */
339 path: string;
340
341 /** the route vhost option if configured. */
342 vhost?: string | string[] | undefined;
343
344 /** the active realm associated with the route. */
345 realm: ServerRealm;
346
347 /** the route options object with all defaults applied. */
348 settings: RouteOptions;
349
350 /** the route internal normalized string representing the normalized path. */
351 fingerprint: string;
352
353 auth: {
354 /**
355 * Validates a request against the route's authentication access configuration, where:
356 * @param request - the request object.
357 * @return Return value: true if the request would have passed the route's access requirements.
358 * Note that the route's authentication mode and strategies are ignored. The only match is made between the request.auth.credentials scope and entity information and the route access
359 * configuration. If the route uses dynamic scopes, the scopes are constructed against the request.query, request.params, request.payload, and request.auth.credentials which may or may
360 * not match between the route and the request's route. If this method is called using a request that has not been authenticated (yet or not at all), it will return false if the route
361 * requires any authentication.
362 * [See docs](https://hapijs.com/api/17.0.1#-requestrouteauthaccessrequest)
363 */
364 access(request: Request): boolean;
365 };
366}
367
368/**
369 * An object containing the values of params, query, and payload before any validation modifications made. Only set when input validation is performed.
370 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestorig)
371 */
372export interface RequestOrig {
373 params: object;
374 query: object;
375 payload: object;
376}
377
378export interface RequestLog {
379 request: string;
380 timestamp: number;
381 tags: string[];
382 data: string | object;
383 channel: string;
384}
385
386export interface RequestQuery {
387 [key: string]: string | string[];
388}
389
390/**
391 * The request object is created internally for each incoming request. It is not the same object received from the node
392 * HTTP server callback (which is available via [request.raw.req](https://github.com/hapijs/hapi/blob/master/API.md#request.raw)). The request properties change throughout
393 * the request [lifecycle](https://github.com/hapijs/hapi/blob/master/API.md#request-lifecycle).
394 */
395export interface Request extends Podium {
396 /**
397 * Application-specific state. Provides a safe place to store application data without potential conflicts with the framework. Should not be used by plugins which should use plugins[name].
398 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestapp)
399 */
400 app: ApplicationState;
401
402 /**
403 * Authentication information:
404 * * artifacts - an artifact object received from the authentication strategy and used in authentication-related actions.
405 * * credentials - the credential object received during the authentication process. The presence of an object does not mean successful authentication.
406 * * error - the authentication error is failed and mode set to 'try'.
407 * * isAuthenticated - true if the request has been successfully authenticated, otherwise false.
408 * * isAuthorized - true is the request has been successfully authorized against the route authentication access configuration. If the route has not access rules defined or if the request failed
409 * authorization, set to false.
410 * * mode - the route authentication mode.
411 * * strategy - the name of the strategy used.
412 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestauth)
413 */
414 readonly auth: RequestAuth;
415
416 /**
417 * Access: read only and the public podium interface.
418 * The request.events supports the following events:
419 * * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
420 * * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
421 * * 'disconnect' - emitted when a request errors or aborts unexpectedly.
422 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
423 */
424 events: RequestEvents;
425
426 /**
427 * The raw request headers (references request.raw.req.headers).
428 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestheaders)
429 */
430 readonly headers: Util.Dictionary<string>;
431
432 /**
433 * Request information:
434 * * acceptEncoding - the request preferred encoding.
435 * * cors - if CORS is enabled for the route, contains the following:
436 * * isOriginMatch - true if the request 'Origin' header matches the configured CORS restrictions. Set to false if no 'Origin' header is found or if it does not match. Note that this is only
437 * available after the 'onRequest' extension point as CORS is configured per-route and no routing decisions are made at that point in the request lifecycle.
438 * * host - content of the HTTP 'Host' header (e.g. 'example.com:8080').
439 * * hostname - the hostname part of the 'Host' header (e.g. 'example.com').
440 * * id - a unique request identifier (using the format '{now}:{connection.info.id}:{5 digits counter}').
441 * * received - request reception timestamp.
442 * * referrer - content of the HTTP 'Referrer' (or 'Referer') header.
443 * * remoteAddress - remote client IP address.
444 * * remotePort - remote client port.
445 * * responded - request response timestamp (0 is not responded yet).
446 * Note that the request.info object is not meant to be modified.
447 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestinfo)
448 */
449 readonly info: RequestInfo;
450
451 /**
452 * An array containing the logged request events.
453 * Note that this array will be empty if route log.collect is set to false.
454 */
455 readonly logs: RequestLog[];
456
457 /**
458 * The request method in lower case (e.g. 'get', 'post').
459 */
460 readonly method: Util.HTTP_METHODS_PARTIAL_LOWERCASE;
461
462 /**
463 * The parsed content-type header. Only available when payload parsing enabled and no payload error occurred.
464 */
465 readonly mime: string;
466
467 /**
468 * An object containing the values of params, query, and payload before any validation modifications made. Only set when input validation is performed.
469 */
470 readonly orig: RequestOrig;
471
472 /**
473 * An object where each key is a path parameter name with matching value as described in [Path parameters](https://github.com/hapijs/hapi/blob/master/API.md#path-parameters).
474 */
475 readonly params: Util.Dictionary<string>;
476
477 /**
478 * An array containing all the path params values in the order they appeared in the path.
479 */
480 readonly paramsArray: string[];
481
482 /**
483 * The request URI's pathname component.
484 */
485 readonly path: string;
486
487 /**
488 * The request payload based on the route payload.output and payload.parse settings.
489 * TODO check this typing and add references / links.
490 */
491 readonly payload: stream.Readable | Buffer | string | object;
492
493 /**
494 * Plugin-specific state. Provides a place to store and pass request-level plugin data. The plugins is an object where each key is a plugin name and the value is the state.
495 */
496 plugins: PluginsStates;
497
498 /**
499 * An object where each key is the name assigned by a route pre-handler methods function. The values are the raw values provided to the continuation function as argument. For the wrapped response
500 * object, use responses.
501 */
502 readonly pre: Util.Dictionary<any>;
503
504 /**
505 * Access: read / write (see limitations below).
506 * The response object when set. The object can be modified but must not be assigned another object. To replace the response with another from within an extension point, use reply(response) to
507 * override with a different response.
508 * In case of an aborted request the status code will be set to `disconnectStatusCode`.
509 */
510 response: ResponseObject | Boom;
511
512 /**
513 * Same as pre but represented as the response object created by the pre method.
514 */
515 readonly preResponses: Util.Dictionary<any>;
516
517 /**
518 * By default the object outputted from node's URL parse() method.
519 */
520 readonly query: RequestQuery;
521
522 /**
523 * An object containing the Node HTTP server objects. Direct interaction with these raw objects is not recommended.
524 * * req - the node request object.
525 * * res - the node response object.
526 */
527 readonly raw: {
528 req: http.IncomingMessage;
529 res: http.ServerResponse;
530 };
531
532 /**
533 * The request route information object and method
534 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestroute)
535 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestrouteauthaccessrequest)
536 */
537 readonly route: RequestRoute;
538
539 /**
540 * Access: read only and the public server interface.
541 * The server object.
542 */
543 server: Server;
544
545 /**
546 * An object containing parsed HTTP state information (cookies) where each key is the cookie name and value is the matching cookie content after processing using any registered cookie definition.
547 */
548 readonly state: Util.Dictionary<any>;
549
550 /**
551 * The parsed request URI.
552 */
553 readonly url: url.URL;
554
555 /**
556 * Returns `true` when the request is active and processing should continue and `false` when the
557 * request terminated early or completed its lifecycle. Useful when request processing is a
558 * resource-intensive operation and should be terminated early if the request is no longer active
559 * (e.g. client disconnected or aborted early).
560 */
561 active(): boolean;
562
563 /**
564 * Returns a response which you can pass into the reply interface where:
565 * @param source - the value to set as the source of the reply interface, optional.
566 * @param options - options for the method, optional.
567 * @return ResponseObject
568 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestgenerateresponsesource-options)
569 */
570 generateResponse(
571 source: string | object | null,
572 options?: {
573 variety?: string | undefined;
574 prepare?: ((response: ResponseObject) => Promise<ResponseObject>) | undefined;
575 marshal?: ((response: ResponseObject) => Promise<ResponseValue>) | undefined;
576 close?: ((response: ResponseObject) => void) | undefined;
577 },
578 ): ResponseObject;
579
580 /**
581 * Logs request-specific events. When called, the server emits a 'request' event which can be used by other listeners or plugins. The arguments are:
582 * @param tags - a string or an array of strings (e.g. ['error', 'database', 'read']) used to identify the event. Tags are used instead of log levels and provide a much more expressive mechanism
583 * for describing and filtering events.
584 * @param data - (optional) an message string or object with the application data being logged. If data is a function, the function signature is function() and it called once to generate (return
585 * value) the actual data emitted to the listeners. Any logs generated by the server internally will be emitted only on the 'request-internal' channel and will include the event.internal flag
586 * set to true.
587 * @return void
588 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestlogtags-data)
589 */
590 log(tags: string | string[], data?: string | object | (() => string | object)): void;
591
592 /**
593 * Changes the request method before the router begins processing the request where:
594 * @param method - is the request HTTP method (e.g. 'GET').
595 * @return void
596 * Can only be called from an 'onRequest' extension method.
597 * [See docs](https://hapijs.com/api/17.0.1#-requestsetmethodmethod)
598 */
599 setMethod(method: Util.HTTP_METHODS_PARTIAL): void;
600
601 /**
602 * Changes the request URI before the router begins processing the request where:
603 * Can only be called from an 'onRequest' extension method.
604 * @param url - the new request URI. If url is a string, it is parsed with node's URL parse() method with parseQueryString set to true. url can also be set to an object compatible with node's URL
605 * parse() method output.
606 * @param stripTrailingSlash - if true, strip the trailing slash from the path. Defaults to false.
607 * @return void
608 * [See docs](https://hapijs.com/api/17.0.1#-requestseturlurl-striptrailingslash)
609 */
610 setUrl(url: string | url.URL, stripTrailingSlash?: boolean): void;
611}
612
613/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
614 + +
615 + +
616 + +
617 + Response +
618 + +
619 + +
620 + +
621 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
622
623/**
624 * Access: read only and the public podium interface.
625 * The response.events object supports the following events:
626 * * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
627 * * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
628 * [See docs](https://hapijs.com/api/17.0.1#-responseevents)
629 */
630export interface ResponseEvents extends Podium {
631 /**
632 * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
633 * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
634 */
635 on(criteria: "peek", listener: PeekListener): void;
636
637 on(criteria: "finish", listener: (data: undefined) => void): void;
638
639 /**
640 * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
641 * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
642 */
643 once(criteria: "peek", listener: PeekListener): void;
644
645 once(criteria: "finish", listener: (data: undefined) => void): void;
646}
647
648/**
649 * Object where:
650 * * append - if true, the value is appended to any existing header value using separator. Defaults to false.
651 * * separator - string used as separator when appending to an existing value. Defaults to ','.
652 * * override - if false, the header value is not set if an existing value present. Defaults to true.
653 * * duplicate - if false, the header value is not modified if the provided value is already included. Does not apply when append is false or if the name is 'set-cookie'. Defaults to true.
654 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheadername-value-options)
655 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#response-object)
656 */
657export interface ResponseObjectHeaderOptions {
658 append?: boolean | undefined;
659 separator?: string | undefined;
660 override?: boolean | undefined;
661 duplicate?: boolean | undefined;
662}
663
664/**
665 * The response object contains the request response value along with various HTTP headers and flags. When a lifecycle
666 * method returns a value, the value is wrapped in a response object along with some default flags (e.g. 200 status
667 * code). In order to customize a response before it is returned, the h.response() method is provided.
668 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#response-object)
669 * TODO, check extending from Podium is correct. Extending because of "The response object supports the following events" [See docs](https://hapijs.com/api/17.0.1#-responseevents)
670 */
671export interface ResponseObject extends Podium {
672 /**
673 * Default value: {}.
674 * Application-specific state. Provides a safe place to store application data without potential conflicts with the framework. Should not be used by plugins which should use plugins[name].
675 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseapp)
676 */
677 app: ApplicationState;
678
679 /**
680 * Access: read only and the public podium interface.
681 * The response.events object supports the following events:
682 * * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
683 * * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
684 * [See docs](https://hapijs.com/api/17.0.1#-responseevents)
685 */
686 readonly events: ResponseEvents;
687
688 /**
689 * Default value: {}.
690 * An object containing the response headers where each key is a header field name and the value is the string header value or array of string.
691 * Note that this is an incomplete list of headers to be included with the response. Additional headers will be added once the response is prepared for transmission.
692 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheaders)
693 */
694 readonly headers: Util.Dictionary<string | string[]>;
695
696 /**
697 * Default value: {}.
698 * Plugin-specific state. Provides a place to store and pass request-level plugin data. plugins is an object where each key is a plugin name and the value is the state.
699 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseplugins)
700 */
701 plugins: PluginsStates;
702
703 /**
704 * Object containing the response handling flags.
705 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesettings)
706 */
707 readonly settings: ResponseSettings;
708
709 /**
710 * The raw value returned by the lifecycle method.
711 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesource)
712 */
713 readonly source: Lifecycle.ReturnValue;
714
715 /**
716 * Default value: 200.
717 * The HTTP response status code.
718 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsestatuscode)
719 */
720 readonly statusCode: number;
721
722 /**
723 * A string indicating the type of source with available values:
724 * * 'plain' - a plain response such as string, number, null, or simple object.
725 * * 'buffer' - a Buffer.
726 * * 'stream' - a Stream.
727 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsevariety)
728 */
729 readonly variety: "plain" | "buffer" | "stream";
730
731 /**
732 * Sets the HTTP 'Content-Length' header (to avoid chunked transfer encoding) where:
733 * @param length - the header value. Must match the actual payload size.
734 * @return Return value: the current response object.
735 * [See docs](https://hapijs.com/api/17.0.1#-responsebyteslength)
736 */
737 bytes(length: number): ResponseObject;
738
739 /**
740 * Sets the 'Content-Type' HTTP header 'charset' property where:
741 * @param charset - the charset property value.
742 * @return Return value: the current response object.
743 * [See docs](https://hapijs.com/api/17.0.1#-responsecharsetcharset)
744 */
745 charset(charset: string): ResponseObject;
746
747 /**
748 * Sets the HTTP status code where:
749 * @param statusCode - the HTTP status code (e.g. 200).
750 * @return Return value: the current response object.
751 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsecodestatuscode)
752 */
753 code(statusCode: number): ResponseObject;
754
755 /**
756 * Sets the HTTP status message where:
757 * @param httpMessage - the HTTP status message (e.g. 'Ok' for status code 200).
758 * @return Return value: the current response object.
759 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsemessagehttpmessage)
760 */
761 message(httpMessage: string): ResponseObject;
762
763 /**
764 * Sets the HTTP status code to Created (201) and the HTTP 'Location' header where:
765 * @param uri - an absolute or relative URI used as the 'Location' header value.
766 * @return Return value: the current response object.
767 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsecreateduri)
768 */
769 created(uri: string): ResponseObject;
770
771 /**
772 * Sets the string encoding scheme used to serial data into the HTTP payload where:
773 * @param encoding the encoding property value (see node Buffer encoding [See docs](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings)).
774 * * 'ascii' - for 7-bit ASCII data only. This encoding is fast and will strip the high bit if set.
775 * * 'utf8' - Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
776 * * 'utf16le' - 2 or 4 bytes, little-endian encoded Unicode characters. Surrogate pairs (U+10000 to U+10FFFF) are supported.
777 * * 'ucs2' - Alias of 'utf16le'.
778 * * 'base64' - Base64 encoding. When creating a Buffer from a string, this encoding will also correctly accept "URL and Filename Safe Alphabet" as specified in RFC4648, Section 5.
779 * * 'latin1' - A way of encoding the Buffer into a one-byte encoded string (as defined by the IANA in RFC1345, page 63, to be the Latin-1 supplement block and C0/C1 control codes).
780 * * 'binary' - Alias for 'latin1'.
781 * * 'hex' - Encode each byte as two hexadecimal characters.
782 * @return Return value: the current response object.
783 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseencodingencoding)
784 */
785 encoding(encoding: "ascii" | "utf8" | "utf16le" | "ucs2" | "base64" | "latin1" | "binary" | "hex"): ResponseObject;
786
787 /**
788 * Sets the representation entity tag where:
789 * @param tag - the entity tag string without the double-quote.
790 * @param options - (optional) settings where:
791 * * weak - if true, the tag will be prefixed with the 'W/' weak signifier. Weak tags will fail to match identical tags for the purpose of determining 304 response status. Defaults to false.
792 * * vary - if true and content encoding is set or applied to the response (e.g 'gzip' or 'deflate'), the encoding name will be automatically added to the tag at transmission time (separated by
793 * a '-' character). Ignored when weak is true. Defaults to true.
794 * @return Return value: the current response object.
795 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseetagtag-options)
796 */
797 etag(tag: string, options?: { weak: boolean; vary: boolean }): ResponseObject;
798
799 /**
800 * Sets an HTTP header where:
801 * @param name - the header name.
802 * @param value - the header value.
803 * @param options - (optional) object where:
804 * * append - if true, the value is appended to any existing header value using separator. Defaults to false.
805 * * separator - string used as separator when appending to an existing value. Defaults to ','.
806 * * override - if false, the header value is not set if an existing value present. Defaults to true.
807 * * duplicate - if false, the header value is not modified if the provided value is already included. Does not apply when append is false or if the name is 'set-cookie'. Defaults to true.
808 * @return Return value: the current response object.
809 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheadername-value-options)
810 */
811 header(name: string, value: string, options?: ResponseObjectHeaderOptions): ResponseObject;
812
813 /**
814 * Sets the HTTP 'Location' header where:
815 * @param uri - an absolute or relative URI used as the 'Location' header value.
816 * @return Return value: the current response object.
817 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responselocationuri)
818 */
819 location(uri: string): ResponseObject;
820
821 /**
822 * Sets an HTTP redirection response (302) and decorates the response with additional methods, where:
823 * @param uri - an absolute or relative URI used to redirect the client to another resource.
824 * @return Return value: the current response object.
825 * Decorates the response object with the response.temporary(), response.permanent(), and response.rewritable() methods to easily change the default redirection code (302).
826 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseredirecturi)
827 */
828 redirect(uri: string): ResponseObject;
829
830 /**
831 * Sets the JSON.stringify() replacer argument where:
832 * @param method - the replacer function or array. Defaults to none.
833 * @return Return value: the current response object.
834 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsereplacermethod)
835 */
836 replacer(method: Json.StringifyReplacer): ResponseObject;
837
838 /**
839 * Sets the JSON.stringify() space argument where:
840 * @param count - the number of spaces to indent nested object keys. Defaults to no indentation.
841 * @return Return value: the current response object.
842 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsespacescount)
843 */
844 spaces(count: number): ResponseObject;
845
846 /**
847 * Sets an HTTP cookie where:
848 * @param name - the cookie name.
849 * @param value - the cookie value. If no options.encoding is defined, must be a string. See server.state() for supported encoding values.
850 * @param options - (optional) configuration. If the state was previously registered with the server using server.state(), the specified keys in options are merged with the default server
851 * definition.
852 * @return Return value: the current response object.
853 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsestatename-value-options)
854 */
855 state(name: string, value: object | string, options?: ServerStateCookieOptions): ResponseObject;
856
857 /**
858 * Sets a string suffix when the response is process via JSON.stringify() where:
859 * @param suffix - the string suffix.
860 * @return Return value: the current response object.
861 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesuffixsuffix)
862 */
863 suffix(suffix: string): ResponseObject;
864
865 /**
866 * Overrides the default route cache expiration rule for this response instance where:
867 * @param msec - the time-to-live value in milliseconds.
868 * @return Return value: the current response object.
869 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsettlmsec)
870 */
871 ttl(msec: number): ResponseObject;
872
873 /**
874 * Sets the HTTP 'Content-Type' header where:
875 * @param mimeType - is the mime type.
876 * @return Return value: the current response object.
877 * Should only be used to override the built-in default for each response type.
878 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsetypemimetype)
879 */
880 type(mimeType: string): ResponseObject;
881
882 /**
883 * Clears the HTTP cookie by setting an expired value where:
884 * @param name - the cookie name.
885 * @param options - (optional) configuration for expiring cookie. If the state was previously registered with the server using server.state(), the specified options are merged with the server
886 * definition.
887 * @return Return value: the current response object.
888 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseunstatename-options)
889 */
890 unstate(name: string, options?: ServerStateCookieOptions): ResponseObject;
891
892 /**
893 * Adds the provided header to the list of inputs affected the response generation via the HTTP 'Vary' header where:
894 * @param header - the HTTP request header name.
895 * @return Return value: the current response object.
896 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsevaryheader)
897 */
898 vary(header: string): ResponseObject;
899
900 /**
901 * Marks the response object as a takeover response.
902 * @return Return value: the current response object.
903 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsetakeover)
904 */
905 takeover(): ResponseObject;
906
907 /**
908 * Sets the status code to 302 or 307 (based on the response.rewritable() setting) where:
909 * @param isTemporary - if false, sets status to permanent. Defaults to true.
910 * @return Return value: the current response object.
911 * Only available after calling the response.redirect() method.
912 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsetemporaryistemporary)
913 */
914 temporary(isTemporary: boolean): ResponseObject;
915
916 /**
917 * Sets the status code to 301 or 308 (based on the response.rewritable() setting) where:
918 * @param isPermanent - if false, sets status to temporary. Defaults to true.
919 * @return Return value: the current response object.
920 * Only available after calling the response.redirect() method.
921 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsepermanentispermanent)
922 */
923 permanent(isPermanent: boolean): ResponseObject;
924
925 /**
926 * Sets the status code to 301/302 for rewritable (allows changing the request method from 'POST' to 'GET') or 307/308 for non-rewritable (does not allow changing the request method from 'POST'
927 * to 'GET'). Exact code based on the response.temporary() or response.permanent() setting. Arguments:
928 * @param isRewritable - if false, sets to non-rewritable. Defaults to true.
929 * @return Return value: the current response object.
930 * Only available after calling the response.redirect() method.
931 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responserewritableisrewritable)
932 */
933 rewritable(isRewritable: boolean): ResponseObject;
934}
935
936/**
937 * Object containing the response handling flags.
938 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesettings)
939 */
940export interface ResponseSettings {
941 /**
942 * Defaults value: true.
943 * If true and source is a Stream, copies the statusCode and headers properties of the stream object to the outbound response.
944 */
945 readonly passThrough: boolean;
946
947 /**
948 * Default value: null (use route defaults).
949 * Override the route json options used when source value requires stringification.
950 */
951 readonly stringify: Json.StringifyArguments;
952
953 /**
954 * Default value: null (use route defaults).
955 * If set, overrides the route cache with an expiration value in milliseconds.
956 */
957 readonly ttl: number;
958
959 /**
960 * Default value: false.
961 * If true, a suffix will be automatically added to the 'ETag' header at transmission time (separated by a '-' character) when the HTTP 'Vary' header is present.
962 */
963 varyEtag: boolean;
964}
965
966/**
967 * See more about Lifecycle
968 * https://github.com/hapijs/hapi/blob/master/API.md#request-lifecycle
969 */
970
971export type ResponseValue = string | object;
972
973export interface AuthenticationData {
974 credentials: AuthCredentials;
975 artifacts?: object | undefined;
976}
977
978export interface Auth {
979 readonly isAuth: true;
980 readonly error?: Error | null | undefined;
981 readonly data?: AuthenticationData | undefined;
982}
983
984/**
985 * The response toolkit is a collection of properties and utilities passed to every [lifecycle method](https://github.com/hapijs/hapi/blob/master/API.md#lifecycle-methods)
986 * It is somewhat hard to define as it provides both utilities for manipulating responses as well as other information. Since the
987 * toolkit is passed as a function argument, developers can name it whatever they want. For the purpose of this
988 * document the h notation is used. It is named in the spirit of the RethinkDB r method, with h for hapi.
989 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#response-toolkit)
990 */
991export interface ResponseToolkit {
992 /**
993 * A response symbol. When returned by a lifecycle method, the request lifecycle skips to the finalizing step
994 * without further interaction with the node response stream. It is the developer's responsibility to write
995 * and end the response directly via [request.raw.res](https://github.com/hapijs/hapi/blob/master/API.md#request.raw).
996 */
997 readonly abandon: symbol;
998
999 /**
1000 * A response symbol. When returned by a lifecycle method, the request lifecycle skips to the finalizing step after
1001 * calling request.raw.res.end()) to close the the node response stream.
1002 */
1003 readonly close: symbol;
1004
1005 /**
1006 * A response symbol. Provides access to the route or server context set via the route [bind](https://github.com/hapijs/hapi/blob/master/API.md#route.options.bind)
1007 * option or [server.bind()](https://github.com/hapijs/hapi/blob/master/API.md#server.bind()).
1008 */
1009 readonly context: any;
1010
1011 /**
1012 * A response symbol. When returned by a lifecycle method, the request lifecycle continues without changing the response.
1013 */
1014 readonly continue: symbol;
1015
1016 /**
1017 * The [server realm](https://github.com/hapijs/hapi/blob/master/API.md#server.realm) associated with the matching
1018 * route. Defaults to the root server realm in the onRequest step.
1019 */
1020 readonly realm: ServerRealm;
1021
1022 /**
1023 * Access: read only and public request interface.
1024 * The [request] object. This is a duplication of the request lifecycle method argument used by
1025 * [toolkit decorations](https://github.com/hapijs/hapi/blob/master/API.md#server.decorate()) to access the current request.
1026 */
1027 readonly request: Readonly<Request>;
1028
1029 /**
1030 * Used by the [authentication] method to pass back valid credentials where:
1031 * @param data - an object with:
1032 * * credentials - (required) object representing the authenticated entity.
1033 * * artifacts - (optional) authentication artifacts object specific to the authentication scheme.
1034 * @return Return value: an internal authentication object.
1035 */
1036 authenticated(data: AuthenticationData): Auth;
1037
1038 /**
1039 * Sets the response 'ETag' and 'Last-Modified' headers and checks for any conditional request headers to decide if
1040 * the response is going to qualify for an HTTP 304 (Not Modified). If the entity values match the request
1041 * conditions, h.entity() returns a response object for the lifecycle method to return as its value which will
1042 * set a 304 response. Otherwise, it sets the provided entity headers and returns undefined.
1043 * The method argumetns are:
1044 * @param options - a required configuration object with:
1045 * * etag - the ETag string. Required if modified is not present. Defaults to no header.
1046 * * modified - the Last-Modified header value. Required if etag is not present. Defaults to no header.
1047 * * vary - same as the response.etag() option. Defaults to true.
1048 * @return Return value: - a response object if the response is unmodified. - undefined if the response has changed.
1049 * If undefined is returned, the developer must return a valid lifecycle method value. If a response is returned,
1050 * it should be used as the return value (but may be customize using the response methods).
1051 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hentityoptions)
1052 */
1053 entity(
1054 options?: { etag?: string | undefined; modified?: string | undefined; vary?: boolean | undefined },
1055 ): ResponseObject | undefined;
1056
1057 /**
1058 * Redirects the client to the specified uri. Same as calling h.response().redirect(uri).
1059 * @param url
1060 * @return Returns a response object.
1061 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hredirecturi)
1062 */
1063 redirect(uri?: string): ResponseObject;
1064
1065 /**
1066 * Wraps the provided value and returns a response object which allows customizing the response
1067 * (e.g. setting the HTTP status code, custom headers, etc.), where:
1068 * @param value - (optional) return value. Defaults to null.
1069 * @return Returns a response object.
1070 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hresponsevalue)
1071 */
1072 response(value?: ResponseValue): ResponseObject;
1073
1074 /**
1075 * Sets a response cookie using the same arguments as response.state().
1076 * @param name of the cookie
1077 * @param value of the cookie
1078 * @param (optional) ServerStateCookieOptions object.
1079 * @return Return value: none.
1080 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hstatename-value-options)
1081 */
1082 state(name: string, value: string | object, options?: ServerStateCookieOptions): void;
1083
1084 /**
1085 * Used by the [authentication] method to indicate authentication failed and pass back the credentials received where:
1086 * @param error - (required) the authentication error.
1087 * @param data - (optional) an object with:
1088 * * credentials - (required) object representing the authenticated entity.
1089 * * artifacts - (optional) authentication artifacts object specific to the authentication scheme.
1090 * @return void.
1091 * The method is used to pass both the authentication error and the credentials. For example, if a request included
1092 * expired credentials, it allows the method to pass back the user information (combined with a 'try'
1093 * authentication mode) for error customization.
1094 * There is no difference between throwing the error or passing it with the h.unauthenticated() method is no credentials are passed, but it might still be helpful for code clarity.
1095 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hunauthenticatederror-data)
1096 */
1097 unauthenticated(error: Error, data?: AuthenticationData): void;
1098
1099 /**
1100 * Clears a response cookie using the same arguments as
1101 * @param name of the cookie
1102 * @param options (optional) ServerStateCookieOptions object.
1103 * @return void.
1104 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hunstatename-options)
1105 */
1106 unstate(name: string, options?: ServerStateCookieOptions): void;
1107}
1108
1109/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1110 + +
1111 + +
1112 + +
1113 + Route +
1114 + +
1115 + +
1116 + +
1117 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
1118
1119export type RouteOptionsAccessScope = false | string | string[];
1120
1121export type RouteOptionsAccessEntity = "any" | "user" | "app";
1122
1123export interface RouteOptionsAccessScopeObject {
1124 scope: RouteOptionsAccessScope;
1125}
1126
1127export interface RouteOptionsAccessEntityObject {
1128 entity: RouteOptionsAccessEntity;
1129}
1130
1131export type RouteOptionsAccessObject =
1132 | RouteOptionsAccessScopeObject
1133 | RouteOptionsAccessEntityObject
1134 | (RouteOptionsAccessScopeObject & RouteOptionsAccessEntityObject);
1135
1136/**
1137 * Route Authentication Options
1138 */
1139export interface RouteOptionsAccess {
1140 /**
1141 * Default value: none.
1142 * An object or array of objects specifying the route access rules. Each rule is evaluated against an incoming request and access is granted if at least one of the rules matches. Each rule object
1143 * must include at least one of scope or entity.
1144 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccess)
1145 */
1146 access?: RouteOptionsAccessObject | RouteOptionsAccessObject[] | undefined;
1147
1148 /**
1149 * Default value: false (no scope requirements).
1150 * The application scope required to access the route. Value can be a scope string or an array of scope strings. When authenticated, the credentials object scope property must contain at least
1151 * one of the scopes defined to access the route. If a scope string begins with a + character, that scope is required. If a scope string begins with a ! character, that scope is forbidden. For
1152 * example, the scope ['!a', '+b', 'c', 'd'] means the incoming request credentials' scope must not include 'a', must include 'b', and must include one of 'c' or 'd'. You may also access
1153 * properties on the request object (query, params, payload, and credentials) to populate a dynamic scope by using the '{' and '}' characters around the property name, such as 'user-{params.id}'.
1154 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccessscope)
1155 */
1156 scope?: RouteOptionsAccessScope | undefined;
1157
1158 /**
1159 * Default value: 'any'.
1160 * The required authenticated entity type. If set, must match the entity value of the request authenticated credentials. Available values:
1161 * * 'any' - the authentication can be on behalf of a user or application.
1162 * * 'user' - the authentication must be on behalf of a user which is identified by the presence of a 'user' attribute in the credentials object returned by the authentication strategy.
1163 * * 'app' - the authentication must be on behalf of an application which is identified by the lack of presence of a user attribute in the credentials object returned by the authentication
1164 * strategy.
1165 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccessentity)
1166 */
1167 entity?: RouteOptionsAccessEntity | undefined;
1168
1169 /**
1170 * Default value: 'required'.
1171 * The authentication mode. Available values:
1172 * * 'required' - authentication is required.
1173 * * 'optional' - authentication is optional - the request must include valid credentials or no credentials at all.
1174 * * 'try' - similar to 'optional', any request credentials are attempted authentication, but if the credentials are invalid, the request proceeds regardless of the authentication error.
1175 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthmode)
1176 */
1177 mode?: "required" | "optional" | "try" | undefined;
1178
1179 /**
1180 * Default value: false, unless the scheme requires payload authentication.
1181 * If set, the incoming request payload is authenticated after it is processed. Requires a strategy with payload authentication support (e.g. Hawk). Cannot be set to a value other than 'required'
1182 * when the scheme sets the authentication options.payload to true. Available values:
1183 * * false - no payload authentication.
1184 * * 'required' - payload authentication required.
1185 * * 'optional' - payload authentication performed only when the client includes payload authentication information (e.g. hash attribute in Hawk).
1186 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthpayload)
1187 */
1188 payload?: false | "required" | "optional" | undefined;
1189
1190 /**
1191 * Default value: the default strategy set via server.auth.default().
1192 * An array of string strategy names in the order they should be attempted. Cannot be used together with strategy.
1193 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthstrategies)
1194 */
1195 strategies?: string[] | undefined;
1196
1197 /**
1198 * Default value: the default strategy set via server.auth.default().
1199 * A string strategy names. Cannot be used together with strategies.
1200 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthstrategy)
1201 */
1202 strategy?: string | undefined;
1203}
1204
1205/**
1206 * Values are:
1207 * * * 'default' - no privacy flag.
1208 * * * 'public' - mark the response as suitable for public caching.
1209 * * * 'private' - mark the response as suitable only for private caching.
1210 * * expiresIn - relative expiration expressed in the number of milliseconds since the item was saved in the cache. Cannot be used together with expiresAt.
1211 * * expiresAt - time of day expressed in 24h notation using the 'HH:MM' format, at which point all cache records for the route expire. Cannot be used together with expiresIn.
1212 * * statuses - an array of HTTP response status code numbers (e.g. 200) which are allowed to include a valid caching directive.
1213 * * otherwise - a string with the value of the 'Cache-Control' header when caching is disabled.
1214 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscache)
1215 */
1216export type RouteOptionsCache =
1217 & {
1218 privacy?: "default" | "public" | "private" | undefined;
1219 statuses?: number[] | undefined;
1220 otherwise?: string | undefined;
1221 }
1222 & (
1223 {
1224 expiresIn?: number | undefined;
1225 expiresAt?: undefined;
1226 } | {
1227 expiresIn?: undefined;
1228 expiresAt?: string | undefined;
1229 } | {
1230 expiresIn?: undefined;
1231 expiresAt?: undefined;
1232 }
1233 );
1234
1235/**
1236 * Default value: false (no CORS headers).
1237 * The Cross-Origin Resource Sharing protocol allows browsers to make cross-origin API calls. CORS is required by web applications running inside a browser which are loaded from a different domain
1238 * than the API server. To enable, set cors to true, or to an object with the following options:
1239 * * origin - an array of allowed origin servers strings ('Access-Control-Allow-Origin'). The array can contain any combination of fully qualified origins along with origin strings containing a
1240 * wildcard '*' character, or a single '*' origin string. If set to 'ignore', any incoming Origin header is ignored (present or not) and the 'Access-Control-Allow-Origin' header is set to '*'.
1241 * Defaults to any origin ['*'].
1242 * * maxAge - number of seconds the browser should cache the CORS response ('Access-Control-Max-Age'). The greater the value, the longer it will take before the browser checks for changes in policy.
1243 * Defaults to 86400 (one day).
1244 * * headers - a strings array of allowed headers ('Access-Control-Allow-Headers'). Defaults to ['Accept', 'Authorization', 'Content-Type', 'If-None-Match'].
1245 * * additionalHeaders - a strings array of additional headers to headers. Use this to keep the default headers in place.
1246 * * exposedHeaders - a strings array of exposed headers ('Access-Control-Expose-Headers'). Defaults to ['WWW-Authenticate', 'Server-Authorization'].
1247 * * additionalExposedHeaders - a strings array of additional headers to exposedHeaders. Use this to keep the default headers in place.
1248 * * credentials - if true, allows user credentials to be sent ('Access-Control-Allow-Credentials'). Defaults to false.
1249 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscors)
1250 */
1251export interface RouteOptionsCors {
1252 /**
1253 * an array of allowed origin servers strings ('Access-Control-Allow-Origin'). The array can contain any combination of fully qualified origins along with origin strings containing a wildcard '*'
1254 * character, or a single '*' origin string. If set to 'ignore', any incoming Origin header is ignored (present or not) and the 'Access-Control-Allow-Origin' header is set to '*'. Defaults to any
1255 * origin ['*'].
1256 */
1257 origin?: string[] | "*" | "ignore" | undefined;
1258 /**
1259 * number of seconds the browser should cache the CORS response ('Access-Control-Max-Age'). The greater the value, the longer it will take before the browser checks for changes in policy.
1260 * Defaults to 86400 (one day).
1261 */
1262 maxAge?: number | undefined;
1263 /**
1264 * a strings array of allowed headers ('Access-Control-Allow-Headers'). Defaults to ['Accept', 'Authorization', 'Content-Type', 'If-None-Match'].
1265 */
1266 headers?: string[] | undefined;
1267 /**
1268 * a strings array of additional headers to headers. Use this to keep the default headers in place.
1269 */
1270 additionalHeaders?: string[] | undefined;
1271 /**
1272 * a strings array of exposed headers ('Access-Control-Expose-Headers'). Defaults to ['WWW-Authenticate', 'Server-Authorization'].
1273 */
1274 exposedHeaders?: string[] | undefined;
1275 /**
1276 * a strings array of additional headers to exposedHeaders. Use this to keep the default headers in place.
1277 */
1278 additionalExposedHeaders?: string[] | undefined;
1279 /**
1280 * if true, allows user credentials to be sent ('Access-Control-Allow-Credentials'). Defaults to false.
1281 */
1282 credentials?: boolean | undefined;
1283}
1284
1285/**
1286 * The value must be one of:
1287 * * 'data' - the incoming payload is read fully into memory. If parse is true, the payload is parsed (JSON, form-decoded, multipart) based on the 'Content-Type' header. If parse is false, a raw
1288 * Buffer is returned.
1289 * * 'stream' - the incoming payload is made available via a Stream.Readable interface. If the payload is 'multipart/form-data' and parse is true, field values are presented as text while files are
1290 * provided as streams. File streams from a 'multipart/form-data' upload will also have a hapi property containing the filename and headers properties. Note that payload streams for multipart
1291 * payloads are a synthetic interface created on top of the entire mutlipart content loaded into memory. To avoid loading large multipart payloads into memory, set parse to false and handle the
1292 * multipart payload in the handler using a streaming parser (e.g. pez).
1293 * * 'file' - the incoming payload is written to temporary file in the directory specified by the uploads settings. If the payload is 'multipart/form-data' and parse is true, field values are
1294 * presented as text while files are saved to disk. Note that it is the sole responsibility of the application to clean up the files generated by the framework. This can be done by keeping track of
1295 * which files are used (e.g. using the request.app object), and listening to the server 'response' event to perform cleanup. For context [See
1296 * docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadoutput)
1297 */
1298export type PayloadOutput = "data" | "stream" | "file";
1299
1300/**
1301 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadcompression)
1302 */
1303export type PayloadCompressionDecoderSettings = object;
1304
1305/**
1306 * Determines how the request payload is processed.
1307 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayload)
1308 */
1309export interface RouteOptionsPayload {
1310 /**
1311 * Default value: allows parsing of the following mime types:
1312 * * application/json
1313 * * application/*+json
1314 * * application/octet-stream
1315 * * application/x-www-form-urlencoded
1316 * * multipart/form-data
1317 * * text/*
1318 * A string or an array of strings with the allowed mime types for the endpoint. Use this settings to limit the set of allowed mime types. Note that allowing additional mime types not listed
1319 * above will not enable them to be parsed, and if parse is true, the request will result in an error response.
1320 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadallow)
1321 */
1322 allow?: string | string[] | undefined;
1323
1324 /**
1325 * Default value: none.
1326 * An object where each key is a content-encoding name and each value is an object with the desired decoder settings. Note that encoder settings are set in compression.
1327 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadcompression)
1328 */
1329 compression?: Util.Dictionary<PayloadCompressionDecoderSettings> | undefined;
1330
1331 /**
1332 * Default value: 'application/json'.
1333 * The default content type if the 'Content-Type' request header is missing.
1334 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloaddefaultcontenttype)
1335 */
1336 defaultContentType?: string | undefined;
1337
1338 /**
1339 * Default value: 'error' (return a Bad Request (400) error response).
1340 * A failAction value which determines how to handle payload parsing errors.
1341 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadfailaction)
1342 */
1343 failAction?: Lifecycle.FailAction | undefined;
1344
1345 /**
1346 * Default value: 1048576 (1MB).
1347 * Limits the size of incoming payloads to the specified byte count. Allowing very large payloads may cause the server to run out of memory.
1348 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadmaxbytes)
1349 */
1350 maxBytes?: number | undefined;
1351
1352 /**
1353 * Default value: none.
1354 * Overrides payload processing for multipart requests. Value can be one of:
1355 * * false - disable multipart processing.
1356 * an object with the following required options:
1357 * * output - same as the output option with an additional value option:
1358 * * * annotated - wraps each multipart part in an object with the following keys: // TODO type this?
1359 * * * * headers - the part headers.
1360 * * * * filename - the part file name.
1361 * * * * payload - the processed part payload.
1362 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadmultipart)
1363 */
1364 multipart?: false | {
1365 output: PayloadOutput | "annotated";
1366 } | undefined;
1367
1368 /**
1369 * Default value: 'data'.
1370 * The processed payload format. The value must be one of:
1371 * * 'data' - the incoming payload is read fully into memory. If parse is true, the payload is parsed (JSON, form-decoded, multipart) based on the 'Content-Type' header. If parse is false, a raw
1372 * Buffer is returned.
1373 * * 'stream' - the incoming payload is made available via a Stream.Readable interface. If the payload is 'multipart/form-data' and parse is true, field values are presented as text while files
1374 * are provided as streams. File streams from a 'multipart/form-data' upload will also have a hapi property containing the filename and headers properties. Note that payload streams for multipart
1375 * payloads are a synthetic interface created on top of the entire mutlipart content loaded into memory. To avoid loading large multipart payloads into memory, set parse to false and handle the
1376 * multipart payload in the handler using a streaming parser (e.g. pez).
1377 * * 'file' - the incoming payload is written to temporary file in the directory specified by the uploads settings. If the payload is 'multipart/form-data' and parse is true, field values are
1378 * presented as text while files are saved to disk. Note that it is the sole responsibility of the application to clean up the files generated by the framework. This can be done by keeping track
1379 * of which files are used (e.g. using the request.app object), and listening to the server 'response' event to perform cleanup.
1380 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadoutput)
1381 */
1382 output?: PayloadOutput | undefined;
1383
1384 /**
1385 * Default value: none.
1386 * A mime type string overriding the 'Content-Type' header value received.
1387 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadoverride)
1388 */
1389 override?: string | undefined;
1390
1391 /**
1392 * Default value: true.
1393 * Determines if the incoming payload is processed or presented raw. Available values:
1394 * * true - if the request 'Content-Type' matches the allowed mime types set by allow (for the whole payload as well as parts), the payload is converted into an object when possible. If the
1395 * format is unknown, a Bad Request (400) error response is sent. Any known content encoding is decoded.
1396 * * false - the raw payload is returned unmodified.
1397 * * 'gunzip' - the raw payload is returned unmodified after any known content encoding is decoded.
1398 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadparse)
1399 */
1400 parse?: boolean | "gunzip" | undefined;
1401
1402 /**
1403 * Default value: to 10000 (10 seconds).
1404 * Payload reception timeout in milliseconds. Sets the maximum time allowed for the client to transmit the request payload (body) before giving up and responding with a Request Timeout (408)
1405 * error response. Set to false to disable.
1406 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadtimeout)
1407 */
1408 timeout?: false | number | undefined;
1409
1410 /**
1411 * Default value: os.tmpdir().
1412 * The directory used for writing file uploads.
1413 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloaduploads)
1414 */
1415 uploads?: string | undefined;
1416}
1417
1418/**
1419 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
1420 */
1421export type RouteOptionsPreArray = RouteOptionsPreAllOptions[];
1422
1423/**
1424 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
1425 */
1426export type RouteOptionsPreAllOptions = RouteOptionsPreObject | RouteOptionsPreObject[] | Lifecycle.Method;
1427
1428/**
1429 * An object with:
1430 * * method - a lifecycle method.
1431 * * assign - key name used to assign the response of the method to in request.pre and request.preResponses.
1432 * * failAction - A failAction value which determine what to do when a pre-handler method throws an error. If assign is specified and the failAction setting is not 'error', the error will be assigned.
1433 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
1434 */
1435export interface RouteOptionsPreObject {
1436 /**
1437 * a lifecycle method.
1438 */
1439 method: Lifecycle.Method;
1440 /**
1441 * key name used to assign the response of the method to in request.pre and request.preResponses.
1442 */
1443 assign?: string | undefined;
1444 /**
1445 * A failAction value which determine what to do when a pre-handler method throws an error. If assign is specified and the failAction setting is not 'error', the error will be assigned.
1446 */
1447 failAction?: Lifecycle.FailAction | undefined;
1448}
1449
1450export type ValidationObject = SchemaMap;
1451
1452/**
1453 * * true - any query parameter value allowed (no validation performed). false - no parameter value allowed.
1454 * * a joi validation object.
1455 * * a validation function using the signature async function(value, options) where:
1456 * * * value - the request.* object containing the request parameters.
1457 * * * options - options.
1458 */
1459export type RouteOptionsResponseSchema =
1460 | boolean
1461 | ValidationObject
1462 | Schema
1463 | ((value: object | Buffer | string, options: ValidationOptions) => Promise<any>);
1464
1465/**
1466 * Processing rules for the outgoing response.
1467 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponse)
1468 */
1469export interface RouteOptionsResponse {
1470 /**
1471 * Default value: 200.
1472 * The default HTTP status code when the payload is considered empty. Value can be 200 or 204. Note that a 200 status code is converted to a 204 only at the time of response transmission (the
1473 * response status code will remain 200 throughout the request lifecycle unless manually set).
1474 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponseemptystatuscode)
1475 */
1476 emptyStatusCode?: 200 | 204 | undefined;
1477
1478 /**
1479 * Default value: 'error' (return an Internal Server Error (500) error response).
1480 * A failAction value which defines what to do when a response fails payload validation.
1481 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponsefailaction)
1482 */
1483 failAction?: Lifecycle.FailAction | undefined;
1484
1485 /**
1486 * Default value: false.
1487 * If true, applies the validation rule changes to the response payload.
1488 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponsemodify)
1489 */
1490 modify?: boolean | undefined;
1491
1492 /**
1493 * Default value: none.
1494 * [joi](https://github.com/hapijs/joi) options object pass to the validation function. Useful to set global options such as stripUnknown or abortEarly (the complete list is available here). If a
1495 * custom validation function is defined via schema or status then options can an arbitrary object that will be passed to this function as the second argument.
1496 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponseoptions)
1497 */
1498 options?: ValidationOptions | undefined; // TODO needs validation
1499
1500 /**
1501 * Default value: true.
1502 * If false, payload range support is disabled.
1503 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponseranges)
1504 */
1505 ranges?: boolean | undefined;
1506
1507 /**
1508 * Default value: 100 (all responses).
1509 * The percent of response payloads validated (0 - 100). Set to 0 to disable all validation.
1510 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponsesample)
1511 */
1512 sample?: number | undefined;
1513
1514 /**
1515 * Default value: true (no validation).
1516 * The default response payload validation rules (for all non-error responses) expressed as one of:
1517 * * true - any payload allowed (no validation).
1518 * * false - no payload allowed.
1519 * * a joi validation object. The options along with the request context ({ headers, params, query, payload, app, auth }) are passed to the validation function.
1520 * * a validation function using the signature async function(value, options) where:
1521 * * * value - the pending response payload.
1522 * * * options - The options along with the request context ({ headers, params, query, payload, app, auth }).
1523 * * * if the function returns a value and modify is true, the value is used as the new response. If the original response is an error, the return value is used to override the original error
1524 * output.payload. If an error is thrown, the error is processed according to failAction.
1525 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponseschema)
1526 */
1527 schema?: RouteOptionsResponseSchema | undefined;
1528
1529 /**
1530 * Default value: none.
1531 * Validation schemas for specific HTTP status codes. Responses (excluding errors) not matching the listed status codes are validated using the default schema.
1532 * status is set to an object where each key is a 3 digit HTTP status code and the value has the same definition as schema.
1533 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponsestatus)
1534 */
1535 status?: Util.Dictionary<RouteOptionsResponseSchema> | undefined;
1536
1537 /**
1538 * The default HTTP status code used to set a response error when the request is closed or aborted before the
1539 * response is fully transmitted.
1540 * Value can be any integer greater or equal to 400.
1541 * The default value 499 is based on the non-standard nginx "CLIENT CLOSED REQUEST" error.
1542 * The value is only used for logging as the request has already ended.
1543 * @default 499
1544 */
1545 disconnectStatusCode?: number | undefined;
1546}
1547
1548/**
1549 * @see https://www.w3.org/TR/referrer-policy/
1550 */
1551export type ReferrerPolicy =
1552 | ""
1553 | "no-referrer"
1554 | "no-referrer-when-downgrade"
1555 | "unsafe-url"
1556 | "same-origin"
1557 | "origin"
1558 | "strict-origin"
1559 | "origin-when-cross-origin"
1560 | "strict-origin-when-cross-origin";
1561
1562/**
1563 * Default value: false (security headers disabled).
1564 * Sets common security headers. To enable, set security to true or to an object with the following options:
1565 * * hsts - controls the 'Strict-Transport-Security' header, where:
1566 * * * true - the header will be set to max-age=15768000. This is the default value.
1567 * * * a number - the maxAge parameter will be set to the provided value.
1568 * * * an object with the following fields:
1569 * * * * maxAge - the max-age portion of the header, as a number. Default is 15768000.
1570 * * * * includeSubDomains - a boolean specifying whether to add the includeSubDomains flag to the header.
1571 * * * * preload - a boolean specifying whether to add the 'preload' flag (used to submit domains inclusion in Chrome's HTTP Strict Transport Security (HSTS) preload list) to the header.
1572 * * xframe - controls the 'X-Frame-Options' header, where:
1573 * * * true - the header will be set to 'DENY'. This is the default value.
1574 * * * 'deny' - the headers will be set to 'DENY'.
1575 * * * 'sameorigin' - the headers will be set to 'SAMEORIGIN'.
1576 * * * an object for specifying the 'allow-from' rule, where:
1577 * * * * rule - one of:
1578 * * * * * 'deny'
1579 * * * * * 'sameorigin'
1580 * * * * * 'allow-from'
1581 * * * * source - when rule is 'allow-from' this is used to form the rest of the header, otherwise this field is ignored. If rule is 'allow-from' but source is unset, the rule will be automatically
1582 * changed to 'sameorigin'.
1583 * * xss - boolean that controls the 'X-XSS-PROTECTION' header for Internet Explorer. Defaults to true which sets the header to equal '1; mode=block'.
1584 * Note: this setting can create a security vulnerability in versions of Internet Exploere below 8, as well as unpatched versions of IE8. See here and here for more information. If you actively
1585 * support old versions of IE, it may be wise to explicitly set this flag to false.
1586 * * noOpen - boolean controlling the 'X-Download-Options' header for Internet Explorer, preventing downloads from executing in your context. Defaults to true setting the header to 'noopen'.
1587 * * noSniff - boolean controlling the 'X-Content-Type-Options' header. Defaults to true setting the header to its only and default option, 'nosniff'.
1588 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionssecurity)
1589 */
1590export interface RouteOptionsSecureObject {
1591 /**
1592 * hsts - controls the 'Strict-Transport-Security' header
1593 */
1594 hsts?: boolean | number | {
1595 /**
1596 * the max-age portion of the header, as a number. Default is 15768000.
1597 */
1598 maxAge: number;
1599 /**
1600 * a boolean specifying whether to add the includeSubDomains flag to the header.
1601 */
1602 includeSubdomains: boolean;
1603 /**
1604 * a boolean specifying whether to add the 'preload' flag (used to submit domains inclusion in Chrome's HTTP Strict Transport Security (HSTS) preload list) to the header.
1605 */
1606 preload: boolean;
1607 } | undefined;
1608 /**
1609 * controls the 'X-Frame-Options' header
1610 */
1611 xframe?: true | "deny" | "sameorigin" | {
1612 /**
1613 * an object for specifying the 'allow-from' rule,
1614 */
1615 rule: "deny" | "sameorigin" | "allow-from";
1616 /**
1617 * when rule is 'allow-from' this is used to form the rest of the header, otherwise this field is ignored. If rule is 'allow-from' but source is unset, the rule will be automatically changed
1618 * to 'sameorigin'.
1619 */
1620 source: string;
1621 } | undefined;
1622 /**
1623 * boolean that controls the 'X-XSS-PROTECTION' header for Internet Explorer. Defaults to true which sets the header to equal '1; mode=block'.
1624 * Note: this setting can create a security vulnerability in versions of Internet Exploere below 8, as well as unpatched versions of IE8. See here and here for more information. If you actively
1625 * support old versions of IE, it may be wise to explicitly set this flag to false.
1626 */
1627 xss: boolean;
1628 /**
1629 * boolean controlling the 'X-Download-Options' header for Internet Explorer, preventing downloads from executing in your context. Defaults to true setting the header to 'noopen'.
1630 */
1631 noOpen?: boolean | undefined;
1632 /**
1633 * boolean controlling the 'X-Content-Type-Options' header. Defaults to true setting the header to its only and default option, 'nosniff'.
1634 */
1635 noSniff?: boolean | undefined;
1636
1637 /**
1638 * Controls the `Referrer-Policy` header, which has the following possible values.
1639 * @default false Header will not be send.
1640 */
1641 referrer?: false | ReferrerPolicy | undefined;
1642}
1643
1644export type RouteOptionsSecure = boolean | RouteOptionsSecureObject;
1645
1646/**
1647 * Default value: { headers: true, params: true, query: true, payload: true, failAction: 'error' }.
1648 * Request input validation rules for various request components.
1649 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidate)
1650 */
1651export interface RouteOptionsValidate {
1652 /**
1653 * Default value: none.
1654 * An optional object with error fields copied into every validation error response.
1655 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidateerrorfields)
1656 */
1657 errorFields?: object | undefined;
1658
1659 /**
1660 * Default value: 'error' (return a Bad Request (400) error response).
1661 * A failAction value which determines how to handle failed validations. When set to a function, the err argument includes the type of validation error under err.output.payload.validation.source.
1662 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidatefailaction)
1663 */
1664 failAction?: Lifecycle.FailAction | undefined;
1665
1666 /**
1667 * Validation rules for incoming request headers:
1668 * * If a value is returned, the value is used as the new request.headers value and the original value is stored in request.orig.headers. Otherwise, the headers are left unchanged. If an error
1669 * is thrown, the error is handled according to failAction. Note that all header field names must be in lowercase to match the headers normalized by node.
1670 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidateheaders)
1671 * @default true
1672 */
1673 headers?: RouteOptionsResponseSchema | undefined;
1674
1675 /**
1676 * An options object passed to the joi rules or the custom validation methods. Used for setting global options such as stripUnknown or abortEarly (the complete list is available here).
1677 * If a custom validation function (see headers, params, query, or payload above) is defined then options can an arbitrary object that will be passed to this function as the second parameter.
1678 * The values of the other inputs (i.e. headers, query, params, payload, app, and auth) are added to the options object under the validation context (accessible in rules as
1679 * Joi.ref('$query.key')).
1680 * Note that validation is performed in order (i.e. headers, params, query, and payload) and if type casting is used (e.g. converting a string to a number), the value of inputs not yet validated
1681 * will reflect the raw, unvalidated and unmodified values. If the validation rules for headers, params, query, and payload are defined at both the server routes level and at the route level, the
1682 * individual route settings override the routes defaults (the rules are not merged).
1683 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidateparams)
1684 * @default true
1685 */
1686 options?: ValidationOptions | object | undefined;
1687
1688 /**
1689 * Validation rules for incoming request path parameters, after matching the path against the route, extracting any parameters, and storing them in request.params, where:
1690 * * true - any path parameter value allowed (no validation performed).
1691 * * a joi validation object.
1692 * * a validation function using the signature async function(value, options) where:
1693 * * * value - the request.params object containing the request path parameters.
1694 * * * options - options.
1695 * if a value is returned, the value is used as the new request.params value and the original value is stored in request.orig.params. Otherwise, the path parameters are left unchanged. If an
1696 * error is thrown, the error is handled according to failAction. Note that failing to match the validation rules to the route path parameters definition will cause all requests to fail.
1697 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidateparams)
1698 * @default true
1699 */
1700 params?: RouteOptionsResponseSchema | undefined;
1701
1702 /**
1703 * Validation rules for incoming request payload (request body), where:
1704 * * If a value is returned, the value is used as the new request.payload value and the original value is stored in request.orig.payload. Otherwise, the payload is left unchanged. If an error is
1705 * thrown, the error is handled according to failAction. Note that validating large payloads and modifying them will cause memory duplication of the payload (since the original is kept), as well
1706 * as the significant performance cost of validating large amounts of data.
1707 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidatepayload)
1708 * @default true
1709 */
1710 payload?: RouteOptionsResponseSchema | undefined;
1711
1712 /**
1713 * Validation rules for incoming request URI query component (the key-value part of the URI between '?' and '#'). The query is parsed into its individual key-value pairs, decoded, and stored in
1714 * request.query prior to validation. Where:
1715 * * If a value is returned, the value is used as the new request.query value and the original value is stored in request.orig.query. Otherwise, the query parameters are left unchanged.
1716 * If an error
1717 * is thrown, the error is handled according to failAction. Note that changes to the query parameters will not be reflected in request.url.
1718 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidatequery)
1719 * @default true
1720 */
1721 query?: RouteOptionsResponseSchema | undefined;
1722
1723 /**
1724 * Validation rules for incoming cookies.
1725 * The cookie header is parsed and decoded into the request.state prior to validation.
1726 * @default true
1727 */
1728 state?: RouteOptionsResponseSchema | undefined;
1729}
1730
1731/**
1732 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscompression)
1733 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverencoderencoding-encoder)
1734 */
1735export type RouteCompressionEncoderSettings = object;
1736
1737/**
1738 * Empty interface to allow for user-defined augmentations.
1739 */
1740/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
1741export interface RouteOptionsApp {
1742}
1743
1744/**
1745 * Each route can be customized to change the default behavior of the request lifecycle.
1746 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#route-options)
1747 */
1748export interface RouteOptions {
1749 /**
1750 * Application-specific route configuration state. Should not be used by plugins which should use options.plugins[name] instead.
1751 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsapp)
1752 */
1753 app?: RouteOptionsApp | undefined;
1754
1755 /**
1756 * Route authentication configuration. Value can be:
1757 * false to disable authentication if a default strategy is set.
1758 * a string with the name of an authentication strategy registered with server.auth.strategy(). The strategy will be set to 'required' mode.
1759 * an authentication configuration object.
1760 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsapp)
1761 */
1762 auth?: false | string | RouteOptionsAccess | undefined;
1763
1764 /**
1765 * Default value: null.
1766 * An object passed back to the provided handler (via this) when called. Ignored if the method is an arrow function.
1767 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsbind)
1768 */
1769 bind?: object | null | undefined;
1770
1771 /**
1772 * Default value: { privacy: 'default', statuses: [200], otherwise: 'no-cache' }.
1773 * If the route method is 'GET', the route can be configured to include HTTP caching directives in the response. Caching can be customized using an object with the following options:
1774 * privacy - determines the privacy flag included in client-side caching using the 'Cache-Control' header. Values are:
1775 * * * 'default' - no privacy flag.
1776 * * * 'public' - mark the response as suitable for public caching.
1777 * * * 'private' - mark the response as suitable only for private caching.
1778 * * expiresIn - relative expiration expressed in the number of milliseconds since the item was saved in the cache. Cannot be used together with expiresAt.
1779 * * expiresAt - time of day expressed in 24h notation using the 'HH:MM' format, at which point all cache records for the route expire. Cannot be used together with expiresIn.
1780 * * statuses - an array of HTTP response status code numbers (e.g. 200) which are allowed to include a valid caching directive.
1781 * * otherwise - a string with the value of the 'Cache-Control' header when caching is disabled.
1782 * The default Cache-Control: no-cache header can be disabled by setting cache to false.
1783 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscache)
1784 */
1785 cache?: false | RouteOptionsCache | undefined;
1786
1787 /**
1788 * An object where each key is a content-encoding name and each value is an object with the desired encoder settings. Note that decoder settings are set in compression.
1789 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscompression)
1790 */
1791 compression?: Util.Dictionary<RouteCompressionEncoderSettings> | undefined;
1792
1793 /**
1794 * Default value: false (no CORS headers).
1795 * The Cross-Origin Resource Sharing protocol allows browsers to make cross-origin API calls. CORS is required by web applications running inside a browser which are loaded from a different
1796 * domain than the API server. To enable, set cors to true, or to an object with the following options:
1797 * * origin - an array of allowed origin servers strings ('Access-Control-Allow-Origin'). The array can contain any combination of fully qualified origins along with origin strings containing a
1798 * wildcard '*' character, or a single '*' origin string. If set to 'ignore', any incoming Origin header is ignored (present or not) and the 'Access-Control-Allow-Origin' header is set to '*'.
1799 * Defaults to any origin ['*'].
1800 * * maxAge - number of seconds the browser should cache the CORS response ('Access-Control-Max-Age'). The greater the value, the longer it will take before the browser checks for changes in
1801 * policy. Defaults to 86400 (one day).
1802 * * headers - a strings array of allowed headers ('Access-Control-Allow-Headers'). Defaults to ['Accept', 'Authorization', 'Content-Type', 'If-None-Match'].
1803 * * additionalHeaders - a strings array of additional headers to headers. Use this to keep the default headers in place.
1804 * * exposedHeaders - a strings array of exposed headers ('Access-Control-Expose-Headers'). Defaults to ['WWW-Authenticate', 'Server-Authorization'].
1805 * * additionalExposedHeaders - a strings array of additional headers to exposedHeaders. Use this to keep the default headers in place.
1806 * * credentials - if true, allows user credentials to be sent ('Access-Control-Allow-Credentials'). Defaults to false.
1807 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscors)
1808 */
1809 cors?: boolean | RouteOptionsCors | undefined;
1810
1811 /**
1812 * Default value: none.
1813 * Route description used for generating documentation (string).
1814 * This setting is not available when setting server route defaults using server.options.routes.
1815 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsdescription)
1816 */
1817 description?: string | undefined;
1818
1819 /**
1820 * Default value: none.
1821 * Route-level request extension points by setting the option to an object with a key for each of the desired extension points ('onRequest' is not allowed), and the value is the same as the
1822 * server.ext(events) event argument.
1823 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsext)
1824 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#request-lifecycle)
1825 */
1826 ext?:
1827 | {
1828 [key in RouteRequestExtType]?: RouteExtObject | RouteExtObject[];
1829 }
1830 | undefined;
1831
1832 /**
1833 * Default value: { relativeTo: '.' }.
1834 * Defines the behavior for accessing files:
1835 * * relativeTo - determines the folder relative paths are resolved against.
1836 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsfiles)
1837 */
1838 files?: {
1839 relativeTo: string;
1840 } | undefined;
1841
1842 /**
1843 * Default value: none.
1844 * The route handler function performs the main business logic of the route and sets the response. handler can be assigned:
1845 * * a lifecycle method.
1846 * * an object with a single property using the name of a handler type registred with the server.handler() method. The matching property value is passed as options to the registered handler
1847 * generator. Note: handlers using a fat arrow style function cannot be bound to any bind property. Instead, the bound context is available under h.context.
1848 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionshandler)
1849 */
1850 handler?: Lifecycle.Method | object | undefined;
1851
1852 /**
1853 * Default value: none.
1854 * An optional unique identifier used to look up the route using server.lookup(). Cannot be assigned to routes added with an array of methods.
1855 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsid)
1856 */
1857 id?: string | undefined;
1858
1859 /**
1860 * Default value: false.
1861 * If true, the route cannot be accessed through the HTTP listener but only through the server.inject() interface with the allowInternals option set to true. Used for internal routes that should
1862 * not be accessible to the outside world.
1863 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsisinternal)
1864 */
1865 isInternal?: boolean | undefined;
1866
1867 /**
1868 * Default value: none.
1869 * Optional arguments passed to JSON.stringify() when converting an object or error response to a string payload or escaping it after stringification. Supports the following:
1870 * * replacer - the replacer function or array. Defaults to no action.
1871 * * space - number of spaces to indent nested object keys. Defaults to no indentation.
1872 * * suffix - string suffix added after conversion to JSON string. Defaults to no suffix.
1873 * * escape - calls Hoek.jsonEscape() after conversion to JSON string. Defaults to false.
1874 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsjson)
1875 */
1876 json?: Json.StringifyArguments | undefined;
1877
1878 /**
1879 * Default value: none.
1880 * Enables JSONP support by setting the value to the query parameter name containing the function name used to wrap the response payload.
1881 * For example, if the value is 'callback', a request comes in with 'callback=me', and the JSON response is '{ "a":"b" }', the payload will be 'me({ "a":"b" });'. Cannot be used with stream
1882 * responses. The 'Content-Type' response header is set to 'text/javascript' and the 'X-Content-Type-Options' response header is set to 'nosniff', and will override those headers even if
1883 * explicitly set by response.type().
1884 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsjsonp)
1885 */
1886 jsonp?: string | undefined;
1887
1888 /**
1889 * Default value: { collect: false }.
1890 * Request logging options:
1891 * collect - if true, request-level logs (both internal and application) are collected and accessible via request.logs.
1892 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionslog)
1893 */
1894 log?: {
1895 collect: boolean;
1896 } | undefined;
1897
1898 /**
1899 * Default value: none.
1900 * Route notes used for generating documentation (string or array of strings).
1901 * This setting is not available when setting server route defaults using server.options.routes.
1902 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsnotes)
1903 */
1904 notes?: string | string[] | undefined;
1905
1906 /**
1907 * Determines how the request payload is processed.
1908 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayload)
1909 */
1910 payload?: RouteOptionsPayload | undefined;
1911
1912 /**
1913 * Default value: {}.
1914 * Plugin-specific configuration. plugins is an object where each key is a plugin name and the value is the plugin configuration.
1915 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsplugins)
1916 */
1917 plugins?: PluginSpecificConfiguration | undefined;
1918
1919 /**
1920 * Default value: none.
1921 * The pre option allows defining methods for performing actions before the handler is called. These methods allow breaking the handler logic into smaller, reusable components that can be shared
1922 * ascross routes, as well as provide a cleaner error handling of prerequisite operations (e.g. load required reference data from a database). pre is assigned an ordered array of methods which
1923 * are called serially in order. If the pre array contains another array of methods as one of its elements, those methods are called in parallel. Note that during parallel execution, if any of
1924 * the methods error, return a takeover response, or abort signal, the other parallel methods will continue to execute but will be ignored once completed. pre can be assigned a mixed array of:
1925 * * an array containing the elements listed below, which are executed in parallel.
1926 * * an object with:
1927 * * * method - a lifecycle method.
1928 * * * assign - key name used to assign the response of the method to in request.pre and request.preResponses.
1929 * * * failAction - A failAction value which determine what to do when a pre-handler method throws an error. If assign is specified and the failAction setting is not 'error', the error will be
1930 * assigned.
1931 * * a method function - same as including an object with a single method key.
1932 * Note that pre-handler methods do not behave the same way other lifecycle methods do when a value is returned. Instead of the return value becoming the new response payload, the value is used
1933 * to assign the corresponding request.pre and request.preResponses properties. Otherwise, the handling of errors, takeover response response, or abort signal behave the same as any other
1934 * lifecycle methods.
1935 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
1936 */
1937 pre?: RouteOptionsPreArray | undefined;
1938
1939 /**
1940 * Processing rules for the outgoing response.
1941 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponse)
1942 */
1943 response?: RouteOptionsResponse | undefined;
1944
1945 /**
1946 * Default value: false (security headers disabled).
1947 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionssecurity)
1948 */
1949 security?: RouteOptionsSecure | undefined;
1950
1951 /**
1952 * Default value: { parse: true, failAction: 'error' }.
1953 * HTTP state management (cookies) allows the server to store information on the client which is sent back to the server with every request (as defined in RFC 6265). state supports the following
1954 * options: parse - determines if incoming 'Cookie' headers are parsed and stored in the request.state object. failAction - A failAction value which determines how to handle cookie parsing
1955 * errors. Defaults to 'error' (return a Bad Request (400) error response).
1956 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsstate)
1957 */
1958 state?: {
1959 parse?: boolean | undefined;
1960 failAction?: Lifecycle.FailAction | undefined;
1961 } | undefined;
1962
1963 /**
1964 * Default value: none.
1965 * Route tags used for generating documentation (array of strings).
1966 * This setting is not available when setting server route defaults using server.options.routes.
1967 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionstags)
1968 */
1969 tags?: string[] | undefined;
1970
1971 /**
1972 * Default value: { server: false }.
1973 * Timeouts for processing durations.
1974 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionstimeout)
1975 */
1976 timeout?: {
1977 /**
1978 * Response timeout in milliseconds. Sets the maximum time allowed for the server to respond to an incoming request before giving up and responding with a Service Unavailable (503) error
1979 * response.
1980 */
1981 server?: boolean | number | undefined;
1982
1983 /**
1984 * Default value: none (use node default of 2 minutes).
1985 * By default, node sockets automatically timeout after 2 minutes. Use this option to override this behavior. Set to false to disable socket timeouts.
1986 */
1987 socket?: boolean | number | undefined;
1988 } | undefined;
1989
1990 /**
1991 * Default value: { headers: true, params: true, query: true, payload: true, failAction: 'error' }.
1992 * Request input validation rules for various request components.
1993 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsvalidate)
1994 */
1995 validate?: RouteOptionsValidate | undefined;
1996}
1997
1998/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1999 + +
2000 + +
2001 + +
2002 + Server +
2003 + +
2004 + +
2005 + +
2006 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
2007
2008/**
2009 * The scheme options argument passed to server.auth.strategy() when instantiation a strategy.
2010 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthschemename-scheme)
2011 */
2012export type ServerAuthSchemeOptions = object;
2013
2014/**
2015 * the method implementing the scheme with signature function(server, options) where:
2016 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthschemename-scheme)
2017 * @param server - a reference to the server object the scheme is added to.
2018 * @param options - (optional) the scheme options argument passed to server.auth.strategy() when instantiation a strategy.
2019 */
2020export type ServerAuthScheme = (server: Server, options?: ServerAuthSchemeOptions) => ServerAuthSchemeObject;
2021
2022/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
2023export interface ServerAuthSchemeObjectApi {
2024}
2025
2026/**
2027 * The scheme method must return an object with the following
2028 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#authentication-scheme)
2029 */
2030export interface ServerAuthSchemeObject {
2031 /**
2032 * optional object which is exposed via the [server.auth.api](https://github.com/hapijs/hapi/blob/master/API.md#server.auth.api) object.
2033 */
2034 api?: ServerAuthSchemeObjectApi | undefined;
2035
2036 /**
2037 * A lifecycle method function called for each incoming request configured with the authentication scheme. The
2038 * method is provided with two special toolkit methods for returning an authenticated or an unauthenticate result:
2039 * * h.authenticated() - indicate request authenticated successfully.
2040 * * h.unauthenticated() - indicate request failed to authenticate.
2041 * @param request the request object.
2042 * @param h the ResponseToolkit
2043 * @return the Lifecycle.ReturnValue
2044 */
2045 authenticate(request: Request, h: ResponseToolkit): Lifecycle.ReturnValue;
2046
2047 /**
2048 * A lifecycle method to authenticate the request payload.
2049 * When the scheme payload() method returns an error with a message, it means payload validation failed due to bad
2050 * payload. If the error has no message but includes a scheme name (e.g. Boom.unauthorized(null, 'Custom')),
2051 * authentication may still be successful if the route auth.payload configuration is set to 'optional'.
2052 * @param request the request object.
2053 * @param h the ResponseToolkit
2054 * @return the Lifecycle.ReturnValue
2055 */
2056 payload?(request: Request, h: ResponseToolkit): Lifecycle.ReturnValue;
2057
2058 /**
2059 * A lifecycle method to decorate the response with authentication headers before the response headers or payload is written.
2060 * @param request the request object.
2061 * @param h the ResponseToolkit
2062 * @return the Lifecycle.ReturnValue
2063 */
2064 response?(request: Request, h: ResponseToolkit): Lifecycle.ReturnValue;
2065
2066 /**
2067 * a method used to verify the authentication credentials provided
2068 * are still valid (e.g. not expired or revoked after the initial authentication).
2069 * the method throws an `Error` when the credentials passed are no longer valid (e.g. expired or
2070 * revoked). Note that the method does not have access to the original request, only to the
2071 * credentials and artifacts produced by the `authenticate()` method.
2072 */
2073 verify?(auth: RequestAuth): Promise<void>;
2074
2075 /**
2076 * An object with the following keys:
2077 * * payload
2078 */
2079 options?: {
2080 /**
2081 * if true, requires payload validation as part of the scheme and forbids routes from disabling payload auth validation. Defaults to false.
2082 */
2083 payload?: boolean | undefined;
2084 } | undefined;
2085}
2086
2087/**
2088 * An authentication configuration object using the same format as the route auth handler options.
2089 * For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthdefaultoptions)
2090 */
2091/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
2092export interface ServerAuthConfig extends RouteOptionsAccess {
2093}
2094
2095export interface ServerAuth {
2096 /**
2097 * An object where each key is an authentication strategy name and the value is the exposed strategy API.
2098 * Available only when the authentication scheme exposes an API by returning an api key in the object
2099 * returned from its implementation function.
2100 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthapi)
2101 */
2102 api: Util.Dictionary<ServerAuthSchemeObjectApi>;
2103
2104 /**
2105 * Contains the default authentication configuration is a default strategy was set via
2106 * [server.auth.default()](https://github.com/hapijs/hapi/blob/master/API.md#server.auth.default()).
2107 */
2108 readonly settings: {
2109 default: ServerAuthConfig;
2110 };
2111
2112 /**
2113 * Sets a default strategy which is applied to every route where:
2114 * @param options - one of:
2115 * * a string with the default strategy name
2116 * * an authentication configuration object using the same format as the route auth handler options.
2117 * @return void.
2118 * The default does not apply when a route config specifies auth as false, or has an authentication strategy
2119 * configured (contains the strategy or strategies authentication settings). Otherwise, the route authentication
2120 * config is applied to the defaults.
2121 * Note that if the route has authentication configured, the default only applies at the time of adding the route,
2122 * not at runtime. This means that calling server.auth.default() after adding a route with some authentication
2123 * config will have no impact on the routes added prior. However, the default will apply to routes added
2124 * before server.auth.default() is called if those routes lack any authentication config.
2125 * The default auth strategy configuration can be accessed via server.auth.settings.default. To obtain the active
2126 * authentication configuration of a route, use server.auth.lookup(request.route).
2127 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthdefaultoptions)
2128 */
2129 default(options: string | ServerAuthConfig): void;
2130
2131 /**
2132 * Registers an authentication scheme where:
2133 * @param name the scheme name.
2134 * @param scheme - the method implementing the scheme with signature function(server, options) where:
2135 * * server - a reference to the server object the scheme is added to.
2136 * * options - (optional) the scheme options argument passed to server.auth.strategy() when instantiation a strategy.
2137 * @return void.
2138 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthschemename-scheme)
2139 */
2140 scheme(name: string, scheme: ServerAuthScheme): void;
2141
2142 /**
2143 * Registers an authentication strategy where:
2144 * @param name - the strategy name.
2145 * @param scheme - the scheme name (must be previously registered using server.auth.scheme()).
2146 * @param options - scheme options based on the scheme requirements.
2147 * @return Return value: none.
2148 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverauthstrategyname-scheme-options)
2149 */
2150 strategy(name: string, scheme: string, options?: object): void;
2151
2152 /**
2153 * Tests a request against an authentication strategy where:
2154 * @param strategy - the strategy name registered with server.auth.strategy().
2155 * @param request - the request object.
2156 * @return an object containing the authentication credentials and artifacts if authentication was successful, otherwise throws an error.
2157 * Note that the test() method does not take into account the route authentication configuration. It also does not
2158 * perform payload authentication. It is limited to the basic strategy authentication execution. It does not
2159 * include verifying scope, entity, or other route properties.
2160 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverauthteststrategy-request)
2161 */
2162 test(strategy: string, request: Request): Promise<AuthenticationData>;
2163
2164 /**
2165 * Verify a request's authentication credentials against an authentication strategy.
2166 * Returns nothing if verification was successful, otherwise throws an error.
2167 *
2168 * Note that the `verify()` method does not take into account the route authentication configuration
2169 * or any other information from the request other than the `request.auth` object. It also does not
2170 * perform payload authentication. It is limited to verifying that the previously valid credentials
2171 * are still valid (e.g. have not been revoked or expired). It does not include verifying scope,
2172 * entity, or other route properties.
2173 */
2174 verify(request: Request): Promise<void>;
2175}
2176
2177export type CachePolicyOptions<T> = PolicyOptionVariants<T> & {
2178 /**
2179 * @default '_default'
2180 */
2181 cache?: string | undefined;
2182 segment?: string | undefined;
2183};
2184
2185/**
2186 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servercacheoptions)
2187 */
2188export interface ServerCache {
2189 /**
2190 * Provisions a cache segment within the server cache facility where:
2191 * @param options - [catbox policy](https://github.com/hapijs/catbox#policy) configuration where:
2192 * * expiresIn - relative expiration expressed in the number of milliseconds since the item was saved in the cache. Cannot be used together with expiresAt.
2193 * * expiresAt - time of day expressed in 24h notation using the 'HH:MM' format, at which point all cache records expire. Uses local time. Cannot be used together with expiresIn.
2194 * * generateFunc - a function used to generate a new cache item if one is not found in the cache when calling get(). The method's signature is async function(id, flags) where:
2195 * - `id` - the `id` string or object provided to the `get()` method.
2196 * - `flags` - an object used to pass back additional flags to the cache where:
2197 * - `ttl` - the cache ttl value in milliseconds. Set to `0` to skip storing in the cache. Defaults to the cache global policy.
2198 * * staleIn - number of milliseconds to mark an item stored in cache as stale and attempt to regenerate it when generateFunc is provided. Must be less than expiresIn.
2199 * * staleTimeout - number of milliseconds to wait before checking if an item is stale.
2200 * * generateTimeout - number of milliseconds to wait before returning a timeout error when the generateFunc function takes too long to return a value. When the value is eventually returned, it
2201 * is stored in the cache for future requests. Required if generateFunc is present. Set to false to disable timeouts which may cause all get() requests to get stuck forever.
2202 * * generateOnReadError - if false, an upstream cache read error will stop the cache.get() method from calling the generate function and will instead pass back the cache error. Defaults to true.
2203 * * generateIgnoreWriteError - if false, an upstream cache write error when calling cache.get() will be passed back with the generated value when calling. Defaults to true.
2204 * * dropOnError - if true, an error or timeout in the generateFunc causes the stale value to be evicted from the cache. Defaults to true.
2205 * * pendingGenerateTimeout - number of milliseconds while generateFunc call is in progress for a given id, before a subsequent generateFunc call is allowed. Defaults to 0 (no blocking of
2206 * concurrent generateFunc calls beyond staleTimeout).
2207 * * cache - the cache name configured in server.cache. Defaults to the default cache.
2208 * * segment - string segment name, used to isolate cached items within the cache partition. When called within a plugin, defaults to '!name' where 'name' is the plugin name. When called within a
2209 * server method, defaults to '#name' where 'name' is the server method name. Required when called outside of a plugin.
2210 * * shared - if true, allows multiple cache provisions to share the same segment. Default to false.
2211 * @return Catbox Policy.
2212 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servercacheoptions)
2213 */
2214 <T, O extends CachePolicyOptions<T> = CachePolicyOptions<T>>(options: O): Policy<T, O>;
2215
2216 /**
2217 * Provisions a server cache as described in server.cache where:
2218 * @param options - same as the server cache configuration options.
2219 * @return Return value: none.
2220 * Note that if the server has been initialized or started, the cache will be automatically started to match the state of any other provisioned server cache.
2221 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-servercacheprovisionoptions)
2222 */
2223 provision(options: ServerOptionsCache): Promise<void>;
2224}
2225
2226/**
2227 * an event name string.
2228 * an event options object.
2229 * a podium emitter object.
2230 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servereventevents)
2231 */
2232export type ServerEventsApplication = string | ServerEventsApplicationObject | Podium;
2233
2234/**
2235 * Object that it will be used in Event
2236 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servereventevents)
2237 */
2238export interface ServerEventsApplicationObject {
2239 /** the event name string (required). */
2240 name: string;
2241 /** a string or array of strings specifying the event channels available. Defaults to no channel restrictions (event updates can specify a channel or not). */
2242 channels?: string | string[] | undefined;
2243 /**
2244 * if true, the data object passed to server.events.emit() is cloned before it is passed to the listeners (unless an override specified by each listener). Defaults to false (data is passed as-is).
2245 */
2246 clone?: boolean | undefined;
2247 /**
2248 * if true, the data object passed to server.event.emit() must be an array and the listener method is called with each array element passed as a separate argument (unless an override specified
2249 * by each listener). This should only be used when the emitted data structure is known and predictable. Defaults to false (data is emitted as a single argument regardless of its type).
2250 */
2251 spread?: boolean | undefined;
2252 /**
2253 * if true and the criteria object passed to server.event.emit() includes tags, the tags are mapped to an object (where each tag string is the key and the value is true) which is appended to
2254 * the arguments list at the end. A configuration override can be set by each listener. Defaults to false.
2255 */
2256 tags?: boolean | undefined;
2257 /**
2258 * if true, the same event name can be registered multiple times where the second registration is ignored. Note that if the registration config is changed between registrations, only the first
2259 * configuration is used. Defaults to false (a duplicate registration will throw an error).
2260 */
2261 shared?: boolean | undefined;
2262}
2263
2264/**
2265 * A criteria object with the following optional keys (unless noted otherwise):
2266 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servereventsoncriteria-listener)
2267 *
2268 * The type parameter T is the type of the name of the event.
2269 */
2270export interface ServerEventCriteria<T> {
2271 /** (required) the event name string. */
2272 name: T;
2273 /**
2274 * a string or array of strings specifying the event channels to subscribe to. If the event registration specified a list of allowed channels, the channels array must match the allowed
2275 * channels. If channels are specified, event updates without any channel designation will not be included in the subscription. Defaults to no channels filter.
2276 */
2277 channels?: string | string[] | undefined;
2278 /** if true, the data object passed to server.event.emit() is cloned before it is passed to the listener method. Defaults to the event registration option (which defaults to false). */
2279 clone?: boolean | undefined;
2280 /**
2281 * a positive integer indicating the number of times the listener can be called after which the subscription is automatically removed. A count of 1 is the same as calling server.events.once().
2282 * Defaults to no limit.
2283 */
2284 count?: number | undefined;
2285 /**
2286 * filter - the event tags (if present) to subscribe to which can be one of:
2287 * * a tag string.
2288 * * an array of tag strings.
2289 * * an object with the following:
2290 * * * tags - a tag string or array of tag strings.
2291 * * * all - if true, all tags must be present for the event update to match the subscription. Defaults to false (at least one matching tag).
2292 */
2293 filter?: string | string[] | { tags: string | string[]; all?: boolean | undefined } | undefined;
2294 /**
2295 * if true, and the data object passed to server.event.emit() is an array, the listener method is called with each array element passed as a separate argument. This should only be used
2296 * when the emitted data structure is known and predictable. Defaults to the event registration option (which defaults to false).
2297 */
2298 spread?: boolean | undefined;
2299 /**
2300 * if true and the criteria object passed to server.event.emit() includes tags, the tags are mapped to an object (where each tag string is the key and the value is true) which is appended
2301 * to the arguments list at the end. Defaults to the event registration option (which defaults to false).
2302 */
2303 tags?: boolean | undefined;
2304}
2305
2306export interface LogEvent {
2307 /** the event timestamp. */
2308 timestamp: string;
2309 /** an array of tags identifying the event (e.g. ['error', 'http']) */
2310 tags: string[];
2311 /** set to 'internal' for internally generated events, otherwise 'app' for events generated by server.log() */
2312 channel: "internal" | "app";
2313 /** the request identifier. */
2314 request: string;
2315 /** event-specific information. Available when event data was provided and is not an error. Errors are passed via error. */
2316 data: object;
2317 /** the error object related to the event if applicable. Cannot appear together with data */
2318 error: object;
2319}
2320
2321export interface RequestEvent {
2322 /** the event timestamp. */
2323 timestamp: string;
2324 /** an array of tags identifying the event (e.g. ['error', 'http']) */
2325 tags: string[];
2326 /** set to 'internal' for internally generated events, otherwise 'app' for events generated by server.log() */
2327 channel: "internal" | "app" | "error";
2328 /** event-specific information. Available when event data was provided and is not an error. Errors are passed via error. */
2329 data: object;
2330 /** the error object related to the event if applicable. Cannot appear together with data */
2331 error: object;
2332}
2333
2334export type LogEventHandler = (event: LogEvent, tags: { [key: string]: true }) => void;
2335export type RequestEventHandler = (request: Request, event: RequestEvent, tags: { [key: string]: true }) => void;
2336export type ResponseEventHandler = (request: Request) => void;
2337export type RouteEventHandler = (route: RequestRoute) => void;
2338export type StartEventHandler = () => void;
2339export type StopEventHandler = () => void;
2340
2341export interface PodiumEvent<K extends string, T> {
2342 emit(criteria: K, listener: (value: T) => void): void;
2343
2344 on(criteria: K, listener: (value: T) => void): void;
2345
2346 once(criteria: K, listener: (value: T) => void): void;
2347
2348 once(criteria: K): Promise<T>;
2349
2350 removeListener(criteria: K, listener: Podium.Listener): this;
2351
2352 removeAllListeners(criteria: K): this;
2353
2354 hasListeners(criteria: K): this;
2355}
2356
2357/**
2358 * Access: podium public interface.
2359 * The server events emitter. Utilizes the podium with support for event criteria validation, channels, and filters.
2360 * Use the following methods to interact with server.events:
2361 * [server.event(events)](https://github.com/hapijs/hapi/blob/master/API.md#server.event()) - register application events.
2362 * [server.events.emit(criteria, data)](https://github.com/hapijs/hapi/blob/master/API.md#server.events.emit()) - emit server events.
2363 * [server.events.on(criteria, listener)](https://github.com/hapijs/hapi/blob/master/API.md#server.events.on()) - subscribe to all events.
2364 * [server.events.once(criteria, listener)](https://github.com/hapijs/hapi/blob/master/API.md#server.events.once()) - subscribe to
2365 * Other methods include: server.events.removeListener(name, listener), server.events.removeAllListeners(name), and server.events.hasListeners(name).
2366 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
2367 */
2368export interface ServerEvents extends Podium {
2369 /**
2370 * Subscribe to an event where:
2371 * @param criteria - the subscription criteria which must be one of:
2372 * * event name string which can be any of the built-in server events
2373 * * a custom application event registered with server.event().
2374 * * a criteria object
2375 * @param listener - the handler method set to receive event updates. The function signature depends on the event argument, and the spread and tags options.
2376 * @return Return value: none.
2377 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servereventsoncriteria-listener)
2378 * See ['log' event](https://github.com/hapijs/hapi/blob/master/API.md#-log-event)
2379 * See ['request' event](https://github.com/hapijs/hapi/blob/master/API.md#-request-event)
2380 * See ['response' event](https://github.com/hapijs/hapi/blob/master/API.md#-response-event)
2381 * See ['route' event](https://github.com/hapijs/hapi/blob/master/API.md#-route-event)
2382 * See ['start' event](https://github.com/hapijs/hapi/blob/master/API.md#-start-event)
2383 * See ['stop' event](https://github.com/hapijs/hapi/blob/master/API.md#-stop-event)
2384 */
2385 on(criteria: "log" | ServerEventCriteria<"log">, listener: LogEventHandler): void;
2386
2387 on(criteria: "request" | ServerEventCriteria<"request">, listener: RequestEventHandler): void;
2388
2389 on(criteria: "response" | ServerEventCriteria<"response">, listener: ResponseEventHandler): void;
2390
2391 on(criteria: "route" | ServerEventCriteria<"route">, listener: RouteEventHandler): void;
2392
2393 on(criteria: "start" | ServerEventCriteria<"start">, listener: StartEventHandler): void;
2394
2395 on(criteria: "stop" | ServerEventCriteria<"stop">, listener: StopEventHandler): void;
2396
2397 /**
2398 * Same as calling [server.events.on()](https://github.com/hapijs/hapi/blob/master/API.md#server.events.on()) with the count option set to 1.
2399 * @param criteria - the subscription criteria which must be one of:
2400 * * event name string which can be any of the built-in server events
2401 * * a custom application event registered with server.event().
2402 * * a criteria object
2403 * @param listener - the handler method set to receive event updates. The function signature depends on the event argument, and the spread and tags options.
2404 * @return Return value: none.
2405 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servereventsoncecriteria-listener)
2406 */
2407 once(criteria: "log" | ServerEventCriteria<"log">, listener: LogEventHandler): void;
2408
2409 once(criteria: "request" | ServerEventCriteria<"request">, listener: RequestEventHandler): void;
2410
2411 once(criteria: "response" | ServerEventCriteria<"response">, listener: ResponseEventHandler): void;
2412
2413 once(criteria: "route" | ServerEventCriteria<"route">, listener: RouteEventHandler): void;
2414
2415 once(criteria: "start" | ServerEventCriteria<"start">, listener: StartEventHandler): void;
2416
2417 once(criteria: "stop" | ServerEventCriteria<"stop">, listener: StopEventHandler): void;
2418
2419 /**
2420 * Same as calling server.events.on() with the count option set to 1.
2421 * @param criteria - the subscription criteria which must be one of:
2422 * * event name string which can be any of the built-in server events
2423 * * a custom application event registered with server.event().
2424 * * a criteria object
2425 * @return Return value: a promise that resolves when the event is emitted.
2426 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-servereventsoncecriteria)
2427 */
2428 once(criteria: string | ServerEventCriteria<string>): Promise<any>;
2429
2430 /**
2431 * The follow method is only mentioned in Hapi API. The doc about that method can be found [here](https://github.com/hapijs/podium/blob/master/API.md#podiumremovelistenername-listener)
2432 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
2433 */
2434 removeListener(name: string, listener: Podium.Listener): Podium;
2435
2436 /**
2437 * The follow method is only mentioned in Hapi API. The doc about that method can be found [here](https://github.com/hapijs/podium/blob/master/API.md#podiumremovealllistenersname)
2438 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
2439 */
2440 removeAllListeners(name: string): Podium;
2441
2442 /**
2443 * The follow method is only mentioned in Hapi API. The doc about that method can be found [here](https://github.com/hapijs/podium/blob/master/API.md#podiumhaslistenersname)
2444 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
2445 */
2446 hasListeners(name: string): boolean;
2447}
2448
2449/**
2450 * The extension point event name. The available extension points include the request extension points as well as the following server extension points:
2451 * 'onPreStart' - called before the connection listeners are started.
2452 * 'onPostStart' - called after the connection listeners are started.
2453 * 'onPreStop' - called before the connection listeners are stopped.
2454 * 'onPostStop' - called after the connection listeners are stopped.
2455 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents)
2456 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#request-lifecycle)
2457 */
2458export type ServerExtType = "onPreStart" | "onPostStart" | "onPreStop" | "onPostStop";
2459export type RouteRequestExtType =
2460 | "onPreAuth"
2461 | "onCredentials"
2462 | "onPostAuth"
2463 | "onPreHandler"
2464 | "onPostHandler"
2465 | "onPreResponse";
2466
2467export type ServerRequestExtType =
2468 | RouteRequestExtType
2469 | "onRequest";
2470
2471/**
2472 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents)
2473 * Registers an extension function in one of the request lifecycle extension points where:
2474 * @param events - an object or array of objects with the following:
2475 * * type - (required) the extension point event name. The available extension points include the request extension points as well as the following server extension points:
2476 * * * 'onPreStart' - called before the connection listeners are started.
2477 * * * 'onPostStart' - called after the connection listeners are started.
2478 * * * 'onPreStop' - called before the connection listeners are stopped.
2479 * * * 'onPostStop' - called after the connection listeners are stopped.
2480 * * method - (required) a function or an array of functions to be executed at a specified point during request processing. The required extension function signature is:
2481 * * * server extension points: async function(server) where:
2482 * * * * server - the server object.
2483 * * * * this - the object provided via options.bind or the current active context set with server.bind().
2484 * * * request extension points: a lifecycle method.
2485 * * options - (optional) an object with the following:
2486 * * * before - a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
2487 * * * after - a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
2488 * * * bind - a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
2489 * * * sandbox - if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level extensions, or
2490 * when adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to.
2491 * @return void
2492 */
2493export interface ServerExtEventsObject {
2494 /**
2495 * (required) the extension point event name. The available extension points include the request extension points as well as the following server extension points:
2496 * * 'onPreStart' - called before the connection listeners are started.
2497 * * 'onPostStart' - called after the connection listeners are started.
2498 * * 'onPreStop' - called before the connection listeners are stopped.
2499 */
2500 type: ServerExtType;
2501 /**
2502 * (required) a function or an array of functions to be executed at a specified point during request processing. The required extension function signature is:
2503 * * server extension points: async function(server) where:
2504 * * * server - the server object.
2505 * * * this - the object provided via options.bind or the current active context set with server.bind().
2506 * * request extension points: a lifecycle method.
2507 */
2508 method: ServerExtPointFunction | ServerExtPointFunction[];
2509 options?: ServerExtOptions | undefined;
2510}
2511
2512export interface RouteExtObject {
2513 method: Lifecycle.Method;
2514 options?: ServerExtOptions | undefined;
2515}
2516
2517/**
2518 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents)
2519 * Registers an extension function in one of the request lifecycle extension points where:
2520 * @param events - an object or array of objects with the following:
2521 * * type - (required) the extension point event name. The available extension points include the request extension points as well as the following server extension points:
2522 * * * 'onPreStart' - called before the connection listeners are started.
2523 * * * 'onPostStart' - called after the connection listeners are started.
2524 * * * 'onPreStop' - called before the connection listeners are stopped.
2525 * * * 'onPostStop' - called after the connection listeners are stopped.
2526 * * method - (required) a function or an array of functions to be executed at a specified point during request processing. The required extension function signature is:
2527 * * * server extension points: async function(server) where:
2528 * * * * server - the server object.
2529 * * * * this - the object provided via options.bind or the current active context set with server.bind().
2530 * * * request extension points: a lifecycle method.
2531 * * options - (optional) an object with the following:
2532 * * * before - a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
2533 * * * after - a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
2534 * * * bind - a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
2535 * * * sandbox - if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level extensions, or
2536 * when adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to.
2537 * @return void
2538 */
2539export interface ServerExtEventsRequestObject {
2540 /**
2541 * (required) the extension point event name. The available extension points include the request extension points as well as the following server extension points:
2542 * * 'onPreStart' - called before the connection listeners are started.
2543 * * 'onPostStart' - called after the connection listeners are started.
2544 * * 'onPreStop' - called before the connection listeners are stopped.
2545 * * 'onPostStop' - called after the connection listeners are stopped.
2546 */
2547 type: ServerRequestExtType;
2548 /**
2549 * (required) a function or an array of functions to be executed at a specified point during request processing. The required extension function signature is:
2550 * * server extension points: async function(server) where:
2551 * * * server - the server object.
2552 * * * this - the object provided via options.bind or the current active context set with server.bind().
2553 * * request extension points: a lifecycle method.
2554 */
2555 method: Lifecycle.Method | Lifecycle.Method[];
2556 /**
2557 * (optional) an object with the following:
2558 * * before - a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
2559 * * after - a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
2560 * * bind - a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
2561 * * sandbox - if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level extensions,
2562 * or when adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to.
2563 */
2564 options?: ServerExtOptions | undefined;
2565}
2566
2567export type ServerExtPointFunction = (server: Server) => void;
2568
2569/**
2570 * An object with the following:
2571 * * before - a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
2572 * * after - a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
2573 * * bind - a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
2574 * * sandbox - if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level extensions, or
2575 * when adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to. For context [See
2576 * docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents)
2577 */
2578export interface ServerExtOptions {
2579 /**
2580 * a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
2581 */
2582 before?: string | string[] | undefined;
2583 /**
2584 * a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
2585 */
2586 after?: string | string[] | undefined;
2587 /**
2588 * a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
2589 */
2590 bind?: object | undefined;
2591 /**
2592 * if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level extensions, or when
2593 * adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to.
2594 */
2595 sandbox?: "server" | "plugin" | undefined;
2596}
2597
2598/**
2599 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverinfo)
2600 * An object containing information about the server where:
2601 */
2602export interface ServerInfo {
2603 /**
2604 * a unique server identifier (using the format '{hostname}:{pid}:{now base36}').
2605 */
2606 id: string;
2607
2608 /**
2609 * server creation timestamp.
2610 */
2611 created: number;
2612
2613 /**
2614 * server start timestamp (0 when stopped).
2615 */
2616 started: number;
2617
2618 /**
2619 * the connection [port](https://github.com/hapijs/hapi/blob/master/API.md#server.options.port) based on the following rules:
2620 * * before the server has been started: the configured port value.
2621 * * after the server has been started: the actual port assigned when no port is configured or was set to 0.
2622 */
2623 port: number | string;
2624
2625 /**
2626 * The [host](https://github.com/hapijs/hapi/blob/master/API.md#server.options.host) configuration value.
2627 */
2628 host: string;
2629
2630 /**
2631 * the active IP address the connection was bound to after starting. Set to undefined until the server has been
2632 * started or when using a non TCP port (e.g. UNIX domain socket).
2633 */
2634 address: undefined | string;
2635
2636 /**
2637 * the protocol used:
2638 * * 'http' - HTTP.
2639 * * 'https' - HTTPS.
2640 * * 'socket' - UNIX domain socket or Windows named pipe.
2641 */
2642 protocol: "http" | "https" | "socket";
2643
2644 /**
2645 * a string representing the connection (e.g. 'http://example.com:8080' or 'socket:/unix/domain/socket/path'). Contains
2646 * the uri value if set, otherwise constructed from the available settings. If no port is configured or is set
2647 * to 0, the uri will not include a port component until the server is started.
2648 */
2649 uri: string;
2650}
2651
2652/**
2653 * An object with:
2654 * * method - (optional) the request HTTP method (e.g. 'POST'). Defaults to 'GET'.
2655 * * url - (required) the request URL. If the URI includes an authority (e.g. 'example.com:8080'), it is used to automatically set an HTTP 'Host' header, unless one was specified in headers.
2656 * * headers - (optional) an object with optional request headers where each key is the header name and the value is the header content. Defaults to no additions to the default shot headers.
2657 * * payload - (optional) an string, buffer or object containing the request payload. In case of an object it will be converted to a string for you. Defaults to no payload. Note that payload
2658 * processing defaults to 'application/json' if no 'Content-Type' header provided.
2659 * * credentials - (optional) an credentials object containing authentication information. The credentials are used to bypass the default authentication strategies, and are validated directly as if
2660 * they were received via an authentication scheme. Defaults to no credentials.
2661 * * artifacts - (optional) an artifacts object containing authentication artifact information. The artifacts are used to bypass the default authentication strategies, and are validated directly as
2662 * if they were received via an authentication scheme. Ignored if set without credentials. Defaults to no artifacts.
2663 * * app - (optional) sets the initial value of request.app, defaults to {}.
2664 * * plugins - (optional) sets the initial value of request.plugins, defaults to {}.
2665 * * allowInternals - (optional) allows access to routes with config.isInternal set to true. Defaults to false.
2666 * * remoteAddress - (optional) sets the remote address for the incoming connection.
2667 * * simulate - (optional) an object with options used to simulate client request stream conditions for testing:
2668 * * error - if true, emits an 'error' event after payload transmission (if any). Defaults to false.
2669 * * close - if true, emits a 'close' event after payload transmission (if any). Defaults to false.
2670 * * end - if false, does not end the stream. Defaults to true.
2671 * * split - indicates whether the request payload will be split into chunks. Defaults to undefined, meaning payload will not be chunked.
2672 * * validate - (optional) if false, the options inputs are not validated. This is recommended for run-time usage of inject() to make it perform faster where input validation can be tested
2673 * separately.
2674 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverinjectoptions)
2675 * For context [Shot module](https://github.com/hapijs/shot)
2676 */
2677export interface ServerInjectOptions extends Shot.RequestOptions {
2678 /**
2679 * Authentication bypass options.
2680 */
2681 auth?: {
2682 /**
2683 * The authentication strategy name matching the provided credentials.
2684 */
2685 strategy: string;
2686 /**
2687 * The credentials are used to bypass the default authentication strategies,
2688 * and are validated directly as if they were received via an authentication scheme.
2689 */
2690 credentials: AuthCredentials;
2691 /**
2692 * The artifacts are used to bypass the default authentication strategies,
2693 * and are validated directly as if they were received via an authentication scheme. Defaults to no artifacts.
2694 */
2695 artifacts?: object | undefined;
2696 } | undefined;
2697 /**
2698 * sets the initial value of request.app, defaults to {}.
2699 */
2700 app?: ApplicationState | undefined;
2701 /**
2702 * sets the initial value of request.plugins, defaults to {}.
2703 */
2704 plugins?: PluginsStates | undefined;
2705 /**
2706 * allows access to routes with config.isInternal set to true. Defaults to false.
2707 */
2708 allowInternals?: boolean | undefined;
2709}
2710
2711/**
2712 * A response object with the following properties:
2713 * * statusCode - the HTTP status code.
2714 * * headers - an object containing the headers set.
2715 * * payload - the response payload string.
2716 * * rawPayload - the raw response payload buffer.
2717 * * raw - an object with the injection request and response objects:
2718 * * req - the simulated node request object.
2719 * * res - the simulated node response object.
2720 * * result - the raw handler response (e.g. when not a stream or a view) before it is serialized for transmission. If not available, the value is set to payload. Useful for inspection and reuse of
2721 * the internal objects returned (instead of parsing the response string).
2722 * * request - the request object.
2723 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverinjectoptions)
2724 * For context [Shot module](https://github.com/hapijs/shot)
2725 */
2726export interface ServerInjectResponse extends Shot.ResponseObject {
2727 /**
2728 * the raw handler response (e.g. when not a stream or a view) before it is serialized for transmission. If not available, the value is set to payload. Useful for inspection and reuse of the
2729 * internal objects returned (instead of parsing the response string).
2730 */
2731 result: object | undefined;
2732 /**
2733 * the request object.
2734 */
2735 request: Request;
2736}
2737
2738/**
2739 * The method function with a signature async function(...args, [flags]) where:
2740 * * ...args - the method function arguments (can be any number of arguments or none).
2741 * * flags - when caching is enabled, an object used to set optional method result flags:
2742 * * * ttl - 0 if result is valid but cannot be cached. Defaults to cache policy.
2743 * For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodname-method-options)
2744 */
2745export type ServerMethod = (...args: any[]) => any;
2746
2747/**
2748 * The same cache configuration used in server.cache().
2749 * The generateTimeout option is required.
2750 * For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodname-method-options)
2751 * For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servercacheoptions)
2752 */
2753export interface ServerMethodCache extends PolicyOptions<any> {
2754 generateTimeout: number | false;
2755}
2756
2757/**
2758 * Configuration object:
2759 * * bind - a context object passed back to the method function (via this) when called. Defaults to active context (set via server.bind() when the method is registered. Ignored if the method is an
2760 * arrow function.
2761 * * cache - the same cache configuration used in server.cache(). The generateTimeout option is required.
2762 * * generateKey - a function used to generate a unique key (for caching) from the arguments passed to the method function (the flags argument is not passed as input). The server will automatically
2763 * generate a unique key if the function's arguments are all of types 'string', 'number', or 'boolean'. However if the method uses other types of arguments, a key generation function must be provided
2764 * which takes the same arguments as the function and returns a unique string (or null if no key can be generated). For reference [See
2765 * docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodname-method-options)
2766 */
2767export interface ServerMethodOptions {
2768 /**
2769 * a context object passed back to the method function (via this) when called. Defaults to active context (set via server.bind() when the method is registered. Ignored if the method is an arrow
2770 * function.
2771 */
2772 bind?: object | undefined;
2773 /**
2774 * the same cache configuration used in server.cache(). The generateTimeout option is required.
2775 */
2776 cache?: ServerMethodCache | undefined;
2777 /**
2778 * a function used to generate a unique key (for caching) from the arguments passed to the method function (the flags argument is not passed as input). The server will automatically generate a
2779 * unique key if the function's arguments are all of types 'string', 'number', or 'boolean'. However if the method uses other types of arguments, a key generation function must be provided which
2780 * takes the same arguments as the function and returns a unique string (or null if no key can be generated).
2781 */
2782 generateKey?(...args: any[]): string | null;
2783}
2784
2785/**
2786 * An object or an array of objects where each one contains:
2787 * * name - the method name.
2788 * * method - the method function.
2789 * * options - (optional) settings.
2790 * For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodmethods)
2791 */
2792export interface ServerMethodConfigurationObject {
2793 /**
2794 * the method name.
2795 */
2796 name: string;
2797 /**
2798 * the method function.
2799 */
2800 method: ServerMethod;
2801 /**
2802 * (optional) settings.
2803 */
2804 options?: ServerMethodOptions | undefined;
2805}
2806
2807export type CacheProvider<T extends ClientOptions = ClientOptions> = EnginePrototype<any> | {
2808 constructor: EnginePrototype<any>;
2809 options?: T | undefined;
2810};
2811
2812/**
2813 * hapi uses catbox for its cache implementation which includes support for common storage solutions (e.g. Redis,
2814 * MongoDB, Memcached, Riak, among others). Caching is only utilized if methods and plugins explicitly store their state in the cache.
2815 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-cache)
2816 */
2817export interface ServerOptionsCache extends PolicyOptions<any> {
2818 /** catbox engine object. */
2819 engine?: ClientApi<any> | undefined;
2820
2821 /**
2822 * a class or a prototype function
2823 */
2824 provider?: CacheProvider | undefined;
2825
2826 /**
2827 * an identifier used later when provisioning or configuring caching for server methods or plugins. Each cache name must be unique. A single item may omit the name option which defines
2828 * the default cache. If every cache includes a name, a default memory cache is provisioned as well.
2829 */
2830 name?: string | undefined;
2831
2832 /** if true, allows multiple cache users to share the same segment (e.g. multiple methods using the same cache storage container). Default to false. */
2833 shared?: boolean | undefined;
2834
2835 /** (optional) string used to isolate cached data. Defaults to 'hapi-cache'. */
2836 partition?: string | undefined;
2837
2838 /** other options passed to the catbox strategy used. Other options are only passed to catbox when engine above is a class or function and ignored if engine is a catbox engine object). */
2839 [s: string]: any;
2840}
2841
2842export interface ServerOptionsCompression {
2843 minBytes: number;
2844}
2845
2846/**
2847 * Empty interface to allow for custom augmentation.
2848 */
2849/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
2850export interface ServerOptionsApp {
2851}
2852
2853/**
2854 * The server options control the behavior of the server object. Note that the options object is deeply cloned
2855 * (with the exception of listener which is shallowly copied) and should not contain any values that are unsafe to perform deep copy on.
2856 * All options are optionals.
2857 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-server-options)
2858 */
2859export interface ServerOptions {
2860 /**
2861 * Default value: '0.0.0.0' (all available network interfaces).
2862 * Sets the hostname or IP address the server will listen on. If not configured, defaults to host if present, otherwise to all available network interfaces. Set to '127.0.0.1' or 'localhost' to
2863 * restrict the server to only those coming from the same host.
2864 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsaddress)
2865 */
2866 address?: string | undefined;
2867
2868 /**
2869 * Default value: {}.
2870 * Provides application-specific configuration which can later be accessed via server.settings.app. The framework does not interact with this object. It is simply a reference made available
2871 * anywhere a server reference is provided. Note the difference between server.settings.app which is used to store static configuration values and server.app which is meant for storing run-time
2872 * state.
2873 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsapp)
2874 */
2875 app?: ServerOptionsApp | undefined;
2876
2877 /**
2878 * Default value: true.
2879 * Used to disable the automatic initialization of the listener. When false, indicates that the listener will be started manually outside the framework.
2880 * Cannot be set to true along with a port value.
2881 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsautolisten)
2882 */
2883 autoListen?: boolean | undefined;
2884
2885 /**
2886 * Default value: { engine: require('catbox-memory' }.
2887 * Sets up server-side caching providers. Every server includes a default cache for storing application state. By default, a simple memory-based cache is created which has limited capacity and
2888 * capabilities. hapi uses catbox for its cache implementation which includes support for common storage solutions (e.g. Redis, MongoDB, Memcached, Riak, among others). Caching is only utilized
2889 * if methods and plugins explicitly store their state in the cache. The server cache configuration only defines the storage container itself. The configuration can be assigned one or more
2890 * (array):
2891 * * a class or prototype function (usually obtained by calling require() on a catbox strategy such as require('catbox-redis')). A new catbox client will be created internally using this
2892 * function.
2893 * * a configuration object with the following:
2894 * * * engine - a class, a prototype function, or a catbox engine object.
2895 * * * name - an identifier used later when provisioning or configuring caching for server methods or plugins. Each cache name must be unique. A single item may omit the name option which defines
2896 * the default cache. If every cache includes a name, a default memory cache is provisioned as well.
2897 * * * shared - if true, allows multiple cache users to share the same segment (e.g. multiple methods using the same cache storage container). Default to false.
2898 * * * partition - (optional) string used to isolate cached data. Defaults to 'hapi-cache'.
2899 * * * other options passed to the catbox strategy used. Other options are only passed to catbox when engine above is a class or function and ignored if engine is a catbox engine object).
2900 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionscache)
2901 */
2902 cache?: CacheProvider | ServerOptionsCache | ServerOptionsCache[] | undefined;
2903
2904 /**
2905 * Default value: { minBytes: 1024 }.
2906 * Defines server handling of content encoding requests. If false, response content encoding is disabled and no compression is performed by the server.
2907 */
2908 compression?: boolean | ServerOptionsCompression | undefined;
2909
2910 /**
2911 * Default value: { request: ['implementation'] }.
2912 * Determines which logged events are sent to the console. This should only be used for development and does not affect which events are actually logged internally and recorded. Set to false to
2913 * disable all console logging, or to an object with:
2914 * * log - a string array of server log tags to be displayed via console.error() when the events are logged via server.log() as well as internally generated server logs. Defaults to no output.
2915 * * request - a string array of request log tags to be displayed via console.error() when the events are logged via request.log() as well as internally generated request logs. For example, to
2916 * display all errors, set the option to ['error']. To turn off all console debug messages set it to false. To display all request logs, set it to '*'. Defaults to uncaught errors thrown in
2917 * external code (these errors are handled automatically and result in an Internal Server Error response) or runtime errors due to developer error. For example, to display all errors, set the log
2918 * or request to ['error']. To turn off all output set the log or request to false. To display all server logs, set the log or request to '*'. To disable all debug information, set debug to
2919 * false.
2920 */
2921 debug?: false | {
2922 log?: string[] | false | undefined;
2923 request?: string[] | false | undefined;
2924 } | undefined;
2925
2926 /**
2927 * Default value: the operating system hostname and if not available, to 'localhost'.
2928 * The public hostname or IP address. Used to set server.info.host and server.info.uri and as address is none provided.
2929 */
2930 host?: string | undefined;
2931
2932 /**
2933 * Default value: none.
2934 * An optional node HTTP (or HTTPS) http.Server object (or an object with a compatible interface).
2935 * If the listener needs to be manually started, set autoListen to false.
2936 * If the listener uses TLS, set tls to true.
2937 */
2938 listener?: http.Server | undefined;
2939
2940 /**
2941 * Default value: { sampleInterval: 0 }.
2942 * Server excessive load handling limits where:
2943 * * sampleInterval - the frequency of sampling in milliseconds. When set to 0, the other load options are ignored. Defaults to 0 (no sampling).
2944 * * maxHeapUsedBytes - maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit).
2945 * * maxRssBytes - maximum process RSS size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit).
2946 * * maxEventLoopDelay - maximum event loop delay duration in milliseconds over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit).
2947 */
2948 load?: {
2949 /** the frequency of sampling in milliseconds. When set to 0, the other load options are ignored. Defaults to 0 (no sampling). */
2950 sampleInterval?: number | undefined;
2951
2952 /**
2953 * Max concurrent requests.
2954 */
2955 concurrent?: number | undefined;
2956
2957 /** maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit). */
2958 maxHeapUsedBytes?: number | undefined;
2959 /**
2960 * maximum process RSS size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit).
2961 */
2962 maxRssBytes?: number | undefined;
2963 /**
2964 * maximum event loop delay duration in milliseconds over which incoming requests are rejected with an HTTP Server Timeout (503) response.
2965 * Defaults to 0 (no limit).
2966 */
2967 maxEventLoopDelay?: number | undefined;
2968 } | undefined;
2969
2970 /**
2971 * Default value: none.
2972 * Options passed to the mimos module when generating the mime database used by the server (and accessed via server.mime):
2973 * * override - an object hash that is merged into the built in mime information specified here. Each key value pair represents a single mime object. Each override value must contain:
2974 * * key - the lower-cased mime-type string (e.g. 'application/javascript').
2975 * * value - an object following the specifications outlined here. Additional values include:
2976 * * * type - specify the type value of result objects, defaults to key.
2977 * * * predicate - method with signature function(mime) when this mime type is found in the database, this function will execute to allows customizations.
2978 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsmime)
2979 */
2980 mime?: MimosOptions | undefined;
2981
2982 /**
2983 * Default value: {}.
2984 * Plugin-specific configuration which can later be accessed via server.settings.plugins. plugins is an object where each key is a plugin name and the value is the configuration. Note the
2985 * difference between server.settings.plugins which is used to store static configuration values and server.plugins which is meant for storing run-time state.
2986 */
2987 plugins?: PluginSpecificConfiguration | undefined;
2988
2989 /**
2990 * Default value: 0 (an ephemeral port).
2991 * The TCP port the server will listen to. Defaults the next available port when the server is started (and assigned to server.info.port).
2992 * If port is a string containing a '/' character, it is used as a UNIX domain socket path. If it starts with '\.\pipe', it is used as a Windows named pipe.
2993 */
2994 port?: number | string | undefined;
2995
2996 /**
2997 * Default value: { isCaseSensitive: true, stripTrailingSlash: false }.
2998 * Controls how incoming request URIs are matched against the routing table:
2999 * * isCaseSensitive - determines whether the paths '/example' and '/EXAMPLE' are considered different resources. Defaults to true.
3000 * * stripTrailingSlash - removes trailing slashes on incoming paths. Defaults to false.
3001 */
3002 router?: {
3003 isCaseSensitive?: boolean | undefined;
3004 stripTrailingSlash?: boolean | undefined;
3005 } | undefined;
3006
3007 /**
3008 * Default value: none.
3009 * A route options object used as the default configuration for every route.
3010 */
3011 routes?: RouteOptions | undefined;
3012
3013 /**
3014 * Default value:
3015 * {
3016 * strictHeader: true,
3017 * ignoreErrors: false,
3018 * isSecure: true,
3019 * isHttpOnly: true,
3020 * isSameSite: 'Strict',
3021 * encoding: 'none'
3022 * }
3023 * Sets the default configuration for every state (cookie) set explicitly via server.state() or implicitly (without definition) using the state configuration object.
3024 */
3025 // TODO I am not sure if I need to use all the server.state() definition (like the default value) OR only the options below. The v16 use "any" here.
3026 // state?: ServerStateCookieOptions;
3027 state?: {
3028 strictHeader?: boolean | undefined;
3029 ignoreErrors?: boolean | undefined;
3030 isSecure?: boolean | undefined;
3031 isHttpOnly?: boolean | undefined;
3032 isSameSite?: false | "Strict" | "Lax" | undefined;
3033 encoding?: "none" | "base64" | "base64json" | "form" | "iron" | undefined;
3034 } | undefined;
3035
3036 /**
3037 * Default value: none.
3038 * Used to create an HTTPS connection. The tls object is passed unchanged to the node HTTPS server as described in the node HTTPS documentation.
3039 */
3040 tls?: boolean | https.ServerOptions | undefined;
3041
3042 /**
3043 * Default value: constructed from runtime server information.
3044 * The full public URI without the path (e.g. 'http://example.com:8080'). If present, used as the server server.info.uri, otherwise constructed from the server settings.
3045 */
3046 uri?: string | undefined;
3047
3048 /**
3049 * Query parameter configuration.
3050 */
3051 query?: {
3052 /**
3053 * the method must return an object where each key is a parameter and matching value is the parameter value.
3054 * If the method throws, the error is used as the response or returned when `request.setUrl` is called.
3055 */
3056 parser(raw: Util.Dictionary<string>): Util.Dictionary<any>;
3057 } | undefined;
3058}
3059
3060/**
3061 * The realm object contains sandboxed server settings specific to each plugin or authentication strategy. When registering a plugin or an authentication scheme, a server object reference is provided
3062 * with a new server.realm container specific to that registration. It allows each plugin to maintain its own settings without leaking and affecting other plugins. For example, a plugin can set a
3063 * default file path for local resources without breaking other plugins' configured paths. When calling server.bind(), the active realm's settings.bind property is set which is then used by routes
3064 * and extensions added at the same level (server root or plugin).
3065 *
3066 * https://github.com/hapijs/hapi/blob/master/API.md#server.realm
3067 */
3068export interface ServerRealm {
3069 /** when the server object is provided as an argument to the plugin register() method, modifiers provides the registration preferences passed the server.register() method and includes: */
3070 modifiers: {
3071 /** routes preferences: */
3072 route: {
3073 /**
3074 * the route path prefix used by any calls to server.route() from the server. Note that if a prefix is used and the route path is set to '/', the resulting path will not include
3075 * the trailing slash.
3076 */
3077 prefix: string;
3078 /** the route virtual host settings used by any calls to server.route() from the server. */
3079 vhost: string;
3080 };
3081 };
3082 /** the realm of the parent server object, or null for the root server. */
3083 parent: ServerRealm | null;
3084 /** the active plugin name (empty string if at the server root). */
3085 plugin: string;
3086 /** the plugin options object passed at registration. */
3087 pluginOptions: object;
3088 /** plugin-specific state to be shared only among activities sharing the same active state. plugins is an object where each key is a plugin name and the value is the plugin state. */
3089 plugins: PluginsStates;
3090 /** settings overrides */
3091 settings: {
3092 files: {
3093 relativeTo: string;
3094 };
3095 bind: object;
3096 };
3097}
3098
3099/**
3100 * Registration options (different from the options passed to the registration function):
3101 * * once - if true, subsequent registrations of the same plugin are skipped without error. Cannot be used with plugin options. Defaults to false. If not set to true, an error will be thrown the
3102 * second time a plugin is registered on the server.
3103 * * routes - modifiers applied to each route added by the plugin:
3104 * * * prefix - string added as prefix to any route path (must begin with '/'). If a plugin registers a child plugin the prefix is passed on to the child or is added in front of the child-specific
3105 * prefix.
3106 * * * vhost - virtual host string (or array of strings) applied to every route. The outer-most vhost overrides the any nested configuration.
3107 * For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverregisterplugins-options)
3108 */
3109export interface ServerRegisterOptions {
3110 /**
3111 * if true, subsequent registrations of the same plugin are skipped without error. Cannot be used with plugin options. Defaults to false. If not set to true, an error will be thrown the second
3112 * time a plugin is registered on the server.
3113 */
3114 once?: boolean | undefined;
3115 /**
3116 * modifiers applied to each route added by the plugin:
3117 */
3118 routes?: {
3119 /**
3120 * string added as prefix to any route path (must begin with '/'). If a plugin registers a child plugin the prefix is passed on to the child or is added in front of the child-specific prefix.
3121 */
3122 prefix: string;
3123 /**
3124 * virtual host string (or array of strings) applied to every route. The outer-most vhost overrides the any nested configuration.
3125 */
3126 vhost?: string | string[] | undefined;
3127 } | undefined;
3128}
3129
3130/**
3131 * An object with the following:
3132 * * plugin - a plugin object.
3133 * * options - (optional) options passed to the plugin during registration.
3134 * * once - if true, subsequent registrations of the same plugin are skipped without error. Cannot be used with plugin options. Defaults to false. If not set to true, an error will be thrown the
3135 * second time a plugin is registered on the server.
3136 * * routes - modifiers applied to each route added by the plugin:
3137 * * * prefix - string added as prefix to any route path (must begin with '/'). If a plugin registers a child plugin the prefix is passed on to the child or is added in front of the child-specific
3138 * prefix.
3139 * * * vhost - virtual host string (or array of strings) applied to every route. The outer-most vhost overrides the any nested configuration.
3140 * For reference [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverregisterplugins-options)
3141 *
3142 * The type parameter T is the type of the plugin configuration options.
3143 */
3144export interface ServerRegisterPluginObject<T> extends ServerRegisterOptions {
3145 /**
3146 * a plugin object.
3147 */
3148 plugin: Plugin<T>;
3149 /**
3150 * options passed to the plugin during registration.
3151 */
3152 options?: T | undefined;
3153}
3154
3155export interface ServerRegisterPluginObjectArray<T, U, V, W, X, Y, Z> extends
3156 Array<
3157 | ServerRegisterPluginObject<T>
3158 | ServerRegisterPluginObject<U>
3159 | ServerRegisterPluginObject<V>
3160 | ServerRegisterPluginObject<W>
3161 | ServerRegisterPluginObject<X>
3162 | ServerRegisterPluginObject<Y>
3163 | ServerRegisterPluginObject<Z>
3164 | undefined
3165 >
3166{
3167 0: ServerRegisterPluginObject<T>;
3168 1?: ServerRegisterPluginObject<U> | undefined;
3169 2?: ServerRegisterPluginObject<V> | undefined;
3170 3?: ServerRegisterPluginObject<W> | undefined;
3171 4?: ServerRegisterPluginObject<X> | undefined;
3172 5?: ServerRegisterPluginObject<Y> | undefined;
3173 6?: ServerRegisterPluginObject<Z> | undefined;
3174}
3175
3176/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
3177export interface HandlerDecorations {
3178}
3179
3180/**
3181 * A route configuration object or an array of configuration objects where each object contains:
3182 * * path - (required) the absolute path used to match incoming requests (must begin with '/'). Incoming requests are compared to the configured paths based on the server's router configuration. The
3183 * path can include named parameters enclosed in {} which will be matched against literal values in the request as described in Path parameters.
3184 * * method - (required) the HTTP method. Typically one of 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', or 'OPTIONS'. Any HTTP method is allowed, except for 'HEAD'. Use '*' to match against any HTTP
3185 * method (only when an exact match was not found, and any match with a specific method will be given a higher priority over a wildcard match). Can be assigned an array of methods which has the same
3186 * result as adding the same route with different methods manually.
3187 * * vhost - (optional) a domain string or an array of domain strings for limiting the route to only requests with a matching host header field. Matching is done against the hostname part of the
3188 * header only (excluding the port). Defaults to all hosts.
3189 * * handler - (required when handler is not set) the route handler function called to generate the response after successful authentication and validation.
3190 * * options - additional route options. The options value can be an object or a function that returns an object using the signature function(server) where server is the server the route is being
3191 * added to and this is bound to the current realm's bind option.
3192 * * rules - route custom rules object. The object is passed to each rules processor registered with server.rules(). Cannot be used if route.options.rules is defined.
3193 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverrouteroute)
3194 */
3195export interface ServerRoute {
3196 /**
3197 * (required) the absolute path used to match incoming requests (must begin with '/'). Incoming requests are compared to the configured paths based on the server's router configuration. The path
3198 * can include named parameters enclosed in {} which will be matched against literal values in the request as described in Path parameters. For context [See
3199 * docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverrouteroute) For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#path-parameters)
3200 */
3201 path: string;
3202
3203 /**
3204 * (required) the HTTP method. Typically one of 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', or 'OPTIONS'. Any HTTP method is allowed, except for 'HEAD'. Use '*' to match against any HTTP method
3205 * (only when an exact match was not found, and any match with a specific method will be given a higher priority over a wildcard match). Can be assigned an array of methods which has the same
3206 * result as adding the same route with different methods manually.
3207 */
3208 method: Util.HTTP_METHODS_PARTIAL | Util.HTTP_METHODS_PARTIAL[] | string | string[];
3209
3210 /**
3211 * (optional) a domain string or an array of domain strings for limiting the route to only requests with a matching host header field. Matching is done against the hostname part of the header
3212 * only (excluding the port). Defaults to all hosts.
3213 */
3214 vhost?: string | string[] | undefined;
3215
3216 /**
3217 * (required when handler is not set) the route handler function called to generate the response after successful authentication and validation.
3218 */
3219 handler?: Lifecycle.Method | HandlerDecorations | undefined;
3220
3221 /**
3222 * additional route options. The options value can be an object or a function that returns an object using the signature function(server) where server is the server the route is being added to
3223 * and this is bound to the current realm's bind option.
3224 */
3225 options?: RouteOptions | ((server: Server) => RouteOptions) | undefined;
3226
3227 /**
3228 * route custom rules object. The object is passed to each rules processor registered with server.rules(). Cannot be used if route.options.rules is defined.
3229 */
3230 rules?: object | undefined;
3231}
3232
3233/**
3234 * Optional cookie settings
3235 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverstatename-options)
3236 */
3237export interface ServerStateCookieOptions {
3238 /** time-to-live in milliseconds. Defaults to null (session time-life - cookies are deleted when the browser is closed). */
3239 ttl?: number | null | undefined;
3240 /** sets the 'Secure' flag. Defaults to true. */
3241 isSecure?: boolean | undefined;
3242 /** sets the 'HttpOnly' flag. Defaults to true. */
3243 isHttpOnly?: boolean | undefined;
3244 /**
3245 * sets the 'SameSite' flag. The value must be one of:
3246 * * false - no flag.
3247 * * 'Strict' - sets the value to 'Strict' (this is the default value).
3248 * * 'Lax' - sets the value to 'Lax'.
3249 */
3250 isSameSite?: false | "Strict" | "Lax" | undefined;
3251 /** the path scope. Defaults to null (no path). */
3252 path?: string | null | undefined;
3253 /** the domain scope. Defaults to null (no domain). */
3254 domain?: string | null | undefined;
3255
3256 /**
3257 * if present and the cookie was not received from the client or explicitly set by the route handler, the
3258 * cookie is automatically added to the response with the provided value. The value can be
3259 * a function with signature async function(request) where:
3260 */
3261 autoValue?(request: Request): void;
3262
3263 /**
3264 * encoding performs on the provided value before serialization. Options are:
3265 * * 'none' - no encoding. When used, the cookie value must be a string. This is the default value.
3266 * * 'base64' - string value is encoded using Base64.
3267 * * 'base64json' - object value is JSON-stringified then encoded using Base64.
3268 * * 'form' - object value is encoded using the x-www-form-urlencoded method.
3269 * * 'iron' - Encrypts and sign the value using iron.
3270 */
3271 encoding?: "none" | "base64" | "base64json" | "form" | "iron" | undefined;
3272 /**
3273 * an object used to calculate an HMAC for cookie integrity validation. This does not provide privacy, only a mean
3274 * to verify that the cookie value was generated by the server. Redundant when 'iron' encoding is used. Options are:
3275 * * integrity - algorithm options. Defaults to require('iron').defaults.integrity.
3276 * * password - password used for HMAC key generation (must be at least 32 characters long).
3277 */
3278 sign?: {
3279 integrity?: SealOptionsSub | undefined;
3280 password: string;
3281 } | undefined;
3282 /** password used for 'iron' encoding (must be at least 32 characters long). */
3283 password?: string | undefined;
3284 /** options for 'iron' encoding. Defaults to require('iron').defaults. */
3285 iron?: SealOptions | undefined;
3286 /** if true, errors are ignored and treated as missing cookies. */
3287 ignoreErrors?: boolean | undefined;
3288 /** if true, automatically instruct the client to remove invalid cookies. Defaults to false. */
3289 clearInvalid?: boolean | undefined;
3290 /** if false, allows any cookie value including values in violation of RFC 6265. Defaults to true. */
3291 strictHeader?: boolean | undefined;
3292 /** used by proxy plugins (e.g. h2o2). */
3293 passThrough?: any;
3294}
3295
3296/**
3297 * A single object or an array of object where each contains:
3298 * * name - the cookie name.
3299 * * value - the cookie value.
3300 * * options - cookie configuration to override the server settings.
3301 */
3302export interface ServerStateFormat {
3303 name: string;
3304 value: string;
3305 options: ServerStateCookieOptions;
3306}
3307
3308/**
3309 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverstatename-options)
3310 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptionsstate)
3311 */
3312export interface ServerState {
3313 /**
3314 * The server cookies manager.
3315 * Access: read only and statehood public interface.
3316 */
3317 readonly states: object;
3318
3319 /**
3320 * The server cookies manager settings. The settings are based on the values configured in [server.options.state](https://github.com/hapijs/hapi/blob/master/API.md#server.options.state).
3321 */
3322 readonly settings: ServerStateCookieOptions;
3323
3324 /**
3325 * An object containing the configuration of each cookie added via [server.state()](https://github.com/hapijs/hapi/blob/master/API.md#server.state()) where each key is the
3326 * cookie name and value is the configuration object.
3327 */
3328 readonly cookies: {
3329 [key: string]: ServerStateCookieOptions;
3330 };
3331
3332 /**
3333 * An array containing the names of all configued cookies.
3334 */
3335 readonly names: string[];
3336
3337 /**
3338 * Same as calling [server.state()](https://github.com/hapijs/hapi/blob/master/API.md#server.state()).
3339 */
3340 add(name: string, options?: ServerStateCookieOptions): void;
3341
3342 /**
3343 * Formats an HTTP 'Set-Cookie' header based on the server.options.state where:
3344 * @param cookies - a single object or an array of object where each contains:
3345 * * name - the cookie name.
3346 * * value - the cookie value.
3347 * * options - cookie configuration to override the server settings.
3348 * @return Return value: a header string.
3349 * Note that this utility uses the server configuration but does not change the server state. It is provided for manual cookie formating (e.g. when headers are set manually).
3350 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-async-serverstatesformatcookies)
3351 */
3352 format(cookies: ServerStateFormat | ServerStateFormat[]): Promise<string>;
3353
3354 /**
3355 * Parses an HTTP 'Cookies' header based on the server.options.state where:
3356 * @param header - the HTTP header.
3357 * @return Return value: an object where each key is a cookie name and value is the parsed cookie.
3358 * Note that this utility uses the server configuration but does not change the server state. It is provided for manual cookie parsing (e.g. when server parsing is disabled).
3359 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-async-serverstatesparseheader)
3360 */
3361 parse(header: string): Promise<Util.Dictionary<string>>;
3362}
3363
3364/**
3365 * The method function can have a defaults object or function property. If the property is set to an object, that object is used as the default route config for routes using this handler.
3366 * If the property is set to a function, the function uses the signature function(method) and returns the route default configuration.
3367 */
3368export interface HandlerDecorationMethod {
3369 (route: RouteOptions, options: any): Lifecycle.Method;
3370 defaults?: RouteOptions | ((method: any) => RouteOptions) | undefined;
3371}
3372
3373/**
3374 * The general case for decorators added via server.decorate.
3375 */
3376export type DecorationMethod<T> = (this: T, ...args: any[]) => any;
3377
3378/**
3379 * An empty interface to allow typings of custom plugin properties.
3380 */
3381/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
3382export interface PluginProperties {
3383}
3384
3385export interface ServerMethods extends Util.Dictionary<ServerMethod> {
3386}
3387
3388export type DecorateName = string | symbol;
3389
3390/**
3391 * The server object is the main application container. The server manages all incoming requests along with all
3392 * the facilities provided by the framework. Each server supports a single connection (e.g. listen to port 80).
3393 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#server)
3394 */
3395export class Server {
3396 /**
3397 * Creates a new server object
3398 * @param options server configuration object.
3399 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serveroptions)
3400 */
3401 constructor(options?: ServerOptions);
3402
3403 /**
3404 * Provides a safe place to store server-specific run-time application data without potential conflicts with
3405 * the framework internals. The data can be accessed whenever the server is accessible.
3406 * Initialized with an empty object.
3407 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverapp)
3408 */
3409 app: ApplicationState;
3410
3411 /**
3412 * Server Auth: properties and methods
3413 */
3414 readonly auth: ServerAuth;
3415
3416 /**
3417 * Links another server to the initialize/start/stop state of the current server by calling the
3418 * controlled server `initialize()`/`start()`/`stop()` methods whenever the current server methods
3419 * are called, where:
3420 */
3421 control(server: Server): void;
3422
3423 /**
3424 * Provides access to the decorations already applied to various framework interfaces. The object must not be
3425 * modified directly, but only through server.decorate.
3426 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverdecorations)
3427 */
3428 readonly decorations: {
3429 /**
3430 * decorations on the request object.
3431 */
3432 request: string[];
3433 /**
3434 * decorations on the response toolkit.
3435 */
3436 toolkit: string[];
3437 /**
3438 * decorations on the server object.
3439 */
3440 server: string[];
3441 };
3442
3443 /**
3444 * Register custom application events where:
3445 * @param events must be one of:
3446 * * an event name string.
3447 * * an event options object with the following optional keys (unless noted otherwise):
3448 * * * name - the event name string (required).
3449 * * * channels - a string or array of strings specifying the event channels available. Defaults to no channel restrictions (event updates can specify a channel or not).
3450 * * * clone - if true, the data object passed to server.events.emit() is cloned before it is passed to the listeners (unless an override specified by each listener). Defaults to false (data is
3451 * passed as-is).
3452 * * * spread - if true, the data object passed to server.event.emit() must be an array and the listener method is called with each array element passed as a separate argument (unless an override
3453 * specified by each listener). This should only be used when the emitted data structure is known and predictable. Defaults to false (data is emitted as a single argument regardless of its
3454 * type).
3455 * * * tags - if true and the criteria object passed to server.event.emit() includes tags, the tags are mapped to an object (where each tag string is the key and the value is true) which is
3456 * appended to the arguments list at the end. A configuration override can be set by each listener. Defaults to false.
3457 * * * shared - if true, the same event name can be registered multiple times where the second registration is ignored. Note that if the registration config is changed between registrations, only
3458 * the first configuration is used. Defaults to false (a duplicate registration will throw an error).
3459 * * a podium emitter object.
3460 * * an array containing any of the above.
3461 * @return Return value: none.
3462 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
3463 */
3464 event(events: ServerEventsApplication | ServerEventsApplication[]): void;
3465
3466 /**
3467 * Access: podium public interface.
3468 * The server events emitter. Utilizes the podium with support for event criteria validation, channels, and filters.
3469 * Use the following methods to interact with server.events:
3470 * [server.events.emit(criteria, data)](https://github.com/hapijs/hapi/blob/master/API.md#server.events.emit()) - emit server events.
3471 * [server.events.on(criteria, listener)](https://github.com/hapijs/hapi/blob/master/API.md#server.events.on()) - subscribe to all events.
3472 * [server.events.once(criteria, listener)](https://github.com/hapijs/hapi/blob/master/API.md#server.events.once()) - subscribe to
3473 * Other methods include: server.events.removeListener(name, listener), server.events.removeAllListeners(name), and server.events.hasListeners(name).
3474 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverevents)
3475 */
3476 events: ServerEvents;
3477
3478 /**
3479 * An object containing information about the server where:
3480 * * id - a unique server identifier (using the format '{hostname}:{pid}:{now base36}').
3481 * * created - server creation timestamp.
3482 * * started - server start timestamp (0 when stopped).
3483 * * port - the connection port based on the following rules:
3484 * * host - The host configuration value.
3485 * * address - the active IP address the connection was bound to after starting. Set to undefined until the server has been started or when using a non TCP port (e.g. UNIX domain socket).
3486 * * protocol - the protocol used:
3487 * * 'http' - HTTP.
3488 * * 'https' - HTTPS.
3489 * * 'socket' - UNIX domain socket or Windows named pipe.
3490 * * uri - a string representing the connection (e.g. 'http://example.com:8080' or 'socket:/unix/domain/socket/path'). Contains the uri value if set, otherwise constructed from the available
3491 * settings. If no port is configured or is set to 0, the uri will not include a port component until the server is started.
3492 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverinfo)
3493 */
3494 readonly info: ServerInfo;
3495
3496 /**
3497 * Access: read only and listener public interface.
3498 * The node HTTP server object.
3499 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverlistener)
3500 */
3501 listener: http.Server;
3502
3503 /**
3504 * An object containing the process load metrics (when load.sampleInterval is enabled):
3505 * * eventLoopDelay - event loop delay milliseconds.
3506 * * heapUsed - V8 heap usage.
3507 * * rss - RSS memory usage.
3508 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverload)
3509 */
3510 readonly load: {
3511 /**
3512 * event loop delay milliseconds.
3513 */
3514 eventLoopDelay: number;
3515
3516 /**
3517 * Max concurrent requests.
3518 */
3519 concurrent: number;
3520 /**
3521 * V8 heap usage.
3522 */
3523 heapUsed: number;
3524 /**
3525 * RSS memory usage.
3526 */
3527 rss: number;
3528 };
3529
3530 /**
3531 * Server methods are functions registered with the server and used throughout the application as a common utility.
3532 * Their advantage is in the ability to configure them to use the built-in cache and share across multiple request
3533 * handlers without having to create a common module.
3534 * sever.methods is an object which provides access to the methods registered via server.method() where each
3535 * server method name is an object property.
3536 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethods
3537 */
3538 readonly methods: ServerMethods;
3539
3540 /**
3541 * Provides access to the server MIME database used for setting content-type information. The object must not be
3542 * modified directly but only through the [mime](https://github.com/hapijs/hapi/blob/master/API.md#server.options.mime) server setting.
3543 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermime)
3544 */
3545 mime: any;
3546
3547 /**
3548 * An object containing the values exposed by each registered plugin where each key is a plugin name and the values
3549 * are the exposed properties by each plugin using server.expose(). Plugins may set the value of
3550 * the server.plugins[name] object directly or via the server.expose() method.
3551 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverplugins)
3552 */
3553 plugins: PluginProperties;
3554
3555 /**
3556 * The realm object contains sandboxed server settings specific to each plugin or authentication strategy. When
3557 * registering a plugin or an authentication scheme, a server object reference is provided with a new server.realm
3558 * container specific to that registration. It allows each plugin to maintain its own settings without leaking
3559 * and affecting other plugins.
3560 * For example, a plugin can set a default file path for local resources without breaking other plugins' configured
3561 * paths. When calling server.bind(), the active realm's settings.bind property is set which is then used by
3562 * routes and extensions added at the same level (server root or plugin).
3563 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverrealm)
3564 */
3565 readonly realm: ServerRealm;
3566
3567 /**
3568 * An object of the currently registered plugins where each key is a registered plugin name and the value is
3569 * an object containing:
3570 * * version - the plugin version.
3571 * * name - the plugin name.
3572 * * options - (optional) options passed to the plugin during registration.
3573 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverregistrations)
3574 */
3575 readonly registrations: PluginsListRegistered;
3576
3577 /**
3578 * The server configuration object after defaults applied.
3579 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serversettings)
3580 */
3581 readonly settings: ServerOptions;
3582
3583 /**
3584 * The server cookies manager.
3585 * Access: read only and statehood public interface.
3586 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverstates)
3587 */
3588 readonly states: ServerState;
3589
3590 /**
3591 * A string indicating the listener type where:
3592 * * 'socket' - UNIX domain socket or Windows named pipe.
3593 * * 'tcp' - an HTTP listener.
3594 */
3595 readonly type: "socket" | "tcp";
3596
3597 /**
3598 * The hapi module version number.
3599 */
3600 readonly version: string;
3601
3602 /**
3603 * Sets a global context used as the default bind object when adding a route or an extension where:
3604 * @param context - the object used to bind this in lifecycle methods such as the route handler and extension methods. The context is also made available as h.context.
3605 * @return Return value: none.
3606 * When setting a context inside a plugin, the context is applied only to methods set up by the plugin. Note that the context applies only to routes and extensions added after it has been set.
3607 * Ignored if the method being bound is an arrow function.
3608 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverbindcontext)
3609 */
3610 bind(context: object): void;
3611
3612 /**
3613 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servercacheoptions)
3614 */
3615 cache: ServerCache;
3616
3617 /**
3618 * Registers a custom content decoding compressor to extend the built-in support for 'gzip' and 'deflate' where:
3619 * @param encoding - the decoder name string.
3620 * @param decoder - a function using the signature function(options) where options are the encoding specific options configured in the route payload.compression configuration option, and the
3621 * return value is an object compatible with the output of node's zlib.createGunzip().
3622 * @return Return value: none.
3623 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverdecoderencoding-decoder)
3624 */
3625 decoder(encoding: string, decoder: (options: PayloadCompressionDecoderSettings) => zlib.Gunzip): void;
3626
3627 /**
3628 * Extends various framework interfaces with custom methods where:
3629 * @param type - the interface being decorated. Supported types:
3630 * 'handler' - adds a new handler type to be used in routes handlers.
3631 * 'request' - adds methods to the Request object.
3632 * 'server' - adds methods to the Server object.
3633 * 'toolkit' - adds methods to the response toolkit.
3634 * @param property - the object decoration key name.
3635 * @param method - the extension function or other value.
3636 * @param options - (optional) supports the following optional settings:
3637 * apply - when the type is 'request', if true, the method function is invoked using the signature function(request) where request is the current request object and the returned value is assigned
3638 * as the decoration. extend - if true, overrides an existing decoration. The method must be a function with the signature function(existing) where: existing - is the previously set
3639 * decoration method value. must return the new decoration function or value. cannot be used to extend handler decorations.
3640 * @return void;
3641 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverdecoratetype-property-method-options)
3642 */
3643 decorate(
3644 type: "handler",
3645 property: DecorateName,
3646 method: HandlerDecorationMethod,
3647 options?: { apply?: boolean | undefined; extend?: boolean | undefined },
3648 ): void;
3649 decorate(
3650 type: "request",
3651 property: DecorateName,
3652 method: (existing: (...args: any[]) => any) => (request: Request) => DecorationMethod<Request>,
3653 options: { apply: true; extend: true },
3654 ): void;
3655 decorate(
3656 type: "request",
3657 property: DecorateName,
3658 method: (request: Request) => DecorationMethod<Request>,
3659 options: { apply: true; extend?: boolean | undefined },
3660 ): void;
3661 decorate(
3662 type: "request",
3663 property: DecorateName,
3664 method: DecorationMethod<Request>,
3665 options?: { apply?: boolean | undefined; extend?: boolean | undefined },
3666 ): void;
3667 decorate(
3668 type: "toolkit",
3669 property: DecorateName,
3670 method: (existing: (...args: any[]) => any) => DecorationMethod<ResponseToolkit>,
3671 options: { apply?: boolean | undefined; extend: true },
3672 ): void;
3673 decorate(
3674 type: "toolkit",
3675 property: DecorateName,
3676 method: DecorationMethod<ResponseToolkit>,
3677 options?: { apply?: boolean | undefined; extend?: boolean | undefined },
3678 ): void;
3679 decorate(
3680 type: "server",
3681 property: DecorateName,
3682 method: (existing: (...args: any[]) => any) => DecorationMethod<Server>,
3683 options: { apply?: boolean | undefined; extend: true },
3684 ): void;
3685 decorate(
3686 type: "server",
3687 property: DecorateName,
3688 method: DecorationMethod<Server>,
3689 options?: { apply?: boolean | undefined; extend?: boolean | undefined },
3690 ): void;
3691
3692 /**
3693 * Used within a plugin to declare a required dependency on other plugins where:
3694 * @param dependencies - plugins which must be registered in order for this plugin to operate. Plugins listed must be registered before the server is
3695 * initialized or started.
3696 * @param after - (optional) a function that is called after all the specified dependencies have been registered and before the server starts. The function is only called if the server is
3697 * initialized or started. The function signature is async function(server) where: server - the server the dependency() method was called on.
3698 * @return Return value: none.
3699 * The after method is identical to setting a server extension point on 'onPreStart'.
3700 * If a circular dependency is detected, an exception is thrown (e.g. two plugins each has an after function to be called after the other).
3701 * The method does not provide version dependency which should be implemented using npm peer dependencies.
3702 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverdependencydependencies-after)
3703 */
3704 dependency(dependencies: Dependencies, after?: (server: Server) => Promise<void>): void;
3705
3706 /**
3707 * Registers a custom content encoding compressor to extend the built-in support for 'gzip' and 'deflate' where:
3708 * @param encoding - the encoder name string.
3709 * @param encoder - a function using the signature function(options) where options are the encoding specific options configured in the route compression option, and the return value is an object
3710 * compatible with the output of node's zlib.createGzip().
3711 * @return Return value: none.
3712 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverencoderencoding-encoder)
3713 */
3714 encoder(encoding: string, encoder: (options: RouteCompressionEncoderSettings) => zlib.Gzip): void;
3715
3716 /**
3717 * Used within a plugin to expose a property via server.plugins[name] where:
3718 * @param key - the key assigned (server.plugins[name][key]).
3719 * @param value - the value assigned.
3720 * @return Return value: none.
3721 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverexposekey-value)
3722 */
3723 expose(key: string, value: any): void;
3724
3725 /**
3726 * Merges an object into to the existing content of server.plugins[name] where:
3727 * @param obj - the object merged into the exposed properties container.
3728 * @return Return value: none.
3729 * Note that all the properties of obj are deeply cloned into server.plugins[name], so avoid using this method
3730 * for exposing large objects that may be expensive to clone or singleton objects such as database client
3731 * objects. Instead favor server.expose(key, value), which only copies a reference to value.
3732 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverexposeobj)
3733 */
3734 expose(obj: object): void;
3735
3736 /**
3737 * Registers an extension function in one of the request lifecycle extension points where:
3738 * @param events - an object or array of objects with the following:
3739 * * type - (required) the extension point event name. The available extension points include the request extension points as well as the following server extension points:
3740 * * * 'onPreStart' - called before the connection listeners are started.
3741 * * * 'onPostStart' - called after the connection listeners are started.
3742 * * * 'onPreStop' - called before the connection listeners are stopped.
3743 * * * 'onPostStop' - called after the connection listeners are stopped.
3744 * * method - (required) a function or an array of functions to be executed at a specified point during request processing. The required extension function signature is:
3745 * * * server extension points: async function(server) where:
3746 * * * * server - the server object.
3747 * * * * this - the object provided via options.bind or the current active context set with server.bind().
3748 * * * request extension points: a lifecycle method.
3749 * * options - (optional) an object with the following:
3750 * * * before - a string or array of strings of plugin names this method must execute before (on the same event). Otherwise, extension methods are executed in the order added.
3751 * * * after - a string or array of strings of plugin names this method must execute after (on the same event). Otherwise, extension methods are executed in the order added.
3752 * * * bind - a context object passed back to the provided method (via this) when called. Ignored if the method is an arrow function.
3753 * * * sandbox - if set to 'plugin' when adding a request extension points the extension is only added to routes defined by the current plugin. Not allowed when configuring route-level
3754 * extensions, or when adding server extensions. Defaults to 'server' which applies to any route added to the server the extension is added to.
3755 * @return void
3756 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevents)
3757 */
3758 ext(
3759 events:
3760 | ServerExtEventsObject
3761 | ServerExtEventsObject[]
3762 | ServerExtEventsRequestObject
3763 | ServerExtEventsRequestObject[],
3764 ): void;
3765
3766 /**
3767 * Registers a single extension event using the same properties as used in server.ext(events), but passed as arguments.
3768 * @return Return value: none.
3769 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverextevent-method-options)
3770 */
3771 ext(event: ServerExtType, method: ServerExtPointFunction, options?: ServerExtOptions): void;
3772 ext(event: ServerRequestExtType, method: Lifecycle.Method, options?: ServerExtOptions): void;
3773
3774 /**
3775 * Initializes the server (starts the caches, finalizes plugin registration) but does not start listening on the connection port.
3776 * @return Return value: none.
3777 * Note that if the method fails and throws an error, the server is considered to be in an undefined state and
3778 * should be shut down. In most cases it would be impossible to fully recover as the various plugins, caches, and
3779 * other event listeners will get confused by repeated attempts to start the server or make assumptions about the
3780 * healthy state of the environment. It is recommended to abort the process when the server fails to start properly.
3781 * If you must try to resume after an error, call server.stop() first to reset the server state.
3782 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverinitialize)
3783 */
3784 initialize(): Promise<void>;
3785
3786 /**
3787 * Injects a request into the server simulating an incoming HTTP request without making an actual socket connection. Injection is useful for testing purposes as well as for invoking routing logic
3788 * internally without the overhead and limitations of the network stack. The method utilizes the shot module for performing injections, with some additional options and response properties:
3789 * @param options - can be assigned a string with the requested URI, or an object with:
3790 * * method - (optional) the request HTTP method (e.g. 'POST'). Defaults to 'GET'.
3791 * * url - (required) the request URL. If the URI includes an authority (e.g. 'example.com:8080'), it is used to automatically set an HTTP 'Host' header, unless one was specified in headers.
3792 * * headers - (optional) an object with optional request headers where each key is the header name and the value is the header content. Defaults to no additions to the default shot headers.
3793 * * payload - (optional) an string, buffer or object containing the request payload. In case of an object it will be converted to a string for you. Defaults to no payload. Note that payload
3794 * processing defaults to 'application/json' if no 'Content-Type' header provided.
3795 * * credentials - (optional) an credentials object containing authentication information. The credentials are used to bypass the default authentication strategies, and are validated directly as
3796 * if they were received via an authentication scheme. Defaults to no credentials.
3797 * * artifacts - (optional) an artifacts object containing authentication artifact information. The artifacts are used to bypass the default authentication strategies, and are validated directly
3798 * as if they were received via an authentication scheme. Ignored if set without credentials. Defaults to no artifacts.
3799 * * app - (optional) sets the initial value of request.app, defaults to {}.
3800 * * plugins - (optional) sets the initial value of request.plugins, defaults to {}.
3801 * * allowInternals - (optional) allows access to routes with config.isInternal set to true. Defaults to false.
3802 * * remoteAddress - (optional) sets the remote address for the incoming connection.
3803 * * simulate - (optional) an object with options used to simulate client request stream conditions for testing:
3804 * * error - if true, emits an 'error' event after payload transmission (if any). Defaults to false.
3805 * * close - if true, emits a 'close' event after payload transmission (if any). Defaults to false.
3806 * * end - if false, does not end the stream. Defaults to true.
3807 * * split - indicates whether the request payload will be split into chunks. Defaults to undefined, meaning payload will not be chunked.
3808 * * validate - (optional) if false, the options inputs are not validated. This is recommended for run-time usage of inject() to make it perform faster where input validation can be tested
3809 * separately.
3810 * @return Return value: a response object with the following properties:
3811 * * statusCode - the HTTP status code.
3812 * * headers - an object containing the headers set.
3813 * * payload - the response payload string.
3814 * * rawPayload - the raw response payload buffer.
3815 * * raw - an object with the injection request and response objects:
3816 * * req - the simulated node request object.
3817 * * res - the simulated node response object.
3818 * * result - the raw handler response (e.g. when not a stream or a view) before it is serialized for transmission. If not available, the value is set to payload. Useful for inspection and reuse
3819 * of the internal objects returned (instead of parsing the response string).
3820 * * request - the request object.
3821 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverinjectoptions)
3822 */
3823 inject(options: string | ServerInjectOptions): Promise<ServerInjectResponse>;
3824
3825 /**
3826 * Logs server events that cannot be associated with a specific request. When called the server emits a 'log' event which can be used by other listeners or plugins to record the information or
3827 * output to the console. The arguments are:
3828 * @param tags - (required) a string or an array of strings (e.g. ['error', 'database', 'read']) used to identify the event. Tags are used instead of log levels and provide a much more expressive
3829 * mechanism for describing and filtering events. Any logs generated by the server internally include the 'hapi' tag along with event-specific information.
3830 * @param data - (optional) an message string or object with the application data being logged. If data is a function, the function signature is function() and it called once to generate (return
3831 * value) the actual data emitted to the listeners. If no listeners match the event, the data function is not invoked.
3832 * @param timestamp - (optional) an timestamp expressed in milliseconds. Defaults to Date.now() (now).
3833 * @return Return value: none.
3834 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverlogtags-data-timestamp)
3835 */
3836 log(tags: string | string[], data?: string | object | (() => any), timestamp?: number): void;
3837
3838 /**
3839 * Looks up a route configuration where:
3840 * @param id - the route identifier.
3841 * @return Return value: the route information if found, otherwise null.
3842 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverlookupid)
3843 */
3844 lookup(id: string): RequestRoute | null;
3845
3846 /**
3847 * Looks up a route configuration where:
3848 * @param method - the HTTP method (e.g. 'GET', 'POST').
3849 * @param path - the requested path (must begin with '/').
3850 * @param host - (optional) hostname (to match against routes with vhost).
3851 * @return Return value: the route information if found, otherwise null.
3852 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermatchmethod-path-host)
3853 */
3854 match(method: Util.HTTP_METHODS, path: string, host?: string): RequestRoute | null;
3855
3856 /**
3857 * Registers a server method where:
3858 * @param name - a unique method name used to invoke the method via server.methods[name].
3859 * @param method - the method function with a signature async function(...args, [flags]) where:
3860 * * ...args - the method function arguments (can be any number of arguments or none).
3861 * * flags - when caching is enabled, an object used to set optional method result flags:
3862 * * * ttl - 0 if result is valid but cannot be cached. Defaults to cache policy.
3863 * @param options - (optional) configuration object:
3864 * * bind - a context object passed back to the method function (via this) when called. Defaults to active context (set via server.bind() when the method is registered. Ignored if the method is
3865 * an arrow function.
3866 * * cache - the same cache configuration used in server.cache(). The generateTimeout option is required.
3867 * * generateKey - a function used to generate a unique key (for caching) from the arguments passed to the method function (the flags argument is not passed as input). The server will
3868 * automatically generate a unique key if the function's arguments are all of types 'string', 'number', or 'boolean'. However if the method uses other types of arguments, a key generation
3869 * function must be provided which takes the same arguments as the function and returns a unique string (or null if no key can be generated).
3870 * @return Return value: none.
3871 * Method names can be nested (e.g. utils.users.get) which will automatically create the full path under server.methods (e.g. accessed via server.methods.utils.users.get).
3872 * When configured with caching enabled, server.methods[name].cache is assigned an object with the following properties and methods: - await drop(...args) - a function that can be used to clear
3873 * the cache for a given key. - stats - an object with cache statistics, see catbox for stats documentation.
3874 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodname-method-options)
3875 */
3876 method(name: string, method: ServerMethod, options?: ServerMethodOptions): void;
3877
3878 /**
3879 * Registers a server method function as described in server.method() using a configuration object where:
3880 * @param methods - an object or an array of objects where each one contains:
3881 * * name - the method name.
3882 * * method - the method function.
3883 * * options - (optional) settings.
3884 * @return Return value: none.
3885 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermethodmethods)
3886 */
3887 method(methods: ServerMethodConfigurationObject | ServerMethodConfigurationObject[]): void;
3888
3889 /**
3890 * Sets the path prefix used to locate static resources (files and view templates) when relative paths are used where:
3891 * @param relativeTo - the path prefix added to any relative file path starting with '.'.
3892 * @return Return value: none.
3893 * Note that setting a path within a plugin only applies to resources accessed by plugin methods. If no path is set, the server default route configuration files.relativeTo settings is used. The
3894 * path only applies to routes added after it has been set.
3895 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverpathrelativeto)
3896 */
3897 path(relativeTo: string): void;
3898
3899 /**
3900 * Registers a plugin where:
3901 * @param plugins - one or an array of:
3902 * * a plugin object.
3903 * * an object with the following:
3904 * * * plugin - a plugin object.
3905 * * * options - (optional) options passed to the plugin during registration.
3906 * * * once, routes - (optional) plugin-specific registration options as defined below.
3907 * @param options - (optional) registration options (different from the options passed to the registration function):
3908 * * once - if true, subsequent registrations of the same plugin are skipped without error. Cannot be used with plugin options. Defaults to false. If not set to true, an error will be thrown the
3909 * second time a plugin is registered on the server.
3910 * * routes - modifiers applied to each route added by the plugin:
3911 * * * prefix - string added as prefix to any route path (must begin with '/'). If a plugin registers a child plugin the prefix is passed on to the child or is added in front of the
3912 * child-specific prefix.
3913 * * * vhost - virtual host string (or array of strings) applied to every route. The outer-most vhost overrides the any nested configuration.
3914 * @return Return value: none.
3915 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverregisterplugins-options)
3916 */
3917 /* eslint-disable-next-line @definitelytyped/no-unnecessary-generics */
3918 register<T>(plugin: ServerRegisterPluginObject<T>, options?: ServerRegisterOptions): Promise<void>;
3919 /* eslint-disable-next-line @definitelytyped/no-unnecessary-generics */
3920 register<T, U, V, W, X, Y, Z>(
3921 plugins: ServerRegisterPluginObjectArray<T, U, V, W, X, Y, Z>,
3922 options?: ServerRegisterOptions,
3923 ): Promise<void>;
3924 register(plugins: Array<ServerRegisterPluginObject<any>>, options?: ServerRegisterOptions): Promise<void>;
3925 /* tslint:disable-next-line:unified-signatures */
3926 register(plugins: Plugin<any> | Array<Plugin<any>>, options?: ServerRegisterOptions): Promise<void>;
3927
3928 /**
3929 * Adds a route where:
3930 * @param route - a route configuration object or an array of configuration objects where each object contains:
3931 * * path - (required) the absolute path used to match incoming requests (must begin with '/'). Incoming requests are compared to the configured paths based on the server's router configuration.
3932 * The path can include named parameters enclosed in {} which will be matched against literal values in the request as described in Path parameters.
3933 * * method - (required) the HTTP method. Typically one of 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', or 'OPTIONS'. Any HTTP method is allowed, except for 'HEAD'. Use '*' to match against any HTTP
3934 * method (only when an exact match was not found, and any match with a specific method will be given a higher priority over a wildcard match). Can be assigned an array of methods which has
3935 * the same result as adding the same route with different methods manually.
3936 * * vhost - (optional) a domain string or an array of domain strings for limiting the route to only requests with a matching host header field. Matching is done against the hostname part of the
3937 * header only (excluding the port). Defaults to all hosts.
3938 * * handler - (required when handler is not set) the route handler function called to generate the response after successful authentication and validation.
3939 * * options - additional route options. The options value can be an object or a function that returns an object using the signature function(server) where server is the server the route is being
3940 * added to and this is bound to the current realm's bind option.
3941 * * rules - route custom rules object. The object is passed to each rules processor registered with server.rules(). Cannot be used if route.options.rules is defined.
3942 * @return Return value: none.
3943 * Note that the options object is deeply cloned (with the exception of bind which is shallowly copied) and cannot contain any values that are unsafe to perform deep copy on.
3944 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverrouteroute)
3945 */
3946 route(route: ServerRoute | ServerRoute[]): void;
3947
3948 /**
3949 * Defines a route rules processor for converting route rules object into route configuration where:
3950 * @param processor - a function using the signature function(rules, info) where:
3951 * * rules -
3952 * * info - an object with the following properties:
3953 * * * method - the route method.
3954 * * * path - the route path.
3955 * * * vhost - the route virtual host (if any defined).
3956 * * returns a route config object.
3957 * @param options - optional settings:
3958 * * validate - rules object validation:
3959 * * * schema - joi schema.
3960 * * * options - optional joi validation options. Defaults to { allowUnknown: true }.
3961 * Note that the root server and each plugin server instance can only register one rules processor. If a route is added after the rules are configured, it will not include the rules config.
3962 * Routes added by plugins apply the rules to each of the parent realms' rules from the root to the route's realm. This means the processor defined by the plugin override the config generated
3963 * by the root processor if they overlap. The route config overrides the rules config if the overlap.
3964 * @return void
3965 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverrulesprocessor-options)
3966 */
3967 rules(
3968 processor: (rules: object, info: { method: string; path: string; vhost?: string | undefined }) => object,
3969 options?: { validate: object },
3970 ): void; // TODO needs implementation
3971
3972 /**
3973 * Starts the server by listening for incoming requests on the configured port (unless the connection was configured with autoListen set to false).
3974 * @return Return value: none.
3975 * Note that if the method fails and throws an error, the server is considered to be in an undefined state and should be shut down. In most cases it would be impossible to fully recover as the
3976 * various plugins, caches, and other event listeners will get confused by repeated attempts to start the server or make assumptions about the healthy state of the environment. It is
3977 * recommended to abort the process when the server fails to start properly. If you must try to resume after an error, call server.stop() first to reset the server state. If a started server
3978 * is started again, the second call to server.start() is ignored. No events will be emitted and no extension points invoked.
3979 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverstart)
3980 */
3981 start(): Promise<void>;
3982
3983 /**
3984 * HTTP state management uses client cookies to persist a state across multiple requests.
3985 * @param name - the cookie name string.
3986 * @param options - are the optional cookie settings
3987 * @return Return value: none.
3988 * State defaults can be modified via the server default state configuration option.
3989 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverstatename-options)
3990 */
3991 state(name: string, options?: ServerStateCookieOptions): void;
3992
3993 /**
3994 * Stops the server's listener by refusing to accept any new connections or requests (existing connections will continue until closed or timeout), where:
3995 * @param options - (optional) object with:
3996 * * timeout - overrides the timeout in millisecond before forcefully terminating a connection. Defaults to 5000 (5 seconds).
3997 * @return Return value: none.
3998 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-await-serverstopoptions)
3999 */
4000 stop(options?: { timeout: number }): Promise<void>;
4001
4002 /**
4003 * Returns a copy of the routing table where:
4004 * @param host - (optional) host to filter routes matching a specific virtual host. Defaults to all virtual hosts.
4005 * @return Return value: an array of routes where each route contains:
4006 * * settings - the route config with defaults applied.
4007 * * method - the HTTP method in lower case.
4008 * * path - the route path.
4009 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servertablehost)
4010 */
4011 table(host?: string): RequestRoute[];
4012}
4013
4014/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
4015 + +
4016 + +
4017 + +
4018 + Utils +
4019 + +
4020 + +
4021 + +
4022 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
4023
4024/**
4025 * User-extensible type for application specific state.
4026 */
4027/* eslint-disable-next-line @typescript-eslint/no-empty-interface */
4028export interface ApplicationState {
4029}
4030
4031export type PeekListener = (chunk: string, encoding: string) => void;
4032
4033export namespace Json {
4034 /**
4035 * @see {@link https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter}
4036 */
4037 type StringifyReplacer = ((key: string, value: any) => any) | Array<(string | number)> | undefined;
4038
4039 /**
4040 * Any value greater than 10 is truncated.
4041 */
4042 type StringifySpace = number | string;
4043
4044 /**
4045 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsjson)
4046 */
4047 interface StringifyArguments {
4048 /** the replacer function or array. Defaults to no action. */
4049 replacer?: StringifyReplacer | undefined;
4050 /** number of spaces to indent nested object keys. Defaults to no indentation. */
4051 space?: StringifySpace | undefined;
4052 /* string suffix added after conversion to JSON string. Defaults to no suffix. */
4053 suffix?: string | undefined;
4054 /* calls Hoek.jsonEscape() after conversion to JSON string. Defaults to false. */
4055 escape?: boolean | undefined;
4056 }
4057}
4058
4059export namespace Lifecycle {
4060 /**
4061 * Lifecycle methods are the interface between the framework and the application. Many of the request lifecycle steps:
4062 * extensions, authentication, handlers, pre-handler methods, and failAction function values are lifecyle methods
4063 * provided by the developer and executed by the framework.
4064 * Each lifecycle method is a function with the signature await function(request, h, [err]) where:
4065 * * request - the request object.
4066 * * h - the response toolkit the handler must call to set a response and return control back to the framework.
4067 * * err - an error object availble only when the method is used as a failAction value.
4068 */
4069 type Method = (request: Request, h: ResponseToolkit, err?: Error) => ReturnValue;
4070
4071 /**
4072 * Each lifecycle method must return a value or a promise that resolves into a value. If a lifecycle method returns
4073 * without a value or resolves to an undefined value, an Internal Server Error (500) error response is sent.
4074 * The return value must be one of:
4075 * - Plain value: null, string, number, boolean
4076 * - Buffer object
4077 * - Error object: plain Error OR a Boom object.
4078 * - Stream object
4079 * - any object or array
4080 * - a toolkit signal:
4081 * - a toolkit method response:
4082 * - a promise object that resolve to any of the above values
4083 * For more info please [See docs](https://github.com/hapijs/hapi/blob/master/API.md#lifecycle-methods)
4084 */
4085 type ReturnValue = ReturnValueTypes | (Promise<ReturnValueTypes>);
4086 type ReturnValueTypes =
4087 | (null | string | number | boolean)
4088 | (Buffer)
4089 | (Error | Boom)
4090 | (stream.Stream)
4091 | (object | object[])
4092 | symbol
4093 | ResponseToolkit;
4094
4095 /**
4096 * Various configuration options allows defining how errors are handled. For example, when invalid payload is received or malformed cookie, instead of returning an error, the framework can be
4097 * configured to perform another action. When supported the failAction option supports the following values:
4098 * * 'error' - return the error object as the response.
4099 * * 'log' - report the error but continue processing the request.
4100 * * 'ignore' - take no action and continue processing the request.
4101 * * a lifecycle method with the signature async function(request, h, err) where:
4102 * * * request - the request object.
4103 * * * h - the response toolkit.
4104 * * * err - the error object.
4105 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-failaction-configuration)
4106 */
4107 type FailAction = "error" | "log" | "ignore" | Method;
4108}
4109
4110export namespace Util {
4111 interface Dictionary<T> {
4112 [key: string]: T;
4113 }
4114
4115 type HTTP_METHODS_PARTIAL_LOWERCASE = "get" | "post" | "put" | "patch" | "delete" | "options";
4116 type HTTP_METHODS_PARTIAL =
4117 | "GET"
4118 | "POST"
4119 | "PUT"
4120 | "PATCH"
4121 | "DELETE"
4122 | "OPTIONS"
4123 | HTTP_METHODS_PARTIAL_LOWERCASE;
4124 type HTTP_METHODS = "HEAD" | "head" | HTTP_METHODS_PARTIAL;
4125}
4126
\No newline at end of file