te.js 2.1.0 → 2.1.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 +197 -196
- package/auto-docs/analysis/handler-analyzer.js +58 -58
- package/auto-docs/analysis/source-resolver.js +101 -101
- package/auto-docs/constants.js +37 -37
- package/auto-docs/docs-llm/index.js +7 -7
- package/auto-docs/docs-llm/prompts.js +222 -222
- package/auto-docs/docs-llm/provider.js +132 -132
- package/auto-docs/index.js +146 -146
- package/auto-docs/openapi/endpoint-processor.js +277 -277
- package/auto-docs/openapi/generator.js +107 -107
- package/auto-docs/openapi/level3.js +131 -131
- package/auto-docs/openapi/spec-builders.js +244 -244
- package/auto-docs/ui/docs-ui.js +186 -186
- package/auto-docs/utils/logger.js +17 -17
- package/auto-docs/utils/strip-usage.js +10 -10
- package/cli/docs-command.js +315 -315
- package/cli/fly-command.js +71 -71
- package/cli/index.js +56 -56
- package/cors/index.js +71 -0
- package/database/index.js +165 -165
- package/database/mongodb.js +146 -146
- package/database/redis.js +201 -201
- package/docs/README.md +36 -36
- package/docs/ammo.md +362 -362
- package/docs/api-reference.md +490 -490
- package/docs/auto-docs.md +216 -216
- package/docs/cli.md +152 -152
- package/docs/configuration.md +275 -275
- package/docs/database.md +390 -390
- package/docs/error-handling.md +438 -438
- package/docs/file-uploads.md +333 -333
- package/docs/getting-started.md +214 -214
- package/docs/middleware.md +355 -355
- package/docs/rate-limiting.md +393 -393
- package/docs/routing.md +302 -302
- package/lib/llm/client.js +73 -0
- package/lib/llm/index.js +7 -0
- package/lib/llm/parse.js +89 -0
- package/package.json +64 -62
- package/rate-limit/algorithms/fixed-window.js +141 -141
- package/rate-limit/algorithms/sliding-window.js +147 -147
- package/rate-limit/algorithms/token-bucket.js +115 -115
- package/rate-limit/base.js +165 -165
- package/rate-limit/index.js +147 -147
- package/rate-limit/storage/base.js +104 -104
- package/rate-limit/storage/memory.js +101 -101
- package/rate-limit/storage/redis.js +88 -88
- package/server/ammo/body-parser.js +220 -220
- package/server/ammo/dispatch-helper.js +103 -103
- package/server/ammo/enhancer.js +57 -57
- package/server/ammo.js +454 -415
- package/server/endpoint.js +97 -74
- package/server/error.js +9 -9
- package/server/errors/code-context.js +125 -125
- package/server/errors/llm-error-service.js +140 -140
- package/server/files/helper.js +33 -33
- package/server/files/uploader.js +143 -143
- package/server/handler.js +158 -119
- package/server/target.js +185 -175
- package/server/targets/middleware-validator.js +22 -22
- package/server/targets/path-validator.js +21 -21
- package/server/targets/registry.js +160 -160
- package/server/targets/shoot-validator.js +21 -21
- package/te.js +428 -402
- package/utils/auto-register.js +17 -17
- package/utils/configuration.js +64 -64
- package/utils/errors-llm-config.js +84 -84
- package/utils/request-logger.js +43 -43
- package/utils/status-codes.js +82 -82
- package/utils/tejas-entrypoint-html.js +18 -18
package/server/ammo/enhancer.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import bodyParser from './body-parser.js';
|
|
2
|
-
|
|
3
|
-
function hostname(req) {
|
|
4
|
-
let host = req.headers['X-Forwarded-Host'];
|
|
5
|
-
|
|
6
|
-
if (!host) {
|
|
7
|
-
host = req.headers.host;
|
|
8
|
-
} else if (host.indexOf(',') !== -1) {
|
|
9
|
-
host = host.substring(0, host.indexOf(',')).trimRight();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return host;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async function generatePayload(req) {
|
|
16
|
-
const obj = {};
|
|
17
|
-
|
|
18
|
-
const searchParams = new URLSearchParams(req.url.split('?')[1]);
|
|
19
|
-
for (const [key, value] of searchParams) {
|
|
20
|
-
obj[key] = value;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Only parse body for methods that typically have a body
|
|
24
|
-
if (req.method !== 'GET' && req.method !== 'HEAD' && req.method !== 'DELETE') {
|
|
25
|
-
const body = await bodyParser(req);
|
|
26
|
-
if (body) Object.assign(obj, body);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return obj;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function protocol(req) {
|
|
33
|
-
const proto = req.connection.encrypted ? 'https' : 'http';
|
|
34
|
-
|
|
35
|
-
const header = req.headers['X-Forwarded-Proto'] || proto;
|
|
36
|
-
const index = header.indexOf(',');
|
|
37
|
-
|
|
38
|
-
return index !== -1 ? header.substring(0, index).trim() : header.trim();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const enhance = async (ammo) => {
|
|
42
|
-
const req = ammo.req;
|
|
43
|
-
|
|
44
|
-
ammo.ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
|
45
|
-
ammo.headers = req.headers;
|
|
46
|
-
ammo.payload = await generatePayload(req);
|
|
47
|
-
ammo.method = req.method;
|
|
48
|
-
|
|
49
|
-
ammo.protocol = protocol(req);
|
|
50
|
-
ammo.hostname = hostname(req);
|
|
51
|
-
ammo.path = req.url;
|
|
52
|
-
ammo.endpoint = req.url.split('?')[0];
|
|
53
|
-
|
|
54
|
-
ammo.fullURL = `${ammo.protocol}://${ammo.hostname}/${ammo.path}`;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export default enhance;
|
|
1
|
+
import bodyParser from './body-parser.js';
|
|
2
|
+
|
|
3
|
+
function hostname(req) {
|
|
4
|
+
let host = req.headers['X-Forwarded-Host'];
|
|
5
|
+
|
|
6
|
+
if (!host) {
|
|
7
|
+
host = req.headers.host;
|
|
8
|
+
} else if (host.indexOf(',') !== -1) {
|
|
9
|
+
host = host.substring(0, host.indexOf(',')).trimRight();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return host;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function generatePayload(req) {
|
|
16
|
+
const obj = {};
|
|
17
|
+
|
|
18
|
+
const searchParams = new URLSearchParams(req.url.split('?')[1]);
|
|
19
|
+
for (const [key, value] of searchParams) {
|
|
20
|
+
obj[key] = value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Only parse body for methods that typically have a body
|
|
24
|
+
if (req.method !== 'GET' && req.method !== 'HEAD' && req.method !== 'DELETE') {
|
|
25
|
+
const body = await bodyParser(req);
|
|
26
|
+
if (body) Object.assign(obj, body);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function protocol(req) {
|
|
33
|
+
const proto = req.connection.encrypted ? 'https' : 'http';
|
|
34
|
+
|
|
35
|
+
const header = req.headers['X-Forwarded-Proto'] || proto;
|
|
36
|
+
const index = header.indexOf(',');
|
|
37
|
+
|
|
38
|
+
return index !== -1 ? header.substring(0, index).trim() : header.trim();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const enhance = async (ammo) => {
|
|
42
|
+
const req = ammo.req;
|
|
43
|
+
|
|
44
|
+
ammo.ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
|
45
|
+
ammo.headers = req.headers;
|
|
46
|
+
ammo.payload = await generatePayload(req);
|
|
47
|
+
ammo.method = req.method;
|
|
48
|
+
|
|
49
|
+
ammo.protocol = protocol(req);
|
|
50
|
+
ammo.hostname = hostname(req);
|
|
51
|
+
ammo.path = req.url;
|
|
52
|
+
ammo.endpoint = req.url.split('?')[0];
|
|
53
|
+
|
|
54
|
+
ammo.fullURL = `${ammo.protocol}://${ammo.hostname}/${ammo.path}`;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default enhance;
|