local-lite-server 0.0.0-stage → 0.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 (90) hide show
  1. package/README.md +103 -2
  2. package/admin/dist/assets/index-B2nX9Pef.js +18 -0
  3. package/admin/dist/assets/index-Dt3bXEks.css +2 -0
  4. package/admin/dist/favicon.svg +11 -0
  5. package/admin/dist/index.html +14 -0
  6. package/dist/admin/console.d.ts +19 -0
  7. package/dist/admin/console.js +166 -0
  8. package/dist/admin/index.d.ts +28 -0
  9. package/dist/admin/index.js +13 -0
  10. package/dist/admin/ops.d.ts +11 -0
  11. package/dist/admin/ops.js +279 -0
  12. package/dist/admin/session.d.ts +14 -0
  13. package/dist/admin/session.js +160 -0
  14. package/dist/apiKeys.d.ts +36 -0
  15. package/dist/apiKeys.js +91 -0
  16. package/dist/app.d.ts +1 -0
  17. package/dist/app.js +10 -0
  18. package/dist/auth.d.ts +16 -0
  19. package/dist/auth.js +99 -0
  20. package/dist/cli.d.ts +2 -0
  21. package/dist/cli.js +127 -0
  22. package/dist/codegen.d.ts +4 -0
  23. package/dist/codegen.js +74 -0
  24. package/dist/config.d.ts +39 -0
  25. package/dist/config.js +51 -0
  26. package/dist/core/broker.d.ts +12 -0
  27. package/dist/core/broker.js +78 -0
  28. package/dist/core/changes.d.ts +17 -0
  29. package/dist/core/changes.js +68 -0
  30. package/dist/core/http.d.ts +8 -0
  31. package/dist/core/http.js +72 -0
  32. package/dist/core/mailer.d.ts +3 -0
  33. package/dist/core/mailer.js +11 -0
  34. package/dist/cpanel.d.ts +1 -0
  35. package/dist/cpanel.js +96 -0
  36. package/dist/crons.d.ts +24 -0
  37. package/dist/crons.js +124 -0
  38. package/dist/db.d.ts +7 -0
  39. package/dist/db.js +37 -0
  40. package/dist/functions/index.d.ts +3 -0
  41. package/dist/functions/index.js +3 -0
  42. package/dist/functions/loader.d.ts +4 -0
  43. package/dist/functions/loader.js +64 -0
  44. package/dist/functions/runtime.d.ts +21 -0
  45. package/dist/functions/runtime.js +238 -0
  46. package/dist/functions/types.d.ts +59 -0
  47. package/dist/functions/types.js +16 -0
  48. package/dist/index.d.ts +12 -0
  49. package/dist/index.js +7 -0
  50. package/dist/migrations.d.ts +16 -0
  51. package/dist/migrations.js +254 -0
  52. package/dist/oauth.d.ts +7 -0
  53. package/dist/oauth.js +152 -0
  54. package/dist/rateLimit.d.ts +12 -0
  55. package/dist/rateLimit.js +54 -0
  56. package/dist/routes.d.ts +15 -0
  57. package/dist/routes.js +29 -0
  58. package/dist/rules.d.ts +23 -0
  59. package/dist/rules.js +73 -0
  60. package/dist/schema.d.ts +18 -0
  61. package/dist/schema.js +89 -0
  62. package/dist/server.d.ts +13 -0
  63. package/dist/server.js +340 -0
  64. package/dist/start.d.ts +8 -0
  65. package/dist/start.js +168 -0
  66. package/dist/storage.d.ts +4 -0
  67. package/dist/storage.js +82 -0
  68. package/dist/tableStorage.d.ts +63 -0
  69. package/dist/tableStorage.js +261 -0
  70. package/docs/api.md +181 -0
  71. package/docs/client-usage.md +104 -0
  72. package/docs/cpanel.md +63 -0
  73. package/docs/functions.md +78 -0
  74. package/docs/schema-and-migrations.md +54 -0
  75. package/docs/vps.md +67 -0
  76. package/package.json +54 -4
  77. package/templates/.env +16 -0
  78. package/templates/.env.example +49 -0
  79. package/templates/README.md +23 -0
  80. package/templates/data/backups/.gitkeep +1 -0
  81. package/templates/data/uploads/.gitkeep +1 -0
  82. package/templates/gitignore +29 -0
  83. package/templates/package.json +14 -0
  84. package/templates/src/functions/notes.ts +47 -0
  85. package/templates/src/lib/validators.ts +9 -0
  86. package/templates/src/rules.ts +12 -0
  87. package/templates/src/schema.ts +9 -0
  88. package/templates/src/types.ts +9 -0
  89. package/templates/tests/notes.test.ts +26 -0
  90. package/templates/tsconfig.json +13 -0
package/README.md CHANGED
@@ -1,3 +1,104 @@
1
- # Temporary Holding Version
1
+ # local-lite-server
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Self-hostable reactive sync & server functions backend powered by [`local-lite`](https://github.com/georgechitechi/local-lite).
4
+ Runs on **MySQL** or **PostgreSQL**, deploys to **cPanel (Node.js App / Passenger)** or any **VPS** with **no Docker**, and includes a built-in React **Admin Console** at `/admin`.
5
+
6
+ ---
7
+
8
+ ## Key Capabilities
9
+
10
+ - **Real SQL Tables from `schema.ts`:** Generates and applies MySQL or PostgreSQL DDL automatically on boot (`AUTO_MIGRATE=true`) or via CLI.
11
+ - **Slim Change Log:** `_server_changes` stores only `(table_name, row_id, timestamp)` for fast delta sync and live SSE invalidation.
12
+ - **Server Functions (`functions/`):** Write `query`, `mutation` (transactional), and `action` handlers in TypeScript with live SSE subscriptions (`GET /subscribe/:module/:name`).
13
+ - **Authentication & Email OTP:** `/auth/signin`, `/auth/signup`, `/auth/refresh`, `/auth/forgot-password`, and `/auth/reset-password` backed by SQL + SMTP.
14
+ - **Admin Console (`/admin`):** Overview, Data Browser (row editor drawer), Auth & Users, Server Functions runner & live SSE subscriber, Schedules, Backups, Storage, Sync Logs, Environment variables, and Settings.
15
+ - **Zero-Framework HTTP:** Built on `node:http` + Web `Request`/`Response` (no Express or Fastify).
16
+
17
+ ---
18
+
19
+ ## Quick Start
20
+
21
+ ### On a Fresh PC (`npx`)
22
+
23
+ ```bash
24
+ npx local-lite-server init my-backend # or run `npx local-lite-server init` inside an existing folder
25
+ cd my-backend
26
+ # Edit .env with your MySQL or Postgres database credentials, then:
27
+ npx local-lite-server start
28
+ ```
29
+
30
+ ### From This Repo (Development)
31
+
32
+ 1. **Install dependencies & build the Admin UI:**
33
+ ```bash
34
+ npm install
35
+ cd admin && npm install && npm run build && cd ..
36
+ ```
37
+ 2. **Configure `.env`:**
38
+ ```bash
39
+ cp .env.example .env
40
+ ```
41
+ Set `DB_DIALECT` (`mysql` or `postgres`), `DB_HOST`, `DB_USER`, `DB_PASSWORD`, `DB_NAME`, `SERVER_API_KEY`, and `APP_SECRET`.
42
+ 3. **Create an empty database:**
43
+ - MySQL: `CREATE DATABASE \`local-admin\` CHARACTER SET utf8mb4;`
44
+ - Postgres: `CREATE DATABASE "local-admin";`
45
+ 4. **Start in dev mode (auto-rebuild + function hot-reload):**
46
+ ```bash
47
+ npm run dev
48
+ ```
49
+ 5. Open **http://localhost:3000/admin** and complete **First-Time Setup** using your `APP_SECRET` (or `SERVER_API_KEY`).
50
+
51
+ ---
52
+
53
+ ## Documentation
54
+
55
+ - [HTTP & SSE API Reference](./docs/api.md) — `/sync`, `/fn`, `/subscribe`, `/auth`, `/storage`, and `/admin` endpoints
56
+ - [Schema & Migrations](./docs/schema-and-migrations.md) — `schema.ts`, supported types, `AUTO_MIGRATE`, and CLI commands
57
+ - [Server Functions & Reactive Queries](./docs/functions.md) — `query`, `mutation`, `action`, and SSE `/subscribe`
58
+ - [Client Usage & Auth](./docs/client-usage.md) — `SelfHostedRemoteAdapter`, `/auth/*`, and calling functions from apps
59
+ - [Deploying on cPanel (Namecheap, etc.)](./docs/cpanel.md) — single-file `app.cjs` bundle for Setup Node.js App
60
+ - [Deploying on a VPS (systemd / PM2 / Nginx)](./docs/vps.md) — production Linux deployment without Docker
61
+
62
+ ---
63
+
64
+ ## Environment Variables
65
+
66
+ | Variable | Required | Default | Description |
67
+ |---|---|---|---|
68
+ | `DB_DIALECT` | Yes | `mysql` | `mysql` or `postgres` |
69
+ | `DB_HOST` | Yes | — | Database host |
70
+ | `DB_PORT` | No | `3306` / `5432` | Database port |
71
+ | `DB_USER` | Yes | — | Database username |
72
+ | `DB_PASSWORD` | No | `""` | Database password |
73
+ | `DB_NAME` | Yes | — | Database name |
74
+ | `DB_SSL` | No | `false` | Enable TLS for Postgres (`rejectUnauthorized: false`) |
75
+ | `DB_POOL_SIZE` | No | `5` | Max connection pool size |
76
+ | `SERVER_PORT` / `PORT` | No | `3000` | HTTP port or Passenger socket path |
77
+ | `SERVER_API_KEY` | Yes | — | Master Bearer key for `/sync`, `/fn`, and `/admin` |
78
+ | `APP_SECRET` | No | — | Enables `/auth/*` user accounts and signs JWTs + admin cookies |
79
+ | `APP_NAME` | No | `local-lite-server` | Display name in emails and admin console |
80
+ | `AUTO_MIGRATE` | No | `true` | Apply core & `schema.ts` migrations on boot |
81
+ | `SCHEMA_PATH` | No | `src/schema.ts` | Path to schema file |
82
+ | `RULES_PATH` | No | `src/rules.ts` | Path to per-table RLS rules (`read`/`write`) |
83
+ | `FUNCTIONS_DIR` | No | `src/functions` | Directory containing server function modules |
84
+ | `UPLOAD_DIR` | No | `./uploads` | Directory for uploaded storage files |
85
+ | `BACKUP_DIR` | No | `./backups` | Directory for JSON backup snapshots |
86
+ | `ENABLE_INTERNAL_CRONS` | No | `false` | Run `_lls_crons` schedules inside Node every 60s |
87
+ | `MULTI_INSTANCE` | No | `false` | Postgres `LISTEN/NOTIFY` (or MySQL tailing) + DB rate limits |
88
+ | `ADMIN_UI` | No | `true` | Set `false` to disable `/admin` routes |
89
+ | `CORS_ORIGINS` | No | `*` | Comma-separated allowed origins, or `*` |
90
+ | `SMTP_HOST`, `SMTP_PORT`, `SMTP_SECURE`, `SMTP_USER`, `SMTP_PASS`, `SMTP_FROM` | No | — | SMTP settings for password-reset OTP emails |
91
+
92
+ ---
93
+
94
+ ## Scripts
95
+
96
+ | Script | Purpose |
97
+ |---|---|
98
+ | `npm run dev` | Watch & rebuild `src/` + restart server + hot-reload `functions/` |
99
+ | `npm run dev:admin` | Vite HMR dev server for `admin/` on `http://localhost:5173/admin/` |
100
+ | `npm run start` | Build `dist/` and run production server |
101
+ | `npm run migrate` | Apply core + `schema.ts` migrations (`status` / `diff` subcommands supported) |
102
+ | `npx local-lite-server codegen` | Generate typed client SDK (`--out src/client.ts`) |
103
+ | `npm run build:cpanel` | Build self-contained `dist/cpanel/` bundle for cPanel |
104
+ | `npm test` | Run Vitest suite |