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
package/docs/cli.md CHANGED
@@ -1,152 +1,152 @@
1
- # CLI Reference
2
-
3
- Tejas includes a command-line interface for starting your server and generating API documentation.
4
-
5
- ## Installation
6
-
7
- The CLI is included when you install te.js. It is available as the `tejas` command:
8
-
9
- ```bash
10
- npm install te.js
11
- ```
12
-
13
- If installed locally, use `npx tejas` to run commands.
14
-
15
- ## Commands
16
-
17
- ### tejas fly
18
-
19
- Start the Tejas server by running your application's entry point.
20
-
21
- ```bash
22
- tejas fly [file]
23
- ```
24
-
25
- **Entry point resolution** (first match wins):
26
-
27
- 1. CLI argument — `tejas fly app.js`
28
- 2. `tejas.config.json` — `"entry": "src/index.js"`
29
- 3. `package.json` — `"main": "index.js"`
30
- 4. Convention files — `index.js`, `app.js`, or `server.js` in the current directory
31
-
32
- **Examples:**
33
-
34
- ```bash
35
- # Use automatic entry point resolution
36
- npx tejas fly
37
-
38
- # Specify an entry file explicitly
39
- npx tejas fly src/server.js
40
- ```
41
-
42
- The server process inherits your environment and current working directory. Press `Ctrl+C` to stop.
43
-
44
- ---
45
-
46
- ### tejas generate:docs
47
-
48
- Generate an OpenAPI 3.0 specification from your registered targets using LLM-powered analysis.
49
-
50
- ```bash
51
- tejas generate:docs [--ci]
52
- ```
53
-
54
- #### Interactive Mode (default)
55
-
56
- Walks you through configuration step by step:
57
-
58
- ```bash
59
- npx tejas generate:docs
60
- ```
61
-
62
- You will be prompted for:
63
-
64
- | Prompt | Default | Description |
65
- |--------|---------|-------------|
66
- | Targets directory | `targets` | Directory containing `.target.js` files |
67
- | Output file | `./openapi.json` | Where to write the OpenAPI spec |
68
- | API title | `API` | Title in the spec's `info` block |
69
- | API version | `1.0.0` | Version in the spec's `info` block |
70
- | API description | *(empty)* | Optional description |
71
- | LLM provider base URL | `https://api.openai.com/v1` | Any OpenAI-compatible endpoint |
72
- | API key | *(from env)* | LLM provider API key |
73
- | Model | `gpt-4o-mini` | LLM model name |
74
- | Token usage level | `1` | Enhancement depth (1–3) |
75
- | Preview docs? | No | Serve a live Scalar UI preview |
76
-
77
- After generation, if you chose to preview, a local server starts on port 3333 (configurable via the `DOCS_PORT` env var).
78
-
79
- #### CI Mode
80
-
81
- Non-interactive mode for automated pipelines. Uses configuration from `tejas.config.json` and environment variables:
82
-
83
- ```bash
84
- npx tejas generate:docs --ci
85
- ```
86
-
87
- **Required environment:**
88
-
89
- | Variable | Fallback | Description |
90
- |----------|----------|-------------|
91
- | `LLM_API_KEY` | `OPENAI_API_KEY` | LLM provider API key |
92
-
93
- **Optional environment:**
94
-
95
- | Variable | Default | Description |
96
- |----------|---------|-------------|
97
- | `LLM_BASE_URL` | `https://api.openai.com/v1` | LLM provider base URL |
98
- | `LLM_MODEL` | `gpt-4o-mini` | LLM model name |
99
-
100
- All other options are read from the `docs` section of `tejas.config.json`. See [Auto-Documentation](./auto-docs.md) for the full config reference.
101
-
102
- ---
103
-
104
- ### tejas docs:on-push
105
-
106
- Generate documentation automatically when pushing to your production branch. Designed for use in a git `pre-push` hook.
107
-
108
- ```bash
109
- tejas docs:on-push
110
- ```
111
-
112
- This command reads git's pre-push stdin to determine which branch is being pushed. If it matches the configured production branch, it runs `generate:docs` in CI mode.
113
-
114
- **Setup with Husky:**
115
-
116
- ```json
117
- // package.json
118
- {
119
- "husky": {
120
- "hooks": {
121
- "pre-push": "tejas docs:on-push"
122
- }
123
- }
124
- }
125
- ```
126
-
127
- **Configuration:**
128
-
129
- | Source | Key | Default |
130
- |--------|-----|---------|
131
- | `tejas.config.json` | `docs.productionBranch` | `"main"` |
132
- | Environment variable | `DOCS_PRODUCTION_BRANCH` | `"main"` |
133
-
134
- If the push is not targeting the production branch, the command exits silently with no action.
135
-
136
- ---
137
-
138
- ## Environment Variables Summary
139
-
140
- | Variable | Used By | Description |
141
- |----------|---------|-------------|
142
- | `LLM_API_KEY` | `generate:docs`, `docs:on-push` | LLM provider API key |
143
- | `OPENAI_API_KEY` | `generate:docs`, `docs:on-push` | Fallback API key |
144
- | `LLM_BASE_URL` | `generate:docs`, `docs:on-push` | LLM provider endpoint |
145
- | `LLM_MODEL` | `generate:docs`, `docs:on-push` | LLM model name |
146
- | `DOCS_PORT` | `generate:docs` | Preview server port (default `3333`) |
147
- | `DOCS_PRODUCTION_BRANCH` | `docs:on-push` | Branch name to trigger generation |
148
-
149
- ## Next Steps
150
-
151
- - [Auto-Documentation](./auto-docs.md) — Enhancement levels, endpoint metadata, and Scalar UI
152
- - [Configuration](./configuration.md) — Full `tejas.config.json` reference
1
+ # CLI Reference
2
+
3
+ Tejas includes a command-line interface for starting your server and generating API documentation.
4
+
5
+ ## Installation
6
+
7
+ The CLI is included when you install te.js. It is available as the `tejas` command:
8
+
9
+ ```bash
10
+ npm install te.js
11
+ ```
12
+
13
+ If installed locally, use `npx tejas` to run commands.
14
+
15
+ ## Commands
16
+
17
+ ### tejas fly
18
+
19
+ Start the Tejas server by running your application's entry point.
20
+
21
+ ```bash
22
+ tejas fly [file]
23
+ ```
24
+
25
+ **Entry point resolution** (first match wins):
26
+
27
+ 1. CLI argument — `tejas fly app.js`
28
+ 2. `tejas.config.json` — `"entry": "src/index.js"`
29
+ 3. `package.json` — `"main": "index.js"`
30
+ 4. Convention files — `index.js`, `app.js`, or `server.js` in the current directory
31
+
32
+ **Examples:**
33
+
34
+ ```bash
35
+ # Use automatic entry point resolution
36
+ npx tejas fly
37
+
38
+ # Specify an entry file explicitly
39
+ npx tejas fly src/server.js
40
+ ```
41
+
42
+ The server process inherits your environment and current working directory. Press `Ctrl+C` to stop.
43
+
44
+ ---
45
+
46
+ ### tejas generate:docs
47
+
48
+ Generate an OpenAPI 3.0 specification from your registered targets using LLM-powered analysis.
49
+
50
+ ```bash
51
+ tejas generate:docs [--ci]
52
+ ```
53
+
54
+ #### Interactive Mode (default)
55
+
56
+ Walks you through configuration step by step:
57
+
58
+ ```bash
59
+ npx tejas generate:docs
60
+ ```
61
+
62
+ You will be prompted for:
63
+
64
+ | Prompt | Default | Description |
65
+ |--------|---------|-------------|
66
+ | Targets directory | `targets` | Directory containing `.target.js` files |
67
+ | Output file | `./openapi.json` | Where to write the OpenAPI spec |
68
+ | API title | `API` | Title in the spec's `info` block |
69
+ | API version | `1.0.0` | Version in the spec's `info` block |
70
+ | API description | *(empty)* | Optional description |
71
+ | LLM provider base URL | `https://api.openai.com/v1` | Any OpenAI-compatible endpoint |
72
+ | API key | *(from env)* | LLM provider API key |
73
+ | Model | `gpt-4o-mini` | LLM model name |
74
+ | Token usage level | `1` | Enhancement depth (1–3) |
75
+ | Preview docs? | No | Serve a live Scalar UI preview |
76
+
77
+ After generation, if you chose to preview, a local server starts on port 3333 (configurable via the `DOCS_PORT` env var).
78
+
79
+ #### CI Mode
80
+
81
+ Non-interactive mode for automated pipelines. Uses configuration from `tejas.config.json` and environment variables:
82
+
83
+ ```bash
84
+ npx tejas generate:docs --ci
85
+ ```
86
+
87
+ **Required environment:**
88
+
89
+ | Variable | Fallback | Description |
90
+ |----------|----------|-------------|
91
+ | `LLM_API_KEY` | `OPENAI_API_KEY` | LLM provider API key |
92
+
93
+ **Optional environment:**
94
+
95
+ | Variable | Default | Description |
96
+ |----------|---------|-------------|
97
+ | `LLM_BASE_URL` | `https://api.openai.com/v1` | LLM provider base URL |
98
+ | `LLM_MODEL` | `gpt-4o-mini` | LLM model name |
99
+
100
+ All other options are read from the `docs` section of `tejas.config.json`. See [Auto-Documentation](./auto-docs.md) for the full config reference.
101
+
102
+ ---
103
+
104
+ ### tejas docs:on-push
105
+
106
+ Generate documentation automatically when pushing to your production branch. Designed for use in a git `pre-push` hook.
107
+
108
+ ```bash
109
+ tejas docs:on-push
110
+ ```
111
+
112
+ This command reads git's pre-push stdin to determine which branch is being pushed. If it matches the configured production branch, it runs `generate:docs` in CI mode.
113
+
114
+ **Setup with Husky:**
115
+
116
+ ```json
117
+ // package.json
118
+ {
119
+ "husky": {
120
+ "hooks": {
121
+ "pre-push": "tejas docs:on-push"
122
+ }
123
+ }
124
+ }
125
+ ```
126
+
127
+ **Configuration:**
128
+
129
+ | Source | Key | Default |
130
+ |--------|-----|---------|
131
+ | `tejas.config.json` | `docs.productionBranch` | `"main"` |
132
+ | Environment variable | `DOCS_PRODUCTION_BRANCH` | `"main"` |
133
+
134
+ If the push is not targeting the production branch, the command exits silently with no action.
135
+
136
+ ---
137
+
138
+ ## Environment Variables Summary
139
+
140
+ | Variable | Used By | Description |
141
+ |----------|---------|-------------|
142
+ | `LLM_API_KEY` | `generate:docs`, `docs:on-push` | LLM provider API key |
143
+ | `OPENAI_API_KEY` | `generate:docs`, `docs:on-push` | Fallback API key |
144
+ | `LLM_BASE_URL` | `generate:docs`, `docs:on-push` | LLM provider endpoint |
145
+ | `LLM_MODEL` | `generate:docs`, `docs:on-push` | LLM model name |
146
+ | `DOCS_PORT` | `generate:docs` | Preview server port (default `3333`) |
147
+ | `DOCS_PRODUCTION_BRANCH` | `docs:on-push` | Branch name to trigger generation |
148
+
149
+ ## Next Steps
150
+
151
+ - [Auto-Documentation](./auto-docs.md) — Enhancement levels, endpoint metadata, and Scalar UI
152
+ - [Configuration](./configuration.md) — Full `tejas.config.json` reference