UNPKG

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