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.
Files changed (70) hide show
  1. package/README.md +197 -196
  2. package/auto-docs/analysis/handler-analyzer.js +58 -58
  3. package/auto-docs/analysis/source-resolver.js +101 -101
  4. package/auto-docs/constants.js +37 -37
  5. package/auto-docs/docs-llm/index.js +7 -7
  6. package/auto-docs/docs-llm/prompts.js +222 -222
  7. package/auto-docs/docs-llm/provider.js +132 -132
  8. package/auto-docs/index.js +146 -146
  9. package/auto-docs/openapi/endpoint-processor.js +277 -277
  10. package/auto-docs/openapi/generator.js +107 -107
  11. package/auto-docs/openapi/level3.js +131 -131
  12. package/auto-docs/openapi/spec-builders.js +244 -244
  13. package/auto-docs/ui/docs-ui.js +186 -186
  14. package/auto-docs/utils/logger.js +17 -17
  15. package/auto-docs/utils/strip-usage.js +10 -10
  16. package/cli/docs-command.js +315 -315
  17. package/cli/fly-command.js +71 -71
  18. package/cli/index.js +56 -56
  19. package/cors/index.js +71 -0
  20. package/database/index.js +165 -165
  21. package/database/mongodb.js +146 -146
  22. package/database/redis.js +201 -201
  23. package/docs/README.md +36 -36
  24. package/docs/ammo.md +362 -362
  25. package/docs/api-reference.md +490 -490
  26. package/docs/auto-docs.md +216 -216
  27. package/docs/cli.md +152 -152
  28. package/docs/configuration.md +275 -275
  29. package/docs/database.md +390 -390
  30. package/docs/error-handling.md +438 -438
  31. package/docs/file-uploads.md +333 -333
  32. package/docs/getting-started.md +214 -214
  33. package/docs/middleware.md +355 -355
  34. package/docs/rate-limiting.md +393 -393
  35. package/docs/routing.md +302 -302
  36. package/lib/llm/client.js +73 -0
  37. package/lib/llm/index.js +7 -0
  38. package/lib/llm/parse.js +89 -0
  39. package/package.json +64 -62
  40. package/rate-limit/algorithms/fixed-window.js +141 -141
  41. package/rate-limit/algorithms/sliding-window.js +147 -147
  42. package/rate-limit/algorithms/token-bucket.js +115 -115
  43. package/rate-limit/base.js +165 -165
  44. package/rate-limit/index.js +147 -147
  45. package/rate-limit/storage/base.js +104 -104
  46. package/rate-limit/storage/memory.js +101 -101
  47. package/rate-limit/storage/redis.js +88 -88
  48. package/server/ammo/body-parser.js +220 -220
  49. package/server/ammo/dispatch-helper.js +103 -103
  50. package/server/ammo/enhancer.js +57 -57
  51. package/server/ammo.js +454 -415
  52. package/server/endpoint.js +97 -74
  53. package/server/error.js +9 -9
  54. package/server/errors/code-context.js +125 -125
  55. package/server/errors/llm-error-service.js +140 -140
  56. package/server/files/helper.js +33 -33
  57. package/server/files/uploader.js +143 -143
  58. package/server/handler.js +158 -119
  59. package/server/target.js +185 -175
  60. package/server/targets/middleware-validator.js +22 -22
  61. package/server/targets/path-validator.js +21 -21
  62. package/server/targets/registry.js +160 -160
  63. package/server/targets/shoot-validator.js +21 -21
  64. package/te.js +428 -402
  65. package/utils/auto-register.js +17 -17
  66. package/utils/configuration.js +64 -64
  67. package/utils/errors-llm-config.js +84 -84
  68. package/utils/request-logger.js +43 -43
  69. package/utils/status-codes.js +82 -82
  70. package/utils/tejas-entrypoint-html.js +18 -18
@@ -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;