@@ -27,23 +27,24 @@ export interface AppCredentials {
27
27
* User-extensible type for request.auth credentials.
28
28
*/
29
29
export interface AuthCredentials <
30
- AuthUser extends object = UserCredentials ,
31
- AuthApp extends object = AppCredentials ,
30
+ AuthUser = UserCredentials ,
31
+ AuthApp = AppCredentials
32
32
> {
33
33
/**
34
34
* The application scopes to be granted.
35
35
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionsauthaccessscope)
36
36
*/
37
37
scope ?: string [ ] | undefined ;
38
+
38
39
/**
39
40
* If set, will only work with routes that set `access.entity` to `user`.
40
41
*/
41
- user ?: MergeType < UserCredentials , AuthUser > | undefined ;
42
+ user ?: AuthUser
42
43
43
44
/**
44
45
* If set, will only work with routes that set `access.entity` to `app`.
45
46
*/
46
- app ?: MergeType < AppCredentials , AuthApp > | undefined ;
47
+ app ?: AuthApp ;
47
48
}
48
49
49
50
export interface AuthArtifacts {
@@ -65,15 +66,20 @@ export type AuthMode = 'required' | 'optional' | 'try';
65
66
* [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-requestauth)
66
67
*/
67
68
export interface RequestAuth <
68
- AuthUser extends object = UserCredentials ,
69
- AuthApp extends object = AppCredentials ,
70
- CredentialsExtra extends object = Record < string , unknown > ,
69
+ AuthUser = UserCredentials ,
70
+ AuthApp = AppCredentials ,
71
+ CredentialsExtra = Record < string , unknown > ,
71
72
ArtifactsExtra = Record < string , unknown >
72
73
> {
73
74
/** an artifact object received from the authentication strategy and used in authentication-related actions. */
74
75
artifacts : ArtifactsExtra ;
75
76
/** the credential object received during the authentication process. The presence of an object does not mean successful authentication. */
76
- credentials : MergeType < CredentialsExtra , AuthCredentials < AuthUser , AuthApp > > ;
77
+ credentials : (
78
+
79
+ AuthCredentials < AuthUser , AuthApp > &
80
+ CredentialsExtra
81
+ ) ;
82
+
77
83
/** the authentication error is failed and mode set to 'try'. */
78
84
error : Error ;
79
85
/** true if the request has been successfully authenticated, otherwise false. */
@@ -89,6 +95,7 @@ export interface RequestAuth<
89
95
strategy : string ;
90
96
}
91
97
98
+
92
99
/**
93
100
* 'peek' - emitted for each chunk of payload data read from the client connection. The event method signature is function(chunk, encoding).
94
101
* 'finish' - emitted when the request payload finished reading. The event method signature is function ().
@@ -296,7 +303,12 @@ export type ReqRef = Partial<Record<keyof ReqRefDefaults, unknown>>;
296
303
/**
297
304
* Utilities for merging request refs and other things
298
305
*/
299
- export type MergeType < T extends object , U extends object > = Omit < T , keyof U > & U ;
306
+ export type MergeType < T , U > = {
307
+ [ K in keyof T ] : K extends keyof U
308
+ ? U [ K ]
309
+ : T [ K ] ;
310
+ } ;
311
+
300
312
export type MergeRefs < T extends ReqRef > = MergeType < ReqRefDefaults , T > ;
301
313
302
314
/**
0 commit comments