quantum-flow 1.20.1 → 1.20.2
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.
- package/README.md +2 -2
- package/dist/app/aws/index.d.ts +1 -1
- package/dist/app/aws/utils/response.d.ts +12 -7
- package/dist/app/aws/utils/response.js +46 -15
- package/dist/app/aws/utils/response.js.map +1 -1
- package/dist/types/common.d.ts +11 -0
- package/dist/types/lambda.d.ts +13 -14
- package/dist/types/plugins.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -146,7 +146,7 @@ Use `LambdaAdapter` to convert API Gateway events to requests and responses. Cre
|
|
|
146
146
|
|
|
147
147
|
```typescript
|
|
148
148
|
Example Lambda handler creation
|
|
149
|
-
import { LambdaAdapter, LambdaRequest } from 'quantum-flow/aws';
|
|
149
|
+
import { LambdaAdapter, LambdaRequest, LambdaResponse } from 'quantum-flow/aws';
|
|
150
150
|
import { Request, Query, Headers, Params, Response } from 'quantum-flow/core'
|
|
151
151
|
|
|
152
152
|
@Controller({ prefix: 'user' })
|
|
@@ -156,7 +156,7 @@ class UserController {
|
|
|
156
156
|
@Headers() headers: Record<string, string | string[]>,
|
|
157
157
|
@Params(ParamDTO, 'param') params: string,
|
|
158
158
|
@Request() req: LambdaRequest,
|
|
159
|
-
@Response() res:
|
|
159
|
+
@Response() res: LambdaResponse
|
|
160
160
|
) { }
|
|
161
161
|
}
|
|
162
162
|
const lambdaAdapter = new LambdaAdapter(UserController);
|
package/dist/app/aws/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { LambdaEvent, LambdaRequest } from '../../types/index.js';
|
|
1
|
+
export { LambdaEvent, LambdaRequest, LambdaResponse } from '../../types/index.js';
|
|
2
2
|
export * from './lambda';
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare class LResponse implements ILResponse {
|
|
4
|
-
private originalResponse?;
|
|
1
|
+
import { CookieOptions, LambdaResponse } from '../../../types/index.js';
|
|
2
|
+
export declare class LResponse implements LambdaResponse {
|
|
5
3
|
private _statusCode;
|
|
6
4
|
private _headers;
|
|
7
5
|
body: any;
|
|
8
|
-
|
|
6
|
+
isBase64Encoded?: boolean;
|
|
7
|
+
_cookies: string[];
|
|
8
|
+
setCookie(name: string, value: string, options?: CookieOptions): void;
|
|
9
|
+
clearCookie(name: string, options?: {
|
|
10
|
+
path?: string;
|
|
11
|
+
domain?: string;
|
|
12
|
+
}): void;
|
|
13
|
+
getCookies(): string[];
|
|
14
|
+
clearAllCookies(): void;
|
|
15
|
+
private _updateCookieHeader;
|
|
9
16
|
setHeader(name: string, value: string): void;
|
|
10
17
|
set statusCode(code: number);
|
|
11
18
|
get statusCode(): number;
|
|
12
19
|
get headers(): Record<string, string>;
|
|
13
|
-
send(): void;
|
|
14
|
-
get original(): ServerResponse | undefined;
|
|
15
20
|
}
|
|
@@ -2,24 +2,61 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LResponse = void 0;
|
|
4
4
|
class LResponse {
|
|
5
|
-
originalResponse;
|
|
6
5
|
_statusCode = 200;
|
|
7
6
|
_headers = {};
|
|
8
7
|
body = null;
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
isBase64Encoded;
|
|
9
|
+
_cookies;
|
|
10
|
+
setCookie(name, value, options) {
|
|
11
|
+
let cookie = `${name}=${encodeURIComponent(value)}`;
|
|
12
|
+
if (options) {
|
|
13
|
+
if (options.maxAge)
|
|
14
|
+
cookie += `; Max-Age=${options.maxAge}`;
|
|
15
|
+
if (options.expires)
|
|
16
|
+
cookie += `; Expires=${options.expires.toUTCString()}`;
|
|
17
|
+
if (options.domain)
|
|
18
|
+
cookie += `; Domain=${options.domain}`;
|
|
19
|
+
if (options.path)
|
|
20
|
+
cookie += `; Path=${options.path}`;
|
|
21
|
+
if (options.secure)
|
|
22
|
+
cookie += `; Secure`;
|
|
23
|
+
if (options.httpOnly)
|
|
24
|
+
cookie += `; HttpOnly`;
|
|
25
|
+
if (options.sameSite)
|
|
26
|
+
cookie += `; SameSite=${options.sameSite}`;
|
|
27
|
+
if (options.priority)
|
|
28
|
+
cookie += `; Priority=${options.priority}`;
|
|
29
|
+
if (options.partitioned)
|
|
30
|
+
cookie += `; Partitioned`;
|
|
31
|
+
}
|
|
32
|
+
this._cookies.push(cookie);
|
|
33
|
+
this._updateCookieHeader();
|
|
34
|
+
}
|
|
35
|
+
clearCookie(name, options) {
|
|
36
|
+
const cookie = `${name}=; Max-Age=0; Expires=${new Date(0).toUTCString()}${options?.path ? `; Path=${options.path}` : ''}${options?.domain ? `; Domain=${options.domain}` : ''}`;
|
|
37
|
+
this._cookies.push(cookie);
|
|
38
|
+
this._updateCookieHeader();
|
|
39
|
+
}
|
|
40
|
+
getCookies() {
|
|
41
|
+
return [...this._cookies];
|
|
42
|
+
}
|
|
43
|
+
clearAllCookies() {
|
|
44
|
+
this._cookies = [];
|
|
45
|
+
delete this._headers['Set-Cookie'];
|
|
46
|
+
}
|
|
47
|
+
_updateCookieHeader() {
|
|
48
|
+
if (this._cookies.length > 0) {
|
|
49
|
+
this._headers['Set-Cookie'] = this._cookies.join(', ');
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
delete this._headers['Set-Cookie'];
|
|
53
|
+
}
|
|
11
54
|
}
|
|
12
55
|
setHeader(name, value) {
|
|
13
56
|
this._headers[name] = value;
|
|
14
|
-
if (this.originalResponse) {
|
|
15
|
-
this.originalResponse.setHeader(name, value);
|
|
16
|
-
}
|
|
17
57
|
}
|
|
18
58
|
set statusCode(code) {
|
|
19
59
|
this._statusCode = code;
|
|
20
|
-
if (this.originalResponse) {
|
|
21
|
-
this.originalResponse.statusCode = code;
|
|
22
|
-
}
|
|
23
60
|
}
|
|
24
61
|
get statusCode() {
|
|
25
62
|
return this._statusCode;
|
|
@@ -27,12 +64,6 @@ class LResponse {
|
|
|
27
64
|
get headers() {
|
|
28
65
|
return { ...this._headers };
|
|
29
66
|
}
|
|
30
|
-
send() {
|
|
31
|
-
throw `Lambda response doesn't have "send" method`;
|
|
32
|
-
}
|
|
33
|
-
get original() {
|
|
34
|
-
return this.originalResponse;
|
|
35
|
-
}
|
|
36
67
|
}
|
|
37
68
|
exports.LResponse = LResponse;
|
|
38
69
|
//# sourceMappingURL=response.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../../../src/app/aws/utils/response.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../../../src/app/aws/utils/response.ts"],"names":[],"mappings":";;;AAEA,MAAa,SAAS;IACZ,WAAW,GAAW,GAAG,CAAC;IAC1B,QAAQ,GAA2B,EAAE,CAAC;IAC9C,IAAI,GAAQ,IAAI,CAAC;IACjB,eAAe,CAAW;IAC1B,QAAQ,CAAW;IAEnB,SAAS,CAAC,IAAY,EAAE,KAAa,EAAE,OAAuB;QAC5D,IAAI,MAAM,GAAG,GAAG,IAAI,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;QAEpD,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,OAAO,CAAC,MAAM;gBAAE,MAAM,IAAI,aAAa,OAAO,CAAC,MAAM,EAAE,CAAC;YAC5D,IAAI,OAAO,CAAC,OAAO;gBAAE,MAAM,IAAI,aAAa,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;YAC5E,IAAI,OAAO,CAAC,MAAM;gBAAE,MAAM,IAAI,YAAY,OAAO,CAAC,MAAM,EAAE,CAAC;YAC3D,IAAI,OAAO,CAAC,IAAI;gBAAE,MAAM,IAAI,UAAU,OAAO,CAAC,IAAI,EAAE,CAAC;YACrD,IAAI,OAAO,CAAC,MAAM;gBAAE,MAAM,IAAI,UAAU,CAAC;YACzC,IAAI,OAAO,CAAC,QAAQ;gBAAE,MAAM,IAAI,YAAY,CAAC;YAC7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AI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,SAAS,CAAC,IAAY,EAAE,KAAa;QACnC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IAC9B,CAAC;IAED,IAAI,UAAU,CAAC,IAAY;QACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,IAAI,OAAO;QACT,OAAO,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;CACF;AAnED,8BAmEC"}
|
package/dist/types/common.d.ts
CHANGED
|
@@ -64,4 +64,15 @@ export declare enum HTTP_METHODS {
|
|
|
64
64
|
OPTIONS = "OPTIONS",
|
|
65
65
|
HEAD = "HEAD"
|
|
66
66
|
}
|
|
67
|
+
export interface CookieOptions {
|
|
68
|
+
maxAge?: number;
|
|
69
|
+
expires?: Date;
|
|
70
|
+
domain?: string;
|
|
71
|
+
path?: string;
|
|
72
|
+
secure?: boolean;
|
|
73
|
+
httpOnly?: boolean;
|
|
74
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
75
|
+
priority?: 'Low' | 'Medium' | 'High';
|
|
76
|
+
partitioned?: boolean;
|
|
77
|
+
}
|
|
67
78
|
export {};
|
package/dist/types/lambda.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APIGatewayProxyEvent, APIGatewayProxyEventV2, Context, Handler } from 'aws-lambda';
|
|
2
|
-
import { HTTP_METHODS } from './common';
|
|
2
|
+
import { CookieOptions, HTTP_METHODS } from './common';
|
|
3
3
|
import { ControllerClass } from './controller';
|
|
4
4
|
import { MultipartFile } from './multipart';
|
|
5
5
|
import { LambdaPlugin } from './plugins';
|
|
@@ -51,14 +51,6 @@ export interface LambdaRequestMeta {
|
|
|
51
51
|
sourceIp?: string;
|
|
52
52
|
userAgent?: string;
|
|
53
53
|
}
|
|
54
|
-
export interface LambdaResponse {
|
|
55
|
-
statusCode: number;
|
|
56
|
-
headers?: Record<string, string>;
|
|
57
|
-
body: string;
|
|
58
|
-
isBase64Encoded?: boolean;
|
|
59
|
-
multiValueHeaders?: Record<string, string[]>;
|
|
60
|
-
cookies?: string[];
|
|
61
|
-
}
|
|
62
54
|
export interface LambdaApp {
|
|
63
55
|
beforeStart?: () => void;
|
|
64
56
|
}
|
|
@@ -86,13 +78,20 @@ export interface LambdaRequest {
|
|
|
86
78
|
sourceIp: string;
|
|
87
79
|
end(): void;
|
|
88
80
|
}
|
|
89
|
-
export interface
|
|
81
|
+
export interface LambdaResponse {
|
|
90
82
|
body: any;
|
|
91
|
-
setHeader(name: string, value: string): void;
|
|
92
83
|
statusCode: number;
|
|
93
|
-
headers
|
|
94
|
-
|
|
95
|
-
|
|
84
|
+
headers?: Record<string, string>;
|
|
85
|
+
cookies?: string[];
|
|
86
|
+
isBase64Encoded?: boolean;
|
|
87
|
+
setHeader(name: string, value: string): void;
|
|
88
|
+
setCookie(name: string, value: string, options?: CookieOptions): void;
|
|
89
|
+
clearCookie(name: string, options?: {
|
|
90
|
+
path?: string;
|
|
91
|
+
domain?: string;
|
|
92
|
+
}): void;
|
|
93
|
+
getCookies(): string[];
|
|
94
|
+
clearAllCookies(): void;
|
|
96
95
|
}
|
|
97
96
|
export interface ILambdaAdapter {
|
|
98
97
|
handler: Handler;
|
package/dist/types/plugins.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Context } from 'aws-lambda';
|
|
|
2
2
|
import { IncomingMessage, Server, ServerResponse } from 'http';
|
|
3
3
|
import { AppRequest, MiddlewareCB } from './common';
|
|
4
4
|
import { IHttpServer } from './http';
|
|
5
|
-
import { ILambdaAdapter,
|
|
5
|
+
import { ILambdaAdapter, LambdaEvent, LambdaRequest, LambdaResponse } from './lambda';
|
|
6
6
|
export interface HttpPluginHooks {
|
|
7
7
|
beforeRequest?: (req: IncomingMessage) => void | Promise<void>;
|
|
8
8
|
beforeRoute?: (req: AppRequest, response: ServerResponse) => void | Promise<void>;
|
|
@@ -21,7 +21,7 @@ export type PluginKeys = keyof Omit<HttpPlugin, 'name' | 'hooks'>;
|
|
|
21
21
|
export interface LambdaPluginHooks {
|
|
22
22
|
beforeRequest?: (event: LambdaEvent, context: Context) => void | Promise<void>;
|
|
23
23
|
beforeRoute?: (req: LambdaRequest) => void | Promise<void>;
|
|
24
|
-
afterResponse?: (req: LambdaRequest, res:
|
|
24
|
+
afterResponse?: (req: LambdaRequest, res: LambdaResponse) => void | Promise<void>;
|
|
25
25
|
}
|
|
26
26
|
export interface LambdaPlugin {
|
|
27
27
|
name: string;
|