Skip to content
Open
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ npm-debug.log*
*.ntvs*
*.njsproj
*.sln
*.sw?
*.sw?.idx/
25 changes: 1 addition & 24 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Module, forwardRef } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ScheduleModule } from '@nestjs/schedule';
import { JwtModule } from '@nestjs/jwt';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './modules/auth/auth.module';
Expand All @@ -27,18 +26,11 @@ import { Webhook } from './modules/webhook/webhook.entity';
import { StellarEvent } from './modules/stellar/entities/stellar-event.entity';
import { AdminModule } from './modules/admin/admin.module';
import { StellarEventModule } from './modules/stellar/stellar-event.module';
import { AssetsModule } from './modules/assets/assets.module';
import { AllowedAsset } from './modules/assets/entities/allowed-asset.entity';
import { IpfsModule } from './modules/ipfs/ipfs.module';
import { EscrowGateway } from './gateways/escrow.gateway';
import stellarConfig from './config/stellar.config';
import ipfsConfig from './config/ipfs.config';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [stellarConfig, ipfsConfig],
}),
ScheduleModule.forRoot(),
TypeOrmModule.forRootAsync({
Expand All @@ -63,7 +55,6 @@ import ipfsConfig from './config/ipfs.config';
AdminAuditLog,
Webhook,
StellarEvent,
AllowedAsset,
],
synchronize: process.env.NODE_ENV === 'test',
migrations: [__dirname + '/migrations/*.ts'],
Expand All @@ -80,22 +71,8 @@ import ipfsConfig from './config/ipfs.config';
NotificationsModule,
ApiKeyModule,
forwardRef(() => StellarEventModule),
AssetsModule,
IpfsModule,
JwtModule.registerAsync({
useFactory: (configService: ConfigService) => ({
secret:
configService.get<string>('JWT_SECRET') ||
'your-secret-key-change-in-production',
signOptions: { expiresIn: '15m' },
}),
inject: [ConfigService],
}),
],
controllers: [AppController],
providers: [
AppService,
EscrowGateway, // WebSocket Gateway for real-time updates
],
providers: [AppService],
})
export class AppModule {}
101 changes: 101 additions & 0 deletions apps/backend/src/app.module.ts.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Module, forwardRef } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ScheduleModule } from '@nestjs/schedule';
import { JwtModule } from '@nestjs/jwt';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { AuthModule } from './modules/auth/auth.module';
import { UserModule } from './modules/user/user.module';
import { StellarModule } from './modules/stellar/stellar.module';
import { WebhookModule } from './modules/webhook/webhook.module';
import { User } from './modules/user/entities/user.entity';
import { RefreshToken } from './modules/user/entities/refresh-token.entity';
import { Escrow } from './modules/escrow/entities/escrow.entity';
import { Party } from './modules/escrow/entities/party.entity';
import { Condition } from './modules/escrow/entities/condition.entity';
import { EscrowEvent } from './modules/escrow/entities/escrow-event.entity';
import { Dispute } from './modules/escrow/entities/dispute.entity';
import { NotificationsModule } from './notifications/notifications.module';
import { EscrowModule } from './modules/escrow/escrow.module';
import { ApiKeyModule } from './api-key/api-key.module';
import { Notification } from './notifications/entities/notification.entity';
import { NotificationPreference } from './notifications/entities/notification-preference.entity';
import { ApiKey } from './api-key/entities/api-key.entity';
import { AdminAuditLog } from './modules/admin/entities/admin-audit-log.entity';
import { Webhook } from './modules/webhook/webhook.entity';
import { StellarEvent } from './modules/stellar/entities/stellar-event.entity';
import { AdminModule } from './modules/admin/admin.module';
import { StellarEventModule } from './modules/stellar/stellar-event.module';
import { AssetsModule } from './modules/assets/assets.module';
import { AllowedAsset } from './modules/assets/entities/allowed-asset.entity';
import { IpfsModule } from './modules/ipfs/ipfs.module';
import { EscrowGateway } from './gateways/escrow.gateway';
import stellarConfig from './config/stellar.config';
import ipfsConfig from './config/ipfs.config';

@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [stellarConfig, ipfsConfig],
}),
ScheduleModule.forRoot(),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
type: 'sqlite',
database: configService.get<string>(
'DATABASE_PATH',
'./data/vaultix.db',
),
entities: [
User,
RefreshToken,
Escrow,
Party,
Condition,
EscrowEvent,
Dispute,
Notification,
NotificationPreference,
ApiKey,
AdminAuditLog,
Webhook,
StellarEvent,
AllowedAsset,
],
synchronize: process.env.NODE_ENV === 'test',
migrations: [__dirname + '/migrations/*.ts'],
migrationsRun: process.env.NODE_ENV !== 'test',
}),
inject: [ConfigService],
}),
AuthModule,
UserModule,
EscrowModule,
StellarModule,
forwardRef(() => AdminModule),
WebhookModule,
NotificationsModule,
ApiKeyModule,
forwardRef(() => StellarEventModule),
AssetsModule,
IpfsModule,
JwtModule.registerAsync({
useFactory: (configService: ConfigService) => ({
secret:
configService.get<string>('JWT_SECRET') ||
'your-secret-key-change-in-production',
signOptions: { expiresIn: '15m' },
}),
inject: [ConfigService],
}),
],
controllers: [AppController],
providers: [
AppService,
EscrowGateway, // WebSocket Gateway for real-time updates
],
})
export class AppModule {}
2 changes: 1 addition & 1 deletion apps/backend/src/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ export default new DataSource({
],
migrations: ['./src/migrations/*.ts'],
synchronize: false,
});
});
79 changes: 79 additions & 0 deletions apps/backend/src/modules/health/health.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Injectable } from '@nestjs/common';
import { InjectDataSource } from '@nestjs/typeorm';
import { DataSource } from 'typeorm';

export interface DatabaseHealth {
status: 'ok' | 'error';
responseTimeMs?: number;
error?: string;
pool?: {
total: number;
idle: number;
waiting: number;
};
}

export interface HealthReport {
status: 'ok' | 'degraded';
timestamp: string;
uptime: number;
database: DatabaseHealth;
}

interface PoolInternals {
totalCount?: number;
idleCount?: number;
waitingCount?: number;
_allClients?: unknown[];
_idle?: unknown[];
_waitingQueue?: unknown[];
}

interface DriverInternals {
master?: PoolInternals;
pool?: PoolInternals;
}

@Injectable()
export class HealthService {
constructor(@InjectDataSource() private readonly dataSource: DataSource) {}

async check(): Promise<HealthReport> {
const database = await this.checkDatabase();
return {
status: database.status === 'ok' ? 'ok' : 'degraded',
timestamp: new Date().toISOString(),
uptime: process.uptime(),
database,
};
}

private async checkDatabase(): Promise<DatabaseHealth> {
const start = Date.now();
try {
await this.dataSource.query('SELECT 1');
const responseTimeMs = Date.now() - start;

const driver = this.dataSource.driver as unknown as DriverInternals;
const pool: PoolInternals | null = driver?.master ?? driver?.pool ?? null;

return {
status: 'ok',
responseTimeMs,
pool: pool
? {
total: pool.totalCount ?? pool._allClients?.length ?? 0,
idle: pool.idleCount ?? pool._idle?.length ?? 0,
waiting: pool.waitingCount ?? pool._waitingQueue?.length ?? 0,
}
: undefined,
};
} catch (error) {
return {
status: 'error',
responseTimeMs: Date.now() - start,
error: error instanceof Error ? error.message : String(error),
};
}
}
}
1 change: 1 addition & 0 deletions apps/onchain/src/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion apps/onchain/src/fee_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn create_test_token<'a>(env: &Env, admin: &Address) -> (token::StellarAssetClie
}

/// Helper function to create token client + admin + address
fn create_token_contract<'a>(
pub(crate) fn create_token_contract<'a>(
env: &Env,
admin: &Address,
) -> (token::Client<'a>, token::StellarAssetClient<'a>, Address) {
Expand Down
Loading
Loading