ntropi 1.0.0-beta.1 → 1.0.0

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 CHANGED
@@ -2,35 +2,29 @@
2
2
  ![Ntropi Logo](https://github.com/Pushpender-18/DeLender/blob/main/ntropi-npm-bg.png?raw=true)
3
3
 
4
4
  <div align="center">
5
- <div style="margin-top: 8px;">
6
- <strong>
7
- <p>A live mock API generator that works without having any actual backend.
8
- Perfect for frontend development, testing, and prototyping.</p>
9
- </strong>
10
- </div>
5
+ <strong>
6
+ <p>
7
+ A live mock API generator for frontend development, testing, and prototyping,
8
+ with a built-in configuration website.
9
+ </p>
10
+ </strong>
11
11
  </div>
12
12
 
13
13
  ## Table of Contents
14
14
 
15
15
  - [Installation](#installation)
16
16
  - [Quick Start](#quick-start)
17
- - [Usage](#usage)
18
- - [Basic Commands](#basic-commands)
19
- - [Command Options](#command-options)
17
+ - [CLI Usage](#cli-usage)
18
+ - [Commands](#commands)
19
+ - [Options](#options)
20
+ - [API Method Syntax](#api-method-syntax)
20
21
  - [Configuration File](#configuration-file)
22
+ - [Top-Level Properties](#top-level-properties)
21
23
  - [Endpoint Properties](#endpoint-properties)
24
+ - [Template and Data Behavior](#template-and-data-behavior)
25
+ - [Dynamic Token Reference](#dynamic-token-reference)
26
+ - [Configuration Website](#configuration-website)
22
27
  - [Examples](#examples)
23
- - [Example 1: Simple API for Frontend Development](#example-1-simple-api-for-frontend-development)
24
- - [Example 2: Simulate Slow Network](#example-2-simulate-slow-network)
25
- - [Example 3: Test Error Handling](#example-3-test-error-handling)
26
- - [Example 4: Multiple Endpoints](#example-4-multiple-endpoints)
27
- - [Example 5: Add Endpoints](#example-5-add-endpoints)
28
- - [Example 6: Custom Config File](#example-6-custom-config-file)
29
- - [Example 7: Complete Workflow](#example-7-complete-workflow)
30
- - [Advanced Usage](#advanced-usage)
31
- - [Custom Response Data](#custom-response-data)
32
- - [Testing Different Scenarios](#testing-different-scenarios)
33
- - [Tips](#tips)
34
28
  - [Troubleshooting](#troubleshooting)
35
29
  - [Authors](#authors)
36
30
 
@@ -42,247 +36,207 @@ npm install -g ntropi
42
36
 
43
37
  ## Quick Start
44
38
 
45
- Generate a config and run the server:
46
-
47
39
  ```bash
48
- ntropi --api users posts --delay 1000 --failure-rate 10
40
+ # 1) Create config
41
+ ntropi --api users posts --delay 500 --failure-rate 10
42
+
43
+ # 2) Run server
49
44
  ntropi run
50
45
  ```
51
46
 
52
- ## Usage
47
+ By default, Ntropi starts at `http://localhost:8008`.
48
+ If port `8008` is occupied, it automatically tries the next free port.
53
49
 
54
- ### Basic Commands
50
+ ## CLI Usage
55
51
 
56
- #### Run the Mock Server
52
+ ### Commands
57
53
 
58
54
  ```bash
59
- # Run with default config (ntropi-config.json)
55
+ # Generate or update config (default: ntropi-config.json)
56
+ ntropi [options]
57
+
58
+ # Run server using default config file
60
59
  ntropi run
61
60
 
62
- # Run with custom config file
63
- ntropi run --config my-config.json
61
+ # Same as above using flag
62
+ ntropi --run
64
63
  ```
65
64
 
66
- #### Generate Configuration
67
-
68
- ```bash
69
- # Generate default config with default settings
70
- ntropi
65
+ ### Options
71
66
 
72
- # Generate config with specific APIs
73
- ntropi --api users posts products
67
+ | Option | Shorthand | Description |
68
+ | --- | --- | --- |
69
+ | `--help` | - | Show help output |
70
+ | `run` | - | Run the mock server |
71
+ | `--run` | `-r` | Run the mock server |
72
+ | `--api <values...>` | `-a` | Endpoints to generate/update |
73
+ | `--delay <num>` | `-d` | Response delay in milliseconds (integer, `>= 0`) |
74
+ | `--failure-rate <num>` | `-f` | Failure percentage (`0` to `100`) |
75
+ | `--config <file>` | `-c` | Config file path |
76
+ | `run --editor-only` | - | Start only the configuration website (no mock endpoints) |
74
77
 
75
- # Generate config with delay (in milliseconds)
76
- ntropi --api users --delay 2000
78
+ ### API Method Syntax
77
79
 
78
- # Generate config with failure rate (0-100%)
79
- ntropi --api users --failure-rate 50
80
+ You can set endpoint methods directly in `--api` values:
80
81
 
81
- # Combine multiple options
82
- ntropi --api users posts --delay 1000 --failure-rate 25
83
- ```
82
+ ```bash
83
+ # Default method is GET
84
+ ntropi --api users products
84
85
 
85
- ### Command Options
86
+ # Explicit method
87
+ ntropi --api users:POST orders:DELETE
86
88
 
87
- | Option | Shorthand | Description | Example |
88
- |--------|-----------|-------------|---------|
89
- | `--help` | | Show help information | `ntropi --help` |
90
- | `run` | | Run the mock server | `ntropi run` |
91
- | `--api` | `-a` | Specify API endpoints | `ntropi --api users posts` |
92
- | `--delay` | `-d` | Set response delay (ms) | `ntropi --delay 2000` |
93
- | `--failure-rate` | `-f` | Set failure rate (0-100%) | `ntropi --failure-rate 30` |
94
- | `--config` | `-c` | Specify config file | `ntropi --config custom.json` |
89
+ # Shorthand methods
90
+ # G=GET, P=POST, U=PUT, D=DELETE, H=PATCH
91
+ ntropi --api users:G orders:P profile:U health:D patch-test:H
92
+ ```
95
93
 
96
94
  ## Configuration File
97
95
 
98
- The configuration file (`ntropi-config.json`) defines your mock API endpoints:
96
+ Default file: `ntropi-config.json`
99
97
 
100
98
  ```json
101
99
  {
100
+ "localhost": true,
102
101
  "endpoints": [
103
102
  {
104
103
  "path": "/api/users",
105
104
  "method": "GET",
106
- // If data is an array then one
107
- // item is sent at random
108
105
  "data": [
109
- {"id": 1, "name": "John Doe"},
110
- {"id": 2, "name": "Jane Smith"}
106
+ { "id": 1, "name": "$name" },
107
+ { "id": 2, "name": "$name" }
111
108
  ],
112
- "delay": 1000,
113
- "failureRate": 10
114
- },
115
- {
116
- "path": "/api/posts",
117
- "method": "GET",
118
- // If data is not an array then
119
- // data is sent as it is
120
- "data":
121
- {"id": 1, "title": "Hello World"},
122
- "delay": 0,
123
- "failureRate": 0
109
+ "delay": 300,
110
+ "failureRate": 5,
111
+ "cacheSize": 5
124
112
  }
125
113
  ]
126
114
  }
127
115
  ```
128
116
 
129
- **Note:** If data is an array then an item is choosen at random otherwise the data is sent as it is.
117
+ ### Top-Level Properties
118
+
119
+ - `endpoints` (required): array of endpoint definitions.
120
+ - `localhost` (optional):
121
+ - `true` or omitted: bind to `127.0.0.1`.
122
+ - `false`: bind to `0.0.0.0` for LAN/network access.
130
123
 
131
124
  ### Endpoint Properties
132
125
 
133
- - **path**: API endpoint path (e.g., `/api/users`)
134
- - **method**: HTTP method (`GET`, `POST`, `PUT`, `DELETE`, etc.)
135
- - **data**: Response data (can be any valid JSON)
136
- - **delay**: Response delay in milliseconds
137
- - **failureRate**: Percentage chance of returning 500 error (0-100)
126
+ - `path` (required): route path, must start with `/`.
127
+ - `method` (required): one of `GET`, `POST`, `PUT`, `DELETE`, `PATCH`.
128
+ - `data` (required): source data used for response generation.
129
+ - `delay` (optional): non-negative number in milliseconds.
130
+ - `failureRate` (optional): number in range `0..100`.
131
+ - `cacheSize` (optional): positive integer response cache size.
132
+ - `template` (optional): object template that maps placeholders to `data`.
138
133
 
139
- ## Examples
134
+ ### Template and Data Behavior
140
135
 
141
- ### Example 1: Simple API for Frontend Development
136
+ - If `template` is not provided:
137
+ - array `data`: one top-level item is randomly selected (token resolved if present).
138
+ - object/string `data`: returned directly (after token resolution).
139
+ - If `template` is provided:
140
+ - `data` must be a non-empty array.
141
+ - indexed placeholders like `$1`, `$2` refer to array positions.
142
+ - nested template objects/arrays are supported.
142
143
 
143
- ```bash
144
- # Create a users API with no delay
145
- ntropi --api users --delay 0 --failure-rate 0
146
- ntropi run
144
+ Template example:
145
+
146
+ ```json
147
+ {
148
+ "endpoints": [
149
+ {
150
+ "path": "/api/profile",
151
+ "method": "GET",
152
+ "data": [
153
+ ["active", "inactive"],
154
+ { "name": "$name", "age": "$int(18-40)" }
155
+ ],
156
+ "template": {
157
+ "status": "$1",
158
+ "user": "$2"
159
+ },
160
+ "delay": 0,
161
+ "failureRate": 0
162
+ }
163
+ ]
164
+ }
147
165
  ```
148
166
 
149
- Access at: `http://localhost:8008/api/users`
167
+ ### Custom Dataset Generator
150
168
 
151
- ### Example 2: Simulate Slow Network
169
+ We have built a powerful custom dataset generator designed to deliver instant, ready-to-use datasets tailored to your exact specifications. Simply define your parameters, set your desired values, and generate structured data on demand, no manual effort required.
152
170
 
153
- ```bash
154
- # Create API with 3 second delay
155
- ntropi --api products --delay 3000
156
- ntropi run
157
- ```
171
+ ### Dynamic Token Reference
158
172
 
159
- ### Example 3: Test Error Handling
173
+ Supported value generators in `data` strings:
160
174
 
161
- ```bash
162
- # Create API with 50% failure rate
163
- ntropi --api orders --failure-rate 50
164
- ntropi run
165
- ```
175
+ - `$name`
176
+ - `$string(min-max)` or `$string(n)`
177
+ - `$int(min-max)` or `$int(n)`
178
+ - `$float(min-max,decimals)`
179
+ - `$bool`
180
+ - `$date(format)` (or `$date` for ISO timestamp)
181
+ - `$uuid`
166
182
 
167
- ### Example 4: Multiple Endpoints
183
+ Escape tokens with `\\$` to keep them as literal text.
168
184
 
169
- ```bash
170
- # Create multiple APIs with different configurations
171
- ntropi --api users posts comments products
172
- ntropi run
173
- ```
185
+ ## Configuration Website
174
186
 
175
- Then manually edit `ntropi-config.json` to customize each endpoint.
176
-
177
- ### Example 5: Add Endpoints
187
+ When you run Ntropi, it also serves a configuration website at the server root.
178
188
 
179
189
  ```bash
180
- # Add APIs to existing configuratoin
181
- ntropi --api users
182
- ntropi --api posts
183
- ntropi --api comments
184
- ntropi --api products
185
190
  ntropi run
186
191
  ```
187
192
 
193
+ Then open:
188
194
 
189
- ### Example 6: Custom Config File
195
+ - `http://localhost:8008/` (or the printed port)
190
196
 
191
- ```bash
192
- # Use a specific config file
193
- ntropi run --config staging-api.json
194
- ```
195
-
196
- ### Example 7: Complete Workflow
197
+ Editor-only mode:
197
198
 
198
199
  ```bash
199
- # 1. Generate config with 3 APIs
200
- ntropi --api users posts comments --delay 500 --failure-rate 5
201
-
202
- # 2. Edit ntropi-config.json to customize responses
200
+ ntropi run --editor-only
201
+ ```
203
202
 
204
- # 3. Run the server
205
- ntropi run
203
+ This starts only the configuration website and management APIs, without generating mock API endpoints.
206
204
 
207
- # 4. Access your mock APIs
208
- # GET http://localhost:8008/api/users
209
- # GET http://localhost:8008/api/posts
210
- # GET http://localhost:8008/api/comments
211
- ```
205
+ ## Examples
212
206
 
213
- ## Advanced Usage
207
+ ```bash
208
+ # Basic endpoints
209
+ ntropi --api users posts comments
214
210
 
215
- ### Custom Response Data
211
+ # With delay and failures
212
+ ntropi --api orders payments --delay 1200 --failure-rate 25
216
213
 
217
- Edit `ntropi-config.json` to add custom response data:
214
+ # Mixed methods
215
+ ntropi --api users:G users:POST users:PUT users:D
218
216
 
219
- ```json
220
- {
221
- "endpoints": [
222
- {
223
- "path": "/api/users/1",
224
- "method": "GET",
225
- "data": {
226
- "id": 1,
227
- "name": "Alice Johnson",
228
- "email": "alice@example.com",
229
- "role": "admin"
230
- },
231
- "delay": 500,
232
- "failureRate": 0
233
- }
234
- ]
235
- }
217
+ # Custom config file
218
+ ntropi --api products --config staging.json
219
+ ntropi run --config staging.json
236
220
  ```
237
221
 
238
- ### Testing Different Scenarios
222
+ ## Troubleshooting
239
223
 
240
- ```json
241
- {
242
- "endpoints": [
243
- {
244
- "path": "/api/fast-endpoint",
245
- "method": "GET",
246
- "data": {"message": "Lightning fast!"},
247
- "delay": 0,
248
- "failureRate": 0
249
- },
250
- {
251
- "path": "/api/slow-endpoint",
252
- "method": "GET",
253
- "data": {"message": "Taking my time..."},
254
- "delay": 5000,
255
- "failureRate": 0
256
- },
257
- {
258
- "path": "/api/unreliable-endpoint",
259
- "method": "GET",
260
- "data": {"message": "Hope I work!"},
261
- "delay": 1000,
262
- "failureRate": 80
263
- }
264
- ]
265
- }
266
- ```
224
+ ### Config validation error
267
225
 
268
- ## Tips
226
+ Check that:
269
227
 
270
- 1. **Start Simple**: Begin with basic endpoints and add complexity as needed
271
- 2. **Test Error States**: Use `failureRate` to ensure your app handles errors gracefully
272
- 3. **Realistic Delays**: Use delays to simulate real-world network conditions
273
- 4. **Version Control**: Commit your config files to share API mocks with your team
274
- 5. **Multiple Configs**: Use different config files for different testing scenarios
228
+ - each endpoint has `path`, `method`, `data`
229
+ - `path` starts with `/`
230
+ - `method` is valid
231
+ - `delay >= 0` and `failureRate` is in `0..100`
275
232
 
276
- ## Troubleshooting
233
+ ### Port already in use
277
234
 
278
- ### Port Already in Use
279
- If port 8008 is busy, Ntropi will automatically try the next available port.
235
+ Ntropi automatically increments the port until it finds a free one.
280
236
 
281
- ### Config File Not Found
282
- Make sure you've generated a config file first or specify the correct path with `--config`.
237
+ ### Endpoint not changing after edit
283
238
 
284
- ### Syntax Error in Config
285
- Validate your JSON file using a JSON validator or linter.
239
+ Ntropi hot-reloads config file changes. If you changed endpoint `path`/`method`, the server restarts automatically. For value-only changes (like `delay`, `failureRate`, `data`), endpoints keep running and use new values on next request.
286
240
 
287
241
  ## Authors
288
242
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ntropi",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0",
4
4
  "description": "A live mock api generator that works without having any actual backend.",
5
5
  "author": "Amitrajeet Konch, Pushpender Singh",
6
6
  "type": "module",
@@ -9,14 +9,15 @@
9
9
  "ntropi": "src/app.js"
10
10
  },
11
11
  "scripts": {
12
- "test": "vitest"
12
+ "test": "vitest",
13
+ "frontend:build": "cd src/frontend && npm run build"
13
14
  },
14
15
  "dependencies": {
15
- "dotenv": "^17.2.3",
16
+ "@fastify/static": "^9.0.0",
16
17
  "fastify": "^5.7.4"
17
18
  },
18
19
  "devDependencies": {
19
- "verdaccio": "^6.2.5",
20
+ "@fastify/cors": "^11.2.0",
20
21
  "vitest": "^4.0.18"
21
22
  }
22
23
  }
package/src/app.js CHANGED
@@ -7,13 +7,11 @@ import { updateConfig } from './libs/config_updater.js';
7
7
  const args = process.argv.slice(2);
8
8
  const CONFIG = parseArgs(args);
9
9
 
10
- // Error Handling
11
10
  if (CONFIG.error) {
12
11
  console.log(`Error: ${CONFIG.error}`);
13
12
  process.exit(1);
14
13
  }
15
14
 
16
- // Help
17
15
  if (CONFIG.help) {
18
16
  console.log(`
19
17
  Usage: node app.js [options]
@@ -30,9 +28,8 @@ Options:
30
28
  }
31
29
 
32
30
  if (CONFIG.run) {
33
- // Run Server
34
31
  const configPath = CONFIG.config || 'ntropi-config.json';
35
- await run_server(configPath);
32
+ await run_server(configPath, CONFIG.configOnly);
36
33
  } else {
37
34
  updateConfig(CONFIG);
38
35
  }
@@ -0,0 +1,16 @@
1
+ # React + Vite
2
+
3
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
+
5
+ Currently, two official plugins are available:
6
+
7
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
+
10
+ ## React Compiler
11
+
12
+ The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
13
+
14
+ ## Expanding the ESLint configuration
15
+
16
+ If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
@@ -0,0 +1,29 @@
1
+ import js from '@eslint/js'
2
+ import globals from 'globals'
3
+ import reactHooks from 'eslint-plugin-react-hooks'
4
+ import reactRefresh from 'eslint-plugin-react-refresh'
5
+ import { defineConfig, globalIgnores } from 'eslint/config'
6
+
7
+ export default defineConfig([
8
+ globalIgnores(['dist']),
9
+ {
10
+ files: ['**/*.{js,jsx}'],
11
+ extends: [
12
+ js.configs.recommended,
13
+ reactHooks.configs.flat.recommended,
14
+ reactRefresh.configs.vite,
15
+ ],
16
+ languageOptions: {
17
+ ecmaVersion: 2020,
18
+ globals: globals.browser,
19
+ parserOptions: {
20
+ ecmaVersion: 'latest',
21
+ ecmaFeatures: { jsx: true },
22
+ sourceType: 'module',
23
+ },
24
+ },
25
+ rules: {
26
+ 'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
27
+ },
28
+ },
29
+ ])
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Ntropi Engine</title>
7
+ </head>
8
+ <body>
9
+ <div id="root"></div>
10
+ <script type="module" src="/src/main.jsx"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "frontend",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "lint": "eslint .",
10
+ "preview": "vite preview"
11
+ },
12
+ "dependencies": {
13
+ "@tailwindcss/vite": "^4.2.1",
14
+ "clsx": "^2.1.1",
15
+ "framer-motion": "^12.36.0",
16
+ "lucide-react": "^0.577.0",
17
+ "react": "^19.2.0",
18
+ "react-dom": "^19.2.0",
19
+ "tailwind-merge": "^3.5.0",
20
+ "tailwindcss": "^4.2.1"
21
+ },
22
+ "devDependencies": {
23
+ "@eslint/js": "^9.39.1",
24
+ "@types/react": "^19.2.7",
25
+ "@types/react-dom": "^19.2.3",
26
+ "@vitejs/plugin-react": "^5.1.1",
27
+ "eslint": "^9.39.1",
28
+ "eslint-plugin-react-hooks": "^7.0.1",
29
+ "eslint-plugin-react-refresh": "^0.4.24",
30
+ "globals": "^16.5.0",
31
+ "vite": "^7.3.1"
32
+ }
33
+ }