nibula 1.2.2 → 1.2.4

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 (50) hide show
  1. package/.eleventy.js +0 -5
  2. package/CHANGELOG.md +21 -9
  3. package/README.md +1 -1
  4. package/bin/create.js +1 -2
  5. package/bin/nibula.js +2 -5
  6. package/nginx.conf +75 -75
  7. package/package.json +74 -74
  8. package/src/backend/_core/index.js +267 -267
  9. package/src/backend/_core/init.js +52 -52
  10. package/src/backend/_core/modules/RateLimiter.js +58 -58
  11. package/src/backend/_core/modules/Response.js +59 -59
  12. package/src/backend/api/protected/example-protected.js +23 -23
  13. package/src/backend/api/public/example-public.js +24 -24
  14. package/src/backend/backend-node.service.example +30 -30
  15. package/src/backend/database/Database.js +46 -46
  16. package/src/backend/example.config.js +37 -37
  17. package/src/backend/package.json +18 -18
  18. package/src/frontend/.htaccess +51 -51
  19. package/src/frontend/assets/brand/favicon.svg +54 -54
  20. package/src/frontend/assets/brand/logo.svg +54 -54
  21. package/src/frontend/data/site.json +48 -48
  22. package/src/frontend/web.config +55 -55
  23. package/tools/assistant.js +122 -151
  24. package/tools/buildJs.js +39 -37
  25. package/tools/cleanOutput.js +23 -25
  26. package/tools/cli/prompt.js +40 -0
  27. package/tools/cli/ui.js +74 -0
  28. package/tools/config/messages.json +76 -0
  29. package/tools/config/settings.json +135 -0
  30. package/tools/lib/colors.js +17 -0
  31. package/tools/lib/files.js +65 -0
  32. package/tools/lib/logger.js +22 -0
  33. package/tools/lib/outputPath.js +141 -0
  34. package/tools/lib/pageActions.js +138 -0
  35. package/tools/lib/pageArtifacts.js +46 -0
  36. package/tools/lib/pageComponents.js +88 -0
  37. package/tools/lib/paths.js +61 -0
  38. package/tools/lib/project.js +54 -0
  39. package/tools/lib/siteData.js +93 -0
  40. package/tools/lib/text.js +47 -0
  41. package/tools/lib/validation.js +39 -0
  42. package/tools/res/templates/template.js +3 -1
  43. package/tools/res/templates/template.ts +3 -1
  44. package/tools/modules/constants.js +0 -66
  45. package/tools/modules/pageComponents.js +0 -77
  46. package/tools/modules/updateData.js +0 -90
  47. package/tools/modules/updateOutputPath.js +0 -112
  48. package/tools/modules/updatePage.js +0 -162
  49. package/tools/modules/utils.js +0 -27
  50. package/tools/modules/validation.js +0 -30
@@ -1,58 +1,58 @@
1
- 'use strict';
2
-
3
- /**
4
- * Mirror of src/backend/_core/modules/RateLimiter.php
5
- *
6
- * Same algorithm and same on-disk format: one JSON file per IP under ../../cache,
7
- * holding an array of request timestamps. Old timestamps outside the window are
8
- * pruned, the current one appended, and if the count exceeds the limit a 429 is
9
- * returned (with a Retry-After header) through the request-bound Response helper.
10
- */
11
-
12
- const fs = require('fs');
13
- const path = require('path');
14
- const crypto = require('crypto');
15
-
16
- class RateLimiter {
17
- /**
18
- * @param {string} ip
19
- * @param {number} maxRequests
20
- * @param {number} windowSeconds
21
- * @param {object} Response request-bound helper from createResponse(res)
22
- * @param {object} res raw http response (to set Retry-After)
23
- */
24
- static check(ip, maxRequests = 60, windowSeconds = 60, Response, res) {
25
- const cacheDir = path.join(__dirname, '..', '..', 'cache');
26
-
27
- if (!fs.existsSync(cacheDir)) {
28
- fs.mkdirSync(cacheDir, { recursive: true, mode: 0o755 });
29
- }
30
-
31
- const hash = crypto.createHash('md5').update(ip).digest('hex');
32
- const cacheFile = path.join(cacheDir, 'rl_' + hash + '.json');
33
- const now = Math.floor(Date.now() / 1000);
34
- let data = [];
35
-
36
- if (fs.existsSync(cacheFile)) {
37
- try {
38
- data = JSON.parse(fs.readFileSync(cacheFile, 'utf8')) || [];
39
- } catch (e) {
40
- data = [];
41
- }
42
- }
43
-
44
- data = data.filter((ts) => ts > (now - windowSeconds));
45
- data.push(now);
46
-
47
- // LOCK_EX equivalent: an exclusive write. Node's writeFileSync is atomic
48
- // enough for this single-process model.
49
- fs.writeFileSync(cacheFile, JSON.stringify(data));
50
-
51
- if (data.length > maxRequests) {
52
- res.setHeader('Retry-After', String(windowSeconds));
53
- Response.error('Too Many Requests', 429);
54
- }
55
- }
56
- }
57
-
58
- module.exports = RateLimiter;
1
+ 'use strict';
2
+
3
+ /**
4
+ * Mirror of src/backend/_core/modules/RateLimiter.php
5
+ *
6
+ * Same algorithm and same on-disk format: one JSON file per IP under ../../cache,
7
+ * holding an array of request timestamps. Old timestamps outside the window are
8
+ * pruned, the current one appended, and if the count exceeds the limit a 429 is
9
+ * returned (with a Retry-After header) through the request-bound Response helper.
10
+ */
11
+
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+ const crypto = require('crypto');
15
+
16
+ class RateLimiter {
17
+ /**
18
+ * @param {string} ip
19
+ * @param {number} maxRequests
20
+ * @param {number} windowSeconds
21
+ * @param {object} Response request-bound helper from createResponse(res)
22
+ * @param {object} res raw http response (to set Retry-After)
23
+ */
24
+ static check(ip, maxRequests = 60, windowSeconds = 60, Response, res) {
25
+ const cacheDir = path.join(__dirname, '..', '..', 'cache');
26
+
27
+ if (!fs.existsSync(cacheDir)) {
28
+ fs.mkdirSync(cacheDir, { recursive: true, mode: 0o755 });
29
+ }
30
+
31
+ const hash = crypto.createHash('md5').update(ip).digest('hex');
32
+ const cacheFile = path.join(cacheDir, 'rl_' + hash + '.json');
33
+ const now = Math.floor(Date.now() / 1000);
34
+ let data = [];
35
+
36
+ if (fs.existsSync(cacheFile)) {
37
+ try {
38
+ data = JSON.parse(fs.readFileSync(cacheFile, 'utf8')) || [];
39
+ } catch (e) {
40
+ data = [];
41
+ }
42
+ }
43
+
44
+ data = data.filter((ts) => ts > (now - windowSeconds));
45
+ data.push(now);
46
+
47
+ // LOCK_EX equivalent: an exclusive write. Node's writeFileSync is atomic
48
+ // enough for this single-process model.
49
+ fs.writeFileSync(cacheFile, JSON.stringify(data));
50
+
51
+ if (data.length > maxRequests) {
52
+ res.setHeader('Retry-After', String(windowSeconds));
53
+ Response.error('Too Many Requests', 429);
54
+ }
55
+ }
56
+ }
57
+
58
+ module.exports = RateLimiter;
@@ -1,59 +1,59 @@
1
- 'use strict';
2
-
3
- /**
4
- * Mirror of src/backend/_core/modules/Response.php
5
- *
6
- * In PHP the Response helper writes JSON and calls exit() to stop execution.
7
- * Node has no per-request exit, so each method writes to the response and then
8
- * throws the HALT sentinel. The front controller catches HALT and stops the
9
- * dispatch, reproducing the same "the endpoint stops here" behaviour.
10
- *
11
- * A fresh, response-bound helper is created per request via createResponse(res)
12
- * so overlapping async requests never clash (PHP was process-per-request).
13
- */
14
-
15
- // Sentinel thrown to unwind execution after a response has been sent (≈ PHP exit).
16
- const HALT = Symbol('RESPONSE_HALT');
17
-
18
- function jsonEncode(obj) {
19
- // JSON.stringify already leaves unicode unescaped and does not escape slashes,
20
- // matching PHP's JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES.
21
- return JSON.stringify(obj);
22
- }
23
-
24
- function createResponse(res) {
25
- return {
26
- success(data = null, code = 200) {
27
- res.statusCode = code;
28
- res.setHeader('Content-Type', 'application/json; charset=UTF-8');
29
- res.end(jsonEncode({
30
- status: 'success',
31
- data: data,
32
- }));
33
- throw HALT;
34
- },
35
-
36
- error(message, code = 400, details = null) {
37
- res.statusCode = code;
38
- res.setHeader('Content-Type', 'application/json; charset=UTF-8');
39
- const body = {
40
- status: 'error',
41
- message: message,
42
- code: code,
43
- };
44
- if (details !== null) {
45
- body.details = details;
46
- }
47
- res.end(jsonEncode(body));
48
- throw HALT;
49
- },
50
-
51
- noContent() {
52
- res.statusCode = 204;
53
- res.end();
54
- throw HALT;
55
- },
56
- };
57
- }
58
-
59
- module.exports = { createResponse, HALT };
1
+ 'use strict';
2
+
3
+ /**
4
+ * Mirror of src/backend/_core/modules/Response.php
5
+ *
6
+ * In PHP the Response helper writes JSON and calls exit() to stop execution.
7
+ * Node has no per-request exit, so each method writes to the response and then
8
+ * throws the HALT sentinel. The front controller catches HALT and stops the
9
+ * dispatch, reproducing the same "the endpoint stops here" behaviour.
10
+ *
11
+ * A fresh, response-bound helper is created per request via createResponse(res)
12
+ * so overlapping async requests never clash (PHP was process-per-request).
13
+ */
14
+
15
+ // Sentinel thrown to unwind execution after a response has been sent (≈ PHP exit).
16
+ const HALT = Symbol('RESPONSE_HALT');
17
+
18
+ function jsonEncode(obj) {
19
+ // JSON.stringify already leaves unicode unescaped and does not escape slashes,
20
+ // matching PHP's JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES.
21
+ return JSON.stringify(obj);
22
+ }
23
+
24
+ function createResponse(res) {
25
+ return {
26
+ success(data = null, code = 200) {
27
+ res.statusCode = code;
28
+ res.setHeader('Content-Type', 'application/json; charset=UTF-8');
29
+ res.end(jsonEncode({
30
+ status: 'success',
31
+ data: data,
32
+ }));
33
+ throw HALT;
34
+ },
35
+
36
+ error(message, code = 400, details = null) {
37
+ res.statusCode = code;
38
+ res.setHeader('Content-Type', 'application/json; charset=UTF-8');
39
+ const body = {
40
+ status: 'error',
41
+ message: message,
42
+ code: code,
43
+ };
44
+ if (details !== null) {
45
+ body.details = details;
46
+ }
47
+ res.end(jsonEncode(body));
48
+ throw HALT;
49
+ },
50
+
51
+ noContent() {
52
+ res.statusCode = 204;
53
+ res.end();
54
+ throw HALT;
55
+ },
56
+ };
57
+ }
58
+
59
+ module.exports = { createResponse, HALT };
@@ -1,23 +1,23 @@
1
- 'use strict';
2
-
3
- /**
4
- * Mirror of src/backend/api/protected/example-protected.php
5
- *
6
- * Protected endpoint: the API key check (X-Api-Key header) runs automatically in
7
- * the front controller before this file is loaded, so here we just handle logic.
8
- */
9
-
10
- module.exports = ({ method, requestParams, Response }) => {
11
- if (method !== 'GET') {
12
- Response.error('Method not allowed', 405);
13
- }
14
-
15
- //
16
- // Your endpoint logic here. You can access route parameters in requestParams
17
- //
18
-
19
- Response.success({
20
- message: 'Protected endpoint is working',
21
- params: requestParams,
22
- });
23
- };
1
+ 'use strict';
2
+
3
+ /**
4
+ * Mirror of src/backend/api/protected/example-protected.php
5
+ *
6
+ * Protected endpoint: the API key check (X-Api-Key header) runs automatically in
7
+ * the front controller before this file is loaded, so here we just handle logic.
8
+ */
9
+
10
+ module.exports = ({ method, requestParams, Response }) => {
11
+ if (method !== 'GET') {
12
+ Response.error('Method not allowed', 405);
13
+ }
14
+
15
+ //
16
+ // Your endpoint logic here. You can access route parameters in requestParams
17
+ //
18
+
19
+ Response.success({
20
+ message: 'Protected endpoint is working',
21
+ params: requestParams,
22
+ });
23
+ };
@@ -1,24 +1,24 @@
1
- 'use strict';
2
-
3
- /**
4
- * Mirror of src/backend/api/public/example-public.php
5
- *
6
- * Public endpoint: no API key required. Receives the request context and calls
7
- * the request-bound Response helper, exactly like the PHP file used the global
8
- * Response class and $method / $requestParams.
9
- */
10
-
11
- module.exports = ({ method, requestParams, Response }) => {
12
- if (method !== 'GET') {
13
- Response.error('Method not allowed', 405);
14
- }
15
-
16
- //
17
- // Your endpoint logic here. You can access route parameters in requestParams
18
- //
19
-
20
- Response.success({
21
- message: 'Public endpoint is working',
22
- params: requestParams,
23
- });
24
- };
1
+ 'use strict';
2
+
3
+ /**
4
+ * Mirror of src/backend/api/public/example-public.php
5
+ *
6
+ * Public endpoint: no API key required. Receives the request context and calls
7
+ * the request-bound Response helper, exactly like the PHP file used the global
8
+ * Response class and $method / $requestParams.
9
+ */
10
+
11
+ module.exports = ({ method, requestParams, Response }) => {
12
+ if (method !== 'GET') {
13
+ Response.error('Method not allowed', 405);
14
+ }
15
+
16
+ //
17
+ // Your endpoint logic here. You can access route parameters in requestParams
18
+ //
19
+
20
+ Response.success({
21
+ message: 'Public endpoint is working',
22
+ params: requestParams,
23
+ });
24
+ };
@@ -1,30 +1,30 @@
1
- # Example systemd unit to keep the Node backend running on your server.
2
- #
3
- # 1. Copy your built site to the server (the `out` folder).
4
- # 2. Adjust WorkingDirectory below to point at out/backend on your server.
5
- # 3. Copy this file to /etc/systemd/system/backend-node.service (drop the .example).
6
- # 4. Enable and start it:
7
- # sudo systemctl daemon-reload
8
- # sudo systemctl enable --now backend-node
9
- # sudo systemctl status backend-node
10
- #
11
- # Check the Node path with `which node` and update ExecStart if it isn't /usr/bin/node
12
- # (nvm installs live elsewhere, e.g. /home/<user>/.nvm/versions/node/<v>/bin/node).
13
-
14
- [Unit]
15
- Description=Nibula Node backend
16
- After=network.target
17
-
18
- [Service]
19
- Type=simple
20
- WorkingDirectory=/var/www/your-site/out/backend
21
- ExecStart=/usr/bin/node _core/index.js
22
- Environment=PORT=3000
23
- Environment=HOST=127.0.0.1
24
- Environment=APP_ENV=production
25
- Restart=on-failure
26
- RestartSec=2
27
- User=www-data
28
-
29
- [Install]
30
- WantedBy=multi-user.target
1
+ # Example systemd unit to keep the Node backend running on your server.
2
+ #
3
+ # 1. Copy your built site to the server (the `out` folder).
4
+ # 2. Adjust WorkingDirectory below to point at out/backend on your server.
5
+ # 3. Copy this file to /etc/systemd/system/backend-node.service (drop the .example).
6
+ # 4. Enable and start it:
7
+ # sudo systemctl daemon-reload
8
+ # sudo systemctl enable --now backend-node
9
+ # sudo systemctl status backend-node
10
+ #
11
+ # Check the Node path with `which node` and update ExecStart if it isn't /usr/bin/node
12
+ # (nvm installs live elsewhere, e.g. /home/<user>/.nvm/versions/node/<v>/bin/node).
13
+
14
+ [Unit]
15
+ Description=Nibula Node backend
16
+ After=network.target
17
+
18
+ [Service]
19
+ Type=simple
20
+ WorkingDirectory=/var/www/your-site/out/backend
21
+ ExecStart=/usr/bin/node _core/index.js
22
+ Environment=PORT=3000
23
+ Environment=HOST=127.0.0.1
24
+ Environment=APP_ENV=production
25
+ Restart=on-failure
26
+ RestartSec=2
27
+ User=www-data
28
+
29
+ [Install]
30
+ WantedBy=multi-user.target
@@ -1,46 +1,46 @@
1
- 'use strict';
2
-
3
- /**
4
- * Mirror of src/backend/database/Database.php
5
- *
6
- * PDO singleton → a single shared mysql2 connection pool. Config is read from
7
- * ../config.js (same relative location as the PHP version's ../config.php).
8
- * Options map the PDO attributes as closely as mysql2 allows:
9
- * - ERRMODE_EXCEPTION → mysql2 rejects/throws on error by default
10
- * - FETCH_ASSOC → rowsAsArray:false (objects keyed by column) is default
11
- * - EMULATE_PREPARES false → native prepared statements via pool.execute()
12
- *
13
- * Requires the "mysql2" package (npm install mysql2). getInstance() returns the
14
- * promise-based pool; use pool.execute(sql, params) for prepared statements.
15
- */
16
-
17
- const path = require('path');
18
-
19
- let instance = null;
20
-
21
- class Database {
22
- static getInstance() {
23
- if (instance === null) {
24
- // Lazy require so the backend boots even without a DB configured.
25
- // eslint-disable-next-line global-require
26
- const mysql = require('mysql2/promise');
27
-
28
- // eslint-disable-next-line global-require
29
- const config = require(path.join(__dirname, '..', 'config.js'));
30
-
31
- instance = mysql.createPool({
32
- host: config.DB_HOST,
33
- database: config.DB_NAME,
34
- user: config.DB_USER,
35
- password: config.DB_PASS,
36
- charset: 'utf8mb4',
37
- waitForConnections: true,
38
- connectionLimit: 10,
39
- namedPlaceholders: false,
40
- });
41
- }
42
- return instance;
43
- }
44
- }
45
-
46
- module.exports = Database;
1
+ 'use strict';
2
+
3
+ /**
4
+ * Mirror of src/backend/database/Database.php
5
+ *
6
+ * PDO singleton → a single shared mysql2 connection pool. Config is read from
7
+ * ../config.js (same relative location as the PHP version's ../config.php).
8
+ * Options map the PDO attributes as closely as mysql2 allows:
9
+ * - ERRMODE_EXCEPTION → mysql2 rejects/throws on error by default
10
+ * - FETCH_ASSOC → rowsAsArray:false (objects keyed by column) is default
11
+ * - EMULATE_PREPARES false → native prepared statements via pool.execute()
12
+ *
13
+ * Requires the "mysql2" package (npm install mysql2). getInstance() returns the
14
+ * promise-based pool; use pool.execute(sql, params) for prepared statements.
15
+ */
16
+
17
+ const path = require('path');
18
+
19
+ let instance = null;
20
+
21
+ class Database {
22
+ static getInstance() {
23
+ if (instance === null) {
24
+ // Lazy require so the backend boots even without a DB configured.
25
+ // eslint-disable-next-line global-require
26
+ const mysql = require('mysql2/promise');
27
+
28
+ // eslint-disable-next-line global-require
29
+ const config = require(path.join(__dirname, '..', 'config.js'));
30
+
31
+ instance = mysql.createPool({
32
+ host: config.DB_HOST,
33
+ database: config.DB_NAME,
34
+ user: config.DB_USER,
35
+ password: config.DB_PASS,
36
+ charset: 'utf8mb4',
37
+ waitForConnections: true,
38
+ connectionLimit: 10,
39
+ namedPlaceholders: false,
40
+ });
41
+ }
42
+ return instance;
43
+ }
44
+ }
45
+
46
+ module.exports = Database;
@@ -1,37 +1,37 @@
1
- 'use strict';
2
-
3
- /**
4
- * Mirror of src/backend/example.config.php
5
- *
6
- * Versioned, secret-free template. On setup, copy this file to config.js and
7
- * fill in real values. config.js is git-ignored and stays local.
8
- */
9
-
10
- module.exports = {
11
- // Default key for protected endpoints that don't have a specific key in CUSTOM_ENDPOINT_KEYS
12
- GENERAL_API_KEY: 'DEFAULT_KEY',
13
-
14
- // If you want to restrict access to protected endpoints to specific clients, define custom keys per endpoint.
15
- // For subfolder endpoints, use the relative path ('subfolder/endpoint')
16
- CUSTOM_ENDPOINT_KEYS: {
17
- 'subfolder/example-protected': 'custom-key',
18
- },
19
-
20
- GENERAL_ALLOWED_ORIGINS: [
21
- '*',
22
- // 'https://example.com',
23
- ],
24
-
25
- CUSTOM_ENDPOINT_ORIGINS: {
26
- 'subfolder/example-protected': ['https://app.example.com'],
27
- },
28
-
29
- // Database configuration
30
- DB_HOST: '127.0.0.1',
31
- DB_NAME: 'example_db',
32
- DB_USER: 'root',
33
- DB_PASS: '',
34
-
35
- // Environment: 'production' hides error details; anything else = debug.
36
- APP_ENV: 'production',
37
- };
1
+ 'use strict';
2
+
3
+ /**
4
+ * Mirror of src/backend/example.config.php
5
+ *
6
+ * Versioned, secret-free template. On setup, copy this file to config.js and
7
+ * fill in real values. config.js is git-ignored and stays local.
8
+ */
9
+
10
+ module.exports = {
11
+ // Default key for protected endpoints that don't have a specific key in CUSTOM_ENDPOINT_KEYS
12
+ GENERAL_API_KEY: 'DEFAULT_KEY',
13
+
14
+ // If you want to restrict access to protected endpoints to specific clients, define custom keys per endpoint.
15
+ // For subfolder endpoints, use the relative path ('subfolder/endpoint')
16
+ CUSTOM_ENDPOINT_KEYS: {
17
+ 'subfolder/example-protected': 'custom-key',
18
+ },
19
+
20
+ GENERAL_ALLOWED_ORIGINS: [
21
+ '*',
22
+ // 'https://example.com',
23
+ ],
24
+
25
+ CUSTOM_ENDPOINT_ORIGINS: {
26
+ 'subfolder/example-protected': ['https://app.example.com'],
27
+ },
28
+
29
+ // Database configuration
30
+ DB_HOST: '127.0.0.1',
31
+ DB_NAME: 'example_db',
32
+ DB_USER: 'root',
33
+ DB_PASS: '',
34
+
35
+ // Environment: 'production' hides error details; anything else = debug.
36
+ APP_ENV: 'production',
37
+ };
@@ -1,18 +1,18 @@
1
- {
2
- "name": "backend-node",
3
- "version": "1.0.0",
4
- "private": true,
5
- "description": "Node.js backend for a Nibula site. Coexists with the PHP backend; pick one at scaffold time. Front controller: _core/index.js.",
6
- "main": "_core/index.js",
7
- "type": "commonjs",
8
- "scripts": {
9
- "start": "node _core/index.js",
10
- "dev": "APP_ENV=development node _core/index.js"
11
- },
12
- "engines": {
13
- "node": ">=18"
14
- },
15
- "dependencies": {
16
- "mysql2": "^3.11.0"
17
- }
18
- }
1
+ {
2
+ "name": "backend-node",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "description": "Node.js backend for a Nibula site. Coexists with the PHP backend; pick one at scaffold time. Front controller: _core/index.js.",
6
+ "main": "_core/index.js",
7
+ "type": "commonjs",
8
+ "scripts": {
9
+ "start": "node _core/index.js",
10
+ "dev": "APP_ENV=development node _core/index.js"
11
+ },
12
+ "engines": {
13
+ "node": ">=18"
14
+ },
15
+ "dependencies": {
16
+ "mysql2": "^3.11.0"
17
+ }
18
+ }