UNPKG

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