@push.rocks/smartdb 2.7.0 → 2.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@push.rocks/smartdb",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "private": false,
5
5
  "description": "A MongoDB-compatible embedded database server with wire protocol support, backed by a high-performance Rust engine.",
6
6
  "exports": {
package/readme.md CHANGED
@@ -248,6 +248,62 @@ const server = new SmartdbServer({
248
248
  persistPath: './data/snapshot.json',
249
249
  persistIntervalMs: 30000, // Save every 30s
250
250
  });
251
+
252
+ // TLS transport for TCP mode
253
+ const tlsServer = new SmartdbServer({
254
+ port: 27017,
255
+ tls: {
256
+ enabled: true,
257
+ certPath: './certs/server.pem',
258
+ keyPath: './certs/server.key',
259
+ // caPath: './certs/client-ca.pem',
260
+ // requireClientCert: true, // Enables mTLS client certificate checks
261
+ },
262
+ });
263
+
264
+ // SCRAM-SHA-256 authentication
265
+ const secureServer = new SmartdbServer({
266
+ port: 27017,
267
+ auth: {
268
+ enabled: true,
269
+ usersPath: './data/smartdb-users.json', // Optional: persists derived SCRAM credentials
270
+ users: [
271
+ {
272
+ username: 'root',
273
+ password: 'change-me',
274
+ database: 'admin',
275
+ roles: ['root'],
276
+ },
277
+ ],
278
+ },
279
+ });
280
+ ```
281
+
282
+ When `auth.enabled` is true, protected commands require successful SCRAM-SHA-256 authentication through the official MongoDB driver:
283
+
284
+ ```typescript
285
+ const client = new MongoClient('mongodb://root:change-me@127.0.0.1:27017/admin?authSource=admin', {
286
+ directConnection: true,
287
+ });
288
+ await client.connect();
289
+ ```
290
+
291
+ TLS is available for TCP listeners. `getConnectionUri()` includes `?tls=true` when TLS is enabled; pass the trusted CA to the MongoDB driver with `tlsCAFile`, `ca`, or `secureContext`.
292
+
293
+ Authentication verifies SCRAM credentials, denies unauthenticated commands, and enforces command-level built-in roles for supported operations.
294
+
295
+ Supported built-in role names are `root`, `read`, `readWrite`, `dbAdmin`, `userAdmin`, `clusterMonitor`, plus `readAnyDatabase`, `readWriteAnyDatabase`, `dbAdminAnyDatabase`, and `userAdminAnyDatabase`. When `usersPath` is set, SmartDB persists SCRAM credential material atomically and does not store plaintext passwords.
296
+
297
+ Basic user management commands are available for authenticated users with `root` or `userAdmin` privileges:
298
+
299
+ ```typescript
300
+ await client.db('admin').command({
301
+ createUser: 'reader',
302
+ pwd: 'readpass',
303
+ roles: [{ role: 'read', db: 'myapp' }],
304
+ });
305
+
306
+ await client.db('admin').command({ usersInfo: 'reader' });
251
307
  ```
252
308
 
253
309
  #### Methods & Properties
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@push.rocks/smartdb',
6
- version: '2.7.0',
6
+ version: '2.7.1',
7
7
  description: 'A MongoDB-compatible embedded database server with wire protocol support, backed by a high-performance Rust engine.'
8
8
  }
@@ -2,7 +2,12 @@
2
2
 
3
3
  // Export server (the main entry point for using SmartDB)
4
4
  export { SmartdbServer } from './server/SmartdbServer.js';
5
- export type { ISmartdbServerOptions } from './server/SmartdbServer.js';
5
+ export type {
6
+ ISmartdbAuthOptions,
7
+ ISmartdbAuthUser,
8
+ ISmartdbServerOptions,
9
+ ISmartdbTlsOptions,
10
+ } from './server/SmartdbServer.js';
6
11
 
7
12
  // Export bridge for advanced usage
8
13
  export { RustDbBridge } from './rust-db-bridge.js';
@@ -117,6 +117,24 @@ interface ISmartDbRustConfig {
117
117
  storagePath?: string;
118
118
  persistPath?: string;
119
119
  persistIntervalMs?: number;
120
+ auth?: {
121
+ enabled?: boolean;
122
+ users?: Array<{
123
+ username: string;
124
+ password: string;
125
+ database?: string;
126
+ roles?: string[];
127
+ }>;
128
+ usersPath?: string;
129
+ scramIterations?: number;
130
+ };
131
+ tls?: {
132
+ enabled?: boolean;
133
+ certPath?: string;
134
+ keyPath?: string;
135
+ caPath?: string;
136
+ requireClientCert?: boolean;
137
+ };
120
138
  }
121
139
 
122
140
  /**
@@ -28,6 +28,32 @@ export interface ISmartdbServerOptions {
28
28
  persistPath?: string;
29
29
  /** Persistence interval in ms (default: 60000) */
30
30
  persistIntervalMs?: number;
31
+ /** Authentication configuration. Disabled by default. */
32
+ auth?: ISmartdbAuthOptions;
33
+ /** TLS transport configuration for TCP listeners. Disabled by default. */
34
+ tls?: ISmartdbTlsOptions;
35
+ }
36
+
37
+ export interface ISmartdbAuthOptions {
38
+ enabled?: boolean;
39
+ users?: ISmartdbAuthUser[];
40
+ usersPath?: string;
41
+ scramIterations?: number;
42
+ }
43
+
44
+ export interface ISmartdbAuthUser {
45
+ username: string;
46
+ password: string;
47
+ database?: string;
48
+ roles?: string[];
49
+ }
50
+
51
+ export interface ISmartdbTlsOptions {
52
+ enabled?: boolean;
53
+ certPath?: string;
54
+ keyPath?: string;
55
+ caPath?: string;
56
+ requireClientCert?: boolean;
31
57
  }
32
58
 
33
59
  /**
@@ -64,6 +90,8 @@ export class SmartdbServer {
64
90
  storagePath: options.storagePath ?? './data',
65
91
  persistPath: options.persistPath,
66
92
  persistIntervalMs: options.persistIntervalMs ?? 60000,
93
+ auth: options.auth,
94
+ tls: options.tls,
67
95
  };
68
96
  this.bridge = new RustDbBridge();
69
97
  }
@@ -106,6 +134,8 @@ export class SmartdbServer {
106
134
  storagePath: this.options.storagePath,
107
135
  persistPath: this.options.persistPath,
108
136
  persistIntervalMs: this.options.persistIntervalMs,
137
+ auth: this.options.auth,
138
+ tls: this.options.tls,
109
139
  });
110
140
 
111
141
  this.resolvedConnectionUri = result.connectionUri;
@@ -142,7 +172,8 @@ export class SmartdbServer {
142
172
  const encodedPath = encodeURIComponent(this.options.socketPath);
143
173
  return `mongodb://${encodedPath}`;
144
174
  }
145
- return `mongodb://${this.options.host ?? '127.0.0.1'}:${this.options.port ?? 27017}`;
175
+ const baseUri = `mongodb://${this.options.host ?? '127.0.0.1'}:${this.options.port ?? 27017}`;
176
+ return this.options.tls?.enabled ? `${baseUri}/?tls=true` : baseUri;
146
177
  }
147
178
 
148
179
  /**