mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-22 04:46:42 +02:00
feat(bots): enable Redis SSO for todo-bot and calendar-bot
- Activate Redis session storage in both bots for cross-bot SSO - Update SessionHelper to async methods for Redis-backed SessionService - Fix async/await issues in todo-bot and calendar-bot matrix.service.ts - Remove unused imports from calendar-api and todo-api services - Add CALENDAR_BACKEND_URL and MANA_CORE_SERVICE_KEY to .env.development Note: SessionService methods are now async (Redis-backed). Other bots need their matrix.service.ts updated to await these async calls. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
7bad849258
commit
2777f604fd
27 changed files with 2997 additions and 838 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { Module, DynamicModule, Global } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { SessionService } from './session.service';
|
||||
import { SessionService, REDIS_SESSION_PROVIDER } from './session.service';
|
||||
import { RedisSessionProvider } from './redis-session.provider';
|
||||
import { SessionModuleOptions, SESSION_MODULE_OPTIONS } from './types';
|
||||
|
||||
/**
|
||||
|
|
@ -11,19 +12,31 @@ import { SessionModuleOptions, SESSION_MODULE_OPTIONS } from './types';
|
|||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // With explicit configuration
|
||||
* // Basic usage (in-memory sessions, per bot)
|
||||
* @Module({
|
||||
* imports: [SessionModule.forRoot()]
|
||||
* })
|
||||
*
|
||||
* // With Redis for cross-bot SSO
|
||||
* @Module({
|
||||
* imports: [
|
||||
* SessionModule.register({
|
||||
* authUrl: 'http://mana-core-auth:3001',
|
||||
* sessionExpiryMs: 7 * 24 * 60 * 60 * 1000 // 7 days
|
||||
* SessionModule.forRoot({
|
||||
* storageMode: 'redis',
|
||||
* redisHost: 'localhost',
|
||||
* redisPort: 6379,
|
||||
* })
|
||||
* ]
|
||||
* })
|
||||
*
|
||||
* // With ConfigService (reads from auth.url or MANA_CORE_AUTH_URL)
|
||||
* // With Matrix-SSO-Link (automatic login)
|
||||
* @Module({
|
||||
* imports: [SessionModule.forRoot()]
|
||||
* imports: [
|
||||
* SessionModule.forRoot({
|
||||
* storageMode: 'redis',
|
||||
* enableMatrixSsoLink: true,
|
||||
* serviceKey: process.env.MANA_CORE_SERVICE_KEY,
|
||||
* })
|
||||
* ]
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
|
|
@ -34,29 +47,76 @@ export class SessionModule {
|
|||
* Register module with explicit options
|
||||
*/
|
||||
static register(options: SessionModuleOptions = {}): DynamicModule {
|
||||
const providers: any[] = [
|
||||
{
|
||||
provide: SESSION_MODULE_OPTIONS,
|
||||
useValue: options,
|
||||
},
|
||||
];
|
||||
|
||||
// Add Redis provider if storage mode is redis
|
||||
if (options.storageMode === 'redis') {
|
||||
providers.push({
|
||||
provide: REDIS_SESSION_PROVIDER,
|
||||
useClass: RedisSessionProvider,
|
||||
});
|
||||
}
|
||||
|
||||
providers.push(SessionService);
|
||||
|
||||
return {
|
||||
module: SessionModule,
|
||||
imports: [ConfigModule],
|
||||
providers: [
|
||||
{
|
||||
provide: SESSION_MODULE_OPTIONS,
|
||||
useValue: options,
|
||||
},
|
||||
SessionService,
|
||||
],
|
||||
providers,
|
||||
exports: [SessionService],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Register module with ConfigService (reads auth.url or MANA_CORE_AUTH_URL from config)
|
||||
* Register module with ConfigService
|
||||
*
|
||||
* Reads configuration from environment:
|
||||
* - MANA_CORE_AUTH_URL: Auth service URL
|
||||
* - REDIS_HOST, REDIS_PORT: Redis for cross-bot SSO
|
||||
* - MANA_CORE_SERVICE_KEY: For Matrix-SSO-Link
|
||||
* - SESSION_STORAGE_MODE: 'memory' or 'redis'
|
||||
*/
|
||||
static forRoot(): DynamicModule {
|
||||
static forRoot(options: SessionModuleOptions = {}): DynamicModule {
|
||||
const providers: any[] = [
|
||||
{
|
||||
provide: SESSION_MODULE_OPTIONS,
|
||||
useValue: options,
|
||||
},
|
||||
];
|
||||
|
||||
// Add Redis provider if storage mode is redis
|
||||
if (options.storageMode === 'redis') {
|
||||
providers.push({
|
||||
provide: REDIS_SESSION_PROVIDER,
|
||||
useClass: RedisSessionProvider,
|
||||
});
|
||||
}
|
||||
|
||||
providers.push(SessionService);
|
||||
|
||||
return {
|
||||
module: SessionModule,
|
||||
imports: [ConfigModule],
|
||||
providers: [SessionService],
|
||||
providers,
|
||||
exports: [SessionService],
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Register module with Redis enabled for cross-bot SSO
|
||||
*
|
||||
* Convenience method that enables Redis storage and Matrix-SSO-Link.
|
||||
*/
|
||||
static forRootWithRedis(options: Omit<SessionModuleOptions, 'storageMode'> = {}): DynamicModule {
|
||||
return this.forRoot({
|
||||
...options,
|
||||
storageMode: 'redis',
|
||||
enableMatrixSsoLink: options.enableMatrixSsoLink ?? true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue