hapii-js 0.0.0-stage → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,568 @@
1
+
2
+ import { Podium } from '@hapi/podium';
3
+
4
+ import { PluginsStates, ServerRealm } from './plugin';
5
+ import {
6
+ UserCredentials,
7
+ AppCredentials,
8
+ AuthArtifacts,
9
+ AuthCredentials,
10
+ ReqRef,
11
+ ReqRefDefaults,
12
+ MergeRefs,
13
+ Request
14
+ } from './request';
15
+ import { PeekListener, Lifecycle, Json } from './utils';
16
+ import { ServerStateCookieOptions } from './server';
17
+
18
+ /**
19
+ * User-extensible type for application specific state on responses (`response.app`).
20
+ */
21
+ export interface ResponseApplicationState {
22
+ }
23
+
24
+ /**
25
+ * Access: read only and the public podium interface.
26
+ * The response.events object supports the following events:
27
+ * * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
28
+ * * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
29
+ * [See docs](https://hapijs.com/api/17.0.1#-responseevents)
30
+ */
31
+ export interface ResponseEvents extends Podium {
32
+ /**
33
+ * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
34
+ * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
35
+ */
36
+ on(criteria: 'peek', listener: PeekListener): this;
37
+
38
+ on(criteria: 'finish', listener: (data: undefined) => void): this;
39
+
40
+ /**
41
+ * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
42
+ * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
43
+ */
44
+ once(criteria: 'peek', listener: PeekListener): this;
45
+ once(criteria: 'peek'): Promise<Parameters<PeekListener>>;
46
+
47
+ once(criteria: 'finish', listener: (data: undefined) => void): this;
48
+ }
49
+
50
+ /**
51
+ * Object where:
52
+ * * append - if true, the value is appended to any existing header value using separator. Defaults to false.
53
+ * * separator - string used as separator when appending to an existing value. Defaults to ','.
54
+ * * override - if false, the header value is not set if an existing value present. Defaults to true.
55
+ * * 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.
56
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheadername-value-options)
57
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#response-object)
58
+ */
59
+ export interface ResponseObjectHeaderOptions {
60
+ append?: boolean | undefined;
61
+ separator?: string | undefined;
62
+ override?: boolean | undefined;
63
+ duplicate?: boolean | undefined;
64
+ }
65
+
66
+ /**
67
+ * The response object contains the request response value along with various HTTP headers and flags. When a lifecycle
68
+ * method returns a value, the value is wrapped in a response object along with some default flags (e.g. 200 status
69
+ * code). In order to customize a response before it is returned, the h.response() method is provided.
70
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#response-object)
71
+ * 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)
72
+ */
73
+ export interface ResponseObject extends Podium {
74
+ /**
75
+ * @default {}.
76
+ * 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].
77
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseapp)
78
+ */
79
+ app: ResponseApplicationState;
80
+
81
+ /**
82
+ * Access: read only and the public podium interface.
83
+ * The response.events object supports the following events:
84
+ * * 'peek' - emitted for each chunk of data written back to the client connection. The event method signature is function(chunk, encoding).
85
+ * * 'finish' - emitted when the response finished writing but before the client response connection is ended. The event method signature is function ().
86
+ * [See docs](https://hapijs.com/api/17.0.1#-responseevents)
87
+ */
88
+ readonly events: ResponseEvents;
89
+
90
+ /**
91
+ * @default {}.
92
+ * 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.
93
+ * 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.
94
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheaders)
95
+ */
96
+ readonly headers: Record<string, string | string[]>;
97
+
98
+ /**
99
+ * @default {}.
100
+ * 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.
101
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseplugins)
102
+ */
103
+ plugins: PluginsStates;
104
+
105
+ /**
106
+ * Object containing the response handling flags.
107
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesettings)
108
+ */
109
+ readonly settings: ResponseSettings;
110
+
111
+ /**
112
+ * The raw value returned by the lifecycle method.
113
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesource)
114
+ */
115
+ readonly source: Lifecycle.ReturnValue;
116
+
117
+ /**
118
+ * @default 200.
119
+ * The HTTP response status code.
120
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsestatuscode)
121
+ */
122
+ readonly statusCode: number;
123
+
124
+ /**
125
+ * A string indicating the type of source with available values:
126
+ * * 'plain' - a plain response such as string, number, null, or simple object.
127
+ * * 'buffer' - a Buffer.
128
+ * * 'stream' - a Stream.
129
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsevariety)
130
+ */
131
+ readonly variety: 'plain' | 'buffer' | 'stream';
132
+
133
+ /**
134
+ * Sets the HTTP 'Content-Length' header (to avoid chunked transfer encoding) where:
135
+ * @param length - the header value. Must match the actual payload size.
136
+ * @return Return value: the current response object.
137
+ * [See docs](https://hapijs.com/api/17.0.1#-responsebyteslength)
138
+ */
139
+ bytes(length: number): ResponseObject;
140
+
141
+ /**
142
+ * Controls the 'Content-Type' HTTP header 'charset' property of the response.
143
+ * * When invoked without any parameter, will prevent hapi from applying its default charset normalization to 'utf-8'
144
+ * * When 'charset' parameter is provided, will set the 'Content-Type' HTTP header 'charset' property where:
145
+ * @param charset - the charset property value.
146
+ * @return Return value: the current response object.
147
+ * [See docs](https://hapijs.com/api/17.0.1#-responsecharsetcharset)
148
+ */
149
+ charset(charset?: string): ResponseObject | undefined;
150
+
151
+ /**
152
+ * Sets the HTTP status code where:
153
+ * @param statusCode - the HTTP status code (e.g. 200).
154
+ * @return Return value: the current response object.
155
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsecodestatuscode)
156
+ */
157
+ code(statusCode: number): ResponseObject;
158
+
159
+ /**
160
+ * Sets the HTTP status message where:
161
+ * @param httpMessage - the HTTP status message (e.g. 'Ok' for status code 200).
162
+ * @return Return value: the current response object.
163
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsemessagehttpmessage)
164
+ */
165
+ message(httpMessage: string): ResponseObject;
166
+
167
+ /**
168
+ * Sets the HTTP 'content-encoding' header where:
169
+ * @param encoding - the header value string.
170
+ * @return Return value: the current response object.
171
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsecompressedencoding)
172
+ */
173
+ compressed(encoding: string): ResponseObject;
174
+
175
+ /**
176
+ * Sets the HTTP status code to Created (201) and the HTTP 'Location' header where:
177
+ * @param uri - an absolute or relative URI used as the 'Location' header value.
178
+ * @return Return value: the current response object.
179
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsecreateduri)
180
+ */
181
+ created(uri: string): ResponseObject;
182
+
183
+ /**
184
+ * Sets the string encoding scheme used to serial data into the HTTP payload where:
185
+ * @param encoding the encoding property value (see node Buffer encoding [See docs](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings)).
186
+ * * 'ascii' - for 7-bit ASCII data only. This encoding is fast and will strip the high bit if set.
187
+ * * 'utf8' - Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.
188
+ * * 'utf16le' - 2 or 4 bytes, little-endian encoded Unicode characters. Surrogate pairs (U+10000 to U+10FFFF) are supported.
189
+ * * 'ucs2' - Alias of 'utf16le'.
190
+ * * '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.
191
+ * * '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).
192
+ * * 'binary' - Alias for 'latin1'.
193
+ * * 'hex' - Encode each byte as two hexadecimal characters.
194
+ * @return Return value: the current response object.
195
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseencodingencoding)
196
+ */
197
+ encoding(encoding: 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64' | 'latin1' | 'binary' | 'hex'): ResponseObject;
198
+
199
+ /**
200
+ * Sets the representation entity tag where:
201
+ * @param tag - the entity tag string without the double-quote.
202
+ * @param options - (optional) settings where:
203
+ * * 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.
204
+ * * 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
205
+ * a '-' character). Ignored when weak is true. Defaults to true.
206
+ * @return Return value: the current response object.
207
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseetagtag-options)
208
+ */
209
+ etag(tag: string, options?: {weak: boolean, vary: boolean} | undefined): ResponseObject;
210
+
211
+ /**
212
+ * Sets an HTTP header where:
213
+ * @param name - the header name.
214
+ * @param value - the header value.
215
+ * @param options - (optional) object where:
216
+ * * append - if true, the value is appended to any existing header value using separator. Defaults to false.
217
+ * * separator - string used as separator when appending to an existing value. Defaults to ','.
218
+ * * override - if false, the header value is not set if an existing value present. Defaults to true.
219
+ * * 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.
220
+ * @return Return value: the current response object.
221
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseheadername-value-options)
222
+ */
223
+ header(name: string, value: string, options?: ResponseObjectHeaderOptions | undefined): ResponseObject;
224
+
225
+ /**
226
+ * Sets the HTTP 'Location' header where:
227
+ * @param uri - an absolute or relative URI used as the 'Location' header value.
228
+ * @return Return value: the current response object.
229
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responselocationuri)
230
+ */
231
+ location(uri: string): ResponseObject;
232
+
233
+ /**
234
+ * Sets an HTTP redirection response (302) and decorates the response with additional methods, where:
235
+ * @param uri - an absolute or relative URI used to redirect the client to another resource.
236
+ * @return Return value: the current response object.
237
+ * Decorates the response object with the response.temporary(), response.permanent(), and response.rewritable() methods to easily change the default redirection code (302).
238
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseredirecturi)
239
+ */
240
+ redirect(uri: string): ResponseObject;
241
+
242
+ /**
243
+ * Sets the JSON.stringify() replacer argument where:
244
+ * @param method - the replacer function or array. Defaults to none.
245
+ * @return Return value: the current response object.
246
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsereplacermethod)
247
+ */
248
+ replacer(method: Json.StringifyReplacer): ResponseObject;
249
+
250
+ /**
251
+ * Sets the JSON.stringify() space argument where:
252
+ * @param count - the number of spaces to indent nested object keys. Defaults to no indentation.
253
+ * @return Return value: the current response object.
254
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsespacescount)
255
+ */
256
+ spaces(count: number): ResponseObject;
257
+
258
+ /**
259
+ * Sets an HTTP cookie where:
260
+ * @param name - the cookie name.
261
+ * @param value - the cookie value. If no options.encoding is defined, must be a string. See server.state() for supported encoding values.
262
+ * @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
263
+ * definition.
264
+ * @return Return value: the current response object.
265
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsestatename-value-options)
266
+ */
267
+ state(name: string, value: object | string, options?: ServerStateCookieOptions | undefined): ResponseObject;
268
+
269
+ /**
270
+ * Sets a string suffix when the response is process via JSON.stringify() where:
271
+ * @param suffix - the string suffix.
272
+ * @return Return value: the current response object.
273
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesuffixsuffix)
274
+ */
275
+ suffix(suffix: string): ResponseObject;
276
+
277
+ /**
278
+ * Overrides the default route cache expiration rule for this response instance where:
279
+ * @param msec - the time-to-live value in milliseconds.
280
+ * @return Return value: the current response object.
281
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsettlmsec)
282
+ */
283
+ ttl(msec: number): ResponseObject;
284
+
285
+ /**
286
+ * Sets the HTTP 'Content-Type' header where:
287
+ * @param mimeType - is the mime type.
288
+ * @return Return value: the current response object.
289
+ * Should only be used to override the built-in default for each response type.
290
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsetypemimetype)
291
+ */
292
+ type(mimeType: string): ResponseObject;
293
+
294
+ /**
295
+ * Clears the HTTP cookie by setting an expired value where:
296
+ * @param name - the cookie name.
297
+ * @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
298
+ * definition.
299
+ * @return Return value: the current response object.
300
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responseunstatename-options)
301
+ */
302
+ unstate(name: string, options?: ServerStateCookieOptions | undefined): ResponseObject;
303
+
304
+ /**
305
+ * Adds the provided header to the list of inputs affected the response generation via the HTTP 'Vary' header where:
306
+ * @param header - the HTTP request header name.
307
+ * @return Return value: the current response object.
308
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsevaryheader)
309
+ */
310
+ vary(header: string): ResponseObject;
311
+
312
+ /**
313
+ * Marks the response object as a takeover response.
314
+ * @return Return value: the current response object.
315
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsetakeover)
316
+ */
317
+ takeover(): ResponseObject;
318
+
319
+ /**
320
+ * Sets the status code to 302 or 307 (based on the response.rewritable() setting) where:
321
+ * @param isTemporary - if false, sets status to permanent. Defaults to true.
322
+ * @return Return value: the current response object.
323
+ * Only available after calling the response.redirect() method.
324
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsetemporaryistemporary)
325
+ */
326
+ temporary(isTemporary?: boolean): ResponseObject;
327
+
328
+ /**
329
+ * Sets the status code to 301 or 308 (based on the response.rewritable() setting) where:
330
+ * @param isPermanent - if false, sets status to temporary. Defaults to true.
331
+ * @return Return value: the current response object.
332
+ * Only available after calling the response.redirect() method.
333
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsepermanentispermanent)
334
+ */
335
+ permanent(isPermanent?: boolean): ResponseObject;
336
+
337
+ /**
338
+ * 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'
339
+ * to 'GET'). Exact code based on the response.temporary() or response.permanent() setting. Arguments:
340
+ * @param isRewritable - if false, sets to non-rewritable. Defaults to true.
341
+ * @return Return value: the current response object.
342
+ * Only available after calling the response.redirect() method.
343
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responserewritableisrewritable)
344
+ */
345
+ rewritable(isRewritable?: boolean): ResponseObject;
346
+ }
347
+
348
+ /**
349
+ * Object containing the response handling flags.
350
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-responsesettings)
351
+ */
352
+ export interface ResponseSettings {
353
+ /**
354
+ * Defaults value: true.
355
+ * If true and source is a Stream, copies the statusCode and headers properties of the stream object to the outbound response.
356
+ */
357
+ readonly passThrough: boolean;
358
+
359
+ /**
360
+ * @default null (use route defaults).
361
+ * Override the route json options used when source value requires stringification.
362
+ */
363
+ readonly stringify: Json.StringifyArguments;
364
+
365
+ /**
366
+ * @default null (use route defaults).
367
+ * If set, overrides the route cache with an expiration value in milliseconds.
368
+ */
369
+ readonly ttl: number;
370
+
371
+ /**
372
+ * @default false.
373
+ * 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.
374
+ */
375
+ varyEtag: boolean;
376
+ }
377
+
378
+ /**
379
+ * See more about Lifecycle
380
+ * https://github.com/hapijs/hapi/blob/master/API.md#request-lifecycle
381
+ *
382
+ */
383
+
384
+ export type ResponseValue = string | object;
385
+
386
+ export interface AuthenticationData<
387
+
388
+ AuthUser = UserCredentials,
389
+ AuthApp = AppCredentials,
390
+ CredentialsExtra = Record<string, unknown>,
391
+ ArtifactsExtra = AuthArtifacts
392
+ > {
393
+ credentials: AuthCredentials<AuthUser, AuthApp> & CredentialsExtra;
394
+ artifacts?: ArtifactsExtra | undefined;
395
+ }
396
+
397
+ export interface Auth<
398
+ AuthUser = UserCredentials,
399
+ AuthApp = AppCredentials,
400
+ CredentialsExtra = Record<string, unknown>,
401
+ ArtifactsExtra = AuthArtifacts
402
+ > {
403
+ readonly isAuth: true;
404
+ readonly error?: Error | null | undefined;
405
+ readonly data?: AuthenticationData<AuthUser, AuthApp, CredentialsExtra, ArtifactsExtra> | undefined;
406
+ }
407
+
408
+ /**
409
+ * 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)
410
+ * It is somewhat hard to define as it provides both utilities for manipulating responses as well as other information. Since the
411
+ * toolkit is passed as a function argument, developers can name it whatever they want. For the purpose of this
412
+ * document the h notation is used. It is named in the spirit of the RethinkDB r method, with h for hapi.
413
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#response-toolkit)
414
+ */
415
+ export interface ResponseToolkit<Refs extends ReqRef = ReqRefDefaults> {
416
+ /**
417
+ * A response symbol. When returned by a lifecycle method, the request lifecycle skips to the finalizing step
418
+ * without further interaction with the node response stream. It is the developer's responsibility to write
419
+ * and end the response directly via [request.raw.res](https://github.com/hapijs/hapi/blob/master/API.md#request.raw).
420
+ */
421
+ readonly abandon: symbol;
422
+
423
+ /**
424
+ * A response symbol. When returned by a lifecycle method, the request lifecycle skips to the finalizing step after
425
+ * calling request.raw.res.end()) to close the the node response stream.
426
+ */
427
+ readonly close: symbol;
428
+
429
+ /**
430
+ * 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)
431
+ * option or [server.bind()](https://github.com/hapijs/hapi/blob/master/API.md#server.bind()).
432
+ */
433
+ readonly context: any;
434
+
435
+ /**
436
+ * A response symbol. When returned by a lifecycle method, the request lifecycle continues without changing the response.
437
+ */
438
+ readonly continue: symbol;
439
+
440
+ /**
441
+ * The [server realm](https://github.com/hapijs/hapi/blob/master/API.md#server.realm) associated with the matching
442
+ * route. Defaults to the root server realm in the onRequest step.
443
+ */
444
+ readonly realm: ServerRealm;
445
+
446
+ /**
447
+ * Access: read only and public request interface.
448
+ * The [request] object. This is a duplication of the request lifecycle method argument used by
449
+ * [toolkit decorations](https://github.com/hapijs/hapi/blob/master/API.md#server.decorate()) to access the current request.
450
+ */
451
+ readonly request: Readonly<Request<Refs>>;
452
+
453
+ /**
454
+ * Used by the [authentication] method to pass back valid credentials where:
455
+ * @param data - an object with:
456
+ * * credentials - (required) object representing the authenticated entity.
457
+ * * artifacts - (optional) authentication artifacts object specific to the authentication scheme.
458
+ * @return Return value: an internal authentication object.
459
+ */
460
+ authenticated <
461
+ AuthUser = MergeRefs<Refs>['AuthUser'],
462
+ AuthApp = MergeRefs<Refs>['AuthApp'],
463
+ CredentialsExtra = MergeRefs<Refs>['AuthCredentialsExtra'],
464
+ ArtifactsExtra = MergeRefs<Refs>['AuthArtifactsExtra']
465
+ >(
466
+ data: (
467
+ AuthenticationData<
468
+ AuthUser,
469
+ AuthApp,
470
+ CredentialsExtra,
471
+ ArtifactsExtra
472
+ >
473
+ )
474
+ ): Auth<
475
+ AuthUser,
476
+ AuthApp,
477
+ CredentialsExtra,
478
+ ArtifactsExtra
479
+ >;
480
+
481
+ /**
482
+ * Sets the response 'ETag' and 'Last-Modified' headers and checks for any conditional request headers to decide if
483
+ * the response is going to qualify for an HTTP 304 (Not Modified). If the entity values match the request
484
+ * conditions, h.entity() returns a response object for the lifecycle method to return as its value which will
485
+ * set a 304 response. Otherwise, it sets the provided entity headers and returns undefined.
486
+ * The method arguments are:
487
+ * @param options - a required configuration object with:
488
+ * * etag - the ETag string. Required if modified is not present. Defaults to no header.
489
+ * * modified - the Last-Modified header value. Required if etag is not present. Defaults to no header.
490
+ * * vary - same as the response.etag() option. Defaults to true.
491
+ * @return Return value: - a response object if the response is unmodified. - undefined if the response has changed.
492
+ * If undefined is returned, the developer must return a valid lifecycle method value. If a response is returned,
493
+ * it should be used as the return value (but may be customize using the response methods).
494
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hentityoptions)
495
+ */
496
+ entity(options?: {etag?: string | undefined, modified?: string | undefined, vary?: boolean | undefined} | undefined): ResponseObject;
497
+
498
+ /**
499
+ * Redirects the client to the specified uri. Same as calling h.response().redirect(uri).
500
+ * @param url
501
+ * @return Returns a response object.
502
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hredirecturi)
503
+ */
504
+ redirect(uri?: string | undefined): ResponseObject;
505
+
506
+ /**
507
+ * Wraps the provided value and returns a response object which allows customizing the response
508
+ * (e.g. setting the HTTP status code, custom headers, etc.), where:
509
+ * @param value - (optional) return value. Defaults to null.
510
+ * @return Returns a response object.
511
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hresponsevalue)
512
+ */
513
+ response(value?: ResponseValue | undefined): ResponseObject;
514
+
515
+ /**
516
+ * Sets a response cookie using the same arguments as response.state().
517
+ * @param name of the cookie
518
+ * @param value of the cookie
519
+ * @param (optional) ServerStateCookieOptions object.
520
+ * @return Return value: none.
521
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hstatename-value-options)
522
+ */
523
+ state(name: string, value: string | object, options?: ServerStateCookieOptions | undefined): void;
524
+
525
+ /**
526
+ * Used by the [authentication] method to indicate authentication failed and pass back the credentials received where:
527
+ * @param error - (required) the authentication error.
528
+ * @param data - (optional) an object with:
529
+ * * credentials - (required) object representing the authenticated entity.
530
+ * * artifacts - (optional) authentication artifacts object specific to the authentication scheme.
531
+ * @return void.
532
+ * The method is used to pass both the authentication error and the credentials. For example, if a request included
533
+ * expired credentials, it allows the method to pass back the user information (combined with a 'try'
534
+ * authentication mode) for error customization.
535
+ * 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.
536
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hunauthenticatederror-data)
537
+ */
538
+ unauthenticated <
539
+ AuthUser = MergeRefs<Refs>['AuthUser'],
540
+ AuthApp = MergeRefs<Refs>['AuthApp'],
541
+ CredentialsExtra = MergeRefs<Refs>['AuthCredentialsExtra'],
542
+ ArtifactsExtra = MergeRefs<Refs>['AuthArtifactsExtra']
543
+ >(
544
+ error: Error,
545
+ data?: (
546
+ AuthenticationData<
547
+ AuthUser,
548
+ AuthApp,
549
+ CredentialsExtra,
550
+ ArtifactsExtra
551
+ >
552
+ ) | undefined
553
+ ): Auth<
554
+ AuthUser,
555
+ AuthApp,
556
+ CredentialsExtra,
557
+ ArtifactsExtra
558
+ >;
559
+
560
+ /**
561
+ * Clears a response cookie using the same arguments as
562
+ * @param name of the cookie
563
+ * @param options (optional) ServerStateCookieOptions object.
564
+ * @return void.
565
+ * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-hunstatename-options)
566
+ */
567
+ unstate(name: string, options?: ServerStateCookieOptions | undefined): void;
568
+ }