te.js 2.0.3 → 2.1.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.
Files changed (68) hide show
  1. package/README.md +197 -187
  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 -0
  6. package/auto-docs/{llm → docs-llm}/prompts.js +222 -222
  7. package/auto-docs/{llm → docs-llm}/provider.js +132 -187
  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/database/index.js +165 -165
  20. package/database/mongodb.js +146 -146
  21. package/database/redis.js +201 -201
  22. package/docs/README.md +36 -36
  23. package/docs/ammo.md +362 -362
  24. package/docs/api-reference.md +490 -489
  25. package/docs/auto-docs.md +216 -215
  26. package/docs/cli.md +152 -152
  27. package/docs/configuration.md +275 -233
  28. package/docs/database.md +390 -391
  29. package/docs/error-handling.md +438 -417
  30. package/docs/file-uploads.md +333 -334
  31. package/docs/getting-started.md +214 -215
  32. package/docs/middleware.md +355 -356
  33. package/docs/rate-limiting.md +393 -394
  34. package/docs/routing.md +302 -302
  35. package/package.json +62 -62
  36. package/rate-limit/algorithms/fixed-window.js +141 -141
  37. package/rate-limit/algorithms/sliding-window.js +147 -147
  38. package/rate-limit/algorithms/token-bucket.js +115 -115
  39. package/rate-limit/base.js +165 -165
  40. package/rate-limit/index.js +147 -147
  41. package/rate-limit/storage/base.js +104 -104
  42. package/rate-limit/storage/memory.js +101 -101
  43. package/rate-limit/storage/redis.js +88 -88
  44. package/server/ammo/body-parser.js +220 -220
  45. package/server/ammo/dispatch-helper.js +103 -103
  46. package/server/ammo/enhancer.js +57 -57
  47. package/server/ammo.js +454 -356
  48. package/server/endpoint.js +97 -74
  49. package/server/error.js +9 -9
  50. package/server/errors/code-context.js +125 -0
  51. package/server/errors/llm-error-service.js +140 -0
  52. package/server/files/helper.js +33 -33
  53. package/server/files/uploader.js +143 -143
  54. package/server/handler.js +158 -113
  55. package/server/target.js +185 -175
  56. package/server/targets/middleware-validator.js +22 -22
  57. package/server/targets/path-validator.js +21 -21
  58. package/server/targets/registry.js +160 -160
  59. package/server/targets/shoot-validator.js +21 -21
  60. package/te.js +428 -363
  61. package/utils/auto-register.js +17 -17
  62. package/utils/configuration.js +64 -64
  63. package/utils/errors-llm-config.js +84 -0
  64. package/utils/request-logger.js +43 -43
  65. package/utils/status-codes.js +82 -82
  66. package/utils/tejas-entrypoint-html.js +18 -18
  67. package/auto-docs/llm/index.js +0 -6
  68. package/auto-docs/llm/parse.js +0 -88
@@ -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;