UNPKG

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