1
+ import {
2
+ APIGatewayEventRequestContext ,
3
+ APIGatewayProxyHandler ,
4
+ Context ,
5
+ } from 'aws-lambda' ;
6
+
7
+ declare interface CookieOptions {
8
+ domain : string ;
9
+ expires : Date ;
10
+ httpOnly : boolean ;
11
+ maxAge : number ;
12
+ path : string ;
13
+ secure : boolean ;
14
+ sameSite : boolean | 'Strict' | 'Lax' ;
15
+ }
16
+
17
+ declare interface CorsOptions {
18
+ credentials : boolean ;
19
+ exposeHeaders : string ;
20
+ headers : string ;
21
+ maxAge : number ;
22
+ methods : string ;
23
+ origin : string ;
24
+ }
25
+
26
+ declare interface FileOptions {
27
+ maxAge : number ;
28
+ root : string ;
29
+ lastModified : boolean | string ;
30
+ headers : { } ;
31
+ cacheControl : boolean | string ;
32
+ private : boolean ;
33
+ }
34
+
35
+ declare interface App {
36
+ [ namespace : string ] : HandlerFunction ;
37
+ }
38
+ declare type ErrorCallback = ( error ?: Error ) => void ;
39
+ declare type HandlerFunction = ( req : Request , res ) => void | { } | Promise < { } > ;
40
+ declare type LoggerFunction = ( message : string ) => void ;
41
+ declare type NextFunction = ( ) => void ;
42
+ declare type TimestampFunction = ( ) => string ;
43
+ declare type FinallyFunction = ( req : Request , res : Response ) => void ;
44
+
45
+ declare type METHODS = 'GET'
46
+ | 'POST'
47
+ | 'PUT'
48
+ | 'PATCH'
49
+ | 'DELETE'
50
+ | 'OPTIONS'
51
+ | 'HEAD'
52
+ | 'ANY' ;
53
+
54
+ declare interface SamplingOptions {
55
+ route : string ;
56
+ target : number ;
57
+ rate : number
58
+ period : number ;
59
+ method : string | string [ ] ;
60
+ }
61
+
62
+ declare interface LoggerOptions {
63
+ access : boolean | string ;
64
+ customKey : string ;
65
+ detail : boolean ;
66
+ level : string ;
67
+ levels : {
68
+ [ key : string ] : string ;
69
+ } ;
70
+ messageKey : string ;
71
+ nested : boolean ;
72
+ timestamp : boolean | TimestampFunction ;
73
+ sampling : {
74
+ target : number ;
75
+ rate : number ;
76
+ period : number ;
77
+ rules : SamplingOptions [ ] ;
78
+ } ;
79
+ serializers : {
80
+ [ name : string ] : ( req : Request ) => { } ;
81
+ } ;
82
+ stack : boolean ;
83
+ }
84
+
85
+ declare interface Options {
86
+ base : string ;
87
+ callbackName : string ;
88
+ logger : boolean | LoggerOptions ;
89
+ mimeTypes : {
90
+ [ key : string ] : string ;
91
+ } ;
92
+ version : string ;
93
+ }
94
+
95
+ declare class Request {
96
+ app : API ;
97
+ version : string ;
98
+ id : string ;
99
+ params : { } ;
100
+ method : string ;
101
+ path : string ;
102
+ query : {
103
+ [ key : string ] : string ;
104
+ } ;
105
+ headers : {
106
+ [ key : string ] : string ;
107
+ } ;
108
+ rawHeaders ?: { } ;
109
+ body : { } | string ;
110
+ rawBody : string ;
111
+ route : '' ;
112
+ requestContext : APIGatewayEventRequestContext ;
113
+ auth : {
114
+ [ key : string ] : any ;
115
+ type : 'Bearer' | 'Basic' | 'OAuth' | 'Digest' ;
116
+ value : string ;
117
+ } ;
118
+ cookies : {
119
+ [ key : string ] : CookieOptions ;
120
+ } ;
121
+ context : Context ;
122
+ coldStart : boolean ;
123
+ requestCount : number ;
124
+ ip : string ;
125
+ userAgent : string ;
126
+ clientType : 'desktop' | 'mobile' | 'tv' | 'tablet' | 'unknown' ;
127
+ clientCountry : string ;
128
+
129
+ log : {
130
+ trace : LoggerFunction ;
131
+ debug : LoggerFunction ;
132
+ info : LoggerFunction ;
133
+ warn : LoggerFunction ;
134
+ error : LoggerFunction ;
135
+ fatal : LoggerFunction ;
136
+ } ;
137
+ }
138
+
139
+ declare class Response {
140
+ status ( code : number ) : this;
141
+ header ( key : string , value : string ) : this;
142
+ getHeader ( key : string ) : string ;
143
+ hasHeader ( key : string ) : boolean ;
144
+ removeHeader ( key : string ) : this;
145
+ getLink ( s3Path : string , expires ?: number , callback ?: ( err , data ) => void ) ;
146
+ send ( body : any ) : void ;
147
+ json ( body : any ) : void ;
148
+ jsonp ( body : any ) : void ;
149
+ html ( body : any ) : void ;
150
+ type ( type : string ) : void ;
151
+ location ( path : string ) : this;
152
+ redirect ( status : number , path : string ) : void ;
153
+ redirect ( path : string ) : void ;
154
+ cors ( options : CorsOptions ) : this;
155
+ error ( message : string , detail ?: any ) ;
156
+ error ( code : number , message : string , detail ?: any ) ;
157
+ cookie ( name : string , value : string , options ?: CookieOptions ) : this;
158
+ clearCookie ( name : string , options ?: CookieOptions ) : this;
159
+ etag ( enable ?: boolean ) : this;
160
+ cache ( age ?: boolean | number | string , private ?: boolean ) : this;
161
+ modified ( date : boolean | string | Date ) : this;
162
+ attachment ( fileName ?: string ) : this;
163
+ download ( file : string | Buffer , fileName ?: string , options ?: FileOptions , callback ?: ErrorCallback ) ;
164
+ sendFile ( file : string | Buffer , options ?: FileOptions , callback ?: ErrorCallback ) ;
165
+ }
166
+
167
+ declare class API {
168
+ app ( namespace : string , handler : HandlerFunction ) : App ;
169
+ app ( options : App ) : App ;
170
+
171
+ get ( path : string , handler : HandlerFunction ) : void ;
172
+ post ( path : string , handler : HandlerFunction ) : void ;
173
+ put ( path : string , handler : HandlerFunction ) : void ;
174
+ patch ( path : string , handler : HandlerFunction ) : void ;
175
+ delete ( path : string , handler : HandlerFunction ) : void ;
176
+ options ( path : string , handler : HandlerFunction ) : void ;
177
+ head ( path : string , handler : HandlerFunction ) : void ;
178
+ any ( path : string , handler : HandlerFunction ) : void ;
179
+ METHOD ( method : METHODS , path : string , handler : HandlerFunction ) : void ;
180
+
181
+ use ( req : Request , res : Response , next : NextFunction ) : void ;
182
+ finally ( callback : FinallyFunction ) : void ;
183
+
184
+ run : APIGatewayProxyHandler ;
185
+ }
186
+
187
+ declare function createAPI ( options ?: Options ) : API ;
188
+
189
+ export default createAPI ;
0 commit comments