@heliosjs/http 1.0.1
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 +540 -0
- package/dist/Application.d.ts +32 -0
- package/dist/Application.js +269 -0
- package/dist/Application.js.map +1 -0
- package/dist/constants.d.ts +25 -0
- package/dist/constants.js +34 -0
- package/dist/constants.js.map +1 -0
- package/dist/decorators.d.ts +43 -0
- package/dist/decorators.js +81 -0
- package/dist/decorators.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/socket/decorators.d.ts +77 -0
- package/dist/socket/decorators.js +112 -0
- package/dist/socket/decorators.js.map +1 -0
- package/dist/socket/index.d.ts +1 -0
- package/dist/socket/index.js +18 -0
- package/dist/socket/index.js.map +1 -0
- package/dist/sse/decorators.d.ts +52 -0
- package/dist/sse/decorators.js +76 -0
- package/dist/sse/decorators.js.map +1 -0
- package/dist/sse/index.d.ts +1 -0
- package/dist/sse/index.js +18 -0
- package/dist/sse/index.js.map +1 -0
- package/dist/types/core/common.d.ts +44 -0
- package/dist/types/core/common.js +15 -0
- package/dist/types/core/common.js.map +1 -0
- package/dist/types/core/controller.d.ts +78 -0
- package/dist/types/core/controller.js +3 -0
- package/dist/types/core/controller.js.map +1 -0
- package/dist/types/core/cors.d.ts +10 -0
- package/dist/types/core/cors.js +3 -0
- package/dist/types/core/cors.js.map +1 -0
- package/dist/types/core/error.d.ts +72 -0
- package/dist/types/core/error.js +19 -0
- package/dist/types/core/error.js.map +1 -0
- package/dist/types/core/index.d.ts +9 -0
- package/dist/types/core/index.js +26 -0
- package/dist/types/core/index.js.map +1 -0
- package/dist/types/core/multipart.d.ts +8 -0
- package/dist/types/core/multipart.js +3 -0
- package/dist/types/core/multipart.js.map +1 -0
- package/dist/types/core/request.d.ts +65 -0
- package/dist/types/core/request.js +3 -0
- package/dist/types/core/request.js.map +1 -0
- package/dist/types/core/response.d.ts +49 -0
- package/dist/types/core/response.js +3 -0
- package/dist/types/core/response.js.map +1 -0
- package/dist/types/core/sanitize.d.ts +8 -0
- package/dist/types/core/sanitize.js +3 -0
- package/dist/types/core/sanitize.js.map +1 -0
- package/dist/types/core/sse.d.ts +37 -0
- package/dist/types/core/sse.js +3 -0
- package/dist/types/core/sse.js.map +1 -0
- package/dist/types/http/http.d.ts +111 -0
- package/dist/types/http/http.js +3 -0
- package/dist/types/http/http.js.map +1 -0
- package/dist/types/http/index.d.ts +3 -0
- package/dist/types/http/index.js +20 -0
- package/dist/types/http/index.js.map +1 -0
- package/dist/types/http/plugin.d.ts +18 -0
- package/dist/types/http/plugin.js +3 -0
- package/dist/types/http/plugin.js.map +1 -0
- package/dist/types/http/static.d.ts +24 -0
- package/dist/types/http/static.js +3 -0
- package/dist/types/http/static.js.map +1 -0
- package/dist/types/ws/index.d.ts +50 -0
- package/dist/types/ws/index.js +3 -0
- package/dist/types/ws/index.js.map +1 -0
- package/dist/utils/core/controller.d.ts +25 -0
- package/dist/utils/core/controller.js +219 -0
- package/dist/utils/core/controller.js.map +1 -0
- package/dist/utils/core/cors.d.ts +8 -0
- package/dist/utils/core/cors.js +128 -0
- package/dist/utils/core/cors.js.map +1 -0
- package/dist/utils/core/endpoint.d.ts +3 -0
- package/dist/utils/core/endpoint.js +28 -0
- package/dist/utils/core/endpoint.js.map +1 -0
- package/dist/utils/core/error/apperror.d.ts +31 -0
- package/dist/utils/core/error/apperror.js +131 -0
- package/dist/utils/core/error/apperror.js.map +1 -0
- package/dist/utils/core/error/authorizations.d.ts +7 -0
- package/dist/utils/core/error/authorizations.js +17 -0
- package/dist/utils/core/error/authorizations.js.map +1 -0
- package/dist/utils/core/error/base.d.ts +20 -0
- package/dist/utils/core/error/base.js +52 -0
- package/dist/utils/core/error/base.js.map +1 -0
- package/dist/utils/core/error/dependencyFailed.d.ts +7 -0
- package/dist/utils/core/error/dependencyFailed.js +17 -0
- package/dist/utils/core/error/dependencyFailed.js.map +1 -0
- package/dist/utils/core/error/duplicateEntry.d.ts +7 -0
- package/dist/utils/core/error/duplicateEntry.js +17 -0
- package/dist/utils/core/error/duplicateEntry.js.map +1 -0
- package/dist/utils/core/error/forbidden.d.ts +7 -0
- package/dist/utils/core/error/forbidden.js +17 -0
- package/dist/utils/core/error/forbidden.js.map +1 -0
- package/dist/utils/core/error/helpers.d.ts +8 -0
- package/dist/utils/core/error/helpers.js +144 -0
- package/dist/utils/core/error/helpers.js.map +1 -0
- package/dist/utils/core/error/index.d.ts +12 -0
- package/dist/utils/core/error/index.js +29 -0
- package/dist/utils/core/error/index.js.map +1 -0
- package/dist/utils/core/error/invalidState.d.ts +7 -0
- package/dist/utils/core/error/invalidState.js +17 -0
- package/dist/utils/core/error/invalidState.js.map +1 -0
- package/dist/utils/core/error/notfound.d.ts +7 -0
- package/dist/utils/core/error/notfound.js +18 -0
- package/dist/utils/core/error/notfound.js.map +1 -0
- package/dist/utils/core/error/rateLimit.d.ts +7 -0
- package/dist/utils/core/error/rateLimit.js +17 -0
- package/dist/utils/core/error/rateLimit.js.map +1 -0
- package/dist/utils/core/error/serviceUnavailable.d.ts +7 -0
- package/dist/utils/core/error/serviceUnavailable.js +17 -0
- package/dist/utils/core/error/serviceUnavailable.js.map +1 -0
- package/dist/utils/core/error/validation.d.ts +10 -0
- package/dist/utils/core/error/validation.js +20 -0
- package/dist/utils/core/error/validation.js.map +1 -0
- package/dist/utils/core/headers.d.ts +2 -0
- package/dist/utils/core/headers.js +10 -0
- package/dist/utils/core/headers.js.map +1 -0
- package/dist/utils/core/helper.d.ts +6 -0
- package/dist/utils/core/helper.js +66 -0
- package/dist/utils/core/helper.js.map +1 -0
- package/dist/utils/core/index.d.ts +10 -0
- package/dist/utils/core/index.js +27 -0
- package/dist/utils/core/index.js.map +1 -0
- package/dist/utils/core/multipart.d.ts +9 -0
- package/dist/utils/core/multipart.js +207 -0
- package/dist/utils/core/multipart.js.map +1 -0
- package/dist/utils/core/request.d.ts +100 -0
- package/dist/utils/core/request.js +218 -0
- package/dist/utils/core/request.js.map +1 -0
- package/dist/utils/core/response.d.ts +48 -0
- package/dist/utils/core/response.js +269 -0
- package/dist/utils/core/response.js.map +1 -0
- package/dist/utils/core/routeWalker.d.ts +2 -0
- package/dist/utils/core/routeWalker.js +115 -0
- package/dist/utils/core/routeWalker.js.map +1 -0
- package/dist/utils/core/sanitize.d.ts +30 -0
- package/dist/utils/core/sanitize.js +134 -0
- package/dist/utils/core/sanitize.js.map +1 -0
- package/dist/utils/http/index.d.ts +5 -0
- package/dist/utils/http/index.js +22 -0
- package/dist/utils/http/index.js.map +1 -0
- package/dist/utils/http/plugin.d.ts +9 -0
- package/dist/utils/http/plugin.js +43 -0
- package/dist/utils/http/plugin.js.map +1 -0
- package/dist/utils/http/request.factory.d.ts +8 -0
- package/dist/utils/http/request.factory.js +55 -0
- package/dist/utils/http/request.factory.js.map +1 -0
- package/dist/utils/http/response.factory.d.ts +9 -0
- package/dist/utils/http/response.factory.js +14 -0
- package/dist/utils/http/response.factory.js.map +1 -0
- package/dist/utils/http/server.d.ts +18 -0
- package/dist/utils/http/server.js +58 -0
- package/dist/utils/http/server.js.map +1 -0
- package/dist/utils/http/static.d.ts +3 -0
- package/dist/utils/http/static.js +151 -0
- package/dist/utils/http/static.js.map +1 -0
- package/dist/utils/shared/index.d.ts +2 -0
- package/dist/utils/shared/index.js +19 -0
- package/dist/utils/shared/index.js.map +1 -0
- package/dist/utils/shared/parsers.d.ts +11 -0
- package/dist/utils/shared/parsers.js +133 -0
- package/dist/utils/shared/parsers.js.map +1 -0
- package/dist/utils/shared/validate.d.ts +1 -0
- package/dist/utils/shared/validate.js +41 -0
- package/dist/utils/shared/validate.js.map +1 -0
- package/dist/utils/socket/index.d.ts +3 -0
- package/dist/utils/socket/index.js +20 -0
- package/dist/utils/socket/index.js.map +1 -0
- package/dist/utils/socket/server.d.ts +33 -0
- package/dist/utils/socket/server.js +218 -0
- package/dist/utils/socket/server.js.map +1 -0
- package/dist/utils/socket/service.d.ts +20 -0
- package/dist/utils/socket/service.js +42 -0
- package/dist/utils/socket/service.js.map +1 -0
- package/dist/utils/socket/socket.d.ts +16 -0
- package/dist/utils/socket/socket.js +33 -0
- package/dist/utils/socket/socket.js.map +1 -0
- package/dist/utils/sse/index.d.ts +2 -0
- package/dist/utils/sse/index.js +19 -0
- package/dist/utils/sse/index.js.map +1 -0
- package/dist/utils/sse/server.d.ts +14 -0
- package/dist/utils/sse/server.js +85 -0
- package/dist/utils/sse/server.js.map +1 -0
- package/dist/utils/sse/service.d.ts +17 -0
- package/dist/utils/sse/service.js +40 -0
- package/dist/utils/sse/service.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./controller"), exports);
|
|
18
|
+
__exportStar(require("./cors"), exports);
|
|
19
|
+
__exportStar(require("./endpoint"), exports);
|
|
20
|
+
__exportStar(require("./error"), exports);
|
|
21
|
+
__exportStar(require("./headers"), exports);
|
|
22
|
+
__exportStar(require("./multipart"), exports);
|
|
23
|
+
__exportStar(require("./request"), exports);
|
|
24
|
+
__exportStar(require("./response"), exports);
|
|
25
|
+
__exportStar(require("./routeWalker"), exports);
|
|
26
|
+
__exportStar(require("./sanitize"), exports);
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,yCAAuB;AACvB,6CAA2B;AAC3B,0CAAwB;AACxB,4CAA0B;AAC1B,8CAA4B;AAC5B,4CAA0B;AAC1B,6CAA2B;AAC3B,gDAA8B;AAC9B,6CAA2B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MultipartFile } from '../../types/core';
|
|
2
|
+
export declare class MultipartProcessor {
|
|
3
|
+
static parse(request: any): {
|
|
4
|
+
fields: Record<string, any>;
|
|
5
|
+
files: Record<string, MultipartFile | MultipartFile[]>;
|
|
6
|
+
};
|
|
7
|
+
static isMultipart(request: any): boolean;
|
|
8
|
+
private static getContentType;
|
|
9
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.MultipartProcessor = void 0;
|
|
37
|
+
// utils/MultipartProcessor.ts
|
|
38
|
+
const multipart = __importStar(require("parse-multipart-data"));
|
|
39
|
+
class MultipartProcessor {
|
|
40
|
+
static parse(request) {
|
|
41
|
+
const { body, headers, isBase64Encoded } = request;
|
|
42
|
+
if (!body) {
|
|
43
|
+
return { fields: {}, files: {} };
|
|
44
|
+
}
|
|
45
|
+
let contentType = headers['content-type'] ?? headers['Content-Type'] ?? '';
|
|
46
|
+
if (Array.isArray(contentType)) {
|
|
47
|
+
contentType = contentType[0];
|
|
48
|
+
}
|
|
49
|
+
if (!contentType.startsWith('multipart/form-data')) {
|
|
50
|
+
throw new Error('Not a multipart request');
|
|
51
|
+
}
|
|
52
|
+
const boundaryMatch = multipart.getBoundary(contentType);
|
|
53
|
+
if (!boundaryMatch) {
|
|
54
|
+
throw new Error('Invalid multipart boundary');
|
|
55
|
+
}
|
|
56
|
+
let bodyBuffer;
|
|
57
|
+
if (Buffer.isBuffer(body)) {
|
|
58
|
+
bodyBuffer = body;
|
|
59
|
+
}
|
|
60
|
+
else if (typeof body === 'string') {
|
|
61
|
+
bodyBuffer = isBase64Encoded ? Buffer.from(body, 'base64') : Buffer.from(body, 'binary');
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
bodyBuffer = Buffer.from(JSON.stringify(body));
|
|
65
|
+
}
|
|
66
|
+
const parts = multipart.parse(bodyBuffer, boundaryMatch);
|
|
67
|
+
const fields = {};
|
|
68
|
+
const files = {};
|
|
69
|
+
parts.forEach((part) => {
|
|
70
|
+
if (part.filename) {
|
|
71
|
+
const fieldName = part.name || 'file';
|
|
72
|
+
const contentType = this.getContentType(part);
|
|
73
|
+
const fileData = {
|
|
74
|
+
fieldname: fieldName,
|
|
75
|
+
filename: part.filename,
|
|
76
|
+
contentType: contentType ?? part.type,
|
|
77
|
+
data: part.data,
|
|
78
|
+
size: part.data.length,
|
|
79
|
+
encoding: part.encoding,
|
|
80
|
+
};
|
|
81
|
+
if (files[fieldName]) {
|
|
82
|
+
if (Array.isArray(files[fieldName])) {
|
|
83
|
+
files[fieldName].push(fileData);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
files[fieldName] = [files[fieldName], fileData];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
files[fieldName] = fileData;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (part.name) {
|
|
94
|
+
const text = part.data.toString('utf-8').trim();
|
|
95
|
+
try {
|
|
96
|
+
fields[part.name] = JSON.parse(text);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
fields[part.name] = text;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return { fields, files };
|
|
104
|
+
}
|
|
105
|
+
static isMultipart(request) {
|
|
106
|
+
const contentType = request.headers?.['content-type'] || request.headers?.['Content-Type'] || '';
|
|
107
|
+
return contentType.startsWith('multipart/form-data');
|
|
108
|
+
}
|
|
109
|
+
static getContentType(part) {
|
|
110
|
+
const filename = part.filename || '';
|
|
111
|
+
const extension = filename.split('.').pop()?.toLowerCase() ?? '';
|
|
112
|
+
const mimeMap = {
|
|
113
|
+
txt: 'text/plain',
|
|
114
|
+
text: 'text/plain',
|
|
115
|
+
log: 'text/plain',
|
|
116
|
+
md: 'text/markdown',
|
|
117
|
+
csv: 'text/csv',
|
|
118
|
+
ts: 'application/typescript',
|
|
119
|
+
tsx: 'application/typescript',
|
|
120
|
+
js: 'application/javascript',
|
|
121
|
+
jsx: 'application/javascript',
|
|
122
|
+
mjs: 'application/javascript',
|
|
123
|
+
cjs: 'application/javascript',
|
|
124
|
+
json: 'application/json',
|
|
125
|
+
xml: 'application/xml',
|
|
126
|
+
yaml: 'application/yaml',
|
|
127
|
+
yml: 'application/yaml',
|
|
128
|
+
toml: 'application/toml',
|
|
129
|
+
php: 'application/x-httpd-php',
|
|
130
|
+
py: 'text/x-python',
|
|
131
|
+
rb: 'text/x-ruby',
|
|
132
|
+
java: 'text/x-java',
|
|
133
|
+
c: 'text/x-c',
|
|
134
|
+
cpp: 'text/x-c++',
|
|
135
|
+
h: 'text/x-c',
|
|
136
|
+
hpp: 'text/x-c++',
|
|
137
|
+
go: 'text/x-go',
|
|
138
|
+
rs: 'text/x-rust',
|
|
139
|
+
swift: 'text/x-swift',
|
|
140
|
+
kt: 'text/x-kotlin',
|
|
141
|
+
kts: 'text/x-kotlin',
|
|
142
|
+
html: 'text/html',
|
|
143
|
+
htm: 'text/html',
|
|
144
|
+
css: 'text/css',
|
|
145
|
+
scss: 'text/x-scss',
|
|
146
|
+
sass: 'text/x-sass',
|
|
147
|
+
less: 'text/x-less',
|
|
148
|
+
jpg: 'image/jpeg',
|
|
149
|
+
jpeg: 'image/jpeg',
|
|
150
|
+
png: 'image/png',
|
|
151
|
+
gif: 'image/gif',
|
|
152
|
+
webp: 'image/webp',
|
|
153
|
+
svg: 'image/svg+xml',
|
|
154
|
+
ico: 'image/x-icon',
|
|
155
|
+
bmp: 'image/bmp',
|
|
156
|
+
tiff: 'image/tiff',
|
|
157
|
+
tif: 'image/tiff',
|
|
158
|
+
avif: 'image/avif',
|
|
159
|
+
heic: 'image/heic',
|
|
160
|
+
heif: 'image/heif',
|
|
161
|
+
pdf: 'application/pdf',
|
|
162
|
+
doc: 'application/msword',
|
|
163
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
164
|
+
xls: 'application/vnd.ms-excel',
|
|
165
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
166
|
+
ppt: 'application/vnd.ms-powerpoint',
|
|
167
|
+
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
168
|
+
odt: 'application/vnd.oasis.opendocument.text',
|
|
169
|
+
ods: 'application/vnd.oasis.opendocument.spreadsheet',
|
|
170
|
+
odp: 'application/vnd.oasis.opendocument.presentation',
|
|
171
|
+
zip: 'application/zip',
|
|
172
|
+
rar: 'application/vnd.rar',
|
|
173
|
+
'7z': 'application/x-7z-compressed',
|
|
174
|
+
tar: 'application/x-tar',
|
|
175
|
+
gz: 'application/gzip',
|
|
176
|
+
bz2: 'application/x-bzip2',
|
|
177
|
+
mp3: 'audio/mpeg',
|
|
178
|
+
wav: 'audio/wav',
|
|
179
|
+
ogg: 'audio/ogg',
|
|
180
|
+
m4a: 'audio/mp4',
|
|
181
|
+
flac: 'audio/flac',
|
|
182
|
+
aac: 'audio/aac',
|
|
183
|
+
mp4: 'video/mp4',
|
|
184
|
+
mpg: 'video/mpeg',
|
|
185
|
+
mpeg: 'video/mpeg',
|
|
186
|
+
mov: 'video/quicktime',
|
|
187
|
+
avi: 'video/x-msvideo',
|
|
188
|
+
wmv: 'video/x-ms-wmv',
|
|
189
|
+
flv: 'video/x-flv',
|
|
190
|
+
webm: 'video/webm',
|
|
191
|
+
mkv: 'video/x-matroska',
|
|
192
|
+
m4v: 'video/x-m4v',
|
|
193
|
+
bin: 'application/octet-stream',
|
|
194
|
+
exe: 'application/vnd.microsoft.portable-executable',
|
|
195
|
+
dll: 'application/vnd.microsoft.portable-executable',
|
|
196
|
+
deb: 'application/vnd.debian.binary-package',
|
|
197
|
+
rpm: 'application/x-rpm',
|
|
198
|
+
iso: 'application/x-iso9660-image',
|
|
199
|
+
sh: 'application/x-sh',
|
|
200
|
+
bat: 'application/x-msdos-program',
|
|
201
|
+
ps1: 'application/x-powershell',
|
|
202
|
+
};
|
|
203
|
+
return mimeMap[extension];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.MultipartProcessor = MultipartProcessor;
|
|
207
|
+
//# sourceMappingURL=multipart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipart.js","sourceRoot":"","sources":["../../../src/utils/core/multipart.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8BAA8B;AAC9B,gEAAkD;AAGlD,MAAa,kBAAkB;IAC7B,MAAM,CAAC,KAAK,CAAC,OAAY;QAIvB,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;QAEnD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;QACnC,CAAC;QAED,IAAI,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,IAAI,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;QAC3E,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QAC/B,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;QAED,MAAM,aAAa,GAAG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AAC,SAAS,CAAC,CAAC;IAC5B,CAAC;CACF;AA5LD,gDA4LC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { IncomingHttpHeaders } from 'http';
|
|
2
|
+
import { URL } from 'url';
|
|
3
|
+
import { IRequest, RequestOptions, RequestSource } from '../../types/core/request';
|
|
4
|
+
export declare class Request implements IRequest {
|
|
5
|
+
method: string;
|
|
6
|
+
path: string;
|
|
7
|
+
requestUrl: URL;
|
|
8
|
+
url: string;
|
|
9
|
+
headers: Record<string, string | string[]>;
|
|
10
|
+
query: Record<string, string | string[]>;
|
|
11
|
+
body: any;
|
|
12
|
+
rawBody: any;
|
|
13
|
+
params: Record<string, string>;
|
|
14
|
+
cookies: Record<string, string>;
|
|
15
|
+
sourceIp: string;
|
|
16
|
+
userAgent: string;
|
|
17
|
+
requestId: string;
|
|
18
|
+
stage: string;
|
|
19
|
+
timestamp: Date;
|
|
20
|
+
source: RequestSource;
|
|
21
|
+
raw: any;
|
|
22
|
+
context: any;
|
|
23
|
+
isBase64Encoded: boolean;
|
|
24
|
+
startTime: number;
|
|
25
|
+
private _state;
|
|
26
|
+
constructor(options: RequestOptions);
|
|
27
|
+
base64Encoded(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Get header value (case-insensitive)
|
|
30
|
+
*/
|
|
31
|
+
getHeader(name: string): string | string[] | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Get cookie value
|
|
34
|
+
*/
|
|
35
|
+
getCookie(name: string): string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Get query parameter
|
|
38
|
+
*/
|
|
39
|
+
getQuery(name: string): string | string[] | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Get path parameter
|
|
42
|
+
*/
|
|
43
|
+
getParam(name: string): string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Check if request is from HTTP server
|
|
46
|
+
*/
|
|
47
|
+
isHttp(): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Check if request is from Lambda
|
|
50
|
+
*/
|
|
51
|
+
isLambda(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Get Lambda event (if from Lambda)
|
|
54
|
+
*/
|
|
55
|
+
getLambdaEvent(): any;
|
|
56
|
+
/**
|
|
57
|
+
* Get Lambda context (if from Lambda)
|
|
58
|
+
*/
|
|
59
|
+
getLambdaContext(): any;
|
|
60
|
+
/**
|
|
61
|
+
* Get HTTP IncomingMessage (if from HTTP)
|
|
62
|
+
*/
|
|
63
|
+
getHttpRequest(): IncomingHttpHeaders | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Store arbitrary data in request state
|
|
66
|
+
*/
|
|
67
|
+
setState(key: string, value: any): void;
|
|
68
|
+
/**
|
|
69
|
+
* Get stored state data
|
|
70
|
+
*/
|
|
71
|
+
getState<T = any>(key: string): T | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Get all stored state
|
|
74
|
+
*/
|
|
75
|
+
getAllState(): Map<string, any>;
|
|
76
|
+
/**
|
|
77
|
+
* Check if request is secure (HTTPS)
|
|
78
|
+
*/
|
|
79
|
+
isSecure(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Get client IP (considering proxies)
|
|
82
|
+
*/
|
|
83
|
+
getClientIp(): string;
|
|
84
|
+
/**
|
|
85
|
+
* Get request host
|
|
86
|
+
*/
|
|
87
|
+
getHost(): string;
|
|
88
|
+
/**
|
|
89
|
+
* Get full URL
|
|
90
|
+
*/
|
|
91
|
+
getFullUrl(): string;
|
|
92
|
+
/**
|
|
93
|
+
* Clone request with modifications
|
|
94
|
+
*/
|
|
95
|
+
clone(overrides?: Partial<RequestOptions>): Request;
|
|
96
|
+
/**
|
|
97
|
+
* Convert to plain object
|
|
98
|
+
*/
|
|
99
|
+
toJSON(): Record<string, any>;
|
|
100
|
+
}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Request = void 0;
|
|
4
|
+
const url_1 = require("url");
|
|
5
|
+
class Request {
|
|
6
|
+
method;
|
|
7
|
+
path;
|
|
8
|
+
requestUrl;
|
|
9
|
+
url;
|
|
10
|
+
headers;
|
|
11
|
+
query;
|
|
12
|
+
body;
|
|
13
|
+
rawBody;
|
|
14
|
+
params;
|
|
15
|
+
cookies;
|
|
16
|
+
sourceIp;
|
|
17
|
+
userAgent;
|
|
18
|
+
requestId;
|
|
19
|
+
stage;
|
|
20
|
+
timestamp;
|
|
21
|
+
source;
|
|
22
|
+
raw;
|
|
23
|
+
context;
|
|
24
|
+
isBase64Encoded;
|
|
25
|
+
startTime;
|
|
26
|
+
_state = new Map();
|
|
27
|
+
constructor(options) {
|
|
28
|
+
this.method = options.method.toUpperCase();
|
|
29
|
+
this.path = options.path;
|
|
30
|
+
this.url = options.path;
|
|
31
|
+
this.requestUrl = new url_1.URL(options.path, `http://${options.headers?.host || 'localhost'}`);
|
|
32
|
+
this.headers = options.headers || {};
|
|
33
|
+
this.query = options.query || {};
|
|
34
|
+
this.body = options.body;
|
|
35
|
+
this.params = options.params || {};
|
|
36
|
+
this.cookies = options.cookies || {};
|
|
37
|
+
this.sourceIp = options.sourceIp || '0.0.0.0';
|
|
38
|
+
this.userAgent = options.userAgent || 'unknown';
|
|
39
|
+
this.requestId = options.requestId;
|
|
40
|
+
this.stage = options.stage || 'dev';
|
|
41
|
+
this.timestamp = options.timestamp || new Date();
|
|
42
|
+
this.source = options.source;
|
|
43
|
+
this.raw = options.raw ?? options.event;
|
|
44
|
+
this.context = options.context;
|
|
45
|
+
this.url = options.url;
|
|
46
|
+
this.rawBody = options.rawBody;
|
|
47
|
+
this.raw = options.raw;
|
|
48
|
+
this.isBase64Encoded = options.isBase64Encoded ?? this.base64Encoded();
|
|
49
|
+
this.startTime = Date.now();
|
|
50
|
+
}
|
|
51
|
+
base64Encoded() {
|
|
52
|
+
if (this.isLambda() && this.raw?.isBase64Encoded) {
|
|
53
|
+
return this.raw.isBase64Encoded;
|
|
54
|
+
}
|
|
55
|
+
const encoding = this.getHeader('content-encoding');
|
|
56
|
+
if (encoding === 'base64') {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
const transferEncoding = this.getHeader('transfer-encoding');
|
|
60
|
+
if (transferEncoding === 'base64') {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get header value (case-insensitive)
|
|
67
|
+
*/
|
|
68
|
+
getHeader(name) {
|
|
69
|
+
const lowerName = name.toLowerCase();
|
|
70
|
+
const entry = Object.entries(this.headers).find(([key]) => key.toLowerCase() === lowerName);
|
|
71
|
+
return entry ? entry[1] : undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get cookie value
|
|
75
|
+
*/
|
|
76
|
+
getCookie(name) {
|
|
77
|
+
return this.cookies[name];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get query parameter
|
|
81
|
+
*/
|
|
82
|
+
getQuery(name) {
|
|
83
|
+
return this.query[name];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get path parameter
|
|
87
|
+
*/
|
|
88
|
+
getParam(name) {
|
|
89
|
+
return this.params[name];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Check if request is from HTTP server
|
|
93
|
+
*/
|
|
94
|
+
isHttp() {
|
|
95
|
+
return this.source === 'http';
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check if request is from Lambda
|
|
99
|
+
*/
|
|
100
|
+
isLambda() {
|
|
101
|
+
return this.source === 'lambda';
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get Lambda event (if from Lambda)
|
|
105
|
+
*/
|
|
106
|
+
getLambdaEvent() {
|
|
107
|
+
return this.isLambda() ? this.raw : undefined;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get Lambda context (if from Lambda)
|
|
111
|
+
*/
|
|
112
|
+
getLambdaContext() {
|
|
113
|
+
return this.isLambda() ? this.context : undefined;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Get HTTP IncomingMessage (if from HTTP)
|
|
117
|
+
*/
|
|
118
|
+
getHttpRequest() {
|
|
119
|
+
return this.isHttp() ? this.raw : undefined;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Store arbitrary data in request state
|
|
123
|
+
*/
|
|
124
|
+
setState(key, value) {
|
|
125
|
+
this._state.set(key, value);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get stored state data
|
|
129
|
+
*/
|
|
130
|
+
getState(key) {
|
|
131
|
+
return this._state.get(key);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get all stored state
|
|
135
|
+
*/
|
|
136
|
+
getAllState() {
|
|
137
|
+
return new Map(this._state);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Check if request is secure (HTTPS)
|
|
141
|
+
*/
|
|
142
|
+
isSecure() {
|
|
143
|
+
const proto = this.getHeader('x-forwarded-proto') || this.requestUrl.protocol.replace(':', '');
|
|
144
|
+
return proto === 'https';
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get client IP (considering proxies)
|
|
148
|
+
*/
|
|
149
|
+
getClientIp() {
|
|
150
|
+
const forwarded = this.getHeader('x-forwarded-for');
|
|
151
|
+
if (forwarded) {
|
|
152
|
+
const ips = Array.isArray(forwarded) ? forwarded : forwarded.split(',');
|
|
153
|
+
return ips[0].trim();
|
|
154
|
+
}
|
|
155
|
+
return this.sourceIp;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get request host
|
|
159
|
+
*/
|
|
160
|
+
getHost() {
|
|
161
|
+
return this.getHeader('host') || 'localhost';
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Get full URL
|
|
165
|
+
*/
|
|
166
|
+
getFullUrl() {
|
|
167
|
+
const protocol = this.isSecure() ? 'https' : 'http';
|
|
168
|
+
return `${protocol}://${this.getHost()}${this.path}`;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Clone request with modifications
|
|
172
|
+
*/
|
|
173
|
+
clone(overrides) {
|
|
174
|
+
return new Request({
|
|
175
|
+
method: overrides?.method || this.method,
|
|
176
|
+
path: overrides?.path || this.path,
|
|
177
|
+
headers: overrides?.headers || this.headers,
|
|
178
|
+
query: overrides?.query || this.query,
|
|
179
|
+
body: overrides?.body !== undefined ? overrides.body : this.body,
|
|
180
|
+
params: overrides?.params || this.params,
|
|
181
|
+
cookies: overrides?.cookies || this.cookies,
|
|
182
|
+
sourceIp: overrides?.sourceIp || this.sourceIp,
|
|
183
|
+
userAgent: overrides?.userAgent || this.userAgent,
|
|
184
|
+
requestId: overrides?.requestId || this.requestId,
|
|
185
|
+
stage: overrides?.stage || this.stage,
|
|
186
|
+
timestamp: overrides?.timestamp || this.timestamp,
|
|
187
|
+
source: this.source,
|
|
188
|
+
raw: this.raw,
|
|
189
|
+
context: this.context,
|
|
190
|
+
url: this.url,
|
|
191
|
+
isBase64Encoded: false,
|
|
192
|
+
requestUrl: this.requestUrl,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Convert to plain object
|
|
197
|
+
*/
|
|
198
|
+
toJSON() {
|
|
199
|
+
return {
|
|
200
|
+
method: this.method,
|
|
201
|
+
path: this.path,
|
|
202
|
+
url: this.url.toString(),
|
|
203
|
+
headers: this.headers,
|
|
204
|
+
query: this.query,
|
|
205
|
+
body: this.body,
|
|
206
|
+
params: this.params,
|
|
207
|
+
cookies: this.cookies,
|
|
208
|
+
sourceIp: this.sourceIp,
|
|
209
|
+
userAgent: this.userAgent,
|
|
210
|
+
requestId: this.requestId,
|
|
211
|
+
stage: this.stage,
|
|
212
|
+
timestamp: this.timestamp.toISOString(),
|
|
213
|
+
source: this.source,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.Request = Request;
|
|
218
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/utils/core/request.ts"],"names":[],"mappings":";;;AAEA,6BAA0B;AAG1B,MAAa,OAAO;IAClB,MAAM,CAAS;IACf,IAAI,CAAS;IACb,UAAU,CAAM;IAChB,GAAG,CAAS;IACZ,OAAO,CAAoC;IAC3C,KAAK,CAAoC;IACzC,IAAI,CAAM;IACV,OAAO,CAAM;IACb,MAAM,CAAyB;IAC/B,OAAO,CAAyB;IAChC,QAAQ,CAAS;IACjB,SAAS,CAAS;IAClB,SAAS,CAAS;IAClB,KAAK,CAAS;IACd,SAAS,CAAO;IAChB,MAAM,CAAgB;IACtB,GAAG,CAAM;IACT,OAAO,CAAM;IACb,eAAe,CAAU;IACzB,SAAS,CAAS;IAEV,MAAM,GAAqB,IAAI,GAAG,EAAE,CAAC;IAE7C,YAAY,OAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,IAAI,SAAG,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,OAAO,CAAC,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,CAAC,CAAC;QAC1F,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QACrC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;QACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,O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YACtB,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE;YACxB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE;YACvC,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;CACF;AA3OD,0BA2OC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CookieOptions, IResponse } from '../../types/core';
|
|
2
|
+
import { Meta } from '../../types/core/common';
|
|
3
|
+
import { ResponseSource } from '../../types/core/response';
|
|
4
|
+
export declare class Response implements IResponse {
|
|
5
|
+
private _status;
|
|
6
|
+
private _headers;
|
|
7
|
+
private _data;
|
|
8
|
+
private _cookies;
|
|
9
|
+
private _isBase64Encoded;
|
|
10
|
+
private _headersSent;
|
|
11
|
+
private _source;
|
|
12
|
+
private _raw;
|
|
13
|
+
meta: Meta;
|
|
14
|
+
constructor(source: ResponseSource | undefined, meta: Meta, raw?: any);
|
|
15
|
+
requestId: string;
|
|
16
|
+
get headers(): Record<string, string | string[]>;
|
|
17
|
+
get ok(): boolean;
|
|
18
|
+
get data(): any;
|
|
19
|
+
set data(data: any);
|
|
20
|
+
get raw(): any;
|
|
21
|
+
get cookies(): string[];
|
|
22
|
+
get isBase64Encoded(): boolean;
|
|
23
|
+
get source(): ResponseSource;
|
|
24
|
+
get headersSent(): boolean;
|
|
25
|
+
set status(code: number);
|
|
26
|
+
get status(): number;
|
|
27
|
+
getStatus(): number;
|
|
28
|
+
setHeader(name: string, value: string | string[]): this;
|
|
29
|
+
getHeader(name: string): string | string[] | undefined;
|
|
30
|
+
hasHeader(name: string): boolean;
|
|
31
|
+
removeHeader(name: string): this;
|
|
32
|
+
setHeaders(headers: Record<string, string | string[]>): this;
|
|
33
|
+
setCookie(name: string, value: string, options?: CookieOptions): this;
|
|
34
|
+
clearCookie(name: string, options?: CookieOptions): this;
|
|
35
|
+
getCookies(): string[];
|
|
36
|
+
send(body: any): this;
|
|
37
|
+
json(data: any): this;
|
|
38
|
+
text(text: string): this;
|
|
39
|
+
html(html: string): this;
|
|
40
|
+
buffer(data: Buffer, contentType?: string): this;
|
|
41
|
+
stream(readable: NodeJS.ReadableStream, contentType?: string): this;
|
|
42
|
+
end(data: unknown): any;
|
|
43
|
+
redirect(url: string, statusCode?: number): this;
|
|
44
|
+
notFound(message?: string): this;
|
|
45
|
+
reset(): this;
|
|
46
|
+
toJSON(): Record<string, any>;
|
|
47
|
+
error(error: any): this;
|
|
48
|
+
}
|