dolphin-server-modules 2.11.3 → 2.11.5

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 (42) hide show
  1. package/DOLPHIN_MASTER_GUIDE_NEPALI.md +4 -4
  2. package/README.md +6 -6
  3. package/TUTORIAL_NEPALI.md +109 -181
  4. package/dist/adapters/mongoose/index.js +13 -0
  5. package/dist/adapters/mongoose/index.js.map +1 -1
  6. package/dist/authController/authController.d.ts +2 -1
  7. package/dist/authController/authController.js +35 -21
  8. package/dist/authController/authController.js.map +1 -1
  9. package/dist/authController/authController.test.js +2 -0
  10. package/dist/authController/authController.test.js.map +1 -1
  11. package/dist/bin/cli.js +142 -111
  12. package/dist/bin/cli.js.map +1 -1
  13. package/dist/client.test.js +6 -6
  14. package/dist/client.test.js.map +1 -1
  15. package/dist/curd/crud.d.ts +18 -0
  16. package/dist/curd/crud.js +11 -1
  17. package/dist/curd/crud.js.map +1 -1
  18. package/dist/curd/crud.test.js +10 -2
  19. package/dist/curd/crud.test.js.map +1 -1
  20. package/dist/realtime/core.d.ts +4 -4
  21. package/dist/realtime/core.js +3 -3
  22. package/dist/realtime/core.js.map +1 -1
  23. package/dist/realtime/devicemanager.d.ts +102 -0
  24. package/dist/realtime/devicemanager.js +209 -1
  25. package/dist/realtime/devicemanager.js.map +1 -1
  26. package/dist/realtime/devicemanager.test.d.ts +1 -0
  27. package/dist/realtime/devicemanager.test.js +156 -0
  28. package/dist/realtime/devicemanager.test.js.map +1 -0
  29. package/dist/realtime/index.d.ts +1 -0
  30. package/dist/realtime/index.js +1 -0
  31. package/dist/realtime/index.js.map +1 -1
  32. package/dist/server/client-serve.d.ts +1 -0
  33. package/dist/server/client-serve.js +17 -0
  34. package/dist/server/client-serve.js.map +1 -0
  35. package/dist/server/server.js +12 -14
  36. package/dist/server/server.js.map +1 -1
  37. package/dist/templates/index.d.ts +6 -0
  38. package/dist/templates/index.js +139 -20
  39. package/dist/templates/index.js.map +1 -1
  40. package/package.json +7 -2
  41. package/scripts/client.js +12 -11
  42. package/scripts/client.mjs +9 -0
@@ -1,9 +1,8 @@
1
1
  export const TEMPLATES = {
2
2
  app: `import { createDolphinServer } from 'dolphin-server-modules/server';
3
- import { createMongooseAdapter } from 'dolphin-server-modules/adapters/mongoose';
4
3
  import { createDolphinAuthController } from 'dolphin-server-modules/auth-controller';
5
- import { connectDB } from './config/db.js';
6
- import { User, RefreshToken } from './models/User.js';
4
+ import { connectDB } from './adapters/connection.js';
5
+ import { db } from './adapters/db.js';
7
6
 
8
7
  const app = createDolphinServer();
9
8
 
@@ -19,12 +18,8 @@ app.use(async (ctx, next) => {
19
18
  // DB connect
20
19
  connectDB(process.env.MONGO_URI || 'mongodb://localhost:27017/dolphin_db');
21
20
 
22
- // Mongoose Adapter
23
- const db = createMongooseAdapter({ User, RefreshToken });
24
-
25
21
  // Auth
26
- const auth = createDolphinAuthController({
27
- adapter: db,
22
+ const auth = createDolphinAuthController(db, {
28
23
  jwtSecret: process.env.JWT_SECRET || 'change_in_production',
29
24
  });
30
25
 
@@ -37,10 +32,44 @@ app.get('/health', (ctx) => ({ status: 'ok', ts: new Date().toISOString() }));
37
32
 
38
33
  const PORT = parseInt(process.env.PORT || '3000');
39
34
  app.listen(PORT, () => console.log(\`🐬 Dolphin Server swimming on port \${PORT}\`));
35
+ `,
36
+ adaptersConnection: `import mongoose from 'mongoose';
37
+
38
+ export const connectDB = async (uri = process.env.MONGO_URI || 'mongodb://localhost:27017/dolphin_db') => {
39
+ try {
40
+ await mongoose.connect(uri, { serverSelectionTimeoutMS: 5000 });
41
+ console.log('✅ MongoDB Connected:', mongoose.connection.host);
42
+ } catch (e) {
43
+ console.error('❌ MongoDB Error:', e.message);
44
+ process.exit(1);
45
+ }
46
+ };
47
+
48
+ mongoose.connection.on('disconnected', () => console.warn('⚠️ MongoDB disconnected'));
49
+ mongoose.connection.on('error', (err) => console.error('❌ MongoDB:', err.message));
50
+ `,
51
+ adaptersDbDecoupled: `import { createMongooseAdapter } from 'dolphin-server-modules/adapters/mongoose';
52
+ import { User, RefreshToken } from '../models/User.js';
53
+
54
+ export const db = createMongooseAdapter({
55
+ User,
56
+ RefreshToken,
57
+ models: {
58
+ User,
59
+ },
60
+ leanByDefault: true,
61
+ softDelete: false
62
+ });
40
63
  `,
41
64
  mongoose: `import mongoose from 'mongoose';
65
+ import { createMongooseAdapter } from 'dolphin-server-modules/adapters/mongoose';
42
66
 
43
- export const connectDB = async (uri) => {
67
+ // Safe default models (error atdaina even if real User model not created yet)
68
+ const dummySchema = new mongoose.Schema({ email: String, token: String }, { versionKey: false });
69
+ const User = mongoose.models.User || mongoose.model('User', dummySchema);
70
+ const RefreshToken = mongoose.models.RefreshToken || mongoose.model('RefreshToken', dummySchema);
71
+
72
+ export const connectDB = async (uri = process.env.MONGO_URI) => {
44
73
  try {
45
74
  await mongoose.connect(uri, { serverSelectionTimeoutMS: 5000 });
46
75
  console.log('✅ MongoDB Connected:', mongoose.connection.host);
@@ -52,6 +81,53 @@ export const connectDB = async (uri) => {
52
81
 
53
82
  mongoose.connection.on('disconnected', () => console.warn('⚠️ MongoDB disconnected'));
54
83
  mongoose.connection.on('error', (err) => console.error('❌ MongoDB:', err.message));
84
+
85
+ // Ready-to-use Dolphin adapter (legacy single file)
86
+ export const db = createMongooseAdapter({
87
+ User,
88
+ RefreshToken,
89
+ models: {
90
+ // Product: (await import('../models/Product.js')).Product
91
+ },
92
+ leanByDefault: true,
93
+ softDelete: false
94
+ });
95
+ `,
96
+ // New separate files for adapters/ folder (recommended for simple projects)
97
+ mongooseConnect: `import mongoose from 'mongoose';
98
+
99
+ export const connectDB = async (uri = process.env.MONGO_URI) => {
100
+ try {
101
+ await mongoose.connect(uri, { serverSelectionTimeoutMS: 5000 });
102
+ console.log('✅ MongoDB Connected:', mongoose.connection.host);
103
+ } catch (e) {
104
+ console.error('❌ MongoDB Error:', e.message);
105
+ process.exit(1);
106
+ }
107
+ };
108
+
109
+ mongoose.connection.on('disconnected', () => console.warn('⚠️ MongoDB disconnected'));
110
+ mongoose.connection.on('error', (err) => console.error('❌ MongoDB:', err.message));
111
+ `,
112
+ mongooseAdapter: `import { createMongooseAdapter } from 'dolphin-server-modules/adapters/mongoose';
113
+
114
+ // =============================================
115
+ // Models यहाँ import गर्नुहोस् (models/ folder बाट)
116
+ // =============================================
117
+ // import { User, RefreshToken } from '../models/User.js';
118
+ // import { Product } from '../models/Product.js';
119
+
120
+ export const db = createMongooseAdapter({
121
+ // Models import गरेपछि तल राख्नुहोस्
122
+ User: undefined,
123
+ RefreshToken: undefined,
124
+
125
+ models: {
126
+ // Product: (await import('../models/Product.js')).Product,
127
+ },
128
+ leanByDefault: true,
129
+ softDelete: false
130
+ });
55
131
  `,
56
132
  sequelize: `import { Sequelize } from 'sequelize';
57
133
 
@@ -98,10 +174,9 @@ export const cache = {
98
174
  };
99
175
  `,
100
176
  auth: `import { createDolphinAuthController } from 'dolphin-server-modules/auth-controller';
101
- import { db } from './adapter.js'; // तपाईंको createMongooseAdapter instance
177
+ import { db } from '../adapters/db.js';
102
178
 
103
- export const auth = createDolphinAuthController({
104
- adapter: db,
179
+ export const auth = createDolphinAuthController(db, {
105
180
  jwtSecret: process.env.JWT_SECRET || 'change_in_production',
106
181
  accessTokenExpiry: '15m',
107
182
  refreshTokenExpiry: '7d',
@@ -109,16 +184,14 @@ export const auth = createDolphinAuthController({
109
184
 
110
185
  export const { register, login, refresh, logout, middleware } = auth;
111
186
  `,
112
- crud: (name) => `import { createCrudController } from 'dolphin-server-modules/crud';
113
- import { db } from '../config/adapter.js';
187
+ crud: (name) => `// Auto-generated by dolphin CLI
188
+ // Add this to your app.js — no separate controller file needed!
114
189
 
115
- const ctrl = createCrudController(db, '${name}', {
116
- softDelete: true,
117
- enforceOwnership: false,
118
- });
190
+ // import { createCrudRouter } from 'dolphin-server-modules/crud';
191
+ // import { db } from './adapters/db.js';
192
+ // import { ${name} } from './models/${name}.js';
119
193
 
120
- export const { getAll, getOne, create, update } = ctrl;
121
- export const remove = ctrl.delete;
194
+ // app.use('/api/${name.toLowerCase()}s', createCrudRouter(db, '${name}', { softDelete: true }));
122
195
  `,
123
196
  crudModel: (name) => `import mongoose from 'mongoose';
124
197
 
@@ -284,6 +357,52 @@ JWT_SECRET=change_this_ultra_secret_key_in_production_32chars
284
357
  # Local Ollama (optional)
285
358
  # USE_OLLAMA=true
286
359
  # OLLAMA_MODEL=gemma3:latest
360
+ `,
361
+ // ── Simple mode templates (npx dolphin init --simple) ─────────────────────
362
+ simpleApp: `import { createDolphinServer } from 'dolphin-server-modules/server';
363
+ import { connectDB } from './config/db.js';
364
+ import { db } from './config/adapter.js';
365
+ import { auth } from './controllers/auth.js';
366
+
367
+ const app = createDolphinServer();
368
+
369
+ // DB connect
370
+ connectDB(process.env.MONGO_URI || 'mongodb://localhost:27017/dolphin_db');
371
+
372
+ // Full Auth Routing
373
+ app.post('/api/auth/register', auth.register);
374
+ app.post('/api/auth/login', auth.login);
375
+ app.post('/api/auth/refresh', auth.refresh);
376
+ app.post('/api/auth/logout', auth.requireAuth, auth.logout);
377
+
378
+ // Example single-line route
379
+ app.get('/ping', (ctx) => {
380
+ return { message: 'pong' };
381
+ });
382
+
383
+ app.get('/health', (ctx) => ({ status: 'ok', ts: new Date().toISOString() }));
384
+
385
+ const PORT = parseInt(process.env.PORT || '3000');
386
+ app.listen(PORT, () => console.log(\`🐬 Dolphin (simple) running on port \${PORT}\`));
387
+ `,
388
+ configAdapter: `import { createMongooseAdapter } from 'dolphin-server-modules/adapters/mongoose';
389
+
390
+ // =============================================
391
+ // Models यहाँ import गर्नुहोस् (models/ folder बाट)
392
+ // =============================================
393
+ import { User, RefreshToken } from '../models/User.js';
394
+ // import { Product } from '../models/Product.js';
395
+
396
+ export const db = createMongooseAdapter({
397
+ User: User,
398
+ RefreshToken: RefreshToken,
399
+
400
+ models: {
401
+ User,
402
+ },
403
+ leanByDefault: true,
404
+ softDelete: false
405
+ });
287
406
  `,
288
407
  };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AAE,CAAC,IAAY,EAAE,EAAE,CAAC;;QAErB,IAAI,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;EAexB,IAAI,CAAC,WAAW,EAAE;EAClB,IAAI,CAAC,WAAW,EAAE;;eAEL,IAAI,sBAAsB,IAAI,MAAM,IAAI,CAAC,WAAW,EAAE;CACpE;IAEG,UAAU,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC;KAC7B,IAAI;oBACW,IAAI,CAAC,WAAW,EAAE,sCAAsC,IAAI,CAAC,WAAW,EAAE;;eAE/E,IAAI,CAAC,WAAW,EAAE;;mBAEd,IAAI;;;CAGtB;IAEG,KAAK,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC;;;iBAGZ,IAAI,CAAC,WAAW,EAAE;;;gDAGa,IAAI;;;;;;;;;;;;;;;;;;;eAmBrC,IAAI,CAAC,WAAW,EAAE;CAChC;IAEG,OAAO,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC;KAC1B,IAAI;;;eAGM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BlB;IAEG,GAAG,EAAE;;;;;;;;;;;;;;;;;;;;;;;CAuBR;IAEG,6EAA6E;IAC7E,SAAS,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;CAyBd;IAEG,aAAa,EAAE;;;;;;;;;;;;;;;;;;CAkBlB;CACA,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dolphin-server-modules",
3
- "version": "2.11.3",
3
+ "version": "2.11.5",
4
4
  "type": "module",
5
5
  "homepage": "https://github.com/Phuyalshankar/dolphin-server-modules#readme",
6
6
  "description": "Core utility modules for Auth, CRUD, and Controllers",
@@ -17,6 +17,7 @@
17
17
  "TUTORIAL_NEPALI.md",
18
18
  "DOLPHIN_MASTER_GUIDE_NEPALI.md",
19
19
  "scripts/client.js",
20
+ "scripts/client.mjs",
20
21
  "scripts/dolphin-persist.js"
21
22
  ],
22
23
  "exports": {
@@ -115,7 +116,11 @@
115
116
  },
116
117
  "./signaling/index.js": "./dist/signaling/index.js",
117
118
  "./cli": "./dist/bin/cli.js",
118
- "./client": "./scripts/client.js",
119
+ "./client": {
120
+ "import": "./scripts/client.mjs",
121
+ "require": "./scripts/client.js",
122
+ "default": "./scripts/client.js"
123
+ },
119
124
  "./utils/ctx": {
120
125
  "types": "./dist/utils/ctx.d.ts",
121
126
  "default": "./dist/utils/ctx.js"
package/scripts/client.js CHANGED
@@ -197,7 +197,7 @@ class AuthHandler {
197
197
  * @param {string} password
198
198
  */
199
199
  async login(email, password) {
200
- const res = await this.client.api.post('/auth/login', { email, password });
200
+ const res = await this.client.api.post('/api/auth/login', { email, password });
201
201
  if (res.accessToken) {
202
202
  this.client.setToken(res.accessToken);
203
203
  this.user = res.user || null;
@@ -210,19 +210,19 @@ class AuthHandler {
210
210
  * @param {{ email: string, password: string, [key: string]: any }} data
211
211
  */
212
212
  async register(data) {
213
- return this.client.api.post('/auth/register', data);
213
+ return this.client.api.post('/api/auth/register', data);
214
214
  }
215
215
 
216
216
  /** Get current user profile. */
217
217
  async me() {
218
- const res = await this.client.api.get('/auth/me');
218
+ const res = await this.client.api.get('/api/auth/me');
219
219
  if (res.success) this.user = res.data;
220
220
  return res;
221
221
  }
222
222
 
223
223
  /** Logout and clear token. */
224
224
  async logout() {
225
- try { await this.client.api.post('/auth/logout'); } catch {}
225
+ try { await this.client.api.post('/api/auth/logout'); } catch {}
226
226
  this.client.setToken(null);
227
227
  this.user = null;
228
228
  }
@@ -241,7 +241,7 @@ class AuthHandler {
241
241
  if (this._refreshing) return false;
242
242
  this._refreshing = true;
243
243
  try {
244
- const res = await this.client.api.post('/auth/refresh', null, {}, true);
244
+ const res = await this.client.api.post('/api/auth/refresh', null, {}, true);
245
245
  if (res.accessToken) {
246
246
  this.client.setToken(res.accessToken);
247
247
  return true;
@@ -265,7 +265,7 @@ class AuthHandler {
265
265
  code,
266
266
  email: email || this.user?.email,
267
267
  };
268
- const res = await this.client.api.post('/auth/2fa/verify', payload);
268
+ const res = await this.client.api.post('/api/auth/2fa/verify', payload);
269
269
  if (res.accessToken) {
270
270
  this.client.setToken(res.accessToken);
271
271
  if (res.user) this.user = res.user;
@@ -277,7 +277,7 @@ class AuthHandler {
277
277
  * Enable 2FA — returns QR code URL and secret.
278
278
  */
279
279
  async enable2FA() {
280
- return this.client.api.post('/auth/2fa/enable');
280
+ return this.client.api.post('/api/auth/2fa/enable');
281
281
  }
282
282
 
283
283
  /**
@@ -285,7 +285,7 @@ class AuthHandler {
285
285
  * @param {string} code — current TOTP code to confirm
286
286
  */
287
287
  async disable2FA(code) {
288
- return this.client.api.post('/auth/2fa/disable', { code });
288
+ return this.client.api.post('/api/auth/2fa/disable', { code });
289
289
  }
290
290
 
291
291
  /**
@@ -293,7 +293,7 @@ class AuthHandler {
293
293
  * @param {string} email
294
294
  */
295
295
  async forgotPassword(email) {
296
- return this.client.api.post('/auth/forgot-password', { email });
296
+ return this.client.api.post('/api/auth/forgot-password', { email });
297
297
  }
298
298
 
299
299
  /**
@@ -302,7 +302,7 @@ class AuthHandler {
302
302
  * @param {string} newPassword
303
303
  */
304
304
  async resetPassword(token, newPassword) {
305
- return this.client.api.post('/auth/reset-password', { token, newPassword });
305
+ return this.client.api.post('/api/auth/reset-password', { token, newPassword });
306
306
  }
307
307
  }
308
308
 
@@ -835,4 +835,5 @@ if (typeof module !== 'undefined' && module.exports) {
835
835
  module.exports = { DolphinClient };
836
836
  }
837
837
 
838
- export { DolphinClient };
838
+ // Note: No top-level `export` here so that this file can be loaded
839
+ // via classic <script src="..."> in browsers / React without "Unexpected token 'export'"
@@ -0,0 +1,9 @@
1
+ // ESM entry point for "dolphin-server-modules/client"
2
+ // Allows: import { DolphinClient } from 'dolphin-server-modules/client'
3
+ // in Vite, React, Next.js, etc. without breaking classic <script src> usage.
4
+
5
+ import { createRequire } from 'node:module';
6
+ const require = createRequire(import.meta.url);
7
+ const { DolphinClient } = require('./client.js');
8
+
9
+ export { DolphinClient };