diff --git a/backend/src/services/capitalLedgerRepository.ts b/backend/src/services/capitalLedgerRepository.ts index ee8eb24..af55c86 100644 --- a/backend/src/services/capitalLedgerRepository.ts +++ b/backend/src/services/capitalLedgerRepository.ts @@ -1,7 +1,7 @@ import { getContainer } from '@bytelyst/cosmos'; import { config } from '../config/index.js'; import logger from '../utils/logger.js'; -import { supabaseService } from './SupabaseService.js'; +import { getLegacySupabaseClient } from './legacySupabaseClient.js'; import type { CapitalLedgerRecord } from './CapitalLedger.js'; const CONTAINER_NAME = 'capital_ledgers'; @@ -27,7 +27,7 @@ function isCosmosConfigured(): boolean { } function getLegacyClient() { - return supabaseService.getClient(); + return getLegacySupabaseClient(); } function toLedgerRecord(doc: Partial | null | undefined): CapitalLedgerRecord | null { diff --git a/backend/src/services/distributedLockService.ts b/backend/src/services/distributedLockService.ts index 70aa874..6f1440e 100644 --- a/backend/src/services/distributedLockService.ts +++ b/backend/src/services/distributedLockService.ts @@ -1,5 +1,5 @@ import logger from '../utils/logger.js'; -import { supabaseService } from './SupabaseService.js'; +import { getLegacySupabaseClient } from './legacySupabaseClient.js'; import { healthTracker } from './healthTracker.js'; import { observabilityService } from './observabilityService.js'; import * as distributedLockRepository from './distributedLockRepository.js'; @@ -21,7 +21,7 @@ export class DistributedLockService { private async tryAcquireRowLockLegacy(profileId: string, symbol: string | undefined, owner: string, ttlSeconds: number = 30): Promise { if (!profileId || !owner) return false; const normalizedSymbol = normalizeSymbol(symbol); - const client = supabaseService.getClient(); + const client = getLegacySupabaseClient(); if (!client) return false; const ttl = Number.isFinite(ttlSeconds) ? Math.max(1, ttlSeconds) : 30; @@ -62,7 +62,7 @@ export class DistributedLockService { private async releaseRowLockLegacy(profileId: string, symbol: string | undefined, owner: string): Promise { if (!profileId || !owner) return false; const normalizedSymbol = normalizeSymbol(symbol); - const client = supabaseService.getClient(); + const client = getLegacySupabaseClient(); if (!client) return false; const { data, error } = await client @@ -97,7 +97,7 @@ export class DistributedLockService { private async tryAcquireReconciliationLockLegacy(profileId: string, owner: string, ttlSeconds: number = 30): Promise { if (!profileId || !owner) return false; - const client = supabaseService.getClient(); + const client = getLegacySupabaseClient(); if (!client) return false; const ttl = Number.isFinite(ttlSeconds) ? Math.max(1, ttlSeconds) : 30; @@ -132,7 +132,7 @@ export class DistributedLockService { private async releaseReconciliationLockLegacy(profileId: string, owner: string): Promise { if (!profileId || !owner) return false; - const client = supabaseService.getClient(); + const client = getLegacySupabaseClient(); if (!client) return false; const { data, error } = await client @@ -162,7 +162,7 @@ export class DistributedLockService { private async isEntryInProgressLegacy(profileId: string, symbol?: string): Promise { if (!profileId) return false; const normalizedSymbol = normalizeSymbol(symbol); - const client = supabaseService.getClient(); + const client = getLegacySupabaseClient(); if (!client) return false; const { data, error } = await client diff --git a/backend/src/services/legacySupabaseClient.ts b/backend/src/services/legacySupabaseClient.ts new file mode 100644 index 0000000..fb9f26f --- /dev/null +++ b/backend/src/services/legacySupabaseClient.ts @@ -0,0 +1,20 @@ +import type { SupabaseClient } from '@supabase/supabase-js'; +import { supabaseService } from './SupabaseService.js'; + +/** + * Single import surface for legacy Postgres (Supabase JS client) access outside SupabaseService. + * Auth-specific entry points stay on platformAuthService / supabaseService as needed. + */ +export function getLegacySupabaseClient(): SupabaseClient | null { + return supabaseService.getClient(); +} + +export async function loadLatestLegacyBotStateSnapshot( + ownerId: string +): Promise<{ state: unknown } | null> { + return supabaseService.loadLatestBotStateSnapshot(ownerId); +} + +export async function saveLegacyBotStateSnapshot(ownerId: string, state: unknown): Promise { + await supabaseService.saveBotStateSnapshot(ownerId, state); +} diff --git a/backend/src/services/profileRepository.ts b/backend/src/services/profileRepository.ts index 9b070cc..8361bdc 100644 --- a/backend/src/services/profileRepository.ts +++ b/backend/src/services/profileRepository.ts @@ -2,7 +2,7 @@ import { getContainer } from '@bytelyst/cosmos'; import { randomUUID } from 'node:crypto'; import { config } from '../config/index.js'; import logger from '../utils/logger.js'; -import { supabaseService } from './SupabaseService.js'; +import { getLegacySupabaseClient } from './legacySupabaseClient.js'; export interface TradingUserProfile { user_id: string; @@ -62,7 +62,7 @@ function isCosmosConfigured(): boolean { } function getLegacyClient() { - return supabaseService.getClient(); + return getLegacySupabaseClient(); } function normalizeProfile(row: Partial | null | undefined): TradeProfileRecord | null { diff --git a/backend/src/services/snapshotRepository.ts b/backend/src/services/snapshotRepository.ts index a617b98..60836b6 100644 --- a/backend/src/services/snapshotRepository.ts +++ b/backend/src/services/snapshotRepository.ts @@ -1,7 +1,7 @@ import { getContainer } from '@bytelyst/cosmos'; import { config } from '../config/index.js'; import logger from '../utils/logger.js'; -import { supabaseService } from './SupabaseService.js'; +import { loadLatestLegacyBotStateSnapshot, saveLegacyBotStateSnapshot } from './legacySupabaseClient.js'; import { listActiveTradingUsers } from './userRepository.js'; const CONTAINER_NAME = 'bot_state_snapshots'; @@ -46,7 +46,7 @@ export async function loadLatestBotStateSnapshot( ): Promise<{ state: unknown } | null> { if (!ownerId) return null; - const loadLegacySnapshot = async () => supabaseService.loadLatestBotStateSnapshot(ownerId); + const loadLegacySnapshot = async () => loadLatestLegacyBotStateSnapshot(ownerId); if (!isCosmosConfigured()) { return loadLegacySnapshot(); @@ -108,5 +108,5 @@ export async function saveBotStateSnapshot( } } - await supabaseService.saveBotStateSnapshot(ownerId, state); + await saveLegacyBotStateSnapshot(ownerId, state); } diff --git a/backend/src/services/strategyPresetRepository.ts b/backend/src/services/strategyPresetRepository.ts index 3837867..ec51d4d 100644 --- a/backend/src/services/strategyPresetRepository.ts +++ b/backend/src/services/strategyPresetRepository.ts @@ -2,7 +2,7 @@ import { getContainer } from '@bytelyst/cosmos'; import { randomUUID } from 'node:crypto'; import { config } from '../config/index.js'; import logger from '../utils/logger.js'; -import { supabaseService } from './SupabaseService.js'; +import { getLegacySupabaseClient } from './legacySupabaseClient.js'; const PRESET_CONTAINER = 'strategy_presets'; @@ -19,7 +19,7 @@ function isCosmosConfigured(): boolean { } function getLegacyClient() { - return supabaseService.getClient(); + return getLegacySupabaseClient(); } export async function listStrategyPresets(): Promise { diff --git a/backend/src/services/userRepository.ts b/backend/src/services/userRepository.ts index d61c386..3d8b2db 100644 --- a/backend/src/services/userRepository.ts +++ b/backend/src/services/userRepository.ts @@ -1,7 +1,7 @@ import { getContainer } from '@bytelyst/cosmos'; import { config } from '../config/index.js'; import logger from '../utils/logger.js'; -import { supabaseService } from './SupabaseService.js'; +import { getLegacySupabaseClient } from './legacySupabaseClient.js'; import type { UserConfig } from './tradingUserTypes.js'; const USER_PROFILE_CONTAINER = 'trading_users'; @@ -63,7 +63,7 @@ export async function listActiveTradingUsers(): Promise { } } - const client = supabaseService.getClient(); + const client = getLegacySupabaseClient(); if (!client) { return []; }