@shohaghinfo/aerojs 0.2.0 → 0.4.0

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 (125) hide show
  1. package/AGENTS.md +226 -0
  2. package/README.md +250 -0
  3. package/dist/auth/index.d.ts +1 -0
  4. package/dist/auth/index.d.ts.map +1 -1
  5. package/dist/auth/index.js +1 -0
  6. package/dist/auth/index.js.map +1 -1
  7. package/dist/auth/oauth/github-driver.d.ts +16 -0
  8. package/dist/auth/oauth/github-driver.d.ts.map +1 -0
  9. package/dist/auth/oauth/github-driver.js +79 -0
  10. package/dist/auth/oauth/github-driver.js.map +1 -0
  11. package/dist/auth/oauth/google-driver.d.ts +16 -0
  12. package/dist/auth/oauth/google-driver.d.ts.map +1 -0
  13. package/dist/auth/oauth/google-driver.js +63 -0
  14. package/dist/auth/oauth/google-driver.js.map +1 -0
  15. package/dist/auth/oauth/index.d.ts +9 -0
  16. package/dist/auth/oauth/index.d.ts.map +1 -0
  17. package/dist/auth/oauth/index.js +9 -0
  18. package/dist/auth/oauth/index.js.map +1 -0
  19. package/dist/auth/oauth/oauth-driver.d.ts +35 -0
  20. package/dist/auth/oauth/oauth-driver.d.ts.map +1 -0
  21. package/dist/auth/oauth/oauth-driver.js +6 -0
  22. package/dist/auth/oauth/oauth-driver.js.map +1 -0
  23. package/dist/auth/oauth/oauth-manager.d.ts +26 -0
  24. package/dist/auth/oauth/oauth-manager.d.ts.map +1 -0
  25. package/dist/auth/oauth/oauth-manager.js +86 -0
  26. package/dist/auth/oauth/oauth-manager.js.map +1 -0
  27. package/dist/cli/commands/make.d.ts +5 -0
  28. package/dist/cli/commands/make.d.ts.map +1 -1
  29. package/dist/cli/commands/make.js +119 -0
  30. package/dist/cli/commands/make.js.map +1 -1
  31. package/dist/cli/runner.d.ts.map +1 -1
  32. package/dist/cli/runner.js +56 -1
  33. package/dist/cli/runner.js.map +1 -1
  34. package/dist/core/application.d.ts +15 -0
  35. package/dist/core/application.d.ts.map +1 -1
  36. package/dist/core/application.js +25 -0
  37. package/dist/core/application.js.map +1 -1
  38. package/dist/core/context.d.ts +5 -0
  39. package/dist/core/context.d.ts.map +1 -1
  40. package/dist/core/context.js +11 -0
  41. package/dist/core/context.js.map +1 -1
  42. package/dist/database/connection.d.ts +32 -0
  43. package/dist/database/connection.d.ts.map +1 -1
  44. package/dist/database/connection.js +51 -0
  45. package/dist/database/connection.js.map +1 -1
  46. package/dist/database/index.d.ts +1 -1
  47. package/dist/database/index.d.ts.map +1 -1
  48. package/dist/database/index.js +1 -1
  49. package/dist/database/index.js.map +1 -1
  50. package/dist/database/model.d.ts +16 -0
  51. package/dist/database/model.d.ts.map +1 -1
  52. package/dist/database/model.js +91 -13
  53. package/dist/database/model.js.map +1 -1
  54. package/dist/database/query-builder.d.ts +18 -0
  55. package/dist/database/query-builder.d.ts.map +1 -1
  56. package/dist/database/query-builder.js +82 -30
  57. package/dist/database/query-builder.js.map +1 -1
  58. package/dist/index.d.ts +3 -2
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +3 -2
  61. package/dist/index.js.map +1 -1
  62. package/dist/notifications/index.d.ts +7 -0
  63. package/dist/notifications/index.d.ts.map +1 -0
  64. package/dist/notifications/index.js +7 -0
  65. package/dist/notifications/index.js.map +1 -0
  66. package/dist/notifications/notification-manager.d.ts +39 -0
  67. package/dist/notifications/notification-manager.d.ts.map +1 -0
  68. package/dist/notifications/notification-manager.js +130 -0
  69. package/dist/notifications/notification-manager.js.map +1 -0
  70. package/dist/notifications/notification.d.ts +48 -0
  71. package/dist/notifications/notification.d.ts.map +1 -0
  72. package/dist/notifications/notification.js +9 -0
  73. package/dist/notifications/notification.js.map +1 -0
  74. package/dist/queue/dashboard.d.ts +30 -0
  75. package/dist/queue/dashboard.d.ts.map +1 -0
  76. package/dist/queue/dashboard.js +371 -0
  77. package/dist/queue/dashboard.js.map +1 -0
  78. package/dist/queue/index.d.ts +1 -0
  79. package/dist/queue/index.d.ts.map +1 -1
  80. package/dist/queue/index.js +1 -0
  81. package/dist/queue/index.js.map +1 -1
  82. package/dist/queue/queue-manager.d.ts +31 -1
  83. package/dist/queue/queue-manager.d.ts.map +1 -1
  84. package/dist/queue/queue-manager.js +60 -0
  85. package/dist/queue/queue-manager.js.map +1 -1
  86. package/dist/queue/worker.d.ts +3 -0
  87. package/dist/queue/worker.d.ts.map +1 -1
  88. package/dist/queue/worker.js +9 -0
  89. package/dist/queue/worker.js.map +1 -1
  90. package/dist/security/encryption.d.ts +60 -0
  91. package/dist/security/encryption.d.ts.map +1 -0
  92. package/dist/security/encryption.js +120 -0
  93. package/dist/security/encryption.js.map +1 -0
  94. package/dist/security/fingerprint.d.ts +47 -0
  95. package/dist/security/fingerprint.d.ts.map +1 -0
  96. package/dist/security/fingerprint.js +83 -0
  97. package/dist/security/fingerprint.js.map +1 -0
  98. package/dist/security/index.d.ts +3 -0
  99. package/dist/security/index.d.ts.map +1 -1
  100. package/dist/security/index.js +3 -0
  101. package/dist/security/index.js.map +1 -1
  102. package/dist/security/signed-url.d.ts +29 -0
  103. package/dist/security/signed-url.d.ts.map +1 -0
  104. package/dist/security/signed-url.js +86 -0
  105. package/dist/security/signed-url.js.map +1 -0
  106. package/dist/session/cookie-session-driver.d.ts +34 -0
  107. package/dist/session/cookie-session-driver.d.ts.map +1 -0
  108. package/dist/session/cookie-session-driver.js +57 -0
  109. package/dist/session/cookie-session-driver.js.map +1 -0
  110. package/dist/session/index.d.ts +8 -0
  111. package/dist/session/index.d.ts.map +1 -0
  112. package/dist/session/index.js +8 -0
  113. package/dist/session/index.js.map +1 -0
  114. package/dist/session/session-manager.d.ts.map +1 -1
  115. package/dist/session/session-manager.js +7 -2
  116. package/dist/session/session-manager.js.map +1 -1
  117. package/dist/storage/drivers/local-driver.d.ts +1 -0
  118. package/dist/storage/drivers/local-driver.d.ts.map +1 -1
  119. package/dist/storage/drivers/local-driver.js +5 -0
  120. package/dist/storage/drivers/local-driver.js.map +1 -1
  121. package/dist/storage/drivers/memory-driver.d.ts +1 -0
  122. package/dist/storage/drivers/memory-driver.d.ts.map +1 -1
  123. package/dist/storage/drivers/memory-driver.js +5 -0
  124. package/dist/storage/drivers/memory-driver.js.map +1 -1
  125. package/package.json +9 -1
package/AGENTS.md CHANGED
@@ -707,3 +707,229 @@ When asked to build or modify any feature in an AeroJS project:
707
707
  npm run build
708
708
  npm test
709
709
  ```
710
+
711
+ ---
712
+
713
+ ## 11. Enterprise Capabilities Reference (v0.3.0)
714
+
715
+ ### 11.1 Fluent HTTP Client (`Http`)
716
+ ```typescript
717
+ import { Http } from 'aerojs';
718
+
719
+ const res = await Http.baseUrl('https://api.example.com')
720
+ .withToken('auth-token')
721
+ .timeout(5000)
722
+ .retry(3, 100)
723
+ .get('/data', { page: 1 });
724
+
725
+ if (res.successful) {
726
+ const data = res.json();
727
+ }
728
+ ```
729
+
730
+ ### 11.2 SMTP Mail Transport (`Mail`)
731
+ ```typescript
732
+ import { Mail } from 'aerojs';
733
+
734
+ Mail.configure({
735
+ default: 'smtp',
736
+ mailers: {
737
+ smtp: {
738
+ driver: 'smtp',
739
+ host: process.env.SMTP_HOST || '127.0.0.1',
740
+ port: Number(process.env.SMTP_PORT) || 587,
741
+ auth: { user: process.env.SMTP_USER!, pass: process.env.SMTP_PASS! },
742
+ },
743
+ },
744
+ });
745
+
746
+ await Mail.send((msg) => {
747
+ msg.to('user@example.com')
748
+ .subject('Welcome')
749
+ .html('<h1>Welcome to AeroJS</h1>');
750
+ });
751
+ ```
752
+
753
+ ### 11.3 Redis Rate Limiter & Redis Queue
754
+ ```typescript
755
+ import { rateLimit, RedisRateLimitStore, RedisClient, Queue } from 'aerojs';
756
+
757
+ const redis = new RedisClient({ host: '127.0.0.1', port: 6379 });
758
+
759
+ // Rate Limiter
760
+ app.use(rateLimit({
761
+ windowMs: 60_000,
762
+ max: 100,
763
+ store: new RedisRateLimitStore({ client: redis, prefix: 'rl:api:' }),
764
+ }));
765
+
766
+ // Queue
767
+ Queue.configure({
768
+ default: 'redis',
769
+ connections: {
770
+ redis: { driver: 'redis', redis },
771
+ },
772
+ });
773
+ ```
774
+
775
+ ### 11.4 OAuth 2.0 Social Login (`OAuth`)
776
+ ```typescript
777
+ import { OAuth } from 'aerojs';
778
+
779
+ router.get('/auth/google', (ctx) => ctx.redirect(OAuth.driver('google').getRedirectUrl()));
780
+ router.get('/auth/google/callback', async (ctx) => {
781
+ const { user } = await OAuth.driver('google').handleCallback(ctx.query.code as string);
782
+ ctx.json({ user });
783
+ });
784
+ ```
785
+
786
+ ### 11.5 Multi-Channel Notifications (`Notifications`, `Notification`)
787
+ ```typescript
788
+ import { Notification, Notifications, MailMessage } from 'aerojs';
789
+
790
+ class OrderAlertNotification extends Notification {
791
+ via() { return ['mail', 'database', 'broadcast']; }
792
+ toMail(u: any) { return new MailMessage().subject('Alert').text('Hello'); }
793
+ toDatabase(u: any) { return { alert: 'Order Confirmed' }; }
794
+ }
795
+
796
+ await Notifications.send(user, new OrderAlertNotification());
797
+ ```
798
+
799
+ ### 11.6 Tamper-Proof Signed URLs (`UrlSigner`, `validateSignedUrl`)
800
+ ```typescript
801
+ import { UrlSigner, validateSignedUrl, Storage } from 'aerojs';
802
+
803
+ // Generate temporary signed link
804
+ const downloadUrl = await Storage.temporaryUrl('invoices/inv-101.pdf', 900);
805
+
806
+ // Validate in route
807
+ router.get('/secure/download', validateSignedUrl(), async (ctx) => {
808
+ ctx.json({ secure: true });
809
+ });
810
+ ```
811
+
812
+ ### 11.7 Extended CLI Generators (`aero make:*`)
813
+ ```bash
814
+ aero make:job ProcessPayment
815
+ aero make:mail OrderReceipt
816
+ aero make:policy PatientPolicy
817
+ aero make:event PatientAdmitted
818
+ aero make:listener NotifyDoctor
819
+ ```
820
+
821
+ ---
822
+
823
+ ## 12. Advanced Enterprise Architecture (v0.4.0)
824
+
825
+ ### 12.1 Field-Level AES-256-GCM Encryption (`Crypt`, `@encrypted`)
826
+ Protect sensitive compliance data (SSN, medical records, credit cards, credentials) transparently at rest:
827
+
828
+ ```typescript
829
+ import { Model, encrypted, Crypt } from 'aerojs';
830
+
831
+ // Encrypt standalone strings or objects
832
+ const ciphertext = Crypt.encrypt('secret-data');
833
+ const plaintext = Crypt.decrypt(ciphertext);
834
+
835
+ // Model field-level transparent encryption
836
+ export class Patient extends Model {
837
+ public static override table = 'patients';
838
+ public static override primaryKey = 'id';
839
+ public static override fillable = ['name', 'ssn', 'medical_record', 'diagnosis'];
840
+
841
+ // Mark fields for automatic AES-256-GCM encryption
842
+ public static override encrypted = ['ssn', 'medical_record'];
843
+
844
+ // Or use TypeScript property decorator:
845
+ // @encrypted()
846
+ // public ssn!: string;
847
+ }
848
+
849
+ // Automatically encrypted on .save() and decrypted on .find() / .all() / .toJSON()
850
+ const patient = await Patient.create({
851
+ name: 'John Doe',
852
+ ssn: '123-45-6789',
853
+ medical_record: 'Asthma diagnosis',
854
+ });
855
+ ```
856
+
857
+ ### 12.2 Database Read Replicas & Master-Slave Routing
858
+ Scale database read throughput across horizontal replica pools with automatic write pinning and master-slave routing:
859
+
860
+ ```typescript
861
+ import { Database, DB } from 'aerojs';
862
+
863
+ Database.configureReplication({
864
+ write: { client: 'pg', connection: { host: 'primary.db.internal' } },
865
+ read: [
866
+ { client: 'pg', connection: { host: 'replica-1.db.internal' } },
867
+ { client: 'pg', connection: { host: 'replica-2.db.internal' } },
868
+ ],
869
+ });
870
+
871
+ // SELECT queries automatically balance across replicas in round-robin:
872
+ const users = await DB.table('users').where('is_active', true).get();
873
+
874
+ // INSERT / UPDATE / DELETE automatically target the primary write connection:
875
+ await DB.table('users').insert({ name: 'Alice', email: 'alice@example.com' });
876
+
877
+ // Read-your-own-writes consistency via .useWriteConnection():
878
+ const freshUser = await DB.table('users').useWriteConnection().where('email', 'alice@example.com').first();
879
+ ```
880
+
881
+ ### 12.3 Interactive Queue Horizon Dashboard
882
+ A dark-mode glassmorphic real-time administration dashboard for inspecting background job queues and metrics:
883
+
884
+ ```typescript
885
+ import { app } from './bootstrap.js';
886
+
887
+ // Mount real-time queue inspector GUI & REST API
888
+ app.useQueueDashboard('/__aero/queue', {
889
+ auth: (ctx) => ctx.state?.user?.role === 'admin', // Optional authorization guard
890
+ });
891
+ ```
892
+ - Web UI: Navigate to `http://localhost:3000/__aero/queue`
893
+ - REST Endpoints:
894
+ - `GET /__aero/queue/api/metrics` — Active jobs, processed counts, failure rates, queue throughput.
895
+ - `GET /__aero/queue/api/failed` — Failed job payloads, error messages, and stack traces.
896
+ - `POST /__aero/queue/api/retry/:id` — Instant dead-letter job retry.
897
+ - `POST /__aero/queue/api/retry-all` — Batch retry all failed jobs.
898
+ - `DELETE /__aero/queue/api/purge-all` — Purge failed jobs.
899
+
900
+ ### 12.4 Encrypted Stateless Cookie Session Driver
901
+ Stateless, horizontally scalable user session storage secured via AES-256-GCM authenticated encryption:
902
+
903
+ ```typescript
904
+ import { SessionManager, CookieSessionDriver } from 'aerojs';
905
+
906
+ const sessionManager = new SessionManager({
907
+ driver: 'cookie',
908
+ secret: process.env.APP_KEY, // 32-byte secret key
909
+ cookie: {
910
+ name: 'aero_session',
911
+ httpOnly: true,
912
+ secure: true,
913
+ sameSite: 'lax',
914
+ },
915
+ });
916
+ ```
917
+
918
+ ### 12.5 Request Fingerprinting & Anti-Hijack Guard
919
+ Prevent session hijacking and credential replay attacks across network switches or spoofed browsers:
920
+
921
+ ```typescript
922
+ import { fingerprintGuard, RequestFingerprint } from 'aerojs';
923
+
924
+ // Generate or inspect request fingerprint
925
+ const hash = RequestFingerprint.generate(ctx, { checkIp: false });
926
+
927
+ // Bind to security middleware stack
928
+ app.use(fingerprintGuard({
929
+ strict: true,
930
+ checkIp: false, // Set true for high-security intranets or false for mobile networks
931
+ onHijackAttempt: (ctx, expected, actual) => {
932
+ ctx.logger?.warn(`Session hijacking attempt detected: expected ${expected}, got ${actual}`);
933
+ },
934
+ }));
935
+ ```
package/README.md CHANGED
@@ -62,6 +62,9 @@
62
62
  32. [Distributed Redis Rate Limiter (`RedisRateLimitStore`)](#32-distributed-redis-rate-limiter-redisratelimitstore)
63
63
  33. [Redis Queue Driver with DLQ (`RedisQueueDriver`)](#33-redis-queue-driver-with-dlq-redisqueuedriver)
64
64
  34. [Fluent HTTP Client (`Http`, `HttpResponse`)](#34-fluent-http-client-http-httpresponse)
65
+ 35. [OAuth 2.0 & Social Login (`OAuth`, Google, GitHub)](#35-oauth-20--social-login-oauth-google-github)
66
+ 36. [Multi-Channel Notifications (`Notification`, `Notifications`)](#36-multi-channel-notifications-notification-notifications)
67
+ 37. [Tamper-Proof Signed URLs (`UrlSigner`, `validateSignedUrl`)](#37-tamper-proof-signed-urls-urlsigner-validatesignedurl)
65
68
  - [Performance, Size & Advantages](#-performance-size--advantages)
66
69
  - [Comparison Matrix](#-comparison-matrix)
67
70
  - [License](#-license)
@@ -1329,6 +1332,253 @@ Http.assertSent((req) => req.url.includes('/billing') && req.method === 'POST');
1329
1332
 
1330
1333
  ---
1331
1334
 
1335
+ ### 35. OAuth 2.0 & Social Login (`OAuth`, Google, GitHub)
1336
+
1337
+ Authenticate users with Google, GitHub, or custom OAuth 2.0 identity providers without external libraries.
1338
+
1339
+ ```typescript
1340
+ import { OAuth, router } from '@shohaghinfo/aerojs';
1341
+
1342
+ // 1. Configure Providers
1343
+ OAuth.configure({
1344
+ providers: {
1345
+ google: {
1346
+ clientId: process.env.GOOGLE_CLIENT_ID!,
1347
+ clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
1348
+ redirectUri: 'https://myapp.com/auth/google/callback',
1349
+ },
1350
+ github: {
1351
+ clientId: process.env.GITHUB_CLIENT_ID!,
1352
+ clientSecret: process.env.GITHUB_CLIENT_SECRET!,
1353
+ redirectUri: 'https://myapp.com/auth/github/callback',
1354
+ },
1355
+ },
1356
+ });
1357
+
1358
+ // 2. Redirect to Provider
1359
+ router.get('/auth/google', (ctx) => {
1360
+ ctx.redirect(OAuth.driver('google').getRedirectUrl());
1361
+ });
1362
+
1363
+ // 3. Handle Callback
1364
+ router.get('/auth/google/callback', async (ctx) => {
1365
+ const code = ctx.query.code as string;
1366
+ const { user, accessToken } = await OAuth.driver('google').handleCallback(code);
1367
+
1368
+ console.log('Logged in user:', user.name, user.email, user.avatarUrl);
1369
+ ctx.json({ success: true, user });
1370
+ });
1371
+ ```
1372
+
1373
+ ---
1374
+
1375
+ ### 36. Multi-Channel Notifications (`Notification`, `Notifications`)
1376
+
1377
+ Deliver notifications simultaneously across multiple delivery channels (Email, Database, Realtime Broadcast, SMS) with unified syntax.
1378
+
1379
+ ```typescript
1380
+ import { Notification, Notifications, MailMessage } from '@shohaghinfo/aerojs';
1381
+
1382
+ class OrderShippedNotification extends Notification {
1383
+ constructor(public order: any) {
1384
+ super();
1385
+ }
1386
+
1387
+ // Choose delivery channels
1388
+ public via(user: any): string[] {
1389
+ return ['mail', 'database', 'broadcast'];
1390
+ }
1391
+
1392
+ public toMail(user: any): MailMessage {
1393
+ const msg = new MailMessage();
1394
+ return msg.subject(`Order #${this.order.id} Shipped`)
1395
+ .html(`<h1>Your package is on its way!</h1>`);
1396
+ }
1397
+
1398
+ public toDatabase(user: any) {
1399
+ return { orderId: this.order.id, trackingNumber: 'TRK-98124' };
1400
+ }
1401
+
1402
+ public toBroadcast(user: any) {
1403
+ return {
1404
+ channel: `user.${user.id}`,
1405
+ event: 'OrderShipped',
1406
+ data: { orderId: this.order.id },
1407
+ };
1408
+ }
1409
+ }
1410
+
1411
+ // Dispatch to single user or array of users
1412
+ await Notifications.send(customer, new OrderShippedNotification(order));
1413
+ ```
1414
+
1415
+ ---
1416
+
1417
+ ### 37. Tamper-Proof Signed URLs (`UrlSigner`, `validateSignedUrl`)
1418
+
1419
+ Generate time-limited, cryptographically verified URLs for private downloads, password resets, or webhooks.
1420
+
1421
+ ```typescript
1422
+ import { UrlSigner, validateSignedUrl, Storage, router } from '@shohaghinfo/aerojs';
1423
+
1424
+ // 1. Generate 15-minute temporary download link
1425
+ const downloadUrl = await Storage.temporaryUrl('invoices/inv-2026.pdf', 900);
1426
+ // Returns: /storage/invoices/inv-2026.pdf?expires=1790924000&signature=8f9a2...
1427
+
1428
+ // 2. Protect route with middleware
1429
+ router.get('/secure/download', validateSignedUrl(), async (ctx) => {
1430
+ ctx.json({ data: 'Confidential file contents' });
1431
+ });
1432
+
1433
+ // 3. Or verify inline inside controller:
1434
+ if (!ctx.hasValidSignature()) {
1435
+ ctx.status(403).json({ error: 'Signature invalid or expired' });
1436
+ return;
1437
+ }
1438
+ ```
1439
+
1440
+ ---
1441
+
1442
+ ### 38. Field-Level Database Encryption (`@encrypted()` & `Crypt`)
1443
+
1444
+ Ensure HIPAA, GDPR, and PCI-DSS compliance by transparently encrypting sensitive database columns at rest using authenticated **AES-256-GCM** encryption:
1445
+
1446
+ ```typescript
1447
+ import { Model, encrypted, Crypt } from '@shohaghinfo/aerojs';
1448
+
1449
+ class PatientRecord extends Model {
1450
+ public static override table = 'patients';
1451
+ public static override fillable = ['name', 'ssn', 'medical_history'];
1452
+ public static override encrypted = ['ssn', 'medical_history'];
1453
+
1454
+ @encrypted()
1455
+ public ssn!: string;
1456
+ }
1457
+
1458
+ // 1. Create - Data is stored as aero:enc:<iv>:<tag>:<ciphertext> in the database
1459
+ const patient = await PatientRecord.create({
1460
+ name: 'Rahim Khan',
1461
+ ssn: '019-99-8888',
1462
+ medical_history: 'Diabetes Type 2, Hypertension',
1463
+ });
1464
+
1465
+ // 2. Read - Transparently decrypted on fetch
1466
+ const loaded = await PatientRecord.find(patient.id);
1467
+ console.log(loaded.ssn); // '019-99-8888' (Plaintext in app code)
1468
+
1469
+ // 3. Arbitrary payload encryption via Crypt facade:
1470
+ const cipher = Crypt.encrypt({ account: '123456', balance: 5000 });
1471
+ const data = Crypt.decrypt(cipher);
1472
+ ```
1473
+
1474
+ ---
1475
+
1476
+ ### 39. Database Read Replicas & Master-Slave Routing
1477
+
1478
+ Route all high-volume read traffic to replica pools with round-robin load distribution while ensuring writes and transactions hit the primary master:
1479
+
1480
+ ```typescript
1481
+ import { Database, DB } from '@shohaghinfo/aerojs';
1482
+
1483
+ // Configure replication pool
1484
+ Database.configureReplication({
1485
+ write: 'primary_master',
1486
+ read: ['replica_east_1', 'replica_east_2', 'replica_west_1'],
1487
+ });
1488
+
1489
+ // 1. Automatically queries a read replica (round-robin balanced)
1490
+ const users = await DB.table('users').where('active', true).get();
1491
+
1492
+ // 2. Force reading from the master node for read-your-own-writes consistency
1493
+ const freshUser = await DB.table('users').useWriteConnection().where('id', 1).first();
1494
+
1495
+ // 3. Direct write queries always execute on the primary write database
1496
+ await DB.table('users').where('id', 1).update({ status: 'verified' });
1497
+ ```
1498
+
1499
+ ---
1500
+
1501
+ ### 40. Interactive Queue Horizon Dashboard (`app.useQueueDashboard`)
1502
+
1503
+ A built-in, dark-mode developer control panel for real-time background task monitoring and failure recovery:
1504
+
1505
+ ```typescript
1506
+ import { Aero } from '@shohaghinfo/aerojs';
1507
+
1508
+ const app = new Aero();
1509
+
1510
+ // Mount the dashboard with optional role-based protection
1511
+ app.useQueueDashboard('/__aero/queue', {
1512
+ title: 'My Hospital Queue Horizon',
1513
+ pollInterval: 3, // auto-refresh every 3s
1514
+ auth: (ctx) => ctx.session?.get('user')?.role === 'superadmin',
1515
+ });
1516
+ ```
1517
+
1518
+ - **Live GUI (`GET /__aero/queue`)**: Glassmorphic dark UI with live throughput KPI cards, queues status, and dead letter queue inspector.
1519
+ - **REST APIs**:
1520
+ - `GET /__aero/queue/api/metrics` — JSON statistics
1521
+ - `GET /__aero/queue/api/failed` — List dead-letter failed jobs with full stack traces
1522
+ - `POST /__aero/queue/api/retry/:id` — Retry single failed task
1523
+ - `DELETE /__aero/queue/api/failed/:id` — Delete failed task
1524
+ - `POST /__aero/queue/api/retry-all` — Batch retry all failed jobs
1525
+ - `DELETE /__aero/queue/api/purge-all` — Purge dead letter queue
1526
+
1527
+ ---
1528
+
1529
+ ### 41. Encrypted Stateless Cookie Session Driver (`CookieSessionDriver`)
1530
+
1531
+ Store session state entirely on the client within an encrypted, authenticated, and tamper-proof HTTP-only cookie using AES-256-GCM. Ideal for serverless, Edge, and horizontal autoscaling:
1532
+
1533
+ ```typescript
1534
+ import { Aero, sessionPlugin, CookieSessionDriver } from '@shohaghinfo/aerojs';
1535
+
1536
+ const app = new Aero();
1537
+
1538
+ app.use(sessionPlugin({
1539
+ driver: new CookieSessionDriver(),
1540
+ cookieName: 'aero_session',
1541
+ lifetime: 8 * 3600, // 8-hour shift
1542
+ cookie: { httpOnly: true, secure: true, sameSite: 'lax' },
1543
+ }));
1544
+
1545
+ app.post('/login', async (ctx) => {
1546
+ await ctx.session.put('user', { id: 1, role: 'physician' });
1547
+ ctx.json({ loggedIn: true });
1548
+ });
1549
+ ```
1550
+
1551
+ ---
1552
+
1553
+ ### 42. Client Request Fingerprinting & Anti-Hijacking Guard
1554
+
1555
+ Prevent stolen session cookies and session fixation attacks by fingerprinting client browser characteristics (User-Agent, client IP, accept headers):
1556
+
1557
+ ```typescript
1558
+ import { Aero, sessionPlugin, fingerprintGuard, RequestFingerprint } from '@shohaghinfo/aerojs';
1559
+
1560
+ const app = new Aero();
1561
+ app.use(sessionPlugin());
1562
+
1563
+ // Automatically binds and verifies client fingerprint on every session request
1564
+ app.use(fingerprintGuard({
1565
+ ip: true,
1566
+ userAgent: true,
1567
+ acceptLanguage: true,
1568
+ onMismatch: (ctx) => {
1569
+ ctx.status(401).json({ error: 'Session hijacked from an unauthorized device' });
1570
+ },
1571
+ }));
1572
+
1573
+ // Or generate manually for audit logs:
1574
+ app.get('/audit', (ctx) => {
1575
+ const fp = RequestFingerprint.generate(ctx);
1576
+ ctx.json({ fingerprint: fp });
1577
+ });
1578
+ ```
1579
+
1580
+ ---
1581
+
1332
1582
  ## 📊 Comparison Matrix
1333
1583
 
1334
1584
  | Feature | Express | Koa | Fastify | AdonisJS | **AeroJS** |
@@ -1,2 +1,3 @@
1
1
  export * from './policy.js';
2
+ export * from './oauth/index.js';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from './policy.js';
2
+ export * from './oauth/index.js';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @file github-driver.ts
3
+ * @description GitHub OAuth 2.0 social login provider for AeroJS.
4
+ */
5
+ import type { OAuthDriver, OAuthDriverConfig, OAuthUser, OAuthCallbackResult } from './oauth-driver.js';
6
+ export declare class GitHubOAuthDriver implements OAuthDriver {
7
+ private config;
8
+ constructor(config: OAuthDriverConfig);
9
+ getRedirectUrl(options?: {
10
+ state?: string;
11
+ scopes?: string[];
12
+ }): string;
13
+ getUserFromToken(accessToken: string): Promise<OAuthUser>;
14
+ handleCallback(code: string): Promise<OAuthCallbackResult>;
15
+ }
16
+ //# sourceMappingURL=github-driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-driver.d.ts","sourceRoot":"","sources":["../../../src/auth/oauth/github-driver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGxG,qBAAa,iBAAkB,YAAW,WAAW;IACnD,OAAO,CAAC,MAAM,CAAoB;gBAEtB,MAAM,EAAE,iBAAiB;IAO9B,cAAc,CAAC,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO,GAAG,MAAM;IAerE,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAkCzD,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAsBxE"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @file github-driver.ts
3
+ * @description GitHub OAuth 2.0 social login provider for AeroJS.
4
+ */
5
+ import { Http } from '../../http/http.js';
6
+ export class GitHubOAuthDriver {
7
+ config;
8
+ constructor(config) {
9
+ this.config = {
10
+ scopes: ['read:user', 'user:email'],
11
+ ...config,
12
+ };
13
+ }
14
+ getRedirectUrl(options = {}) {
15
+ const scopes = options.scopes || this.config.scopes || ['read:user', 'user:email'];
16
+ const params = new URLSearchParams({
17
+ client_id: this.config.clientId,
18
+ redirect_uri: this.config.redirectUri,
19
+ scope: scopes.join(' '),
20
+ });
21
+ if (options.state) {
22
+ params.set('state', options.state);
23
+ }
24
+ return `https://github.com/login/oauth/authorize?${params.toString()}`;
25
+ }
26
+ async getUserFromToken(accessToken) {
27
+ const res = await Http.withToken(accessToken)
28
+ .withHeaders({ 'User-Agent': 'AeroJS-OAuth' })
29
+ .get('https://api.github.com/user');
30
+ res.throw();
31
+ const data = res.json();
32
+ // If primary email is private in GitHub, fetch from /user/emails
33
+ let email = data.email || null;
34
+ if (!email) {
35
+ try {
36
+ const emailsRes = await Http.withToken(accessToken)
37
+ .withHeaders({ 'User-Agent': 'AeroJS-OAuth' })
38
+ .get('https://api.github.com/user/emails');
39
+ if (emailsRes.successful) {
40
+ const emails = emailsRes.json();
41
+ const primary = emails.find((e) => e.primary && e.verified) || emails[0];
42
+ if (primary)
43
+ email = primary.email;
44
+ }
45
+ }
46
+ catch {
47
+ // Ignored
48
+ }
49
+ }
50
+ return {
51
+ id: String(data.id),
52
+ email,
53
+ name: data.name || data.login || null,
54
+ avatarUrl: data.avatar_url || null,
55
+ raw: data,
56
+ };
57
+ }
58
+ async handleCallback(code) {
59
+ const res = await Http.acceptJson()
60
+ .withHeaders({ 'User-Agent': 'AeroJS-OAuth' })
61
+ .post('https://github.com/login/oauth/access_token', {
62
+ client_id: this.config.clientId,
63
+ client_secret: this.config.clientSecret,
64
+ code,
65
+ redirect_uri: this.config.redirectUri,
66
+ });
67
+ res.throw();
68
+ const tokenData = res.json();
69
+ const accessToken = tokenData.access_token;
70
+ const user = await this.getUserFromToken(accessToken);
71
+ return {
72
+ accessToken,
73
+ tokenType: tokenData.token_type,
74
+ scope: tokenData.scope,
75
+ user,
76
+ };
77
+ }
78
+ }
79
+ //# sourceMappingURL=github-driver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-driver.js","sourceRoot":"","sources":["../../../src/auth/oauth/github-driver.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @file google-driver.ts
3
+ * @description Google OAuth 2.0 social login provider for AeroJS.
4
+ */
5
+ import type { OAuthDriver, OAuthDriverConfig, OAuthUser, OAuthCallbackResult } from './oauth-driver.js';
6
+ export declare class GoogleOAuthDriver implements OAuthDriver {
7
+ private config;
8
+ constructor(config: OAuthDriverConfig);
9
+ getRedirectUrl(options?: {
10
+ state?: string;
11
+ scopes?: string[];
12
+ }): string;
13
+ getUserFromToken(accessToken: string): Promise<OAuthUser>;
14
+ handleCallback(code: string): Promise<OAuthCallbackResult>;
15
+ }
16
+ //# sourceMappingURL=google-driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-driver.d.ts","sourceRoot":"","sources":["../../../src/auth/oauth/google-driver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAGxG,qBAAa,iBAAkB,YAAW,WAAW;IACnD,OAAO,CAAC,MAAM,CAAoB;gBAEtB,MAAM,EAAE,iBAAiB;IAO9B,cAAc,CAAC,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAO,GAAG,MAAM;IAkBrE,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAczD,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAuBxE"}