UNPKG

227 kBTypeScriptView Raw
1// Type definitions for hapi 18.0
2// Project: https://github.com/hapijs/hapi, https://hapijs.com
3// Definitions by: Rafael Souza Fijalkowski <https://github.com/rafaelsouzaf>
4// Justin Simms <https://github.com/jhsimms>
5// Simon Schick <https://github.com/SimonSchick>
6// Rodrigo Saboya <https://github.com/saboya>
7// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
8// TypeScript Version: 2.8
9
10/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
11 + +
12 + +
13 + +
14 + WARNING: BACKWARDS INCOMPATIBLE +
15 + +
16 + +
17 + +
18 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
19
20/// <reference types='node' />
21
22import * as Boom from "boom";
23import * as http from "http";
24import * as https from "https";
25import * as Shot from "shot";
26import * as stream from "stream";
27import * as url from "url";
28import * as zlib from "zlib";
29
30import { SealOptions, SealOptionsSub } from "iron";
31import { Schema, SchemaMap, ValidationOptions } from "joi";
32import { MimosOptions } from "mimos";
33import Podium = require("podium");
34import {
35 ClientApi,
36 ClientOptions,
37 EnginePrototype,
38 EnginePrototypeOrObject,
39 Policy,
40 PolicyOptions,
41 PolicyOptionVariants,
42} from "catbox";
43
44/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
45 + +
46 + +
47 + +
48 + Plugin +
49 + +
50 + +
51 + +
52 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
53
54/**
55 * one of
56 * a single plugin name string.
57 * an array of plugin name strings.
58 * an object where each key is a plugin name and each matching value is a
59 * {@link https://www.npmjs.com/package/semver version range string} which must match the registered
60 * plugin version.
61 */
62export type Dependencies = string | string[] | {
63 [key: string]: string;
64};
65
66/**
67 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverregistrations)
68 */
69
70/* tslint:disable-next-line:no-empty-interface */
71export interface PluginsListRegistered {
72}
73
74/**
75 * An object of the currently registered plugins where each key is a registered plugin name and the value is an
76 * object containing:
77 * * version - the plugin version.
78 * * name - the plugin name.
79 * * options - (optional) options passed to the plugin during registration.
80 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-serverregistrations)
81 */
82export interface PluginRegistered {
83 /**
84 * the plugin version.
85 */
86 version: string;
87
88 /**
89 * the plugin name.
90 */
91 name: string;
92
93 /**
94 * options used to register the plugin.
95 */
96 options: object;
97}
98
99/* tslint:disable-next-line:no-empty-interface */
100export interface PluginsStates {
101}
102
103/* tslint:disable-next-line:no-empty-interface */
104export interface PluginSpecificConfiguration {
105}
106
107export interface PluginNameVersion {
108 /**
109 * (required) the plugin name string. The name is used as a unique key. Published plugins (e.g. published in the npm
110 * registry) should use the same name as the name field in their 'package.json' file. Names must be
111 * unique within each application.
112 */
113 name: string;
114
115 /**
116 * optional plugin version. The version is only used informatively to enable other plugins to find out the versions loaded. The version should be the same as the one specified in the plugin's
117 * 'package.json' file.
118 */
119 version?: string | undefined;
120}
121
122export interface PluginPackage {
123 /**
124 * Alternatively, the name and version can be included via the pkg property containing the 'package.json' file for the module which already has the name and version included
125 */
126 pkg: any;
127}
128
129/**
130 * Plugins provide a way to organize application code by splitting the server logic into smaller components. Each
131 * plugin can manipulate the server through the standard server interface, but with the added ability to sandbox
132 * certain properties. For example, setting a file path in one plugin doesn't affect the file path set
133 * in another plugin.
134 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#plugins)
135 *
136 * The type T is the type of the plugin options.
137 */
138export interface PluginBase<T> {
139 /**
140 * (required) the registration function with the signature async function(server, options) where:
141 * * server - the server object with a plugin-specific server.realm.
142 * * options - any options passed to the plugin during registration via server.register().
143 */
144 register: (server: Server, options: T) => void | Promise<void>;
145
146 /** (optional) if true, allows the plugin to be registered multiple times with the same server. Defaults to false. */
147 multiple?: boolean | undefined;
148
149 /** (optional) a string or an array of strings indicating a plugin dependency. Same as setting dependencies via server.dependency(). */
150 dependencies?: Dependencies | undefined;
151
152 /**
153 * Allows defining semver requirements for node and hapi.
154 * @default Allows all.
155 */
156 requirements?: {
157 node?: string | undefined;
158 hapi?: string | undefined;
159 } | undefined;
160
161 /** once - (optional) if true, will only register the plugin once per server. If set, overrides the once option passed to server.register(). Defaults to no override. */
162 once?: boolean | undefined;
163}
164
165export type Plugin<T> = PluginBase<T> & (PluginNameVersion | PluginPackage);
166
167/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
168 + +
169 + +
170 + +
171 + Request +
172 + +
173 + +
174 + +
175 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
176
177/**
178 * User extensible types user credentials.
179 */
180// tslint:disable-next-line:no-empty-interface
181export interface UserCredentials {
182}
183
184/**
185 * User extensible types app credentials.
186 */
187// tslint:disable-next-line:no-empty-interface
188export interface AppCredentials {
189}
190
191/**
192 * User-extensible type for request.auth credentials.
193 */
194export interface AuthCredentials {
195 /**
196 * The application scopes to be granted.
197 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccessscope)
198 */
199 scope?: string[] | undefined;
200 /**
201 * If set, will only work with routes that set `access.entity` to `user`.
202 */
203 user?: UserCredentials | undefined;
204
205 /**
206 * If set, will only work with routes that set `access.entity` to `app`.
207 */
208 app?: AppCredentials | undefined;
209}
210
211/**
212 * Authentication information:
213 * * artifacts - an artifact object received from the authentication strategy and used in authentication-related actions.
214 * * credentials - the credential object received during the authentication process. The presence of an object does not mean successful authentication.
215 * * error - the authentication error is failed and mode set to 'try'.
216 * * isAuthenticated - true if the request has been successfully authenticated, otherwise false.
217 * * isAuthorized - true is the request has been successfully authorized against the route authentication access configuration. If the route has not access rules defined or if the request failed
218 * authorization, set to false.
219 * * mode - the route authentication mode.
220 * * strategy - the name of the strategy used.
221 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestauth)
222 */
223export interface RequestAuth {
224 /** an artifact object received from the authentication strategy and used in authentication-related actions. */
225 artifacts: object;
226 /** the credential object received during the authentication process. The presence of an object does not mean successful authentication. */
227 credentials: AuthCredentials;
228 /** the authentication error is failed and mode set to 'try'. */
229 error: Error;
230 /** true if the request has been successfully authenticated, otherwise false. */
231 isAuthenticated: boolean;
232 /**
233 * true is the request has been successfully authorized against the route authentication access configuration. If the route has not access rules defined or if the request failed authorization,
234 * set to false.
235 */
236 isAuthorized: boolean;
237 /** the route authentication mode. */
238 mode: string;
239 /** the name of the strategy used. */
240 strategy: string;
241}
242
243/**
244 * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
245 * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
246 * 'disconnect' - emitted when a request errors or aborts unexpectedly.
247 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
248 */
249export type RequestEventType = "peek" | "finish" | "disconnect";
250
251/**
252 * Access: read only and the public podium interface.
253 * The request.events supports the following events:
254 * * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
255 * * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
256 * * 'disconnect' - emitted when a request errors or aborts unexpectedly.
257 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
258 */
259export interface RequestEvents extends Podium {
260 /**
261 * Access: read only and the public podium interface.
262 * The request.events supports the following events:
263 * * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
264 * * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
265 * * 'disconnect' - emitted when a request errors or aborts unexpectedly.
266 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
267 */
268 on(criteria: "peek", listener: PeekListener): void;
269
270 on(criteria: "finish" | "disconnect", listener: (data: undefined) => void): void;
271
272 /**
273 * Access: read only and the public podium interface.
274 * The request.events supports the following events:
275 * * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
276 * * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
277 * * 'disconnect' - emitted when a request errors or aborts unexpectedly.
278 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
279 */
280 once(criteria: "peek", listener: PeekListener): void;
281
282 once(criteria: "finish" | "disconnect", listener: (data: undefined) => void): void;
283}
284
285/**
286 * Request information:
287 * * acceptEncoding - the request preferred encoding.
288 * * cors - if CORS is enabled for the route, contains the following:
289 * * isOriginMatch - true if the request 'Origin' header matches the configured CORS restrictions. Set to false if no 'Origin' header is found or if it does not match. Note that this is only
290 * available after the 'onRequest' extension point as CORS is configured per-route and no routing decisions are made at that point in the request lifecycle.
291 * * host - content of the HTTP 'Host' header (e.g. 'example.com:8080').
292 * * hostname - the hostname part of the 'Host' header (e.g. 'example.com').
293 * * id - a unique request identifier (using the format '{now}:{connection.info.id}:{5 digits counter}').
294 * * received - request reception timestamp.
295 * * referrer - content of the HTTP 'Referrer' (or 'Referer') header.
296 * * remoteAddress - remote client IP address.
297 * * remotePort - remote client port.
298 * * responded - request response timestamp (0 is not responded yet).
299 * Note that the request.info object is not meant to be modified.
300 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestinfo)
301 */
302export interface RequestInfo {
303 /** the request preferred encoding. */
304 acceptEncoding: string;
305 /** if CORS is enabled for the route, contains the following: */
306 cors: {
307 /**
308 * true if the request 'Origin' header matches the configured CORS restrictions. Set to false if no 'Origin' header is found or if it does not match. Note that this is only available after
309 * the 'onRequest' extension point as CORS is configured per-route and no routing decisions are made at that point in the request lifecycle.
310 */
311 isOriginMatch?: boolean | undefined;
312 };
313 /** content of the HTTP 'Host' header (e.g. 'example.com:8080'). */
314 host: string;
315 /** the hostname part of the 'Host' header (e.g. 'example.com'). */
316 hostname: string;
317 /** a unique request identifier (using the format '{now}:{connection.info.id}:{5 digits counter}') */
318 id: string;
319 /** request reception timestamp. */
320 received: number;
321 /** content of the HTTP 'Referrer' (or 'Referer') header. */
322 referrer: string;
323 /** remote client IP address. */
324 remoteAddress: string;
325 /** remote client port. */
326 remotePort: string;
327 /** request response timestamp (0 is not responded yet). */
328 responded: number;
329 /** request processing completion timestamp (0 is still processing). */
330 completed: number;
331}
332
333/**
334 * The request route information object, where:
335 * * method - the route HTTP method.
336 * * path - the route path.
337 * * vhost - the route vhost option if configured.
338 * * realm - the active realm associated with the route.
339 * * settings - the route options object with all defaults applied.
340 * * fingerprint - the route internal normalized string representing the normalized path.
341 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestroute)
342 */
343export interface RequestRoute {
344 /** the route HTTP method. */
345 method: Util.HTTP_METHODS_PARTIAL;
346
347 /** the route path. */
348 path: string;
349
350 /** the route vhost option if configured. */
351 vhost?: string | string[] | undefined;
352
353 /** the active realm associated with the route. */
354 realm: ServerRealm;
355
356 /** the route options object with all defaults applied. */
357 settings: RouteOptions;
358
359 /** the route internal normalized string representing the normalized path. */
360 fingerprint: string;
361
362 auth: {
363 /**
364 * Validates a request against the route's authentication access configuration, where:
365 * @param request - the request object.
366 * @return Return value: true if the request would have passed the route's access requirements.
367 * Note that the route's authentication mode and strategies are ignored. The only match is made between the request.auth.credentials scope and entity information and the route access
368 * configuration. If the route uses dynamic scopes, the scopes are constructed against the request.query, request.params, request.payload, and request.auth.credentials which may or may
369 * not match between the route and the request's route. If this method is called using a request that has not been authenticated (yet or not at all), it will return false if the route
370 * requires any authentication.
371 * [See docs](https://hapijs.com/api/17.0.1#-requestrouteauthaccessrequest)
372 */
373 access(request: Request): boolean;
374 };
375}
376
377/**
378 * An object containing the values of params, query, and payload before any validation modifications made. Only set when input validation is performed.
379 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestorig)
380 */
381export interface RequestOrig {
382 params: object;
383 query: object;
384 payload: object;
385}
386
387export interface RequestLog {
388 request: string;
389 timestamp: number;
390 tags: string[];
391 data: string | object;
392 channel: string;
393}
394
395export interface RequestQuery {
396 [key: string]: string | string[];
397}
398
399/**
400 * The request object is created internally for each incoming request. It is not the same object received from the node
401 * HTTP server callback (which is available via [request.raw.req](https://github.com/hapijs/hapi/blob/master/API.md#request.raw)). The request properties change throughout
402 * the request [lifecycle](https://github.com/hapijs/hapi/blob/master/API.md#request-lifecycle).
403 */
404export interface Request extends Podium {
405 /**
406 * Application-specific state. Provides a safe place to store application data without potential conflicts with the framework. Should not be used by plugins which should use plugins[name].
407 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestapp)
408 */
409 app: ApplicationState;
410
411 /**
412 * Authentication information:
413 * * artifacts - an artifact object received from the authentication strategy and used in authentication-related actions.
414 * * credentials - the credential object received during the authentication process. The presence of an object does not mean successful authentication.
415 * * error - the authentication error is failed and mode set to 'try'.
416 * * isAuthenticated - true if the request has been successfully authenticated, otherwise false.
417 * * isAuthorized - true is the request has been successfully authorized against the route authentication access configuration. If the route has not access rules defined or if the request failed
418 * authorization, set to false.
419 * * mode - the route authentication mode.
420 * * strategy - the name of the strategy used.
421 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestauth)
422 */
423 readonly auth: RequestAuth;
424
425 /**
426 * Access: read only and the public podium interface.
427 * The request.events supports the following events:
428 * * 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
429 * * 'finish' - emitted when the request payload finished reading. The event method signature is function ().
430 * * 'disconnect' - emitted when a request errors or aborts unexpectedly.
431 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestevents)
432 */
433 events: RequestEvents;
434
435 /**
436 * The raw request headers (references request.raw.req.headers).
437 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestheaders)
438 */
439 readonly headers: Util.Dictionary<string>;
440
441 /**
442 * Request information:
443 * * acceptEncoding - the request preferred encoding.
444 * * cors - if CORS is enabled for the route, contains the following:
445 * * isOriginMatch - true if the request 'Origin' header matches the configured CORS restrictions. Set to false if no 'Origin' header is found or if it does not match. Note that this is only
446 * available after the 'onRequest' extension point as CORS is configured per-route and no routing decisions are made at that point in the request lifecycle.
447 * * host - content of the HTTP 'Host' header (e.g. 'example.com:8080').
448 * * hostname - the hostname part of the 'Host' header (e.g. 'example.com').
449 * * id - a unique request identifier (using the format '{now}:{connection.info.id}:{5 digits counter}').
450 * * received - request reception timestamp.
451 * * referrer - content of the HTTP 'Referrer' (or 'Referer') header.
452 * * remoteAddress - remote client IP address.
453 * * remotePort - remote client port.
454 * * responded - request response timestamp (0 is not responded yet).
455 * Note that the request.info object is not meant to be modified.
456 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestinfo)
457 */
458 readonly info: RequestInfo;
459
460 /**
461 * An array containing the logged request events.
462 * Note that this array will be empty if route log.collect is set to false.
463 */
464 readonly logs: RequestLog[];
465
466 /**
467 * The request method in lower case (e.g. 'get', 'post').
468 */
469 readonly method: Util.HTTP_METHODS_PARTIAL_LOWERCASE;
470
471 /**
472 * The parsed content-type header. Only available when payload parsing enabled and no payload error occurred.
473 */
474 readonly mime: string;
475
476 /**
477 * An object containing the values of params, query, and payload before any validation modifications made. Only set when input validation is performed.
478 */
479 readonly orig: RequestOrig;
480
481 /**
482 * An object where each key is a path parameter name with matching value as described in [Path parameters](https://github.com/hapijs/hapi/blob/master/API.md#path-parameters).
483 */
484 readonly params: Util.Dictionary<string>;
485
486 /**
487 * An array containing all the path params values in the order they appeared in the path.
488 */
489 readonly paramsArray: string[];
490
491 /**
492 * The request URI's pathname component.
493 */
494 readonly path: string;
495
496 /**
497 * The request payload based on the route payload.output and payload.parse settings.
498 * TODO check this typing and add references / links.
499 */
500 readonly payload: stream.Readable | Buffer | string | object;
501
502 /**
503 * Plugin-specific state. Provides a place to store and pass request-level plugin data. The plugins is an object where each key is a plugin name and the value is the state.
504 */
505 plugins: PluginsStates;
506
507 /**
508 * An object where each key is the name assigned by a route pre-handler methods function. The values are the raw values provided to the continuation function as argument. For the wrapped response
509 * object, use responses.
510 */
511 readonly pre: Util.Dictionary<any>;
512
513 /**
514 * Access: read / write (see limitations below).
515 * The response object when set. The object can be modified but must not be assigned another object. To replace the response with another from within an extension point, use reply(response) to
516 * override with a different response.
517 * In case of an aborted request the status code will be set to `disconnectStatusCode`.
518 */
519 response: ResponseObject | Boom;
520
521 /**
522 * Same as pre but represented as the response object created by the pre method.
523 */
524 readonly preResponses: Util.Dictionary<any>;
525
526 /**
527 * By default the object outputted from node's URL parse() method.
528 */
529 readonly query: RequestQuery;
530
531 /**
532 * An object containing the Node HTTP server objects. Direct interaction with these raw objects is not recommended.
533 * * req - the node request object.
534 * * res - the node response object.
535 */
536 readonly raw: {
537 req: http.IncomingMessage;
538 res: http.ServerResponse;
539 };
540
541 /**
542 * The request route information object and method
543 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestroute)
544 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestrouteauthaccessrequest)
545 */
546 readonly route: RequestRoute;
547
548 /**
549 * Access: read only and the public server interface.
550 * The server object.
551 */
552 server: Server;
553
554 /**
555 * An object containing parsed HTTP state information (cookies) where each key is the cookie name and value is the matching cookie content after processing using any registered cookie definition.
556 */
557 readonly state: Util.Dictionary<any>;
558
559 /**
560 * The parsed request URI.
561 */
562 readonly url: url.URL;
563
564 /**
565 * Returns `true` when the request is active and processing should continue and `false` when the
566 * request terminated early or completed its lifecycle. Useful when request processing is a
567 * resource-intensive operation and should be terminated early if the request is no longer active
568 * (e.g. client disconnected or aborted early).
569 */
570 active(): boolean;
571
572 /**
573 * Returns a response which you can pass into the reply interface where:
574 * @param source - the value to set as the source of the reply interface, optional.
575 * @param options - options for the method, optional.
576 * @return ResponseObject
577 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestgenerateresponsesource-options)
578 */
579 generateResponse(
580 source: string | object | null,
581 options?: {
582 variety?: string | undefined;
583 prepare?: ((response: ResponseObject) => Promise<ResponseObject>) | undefined;
584 marshal?: ((response: ResponseObject) => Promise<ResponseValue>) | undefined;
585 close?: ((response: ResponseObject) => void) | undefined;
586 },
587 ): ResponseObject;
588
589 /**
590 * Logs request-specific events. When called, the server emits a 'request' event which can be used by other listeners or plugins. The arguments are:
591 * @param tags - a string or an array of strings (e.g. ['error', 'database', 'read']) used to identify the event. Tags are used instead of log levels and provide a much more expressive mechanism
592 * for describing and filtering events.
593 * @param data - (optional) an message string or object with the application data being logged. If data is a function, the function signature is function() and it called once to generate (return
594 * value) the actual data emitted to the listeners. Any logs generated by the server internally will be emitted only on the 'request-internal' channel and will include the event.internal flag
595 * set to true.
596 * @return void
597 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestlogtags-data)
598 */
599 log(tags: string | string[], data?: string | object | (() => string | object)): void;
600
601 /**
602 * Changes the request method before the router begins processing the request where:
603 * @param method - is the request HTTP method (e.g. 'GET').
604 * @return void
605 * Can only be called from an 'onRequest' extension method.
606 * [See docs](https://hapijs.com/api/17.0.1#-requestsetmethodmethod)
607 */
608 setMethod(method: Util.HTTP_METHODS_PARTIAL): void;
609
610 /**
611 * Changes the request URI before the router begins processing the request where:
612 * Can only be called from an 'onRequest' extension method.
613 * @param url - the new request URI. If url is a string, it is parsed with node's URL parse() method with parseQueryString set to true. url can also be set to an object compatible with node's URL
614 * parse() method output.
615 * @param stripTrailingSlash - if true, strip the trailing slash from the path. Defaults to false.
616 * @return void
617 * [See docs](https://hapijs.com/api/17.0.1#-requestseturlurl-striptrailingslash)
618 */
619 setUrl(url: string | url.URL, stripTrailingSlash?: boolean): void;
620}
621
622/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
623 + +
624 + +
625 + +
626 + Response +
627 + +
628 + +
629 + +
630 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
631
632/**
633 * Access: read only and the public podium interface.
634 * The response.events object supports the following events:
635 * * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
636 * * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
637 * [See docs](https://hapijs.com/api/17.0.1#-responseevents)
638 */
639export interface ResponseEvents extends Podium {
640 /**
641 * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
642 * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
643 */
644 on(criteria: "peek", listener: PeekListener): void;
645
646 on(criteria: "finish", listener: (data: undefined) => void): void;
647
648 /**
649 * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
650 * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
651 */
652 once(criteria: "peek", listener: PeekListener): void;
653
654 once(criteria: "finish", listener: (data: undefined) => void): void;
655}
656
657/**
658 * Object where:
659 * * append - if true, the value is appended to any existing header value using separator. Defaults to false.
660 * * separator - string used as separator when appending to an existing value. Defaults to ','.
661 * * override - if false, the header value is not set if an existing value present. Defaults to true.
662 * * duplicate - if false, the header value is not modified if the provided value is already included. Does not apply when append is false or if the name is 'set-cookie'. Defaults to true.
663 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheadername-value-options)
664 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#response-object)
665 */
666export interface ResponseObjectHeaderOptions {
667 append?: boolean | undefined;
668 separator?: string | undefined;
669 override?: boolean | undefined;
670 duplicate?: boolean | undefined;
671}
672
673/**
674 * The response object contains the request response value along with various HTTP headers and flags. When a lifecycle
675 * method returns a value, the value is wrapped in a response object along with some default flags (e.g. 200 status
676 * code). In order to customize a response before it is returned, the h.response() method is provided.
677 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#response-object)
678 * TODO, check extending from Podium is correct. Extending because of "The response object supports the following events" [See docs](https://hapijs.com/api/17.0.1#-responseevents)
679 */
680export interface ResponseObject extends Podium {
681 /**
682 * Default value: {}.
683 * Application-specific state. Provides a safe place to store application data without potential conflicts with the framework. Should not be used by plugins which should use plugins[name].
684 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseapp)
685 */
686 app: ApplicationState;
687
688 /**
689 * Access: read only and the public podium interface.
690 * The response.events object supports the following events:
691 * * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
692 * * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
693 * [See docs](https://hapijs.com/api/17.0.1#-responseevents)
694 */
695 readonly events: ResponseEvents;
696
697 /**
698 * Default value: {}.
699 * An object containing the response headers where each key is a header field name and the value is the string header value or array of string.
700 * Note that this is an incomplete list of headers to be included with the response. Additional headers will be added once the response is prepared for transmission.
701 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheaders)
702 */
703 readonly headers: Util.Dictionary<string | string[]>;
704
705 /**
706 * Default value: {}.
707 * Plugin-specific state. Provides a place to store and pass request-level plugin data. plugins is an object where each key is a plugin name and the value is the state.
708 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseplugins)
709 */
710 plugins: PluginsStates;
711
712 /**
713 * Object containing the response handling flags.
714 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesettings)
715 */
716 readonly settings: ResponseSettings;
717
718 /**
719 * The raw value returned by the lifecycle method.
720 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesource)
721 */
722 readonly source: Lifecycle.ReturnValue;
723
724 /**
725 * Default value: 200.
726 * The HTTP response status code.
727 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsestatuscode)
728 */
729 readonly statusCode: number;
730
731 /**
732 * A string indicating the type of source with available values:
733 * * 'plain' - a plain response such as string, number, null, or simple object.
734 * * 'buffer' - a Buffer.
735 * * 'stream' - a Stream.
736 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsevariety)
737 */
738 readonly variety: "plain" | "buffer" | "stream";
739
740 /**
741 * Sets the HTTP 'Content-Length' header (to avoid chunked transfer encoding) where:
742 * @param length - the header value. Must match the actual payload size.
743 * @return Return value: the current response object.
744 * [See docs](https://hapijs.com/api/17.0.1#-responsebyteslength)
745 */
746 bytes(length: number): ResponseObject;
747
748 /**
749 * Sets the 'Content-Type' HTTP header 'charset' property where:
750 * @param charset - the charset property value.
751 * @return Return value: the current response object.
752 * [See docs](https://hapijs.com/api/17.0.1#-responsecharsetcharset)
753 */
754 charset(charset: string): ResponseObject;
755
756 /**
757 * Sets the HTTP status code where:
758 * @param statusCode - the HTTP status code (e.g. 200).
759 * @return Return value: the current response object.
760 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsecodestatuscode)
761 */
762 code(statusCode: number): ResponseObject;
763
764 /**
765 * Sets the HTTP status message where:
766 * @param httpMessage - the HTTP status message (e.g. 'Ok' for status code 200).
767 * @return Return value: the current response object.
768 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsemessagehttpmessage)
769 */
770 message(httpMessage: string): ResponseObject;
771
772 /**
773 * Sets the HTTP status code to Created (201) and the HTTP 'Location' header where:
774 * @param uri - an absolute or relative URI used as the 'Location' header value.
775 * @return Return value: the current response object.
776 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsecreateduri)
777 */
778 created(uri: string): ResponseObject;
779
780 /**
781 * Sets the string encoding scheme used to serial data into the HTTP payload where:
782 * @param encoding the encoding property value (see node Buffer encoding [See docs](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings)).
783 * * 'ascii' - for 7-bit ASCII data only. This encoding is fast and will strip the high bit if set.
784 * * 'utf8' - Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
785 * * 'utf16le' - 2 or 4 bytes, little-endian encoded Unicode characters. Surrogate pairs (U+10000 to U+10FFFF) are supported.
786 * * 'ucs2' - Alias of 'utf16le'.
787 * * 'base64' - Base64 encoding. When creating a Buffer from a string, this encoding will also correctly accept "URL and Filename Safe Alphabet" as specified in RFC4648, Section 5.
788 * * 'latin1' - A way of encoding the Buffer into a one-byte encoded string (as defined by the IANA in RFC1345, page 63, to be the Latin-1 supplement block and C0/C1 control codes).
789 * * 'binary' - Alias for 'latin1'.
790 * * 'hex' - Encode each byte as two hexadecimal characters.
791 * @return Return value: the current response object.
792 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseencodingencoding)
793 */
794 encoding(encoding: "ascii" | "utf8" | "utf16le" | "ucs2" | "base64" | "latin1" | "binary" | "hex"): ResponseObject;
795
796 /**
797 * Sets the representation entity tag where:
798 * @param tag - the entity tag string without the double-quote.
799 * @param options - (optional) settings where:
800 * * weak - if true, the tag will be prefixed with the 'W/' weak signifier. Weak tags will fail to match identical tags for the purpose of determining 304 response status. Defaults to false.
801 * * vary - if true and content encoding is set or applied to the response (e.g 'gzip' or 'deflate'), the encoding name will be automatically added to the tag at transmission time (separated by
802 * a '-' character). Ignored when weak is true. Defaults to true.
803 * @return Return value: the current response object.
804 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseetagtag-options)
805 */
806 etag(tag: string, options?: { weak: boolean; vary: boolean }): ResponseObject;
807
808 /**
809 * Sets an HTTP header where:
810 * @param name - the header name.
811 * @param value - the header value.
812 * @param options - (optional) object where:
813 * * append - if true, the value is appended to any existing header value using separator. Defaults to false.
814 * * separator - string used as separator when appending to an existing value. Defaults to ','.
815 * * override - if false, the header value is not set if an existing value present. Defaults to true.
816 * * duplicate - if false, the header value is not modified if the provided value is already included. Does not apply when append is false or if the name is 'set-cookie'. Defaults to true.
817 * @return Return value: the current response object.
818 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheadername-value-options)
819 */
820 header(name: string, value: string, options?: ResponseObjectHeaderOptions): ResponseObject;
821
822 /**
823 * Sets the HTTP 'Location' header where:
824 * @param uri - an absolute or relative URI used as the 'Location' header value.
825 * @return Return value: the current response object.
826 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responselocationuri)
827 */
828 location(uri: string): ResponseObject;
829
830 /**
831 * Sets an HTTP redirection response (302) and decorates the response with additional methods, where:
832 * @param uri - an absolute or relative URI used to redirect the client to another resource.
833 * @return Return value: the current response object.
834 * Decorates the response object with the response.temporary(), response.permanent(), and response.rewritable() methods to easily change the default redirection code (302).
835 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseredirecturi)
836 */
837 redirect(uri: string): ResponseObject;
838
839 /**
840 * Sets the JSON.stringify() replacer argument where:
841 * @param method - the replacer function or array. Defaults to none.
842 * @return Return value: the current response object.
843 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsereplacermethod)
844 */
845 replacer(method: Json.StringifyReplacer): ResponseObject;
846
847 /**
848 * Sets the JSON.stringify() space argument where:
849 * @param count - the number of spaces to indent nested object keys. Defaults to no indentation.
850 * @return Return value: the current response object.
851 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsespacescount)
852 */
853 spaces(count: number): ResponseObject;
854
855 /**
856 * Sets an HTTP cookie where:
857 * @param name - the cookie name.
858 * @param value - the cookie value. If no options.encoding is defined, must be a string. See server.state() for supported encoding values.
859 * @param options - (optional) configuration. If the state was previously registered with the server using server.state(), the specified keys in options are merged with the default server
860 * definition.
861 * @return Return value: the current response object.
862 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsestatename-value-options)
863 */
864 state(name: string, value: object | string, options?: ServerStateCookieOptions): ResponseObject;
865
866 /**
867 * Sets a string suffix when the response is process via JSON.stringify() where:
868 * @param suffix - the string suffix.
869 * @return Return value: the current response object.
870 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesuffixsuffix)
871 */
872 suffix(suffix: string): ResponseObject;
873
874 /**
875 * Overrides the default route cache expiration rule for this response instance where:
876 * @param msec - the time-to-live value in milliseconds.
877 * @return Return value: the current response object.
878 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsettlmsec)
879 */
880 ttl(msec: number): ResponseObject;
881
882 /**
883 * Sets the HTTP 'Content-Type' header where:
884 * @param mimeType - is the mime type.
885 * @return Return value: the current response object.
886 * Should only be used to override the built-in default for each response type.
887 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsetypemimetype)
888 */
889 type(mimeType: string): ResponseObject;
890
891 /**
892 * Clears the HTTP cookie by setting an expired value where:
893 * @param name - the cookie name.
894 * @param options - (optional) configuration for expiring cookie. If the state was previously registered with the server using server.state(), the specified options are merged with the server
895 * definition.
896 * @return Return value: the current response object.
897 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseunstatename-options)
898 */
899 unstate(name: string, options?: ServerStateCookieOptions): ResponseObject;
900
901 /**
902 * Adds the provided header to the list of inputs affected the response generation via the HTTP 'Vary' header where:
903 * @param header - the HTTP request header name.
904 * @return Return value: the current response object.
905 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsevaryheader)
906 */
907 vary(header: string): ResponseObject;
908
909 /**
910 * Marks the response object as a takeover response.
911 * @return Return value: the current response object.
912 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsetakeover)
913 */
914 takeover(): ResponseObject;
915
916 /**
917 * Sets the status code to 302 or 307 (based on the response.rewritable() setting) where:
918 * @param isTemporary - if false, sets status to permanent. Defaults to true.
919 * @return Return value: the current response object.
920 * Only available after calling the response.redirect() method.
921 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsetemporaryistemporary)
922 */
923 temporary(isTemporary: boolean): ResponseObject;
924
925 /**
926 * Sets the status code to 301 or 308 (based on the response.rewritable() setting) where:
927 * @param isPermanent - if false, sets status to temporary. Defaults to true.
928 * @return Return value: the current response object.
929 * Only available after calling the response.redirect() method.
930 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsepermanentispermanent)
931 */
932 permanent(isPermanent: boolean): ResponseObject;
933
934 /**
935 * Sets the status code to 301/302 for rewritable (allows changing the request method from 'POST' to 'GET') or 307/308 for non-rewritable (does not allow changing the request method from 'POST'
936 * to 'GET'). Exact code based on the response.temporary() or response.permanent() setting. Arguments:
937 * @param isRewritable - if false, sets to non-rewritable. Defaults to true.
938 * @return Return value: the current response object.
939 * Only available after calling the response.redirect() method.
940 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responserewritableisrewritable)
941 */
942 rewritable(isRewritable: boolean): ResponseObject;
943}
944
945/**
946 * Object containing the response handling flags.
947 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesettings)
948 */
949export interface ResponseSettings {
950 /**
951 * Defaults value: true.
952 * If true and source is a Stream, copies the statusCode and headers properties of the stream object to the outbound response.
953 */
954 readonly passThrough: boolean;
955
956 /**
957 * Default value: null (use route defaults).
958 * Override the route json options used when source value requires stringification.
959 */
960 readonly stringify: Json.StringifyArguments;
961
962 /**
963 * Default value: null (use route defaults).
964 * If set, overrides the route cache with an expiration value in milliseconds.
965 */
966 readonly ttl: number;
967
968 /**
969 * Default value: false.
970 * If true, a suffix will be automatically added to the 'ETag' header at transmission time (separated by a '-' character) when the HTTP 'Vary' header is present.
971 */
972 varyEtag: boolean;
973}
974
975/**
976 * See more about Lifecycle
977 * https://github.com/hapijs/hapi/blob/master/API.md#request-lifecycle
978 */
979
980export type ResponseValue = string | object;
981
982export interface AuthenticationData {
983 credentials: AuthCredentials;
984 artifacts?: object | undefined;
985}
986
987export interface Auth {
988 readonly isAuth: true;
989 readonly error?: Error | null | undefined;
990 readonly data?: AuthenticationData | undefined;
991}
992
993/**
994 * The response toolkit is a collection of properties and utilities passed to every [lifecycle method](https://github.com/hapijs/hapi/blob/master/API.md#lifecycle-methods)
995 * It is somewhat hard to define as it provides both utilities for manipulating responses as well as other information. Since the
996 * toolkit is passed as a function argument, developers can name it whatever they want. For the purpose of this
997 * document the h notation is used. It is named in the spirit of the RethinkDB r method, with h for hapi.
998 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#response-toolkit)
999 */
1000export interface ResponseToolkit {
1001 /**
1002 * A response symbol. When returned by a lifecycle method, the request lifecycle skips to the finalizing step
1003 * without further interaction with the node response stream. It is the developer's responsibility to write
1004 * and end the response directly via [request.raw.res](https://github.com/hapijs/hapi/blob/master/API.md#request.raw).
1005 */
1006 readonly abandon: symbol;
1007
1008 /**
1009 * A response symbol. When returned by a lifecycle method, the request lifecycle skips to the finalizing step after
1010 * calling request.raw.res.end()) to close the the node response stream.
1011 */
1012 readonly close: symbol;
1013
1014 /**
1015 * A response symbol. Provides access to the route or server context set via the route [bind](https://github.com/hapijs/hapi/blob/master/API.md#route.options.bind)
1016 * option or [server.bind()](https://github.com/hapijs/hapi/blob/master/API.md#server.bind()).
1017 */
1018 readonly context: any;
1019
1020 /**
1021 * A response symbol. When returned by a lifecycle method, the request lifecycle continues without changing the response.
1022 */
1023 readonly continue: symbol;
1024
1025 /**
1026 * The [server realm](https://github.com/hapijs/hapi/blob/master/API.md#server.realm) associated with the matching
1027 * route. Defaults to the root server realm in the onRequest step.
1028 */
1029 readonly realm: ServerRealm;
1030
1031 /**
1032 * Access: read only and public request interface.
1033 * The [request] object. This is a duplication of the request lifecycle method argument used by
1034 * [toolkit decorations](https://github.com/hapijs/hapi/blob/master/API.md#server.decorate()) to access the current request.
1035 */
1036 readonly request: Readonly<Request>;
1037
1038 /**
1039 * Used by the [authentication] method to pass back valid credentials where:
1040 * @param data - an object with:
1041 * * credentials - (required) object representing the authenticated entity.
1042 * * artifacts - (optional) authentication artifacts object specific to the authentication scheme.
1043 * @return Return value: an internal authentication object.
1044 */
1045 authenticated(data: AuthenticationData): Auth;
1046
1047 /**
1048 * Sets the response 'ETag' and 'Last-Modified' headers and checks for any conditional request headers to decide if
1049 * the response is going to qualify for an HTTP 304 (Not Modified). If the entity values match the request
1050 * conditions, h.entity() returns a response object for the lifecycle method to return as its value which will
1051 * set a 304 response. Otherwise, it sets the provided entity headers and returns undefined.
1052 * The method argumetns are:
1053 * @param options - a required configuration object with:
1054 * * etag - the ETag string. Required if modified is not present. Defaults to no header.
1055 * * modified - the Last-Modified header value. Required if etag is not present. Defaults to no header.
1056 * * vary - same as the response.etag() option. Defaults to true.
1057 * @return Return value: - a response object if the response is unmodified. - undefined if the response has changed.
1058 * If undefined is returned, the developer must return a valid lifecycle method value. If a response is returned,
1059 * it should be used as the return value (but may be customize using the response methods).
1060 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hentityoptions)
1061 */
1062 entity(
1063 options?: { etag?: string | undefined; modified?: string | undefined; vary?: boolean | undefined },
1064 ): ResponseObject | undefined;
1065
1066 /**
1067 * Redirects the client to the specified uri. Same as calling h.response().redirect(uri).
1068 * @param url
1069 * @return Returns a response object.
1070 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hredirecturi)
1071 */
1072 redirect(uri?: string): ResponseObject;
1073
1074 /**
1075 * Wraps the provided value and returns a response object which allows customizing the response
1076 * (e.g. setting the HTTP status code, custom headers, etc.), where:
1077 * @param value - (optional) return value. Defaults to null.
1078 * @return Returns a response object.
1079 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hresponsevalue)
1080 */
1081 response(value?: ResponseValue): ResponseObject;
1082
1083 /**
1084 * Sets a response cookie using the same arguments as response.state().
1085 * @param name of the cookie
1086 * @param value of the cookie
1087 * @param (optional) ServerStateCookieOptions object.
1088 * @return Return value: none.
1089 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hstatename-value-options)
1090 */
1091 state(name: string, value: string | object, options?: ServerStateCookieOptions): void;
1092
1093 /**
1094 * Used by the [authentication] method to indicate authentication failed and pass back the credentials received where:
1095 * @param error - (required) the authentication error.
1096 * @param data - (optional) an object with:
1097 * * credentials - (required) object representing the authenticated entity.
1098 * * artifacts - (optional) authentication artifacts object specific to the authentication scheme.
1099 * @return void.
1100 * The method is used to pass both the authentication error and the credentials. For example, if a request included
1101 * expired credentials, it allows the method to pass back the user information (combined with a 'try'
1102 * authentication mode) for error customization.
1103 * There is no difference between throwing the error or passing it with the h.unauthenticated() method is no credentials are passed, but it might still be helpful for code clarity.
1104 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hunauthenticatederror-data)
1105 */
1106 unauthenticated(error: Error, data?: AuthenticationData): void;
1107
1108 /**
1109 * Clears a response cookie using the same arguments as
1110 * @param name of the cookie
1111 * @param options (optional) ServerStateCookieOptions object.
1112 * @return void.
1113 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hunstatename-options)
1114 */
1115 unstate(name: string, options?: ServerStateCookieOptions): void;
1116}
1117
1118/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1119 + +
1120 + +
1121 + +
1122 + Route +
1123 + +
1124 + +
1125 + +
1126 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + */
1127
1128export type RouteOptionsAccessScope = false | string | string[];
1129
1130export type RouteOptionsAccessEntity = "any" | "user" | "app";
1131
1132export interface RouteOptionsAccessScopeObject {
1133 scope: RouteOptionsAccessScope;
1134}
1135
1136export interface RouteOptionsAccessEntityObject {
1137 entity: RouteOptionsAccessEntity;
1138}
1139
1140export type RouteOptionsAccessObject =
1141 | RouteOptionsAccessScopeObject
1142 | RouteOptionsAccessEntityObject
1143 | (RouteOptionsAccessScopeObject & RouteOptionsAccessEntityObject);
1144
1145/**
1146 * Route Authentication Options
1147 */
1148export interface RouteOptionsAccess {
1149 /**
1150 * Default value: none.
1151 * An object or array of objects specifying the route access rules. Each rule is evaluated against an incoming request and access is granted if at least one of the rules matches. Each rule object
1152 * must include at least one of scope or entity.
1153 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccess)
1154 */
1155 access?: RouteOptionsAccessObject | RouteOptionsAccessObject[] | undefined;
1156
1157 /**
1158 * Default value: false (no scope requirements).
1159 * The application scope required to access the route. Value can be a scope string or an array of scope strings. When authenticated, the credentials object scope property must contain at least
1160 * one of the scopes defined to access the route. If a scope string begins with a + character, that scope is required. If a scope string begins with a ! character, that scope is forbidden. For
1161 * example, the scope ['!a', '+b', 'c', 'd'] means the incoming request credentials' scope must not include 'a', must include 'b', and must include one of 'c' or 'd'. You may also access
1162 * properties on the request object (query, params, payload, and credentials) to populate a dynamic scope by using the '{' and '}' characters around the property name, such as 'user-{params.id}'.
1163 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccessscope)
1164 */
1165 scope?: RouteOptionsAccessScope | undefined;
1166
1167 /**
1168 * Default value: 'any'.
1169 * The required authenticated entity type. If set, must match the entity value of the request authenticated credentials. Available values:
1170 * * 'any' - the authentication can be on behalf of a user or application.
1171 * * 'user' - the authentication must be on behalf of a user which is identified by the presence of a 'user' attribute in the credentials object returned by the authentication strategy.
1172 * * 'app' - the authentication must be on behalf of an application which is identified by the lack of presence of a user attribute in the credentials object returned by the authentication
1173 * strategy.
1174 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccessentity)
1175 */
1176 entity?: RouteOptionsAccessEntity | undefined;
1177
1178 /**
1179 * Default value: 'required'.
1180 * The authentication mode. Available values:
1181 * * 'required' - authentication is required.
1182 * * 'optional' - authentication is optional - the request must include valid credentials or no credentials at all.
1183 * * 'try' - similar to 'optional', any request credentials are attempted authentication, but if the credentials are invalid, the request proceeds regardless of the authentication error.
1184 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthmode)
1185 */
1186 mode?: "required" | "optional" | "try" | undefined;
1187
1188 /**
1189 * Default value: false, unless the scheme requires payload authentication.
1190 * If set, the incoming request payload is authenticated after it is processed. Requires a strategy with payload authentication support (e.g. Hawk). Cannot be set to a value other than 'required'
1191 * when the scheme sets the authentication options.payload to true. Available values:
1192 * * false - no payload authentication.
1193 * * 'required' - payload authentication required.
1194 * * 'optional' - payload authentication performed only when the client includes payload authentication information (e.g. hash attribute in Hawk).
1195 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthpayload)
1196 */
1197 payload?: false | "required" | "optional" | undefined;
1198
1199 /**
1200 * Default value: the default strategy set via server.auth.default().
1201 * An array of string strategy names in the order they should be attempted. Cannot be used together with strategy.
1202 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthstrategies)
1203 */
1204 strategies?: string[] | undefined;
1205
1206 /**
1207 * Default value: the default strategy set via server.auth.default().
1208 * A string strategy names. Cannot be used together with strategies.
1209 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthstrategy)
1210 */
1211 strategy?: string | undefined;
1212}
1213
1214/**
1215 * Values are:
1216 * * * 'default' - no privacy flag.
1217 * * * 'public' - mark the response as suitable for public caching.
1218 * * * 'private' - mark the response as suitable only for private caching.
1219 * * expiresIn - relative expiration expressed in the number of milliseconds since the item was saved in the cache. Cannot be used together with expiresAt.
1220 * * expiresAt - time of day expressed in 24h notation using the 'HH:MM' format, at which point all cache records for the route expire. Cannot be used together with expiresIn.
1221 * * statuses - an array of HTTP response status code numbers (e.g. 200) which are allowed to include a valid caching directive.
1222 * * otherwise - a string with the value of the 'Cache-Control' header when caching is disabled.
1223 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscache)
1224 */
1225export type RouteOptionsCache =
1226 & {
1227 privacy?: "default" | "public" | "private" | undefined;
1228 statuses?: number[] | undefined;
1229 otherwise?: string | undefined;
1230 }
1231 & (
1232 {
1233 expiresIn?: number | undefined;
1234 expiresAt?: undefined;
1235 } | {
1236 expiresIn?: undefined;
1237 expiresAt?: string | undefined;
1238 } | {
1239 expiresIn?: undefined;
1240 expiresAt?: undefined;
1241 }
1242 );
1243
1244/**
1245 * Default value: false (no CORS headers).
1246 * The Cross-Origin Resource Sharing protocol allows browsers to make cross-origin API calls. CORS is required by web applications running inside a browser which are loaded from a different domain
1247 * than the API server. To enable, set cors to true, or to an object with the following options:
1248 * * origin - an array of allowed origin servers strings ('Access-Control-Allow-Origin'). The array can contain any combination of fully qualified origins along with origin strings containing a
1249 * wildcard '*' character, or a single '*' origin string. If set to 'ignore', any incoming Origin header is ignored (present or not) and the 'Access-Control-Allow-Origin' header is set to '*'.
1250 * Defaults to any origin ['*'].
1251 * * maxAge - number of seconds the browser should cache the CORS response ('Access-Control-Max-Age'). The greater the value, the longer it will take before the browser checks for changes in policy.
1252 * Defaults to 86400 (one day).
1253 * * headers - a strings array of allowed headers ('Access-Control-Allow-Headers'). Defaults to ['Accept', 'Authorization', 'Content-Type', 'If-None-Match'].
1254 * * additionalHeaders - a strings array of additional headers to headers. Use this to keep the default headers in place.
1255 * * exposedHeaders - a strings array of exposed headers ('Access-Control-Expose-Headers'). Defaults to ['WWW-Authenticate', 'Server-Authorization'].
1256 * * additionalExposedHeaders - a strings array of additional headers to exposedHeaders. Use this to keep the default headers in place.
1257 * * credentials - if true, allows user credentials to be sent ('Access-Control-Allow-Credentials'). Defaults to false.
1258 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionscors)
1259 */
1260export interface RouteOptionsCors {
1261 /**
1262 * an array of allowed origin servers strings ('Access-Control-Allow-Origin'). The array can contain any combination of fully qualified origins along with origin strings containing a wildcard '*'
1263 * character, or a single '*' origin string. If set to 'ignore', any incoming Origin header is ignored (present or not) and the 'Access-Control-Allow-Origin' header is set to '*'. Defaults to any
1264 * origin ['*'].
1265 */
1266 origin?: string[] | "*" | "ignore" | undefined;
1267 /**
1268 * number of seconds the browser should cache the CORS response ('Access-Control-Max-Age'). The greater the value, the longer it will take before the browser checks for changes in policy.
1269 * Defaults to 86400 (one day).
1270 */
1271 maxAge?: number | undefined;
1272 /**
1273 * a strings array of allowed headers ('Access-Control-Allow-Headers'). Defaults to ['Accept', 'Authorization', 'Content-Type', 'If-None-Match'].
1274 */
1275 headers?: string[] | undefined;
1276 /**
1277 * a strings array of additional headers to headers. Use this to keep the default headers in place.
1278 */
1279 additionalHeaders?: string[] | undefined;
1280 /**
1281 * a strings array of exposed headers ('Access-Control-Expose-Headers'). Defaults to ['WWW-Authenticate', 'Server-Authorization'].
1282 */
1283 exposedHeaders?: string[] | undefined;
1284 /**
1285 * a strings array of additional headers to exposedHeaders. Use this to keep the default headers in place.
1286 */
1287 additionalExposedHeaders?: string[] | undefined;
1288 /**
1289 * if true, allows user credentials to be sent ('Access-Control-Allow-Credentials'). Defaults to false.
1290 */
1291 credentials?: boolean | undefined;
1292}
1293
1294/**
1295 * The value must be one of:
1296 * * 'data' - the incoming payload is read fully into memory. If parse is true, the payload is parsed (JSON, form-decoded, multipart) based on the 'Content-Type' header. If parse is false, a raw
1297 * Buffer is returned.
1298 * * 'stream' - the incoming payload is made available via a Stream.Readable interface. If the payload is 'multipart/form-data' and parse is true, field values are presented as text while files are
1299 * provided as streams. File streams from a 'multipart/form-data' upload will also have a hapi property containing the filename and headers properties. Note that payload streams for multipart
1300 * payloads are a synthetic interface created on top of the entire mutlipart content loaded into memory. To avoid loading large multipart payloads into memory, set parse to false and handle the
1301 * multipart payload in the handler using a streaming parser (e.g. pez).
1302 * * 'file' - the incoming payload is written to temporary file in the directory specified by the uploads settings. If the payload is 'multipart/form-data' and parse is true, field values are
1303 * presented as text while files are saved to disk. Note that it is the sole responsibility of the application to clean up the files generated by the framework. This can be done by keeping track of
1304 * which files are used (e.g. using the request.app object), and listening to the server 'response' event to perform cleanup. For context [See
1305 * docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadoutput)
1306 */
1307export type PayloadOutput = "data" | "stream" | "file";
1308
1309/**
1310 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadcompression)
1311 */
1312export type PayloadCompressionDecoderSettings = object;
1313
1314/**
1315 * Determines how the request payload is processed.
1316 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayload)
1317 */
1318export interface RouteOptionsPayload {
1319 /**
1320 * Default value: allows parsing of the following mime types:
1321 * * application/json
1322 * * application/*+json
1323 * * application/octet-stream
1324 * * application/x-www-form-urlencoded
1325 * * multipart/form-data
1326 * * text/*
1327 * A string or an array of strings with the allowed mime types for the endpoint. Use this settings to limit the set of allowed mime types. Note that allowing additional mime types not listed
1328 * above will not enable them to be parsed, and if parse is true, the request will result in an error response.
1329 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadallow)
1330 */
1331 allow?: string | string[] | undefined;
1332
1333 /**
1334 * Default value: none.
1335 * An object where each key is a content-encoding name and each value is an object with the desired decoder settings. Note that encoder settings are set in compression.
1336 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadcompression)
1337 */
1338 compression?: Util.Dictionary<PayloadCompressionDecoderSettings> | undefined;
1339
1340 /**
1341 * Default value: 'application/json'.
1342 * The default content type if the 'Content-Type' request header is missing.
1343 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloaddefaultcontenttype)
1344 */
1345 defaultContentType?: string | undefined;
1346
1347 /**
1348 * Default value: 'error' (return a Bad Request (400) error response).
1349 * A failAction value which determines how to handle payload parsing errors.
1350 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadfailaction)
1351 */
1352 failAction?: Lifecycle.FailAction | undefined;
1353
1354 /**
1355 * Default value: 1048576 (1MB).
1356 * Limits the size of incoming payloads to the specified byte count. Allowing very large payloads may cause the server to run out of memory.
1357 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadmaxbytes)
1358 */
1359 maxBytes?: number | undefined;
1360
1361 /**
1362 * Default value: none.
1363 * Overrides payload processing for multipart requests. Value can be one of:
1364 * * false - disable multipart processing.
1365 * an object with the following required options:
1366 * * output - same as the output option with an additional value option:
1367 * * * annotated - wraps each multipart part in an object with the following keys: // TODO type this?
1368 * * * * headers - the part headers.
1369 * * * * filename - the part file name.
1370 * * * * payload - the processed part payload.
1371 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadmultipart)
1372 */
1373 multipart?: false | {
1374 output: PayloadOutput | "annotated";
1375 } | undefined;
1376
1377 /**
1378 * Default value: 'data'.
1379 * The processed payload format. The value must be one of:
1380 * * 'data' - the incoming payload is read fully into memory. If parse is true, the payload is parsed (JSON, form-decoded, multipart) based on the 'Content-Type' header. If parse is false, a raw
1381 * Buffer is returned.
1382 * * 'stream' - the incoming payload is made available via a Stream.Readable interface. If the payload is 'multipart/form-data' and parse is true, field values are presented as text while files
1383 * are provided as streams. File streams from a 'multipart/form-data' upload will also have a hapi property containing the filename and headers properties. Note that payload streams for multipart
1384 * payloads are a synthetic interface created on top of the entire mutlipart content loaded into memory. To avoid loading large multipart payloads into memory, set parse to false and handle the
1385 * multipart payload in the handler using a streaming parser (e.g. pez).
1386 * * 'file' - the incoming payload is written to temporary file in the directory specified by the uploads settings. If the payload is 'multipart/form-data' and parse is true, field values are
1387 * presented as text while files are saved to disk. Note that it is the sole responsibility of the application to clean up the files generated by the framework. This can be done by keeping track
1388 * of which files are used (e.g. using the request.app object), and listening to the server 'response' event to perform cleanup.
1389 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadoutput)
1390 */
1391 output?: PayloadOutput | undefined;
1392
1393 /**
1394 * Default value: none.
1395 * A mime type string overriding the 'Content-Type' header value received.
1396 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadoverride)
1397 */
1398 override?: string | undefined;
1399
1400 /**
1401 * Default value: true.
1402 * Determines if the incoming payload is processed or presented raw. Available values:
1403 * * true - if the request 'Content-Type' matches the allowed mime types set by allow (for the whole payload as well as parts), the payload is converted into an object when possible. If the
1404 * format is unknown, a Bad Request (400) error response is sent. Any known content encoding is decoded.
1405 * * false - the raw payload is returned unmodified.
1406 * * 'gunzip' - the raw payload is returned unmodified after any known content encoding is decoded.
1407 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadparse)
1408 */
1409 parse?: boolean | "gunzip" | undefined;
1410
1411 /**
1412 * Default value: to 10000 (10 seconds).
1413 * Payload reception timeout in milliseconds. Sets the maximum time allowed for the client to transmit the request payload (body) before giving up and responding with a Request Timeout (408)
1414 * error response. Set to false to disable.
1415 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloadtimeout)
1416 */
1417 timeout?: false | number | undefined;
1418
1419 /**
1420 * Default value: os.tmpdir().
1421 * The directory used for writing file uploads.
1422 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspayloaduploads)
1423 */
1424 uploads?: string | undefined;
1425}
1426
1427/**
1428 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
1429 */
1430export type RouteOptionsPreArray = RouteOptionsPreAllOptions[];
1431
1432/**
1433 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
1434 */
1435export type RouteOptionsPreAllOptions = RouteOptionsPreObject | RouteOptionsPreObject[] | Lifecycle.Method;
1436
1437/**
1438 * An object with:
1439 * * method - a lifecycle method.
1440 * * assign - key name used to assign the response of the method to in request.pre and request.preResponses.
1441 * * failAction - A failAction value which determine what to do when a pre-handler method throws an error. If assign is specified and the failAction setting is not 'error', the error will be assigned.
1442 * For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
1443 */
1444export interface RouteOptionsPreObject {
1445 /**
1446 * a lifecycle method.
1447 */
1448 method: Lifecycle.Method;
1449 /**
1450 * key name used to assign the response of the method to in request.pre and request.preResponses.
1451 */
1452 assign?: string | undefined;
1453 /**
1454 * A failAction value which determine what to do when a pre-handler method throws an error. If assign is specified and the failAction setting is not 'error', the error will be assigned.
1455 */
1456 failAction?: Lifecycle.FailAction | undefined;
1457}
1458
1459export type ValidationObject = SchemaMap;
1460
1461/**
1462 * * true - any query parameter value allowed (no validation performed). false - no parameter value allowed.
1463 * * a joi validation object.
1464 * * a validation function using the signature async function(value, options) where:
1465 * * * value - the request.* object containing the request parameters.
1466 * * * options - options.
1467 */
1468export type RouteOptionsResponseSchema =
1469 | boolean
1470 | ValidationObject
1471 | Schema
1472 | ((value: object | Buffer | string, options: ValidationOptions) => Promise<any>);
1473
1474/**
1475 * Processing rules for the outgoing response.
1476 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponse)
1477 */
1478export interface RouteOptionsResponse {
1479 /**
1480 * Default value: 200.
1481 * The default HTTP status code when the payload is considered empty. Value can be 200 or 204. Note that a 200 status code is converted to a 204 only at the time of response transmission (the
1482 * response status code will remain 200 throughout the request lifecycle unless manually set).
1483 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponseemptystatuscode)
1484 */
1485 emptyStatusCode?: 200 | 204 | undefined;
1486
1487 /**
1488 * Default value: 'error' (return an Internal Server Error (500) error response).
1489 * A failAction value which defines what to do when a response fails payload validation.
1490 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponsefailaction)
1491 */
1492 failAction?: Lifecycle.FailAction | undefined;
1493
1494 /**
1495 * Default value: false.
1496 * If true, applies the validation rule changes to the response payload.
1497 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponsemodify)
1498 */
1499 modify?: boolean | undefined;
1500
1501 /**
1502 * Default value: none.
1503 * [joi](https://github.com/hapijs/joi) options object pass to the validation function. Useful to set global options such as stripUnknown or abortEarly (the complete list is available here). If a
1504 * custom validation function is defined via schema or status then options can an arbitrary object that will be passed to this function as the second argument.
1505 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponseoptions)
1506 */
1507 options?: ValidationOptions | undefined; // TODO needs validation
1508
1509 /**
1510 * Default value: true.
1511 * If false, payload range support is disabled.
1512 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponseranges)
1513 */
1514 ranges?: boolean | undefined;
1515
1516 /**
1517 * Default value: 100 (all responses).
1518 * The percent of response payloads validated (0 - 100). Set to 0 to disable all validation.
1519 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponsesample)
1520 */
1521 sample?: number | undefined;
1522
1523 /**
1524 * Default value: true (no validation).
1525 * The default response payload validation rules (for all non-error responses) expressed as one of:
1526 * * true - any payload allowed (no validation).
1527 * * false - no payload allowed.
1528 * * a joi validation object. The options along with the request context ({ headers, params, query, payload, app, auth }) are passed to the validation function.
1529 * * a validation function using the signature async function(value, options) where:
1530 * * * value - the pending response payload.
1531 * * * options - The options along with the request context ({ headers, params, query, payload, app, auth }).
1532 * * * if the function returns a value and modify is true, the value is used as the new response. If the original response is an error, the return value is used to override the original error
1533 * output.payload. If an error is thrown, the error is processed according to failAction.
1534 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponseschema)
1535 */
1536 schema?: RouteOptionsResponseSchema | undefined;
1537
1538 /**
1539 * Default value: none.
1540 * Validation schemas for specific HTTP status codes. Responses (excluding errors) not matching the listed status codes are validated using the default schema.
1541 * status is set to an object where each key is a 3 digit HTTP status code and the value has the same definition as schema.
1542 * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsresponsestatus)
1543 */
1544 status?: Util.Dictionary<RouteOptionsResponseSchema> | undefined;
1545
1546 /**
1547 * The default HTTP status code used to set a response error when the request is closed or aborted before the
1548 * response is fully transmitted.
1549 * Value can be any integer greater or equal to 400.
1550 * The default value 499 is based on the non-standard nginx "CLIENT CLOSED REQUEST" error.
1551