local-lite-server 0.1.0 → 0.1.2

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 (54) hide show
  1. package/admin/dist/assets/{index-DMJ7Ri2R.js → index-6REgGhGR.js} +4 -4
  2. package/admin/dist/index.html +1 -1
  3. package/dist/admin/console.d.ts +19 -0
  4. package/dist/admin/index.d.ts +28 -0
  5. package/dist/admin/ops.d.ts +11 -0
  6. package/dist/admin/session.d.ts +14 -0
  7. package/dist/admin/session.js +2 -1
  8. package/dist/apiKeys.d.ts +36 -0
  9. package/dist/app.d.ts +1 -0
  10. package/dist/app.js +5 -1
  11. package/dist/auth.d.ts +16 -0
  12. package/dist/cli.d.ts +2 -0
  13. package/dist/codegen.d.ts +4 -0
  14. package/dist/config.d.ts +39 -0
  15. package/dist/core/broker.d.ts +12 -0
  16. package/dist/core/broker.js +2 -8
  17. package/dist/core/changes.d.ts +17 -0
  18. package/dist/core/changes.js +1 -5
  19. package/dist/core/http.d.ts +8 -0
  20. package/dist/core/http.js +1 -1
  21. package/dist/core/mailer.d.ts +3 -0
  22. package/dist/core/resolve.d.ts +2 -0
  23. package/dist/core/resolve.js +20 -0
  24. package/dist/cpanel.d.ts +1 -0
  25. package/dist/cpanel.js +24 -6
  26. package/dist/crons.d.ts +24 -0
  27. package/dist/db.d.ts +17 -0
  28. package/dist/db.js +12 -6
  29. package/dist/functions/index.d.ts +3 -0
  30. package/dist/functions/loader.d.ts +4 -0
  31. package/dist/functions/runtime.d.ts +21 -0
  32. package/dist/functions/types.d.ts +59 -0
  33. package/dist/index.d.ts +12 -0
  34. package/dist/index.js +1 -0
  35. package/dist/migrations.d.ts +16 -0
  36. package/dist/migrations.js +13 -0
  37. package/dist/oauth.d.ts +7 -0
  38. package/dist/oauth.js +149 -0
  39. package/dist/rateLimit.d.ts +12 -0
  40. package/dist/routes.d.ts +15 -0
  41. package/dist/routes.js +13 -0
  42. package/dist/rules.d.ts +23 -0
  43. package/dist/rules.js +3 -19
  44. package/dist/schema.d.ts +18 -0
  45. package/dist/schema.js +5 -19
  46. package/dist/server.d.ts +13 -0
  47. package/dist/server.js +47 -72
  48. package/dist/start.d.ts +8 -0
  49. package/dist/start.js +13 -13
  50. package/dist/storage.d.ts +4 -0
  51. package/dist/tableStorage.d.ts +63 -0
  52. package/dist/tableStorage.js +1 -6
  53. package/package.json +1 -1
  54. package/templates/.env.example +33 -0
@@ -0,0 +1,63 @@
1
+ import { type ServerSyncStorage, type SqlExecutor, type SyncEventBroker } from 'local-lite/server';
2
+ import type { RuleContext, RulesDictionary } from './rules.js';
3
+ import type { SchemaDictionary, SchemaFieldType } from './schema.js';
4
+ type Op = {
5
+ id: string;
6
+ tableName: string;
7
+ rowId: string;
8
+ operation: 'INSERT' | 'UPDATE' | 'DELETE';
9
+ payload?: Record<string, any> | null;
10
+ timestamp: number;
11
+ };
12
+ /** Thrown for bad client input; the HTTP layer maps it to 400. */
13
+ export declare class ClientError extends Error {
14
+ }
15
+ /** Thrown when a row-level access rule rejects the operation; mapped to 403. */
16
+ export declare class ForbiddenError extends Error {
17
+ }
18
+ /** Client value -> DB parameter. */
19
+ export declare function toDbValue(type: SchemaFieldType, value: unknown, dialect: string): unknown;
20
+ /** DB row -> client payload. */
21
+ export declare function fromDbRow(fields: Record<string, SchemaFieldType>, row: Record<string, any>): Record<string, any>;
22
+ export interface TableSyncStorageOptions {
23
+ schema: SchemaDictionary;
24
+ rules?: RulesDictionary;
25
+ broker?: SyncEventBroker;
26
+ changesTable?: string;
27
+ clockTable?: string;
28
+ /** Column used as the realtime event scope when a payload has it. */
29
+ scopeField?: string;
30
+ }
31
+ /**
32
+ * Stores every synced table as a real SQL table. `_server_changes` keeps only
33
+ * (table_name, row_id, timestamp) as a monotonic cursor/event log.
34
+ */
35
+ export declare class TableSyncStorage implements ServerSyncStorage {
36
+ private db;
37
+ private schema;
38
+ private rules;
39
+ private broker?;
40
+ private changes;
41
+ private clock;
42
+ private scopeField;
43
+ constructor(db: SqlExecutor, opts: TableSyncStorageOptions);
44
+ get tables(): string[];
45
+ private q;
46
+ private fields;
47
+ applyOperations(operations: Op[] | any[], _serverTime?: number, auth?: RuleContext): Promise<{
48
+ applied: number;
49
+ successfulIds: string[];
50
+ serverTime: number;
51
+ cursor: number;
52
+ }>;
53
+ getDeltas(tables: string[], since: number, limit?: number, auth?: RuleContext): Promise<{
54
+ changes: {
55
+ timestamp: number;
56
+ changes: any[];
57
+ };
58
+ cursor: number;
59
+ hasMore: boolean;
60
+ serverTime: number;
61
+ }>;
62
+ }
63
+ export {};
@@ -149,12 +149,7 @@ export class TableSyncStorage {
149
149
  throw new ForbiddenError(`Write denied on ${op.tableName}/${op.rowId}.`);
150
150
  }
151
151
  }
152
- else if (op.operation === 'DELETE') {
153
- if (!(await writeRule(auth, { id: op.rowId, ...payload }))) {
154
- throw new ForbiddenError(`Delete denied on ${op.tableName}/${op.rowId}.`);
155
- }
156
- }
157
- if (op.operation !== 'DELETE') {
152
+ if (!existing || op.operation !== 'DELETE') {
158
153
  if (!(await writeRule(auth, { id: op.rowId, ...payload }))) {
159
154
  throw new ForbiddenError(`Write denied on ${op.tableName}/${op.rowId}.`);
160
155
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "local-lite-server",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Self-hostable local-lite sync server for MySQL or Postgres. Runs on cPanel Node.js apps or any VPS, no Docker.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,16 +1,49 @@
1
+ # Server bind host and port. Use 0.0.0.0 for LAN / physical mobile device connections.
2
+ SERVER_HOST=127.0.0.1
1
3
  SERVER_PORT=3000
4
+
5
+ # Database: mysql | postgres
2
6
  DB_DIALECT=mysql
3
7
  DB_HOST=127.0.0.1
4
8
  DB_PORT=3306
5
9
  DB_USER=root
6
10
  DB_PASSWORD=
7
11
  DB_NAME=local_lite
12
+ # DB_SSL=true
8
13
  DB_POOL_SIZE=5
14
+
15
+ # Migrations & custom paths
9
16
  AUTO_MIGRATE=true
17
+ # SCHEMA_PATH=./src/schema.ts
18
+ # RULES_PATH=./src/rules.ts
19
+ # FUNCTIONS_DIR=./src/functions
20
+ # ROUTES_PATH=./src/routes.ts
21
+
22
+ # Storage & backups
10
23
  UPLOAD_DIR=./data/uploads
11
24
  BACKUP_DIR=./data/backups
25
+
26
+ # Auth & Admin Console
12
27
  SERVER_API_KEY=change-me
13
28
  APP_SECRET=change-me
14
29
  APP_NAME={{PKG_NAME}}
15
30
  ADMIN_UI=true
31
+
32
+ # OAuth code exchange (optional: POST /auth/google-token & /auth/github-token)
33
+ # GOOGLE_CLIENT_SECRET=
34
+ # GITHUB_CLIENT_SECRET=
35
+
36
+ # SMTP for password-reset emails (optional)
37
+ # SMTP_HOST=mail.yourdomain.com
38
+ # SMTP_PORT=465
39
+ # SMTP_SECURE=true
40
+ # SMTP_USER=no-reply@yourdomain.com
41
+ # SMTP_PASS=
42
+ # SMTP_FROM={{PKG_NAME}} <no-reply@yourdomain.com>
43
+
44
+ # Background crons & multi-instance sync (optional)
45
+ # ENABLE_INTERNAL_CRONS=true
46
+ # MULTI_INSTANCE=true
47
+
48
+ # CORS
16
49
  CORS_ORIGINS=*