lint fix wip

This commit is contained in:
Nicolas Cantu 2026-01-06 23:07:30 +01:00
parent fa1db1faa6
commit dec7359dcd
15 changed files with 84 additions and 39 deletions

View File

@ -66,9 +66,10 @@ export async function publishSeries(params: {
throw new Error('Failed to publish series') throw new Error('Failed to publish series')
} }
const parsed = parseObjectId(published.id) const parsed = parseObjectId(published.id)
const hash = parsed.hash ?? published.id const {hash: parsedHash, version: parsedVersion, index: parsedIndex} = parsed
const version = parsed.version ?? 0 const hash = parsedHash ?? published.id
const index = parsed.index ?? 0 const version = parsedVersion ?? 0
const index = parsedIndex ?? 0
return { return {
id: published.id, id: published.id,
hash, hash,
@ -171,9 +172,10 @@ export async function publishReview(params: {
throw new Error('Failed to publish review') throw new Error('Failed to publish review')
} }
const parsed = parseObjectId(published.id) const parsed = parseObjectId(published.id)
const hash = parsed.hash ?? published.id const {hash: parsedHash, version: parsedVersion, index: parsedIndex} = parsed
const version = parsed.version ?? 0 const hash = parsedHash ?? published.id
const index = parsed.index ?? 0 const version = parsedVersion ?? 0
const index = parsedIndex ?? 0
return { return {
id: published.id, id: published.id,
hash, hash,

View File

@ -49,7 +49,7 @@ async function publishEncryptedMessage(
return null return null
} }
console.log('Private message published', { console.warn('Private message published', {
messageEventId: publishedEvent.id, messageEventId: publishedEvent.id,
articleId, articleId,
recipientPubkey, recipientPubkey,

View File

@ -30,7 +30,7 @@ export function handleMessageVerificationEvent(
authorPubkey: string, authorPubkey: string,
finalize: (value: boolean) => void finalize: (value: boolean) => void
): void { ): void {
console.log('Private message verified on relay', { console.warn('Private message verified on relay', {
messageEventId: event.id, messageEventId: event.id,
articleId, articleId,
recipientPubkey, recipientPubkey,
@ -157,7 +157,7 @@ export async function publishAndVerifyMessage(
): Promise<boolean> { ): Promise<boolean> {
const verified = await verifyPrivateMessagePublished(messageEventId, authorPubkey, recipientPubkey, articleId) const verified = await verifyPrivateMessagePublished(messageEventId, authorPubkey, recipientPubkey, articleId)
if (verified) { if (verified) {
console.log('Private message verified on relay', { messageEventId, articleId, recipientPubkey }) console.warn('Private message verified on relay', { messageEventId, articleId, recipientPubkey })
} else { } else {
console.warn('Private message published but not yet verified on relay', { messageEventId, articleId, recipientPubkey }) console.warn('Private message published but not yet verified on relay', { messageEventId, articleId, recipientPubkey })
} }

View File

@ -57,7 +57,7 @@ export async function encryptAndPublish(
} }
await storePrivateContent(publishedEvent.id, draft.content, authorPubkey, invoice, key, iv) await storePrivateContent(publishedEvent.id, draft.content, authorPubkey, invoice, key, iv)
console.log('Article published with encrypted content', { console.warn('Article published with encrypted content', {
articleId: publishedEvent.id, articleId: publishedEvent.id,
authorPubkey, authorPubkey,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),

View File

@ -137,7 +137,7 @@ export class AutomaticTransferService {
// 2. Trigger automatic transfer via platform's Lightning node // 2. Trigger automatic transfer via platform's Lightning node
// 3. Update tracking when transfer is complete // 3. Update tracking when transfer is complete
console.log('Transfer requirement tracked', { console.warn('Transfer requirement tracked', {
type, type,
id, id,
recipientPubkey, recipientPubkey,

View File

@ -81,7 +81,7 @@ export function logPaymentSuccess(
verified: boolean verified: boolean
): void { ): void {
const expectedSplit = calculateArticleSplit() const expectedSplit = calculateArticleSplit()
console.log('Article payment processed with commission', { console.warn('Article payment processed with commission', {
articleId, articleId,
totalAmount: amount, totalAmount: amount,
authorPortion: expectedSplit.author, authorPortion: expectedSplit.author,
@ -91,7 +91,7 @@ export function logPaymentSuccess(
}) })
if (verified) { if (verified) {
console.log('Private content sent and verified on relay', { console.warn('Private content sent and verified on relay', {
articleId, articleId,
recipientPubkey, recipientPubkey,
messageEventId, messageEventId,

View File

@ -18,7 +18,7 @@ class PlatformSyncService {
private syncSubscription: { unsub: () => void } | null = null private syncSubscription: { unsub: () => void } | null = null
private lastSyncTime: number = 0 private lastSyncTime: number = 0
private readonly SYNC_INTERVAL_MS = 60000 // Sync every minute private readonly SYNC_INTERVAL_MS = 60000 // Sync every minute
private readonly SYNC_TIMEOUT_MS = 30000 // 30 seconds timeout per sync private readonly SYNC_TIMEOUT_MS = 60000 // 60 seconds timeout per relay (increased from 30s)
/** /**
* Start background sync * Start background sync
@ -80,6 +80,9 @@ class PlatformSyncService {
}, },
] ]
console.warn(`[PlatformSync] Starting sync with filter:`, JSON.stringify(filters, null, 2))
console.warn(`[PlatformSync] MIN_EVENT_DATE: ${MIN_EVENT_DATE} (${new Date(MIN_EVENT_DATE * 1000).toISOString()})`)
const { relaySessionManager } = await import('./relaySessionManager') const { relaySessionManager } = await import('./relaySessionManager')
const { syncProgressManager } = await import('./syncProgressManager') const { syncProgressManager } = await import('./syncProgressManager')
const activeRelays = await relaySessionManager.getActiveRelays() const activeRelays = await relaySessionManager.getActiveRelays()
@ -114,6 +117,7 @@ class PlatformSyncService {
const relayEvents: Event[] = [] const relayEvents: Event[] = []
let resolved = false let resolved = false
let eventCount = 0
const finalize = (): void => { const finalize = (): void => {
if (resolved) { if (resolved) {
@ -130,14 +134,19 @@ class PlatformSyncService {
} }
} }
console.warn(`[PlatformSync] Relay ${relayUrl} completed, received ${relayEvents.length} events`) console.warn(`[PlatformSync] Relay ${relayUrl} completed: received ${eventCount} total events, ${relayEvents.length} with service='${PLATFORM_SERVICE}'`)
} }
await new Promise<void>((resolve) => { await new Promise<void>((resolve) => {
sub.on('event', (event: Event): void => { sub.on('event', (event: Event): void => {
eventCount++
// Log every 10th event to track progress
if (eventCount % 10 === 0) {
console.warn(`[PlatformSync] Received ${eventCount} events from relay ${relayUrl}`)
}
// Log target event for debugging // Log target event for debugging
if (event.id === '527d83e0af20bf23c3e104974090ccc21536ece72c24eb784b3642890f63b763') { if (event.id === '527d83e0af20bf23c3e104974090ccc21536ece72c24eb784b3642890f63b763') {
console.warn(`[PlatformSync] Received target event from relay ${relayUrl}:`, { console.warn(`[PlatformSync] Received target event from relay ${relayUrl} (event #${eventCount}):`, {
id: event.id, id: event.id,
created_at: event.created_at, created_at: event.created_at,
created_at_date: new Date(event.created_at * 1000).toISOString(), created_at_date: new Date(event.created_at * 1000).toISOString(),
@ -173,15 +182,18 @@ class PlatformSyncService {
}) })
sub.on('eose', (): void => { sub.on('eose', (): void => {
console.warn(`[PlatformSync] Relay ${relayUrl} sent EOSE signal`)
finalize() finalize()
resolve() resolve()
}) })
// Timeout after SYNC_TIMEOUT_MS // Timeout after SYNC_TIMEOUT_MS
setTimeout((): void => { const timeoutId = setTimeout((): void => {
console.warn(`[PlatformSync] Relay ${relayUrl} timeout after ${this.SYNC_TIMEOUT_MS}ms`)
finalize() finalize()
resolve() resolve()
}, this.SYNC_TIMEOUT_MS).unref?.() }, this.SYNC_TIMEOUT_MS)
timeoutId.unref?.()
this.syncSubscription = sub this.syncSubscription = sub
}) })
@ -235,16 +247,47 @@ class PlatformSyncService {
private async processEvent(event: Event): Promise<void> { private async processEvent(event: Event): Promise<void> {
const tags = extractTagsFromEvent(event) const tags = extractTagsFromEvent(event)
// Log target event for debugging
if (event.id === '527d83e0af20bf23c3e104974090ccc21536ece72c24eb784b3642890f63b763') {
console.warn(`[PlatformSync] Processing target event:`, {
id: event.id,
type: tags.type,
hidden: tags.hidden,
service: tags.service,
version: tags.version,
})
}
// Skip hidden events // Skip hidden events
if (tags.hidden) { if (tags.hidden) {
if (event.id === '527d83e0af20bf23c3e104974090ccc21536ece72c24eb784b3642890f63b763') {
console.warn(`[PlatformSync] Target event skipped: hidden=${tags.hidden}`)
}
return return
} }
// Try to parse and cache by type // Try to parse and cache by type
if (tags.type === 'author') { if (tags.type === 'author') {
if (event.id === '527d83e0af20bf23c3e104974090ccc21536ece72c24eb784b3642890f63b763') {
console.warn(`[PlatformSync] Attempting to parse target event as author presentation`)
}
const parsed = await parsePresentationEvent(event) const parsed = await parsePresentationEvent(event)
if (event.id === '527d83e0af20bf23c3e104974090ccc21536ece72c24eb784b3642890f63b763') {
console.warn(`[PlatformSync] parsePresentationEvent result for target event:`, {
parsed: parsed !== null,
hasHash: parsed?.hash !== undefined,
hash: parsed?.hash,
})
}
if (parsed && parsed.hash) { if (parsed && parsed.hash) {
await objectCache.set('author', parsed.hash, event, parsed, tags.version ?? 0, tags.hidden, parsed.index) await objectCache.set('author', parsed.hash, event, parsed, tags.version ?? 0, tags.hidden, parsed.index)
if (event.id === '527d83e0af20bf23c3e104974090ccc21536ece72c24eb784b3642890f63b763') {
console.warn(`[PlatformSync] Target event cached successfully as author with hash:`, parsed.hash)
}
} else {
if (event.id === '527d83e0af20bf23c3e104974090ccc21536ece72c24eb784b3642890f63b763') {
console.warn(`[PlatformSync] Target event NOT cached: parsed=${parsed !== null}, hasHash=${parsed?.hash !== undefined}`)
}
} }
} else if (tags.type === 'series') { } else if (tags.type === 'series') {
const parsed = await parseSeriesFromEvent(event) const parsed = await parseSeriesFromEvent(event)

View File

@ -34,7 +34,7 @@ export class PlatformTrackingService {
await Promise.all(pubs) await Promise.all(pubs)
} else { } else {
// Publish to all active relays // Publish to all active relays
console.log(`[PlatformTracking] Publishing tracking event ${event.id} to ${activeRelays.length} active relay(s)`) console.warn(`[PlatformTracking] Publishing tracking event ${event.id} to ${activeRelays.length} active relay(s)`)
const pubs = pool.publish(activeRelays, event) const pubs = pool.publish(activeRelays, event)
// Track failed relays and mark them inactive for the session // Track failed relays and mark them inactive for the session
@ -88,7 +88,7 @@ export class PlatformTrackingService {
const event = buildTrackingEvent(tracking, authorPubkey, authorPrivateKey, this.platformPubkey) const event = buildTrackingEvent(tracking, authorPubkey, authorPrivateKey, this.platformPubkey)
await this.publishTrackingEvent(event) await this.publishTrackingEvent(event)
console.log('Platform tracking event published', { console.warn('Platform tracking event published', {
eventId: event.id, eventId: event.id,
articleId: tracking.articleId, articleId: tracking.articleId,
recipientPubkey: tracking.recipientPubkey, recipientPubkey: tracking.recipientPubkey,

View File

@ -50,7 +50,7 @@ export async function tryWithRelayRotation<T>(
// We continue to use it but it's lower priority // We continue to use it but it's lower priority
try { try {
console.log(`[RelayRotation] Trying relay ${relayIndex + 1}/${currentActiveRelays.length}: ${relayUrl}`) console.warn(`[RelayRotation] Trying relay ${relayIndex + 1}/${currentActiveRelays.length}: ${relayUrl}`)
// Notify progress manager that we're switching to a new relay (reset to 0 for this relay) // Notify progress manager that we're switching to a new relay (reset to 0 for this relay)
const { syncProgressManager } = await import('./syncProgressManager') const { syncProgressManager } = await import('./syncProgressManager')
@ -70,7 +70,7 @@ export async function tryWithRelayRotation<T>(
setTimeout(() => reject(new Error(`Timeout after ${timeout}ms`)), timeout) setTimeout(() => reject(new Error(`Timeout after ${timeout}ms`)), timeout)
), ),
]) ])
console.log(`[RelayRotation] Success with relay: ${relayUrl}`) console.warn(`[RelayRotation] Success with relay: ${relayUrl}`)
return result return result
} catch (error) { } catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error) const errorMessage = error instanceof Error ? error.message : String(error)

View File

@ -15,7 +15,7 @@ class RelaySessionManager {
*/ */
public async initialize(): Promise<void> { public async initialize(): Promise<void> {
this.failedRelays.clear() this.failedRelays.clear()
console.log('[RelaySessionManager] Session initialized - all relays active') console.warn('[RelaySessionManager] Session initialized - all relays active')
} }
/** /**

View File

@ -63,7 +63,7 @@ export function buildRewardEvent(originalEvent: Event, reviewId: string): {
export function checkIfAlreadyRewarded(originalEvent: Event, reviewId: string): boolean { export function checkIfAlreadyRewarded(originalEvent: Event, reviewId: string): boolean {
const alreadyRewarded = originalEvent.tags.some((tag) => tag[0] === 'rewarded' && tag[1] === 'true') const alreadyRewarded = originalEvent.tags.some((tag) => tag[0] === 'rewarded' && tag[1] === 'true')
if (alreadyRewarded) { if (alreadyRewarded) {
console.log('Review already marked as rewarded', { console.warn('Review already marked as rewarded', {
reviewId, reviewId,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
}) })
@ -82,7 +82,7 @@ export async function publishRewardEvent(
): Promise<void> { ): Promise<void> {
const publishedEvent = await nostrService.publishEvent(updatedEvent) const publishedEvent = await nostrService.publishEvent(updatedEvent)
if (publishedEvent) { if (publishedEvent) {
console.log('Review updated with reward tag', { console.warn('Review updated with reward tag', {
reviewId, reviewId,
updatedEventId: publishedEvent.id, updatedEventId: publishedEvent.id,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),

View File

@ -39,7 +39,7 @@ export class SponsoringPaymentService {
return buildErrorResult('Invalid author Bitcoin address', request) return buildErrorResult('Invalid author Bitcoin address', request)
} }
console.log('Sponsoring payment request created', { console.warn('Sponsoring payment request created', {
authorPubkey: request.authorPubkey, authorPubkey: request.authorPubkey,
authorAddress: request.authorMainnetAddress, authorAddress: request.authorMainnetAddress,
platformAddress: PLATFORM_BITCOIN_ADDRESS, platformAddress: PLATFORM_BITCOIN_ADDRESS,

View File

@ -63,7 +63,7 @@ export function logTrackingSuccess(
split: { authorSats: number; platformSats: number }, split: { authorSats: number; platformSats: number },
verification: { confirmed: boolean; confirmations: number } verification: { confirmed: boolean; confirmations: number }
): void { ): void {
console.log('Sponsoring payment tracked', { console.warn('Sponsoring payment tracked', {
transactionId, transactionId,
authorPubkey, authorPubkey,
authorAmount: split.authorSats, authorAmount: split.authorSats,

View File

@ -86,7 +86,7 @@ export class SponsoringTrackingService {
await Promise.all(pubs) await Promise.all(pubs)
} else { } else {
// Publish to all active relays // Publish to all active relays
console.log(`[SponsoringTracking] Publishing tracking event ${event.id} to ${activeRelays.length} active relay(s)`) console.warn(`[SponsoringTracking] Publishing tracking event ${event.id} to ${activeRelays.length} active relay(s)`)
const pubs = pool.publish(activeRelays, event) const pubs = pool.publish(activeRelays, event)
// Track failed relays and mark them inactive for the session // Track failed relays and mark them inactive for the session
@ -125,7 +125,7 @@ export class SponsoringTrackingService {
const event = this.buildSponsoringTrackingEvent(tracking, authorPubkey, authorPrivateKey) const event = this.buildSponsoringTrackingEvent(tracking, authorPubkey, authorPrivateKey)
await this.publishSponsoringTrackingEvent(event) await this.publishSponsoringTrackingEvent(event)
console.log('Sponsoring payment tracked', { console.warn('Sponsoring payment tracked', {
eventId: event.id, eventId: event.id,
transactionId: tracking.transactionId, transactionId: tracking.transactionId,
authorPubkey: tracking.authorPubkey, authorPubkey: tracking.authorPubkey,
@ -160,7 +160,7 @@ export class SponsoringTrackingService {
// 2. Update the total_sponsoring tag // 2. Update the total_sponsoring tag
// 3. Publish updated event // 3. Publish updated event
console.log('Presentation sponsoring updated', { console.warn('Presentation sponsoring updated', {
presentationArticleId, presentationArticleId,
newTotalSponsoring, newTotalSponsoring,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),

View File

@ -64,7 +64,7 @@ async function fetchAndCachePublications(
5000 // 5 second timeout per relay 5000 // 5 second timeout per relay
) )
sub = result sub = result
} catch (rotationError) { } catch (_rotationError) {
// Fallback to primary relay if rotation fails // Fallback to primary relay if rotation fails
usedRelayUrl = getPrimaryRelaySync() usedRelayUrl = getPrimaryRelaySync()
sub = createSubscription(pool, [usedRelayUrl], filters) sub = createSubscription(pool, [usedRelayUrl], filters)
@ -192,7 +192,7 @@ async function fetchAndCacheSeries(
5000 // 5 second timeout per relay 5000 // 5 second timeout per relay
) )
sub = result sub = result
} catch (rotationError) { } catch (_rotationError) {
// Fallback to primary relay if rotation fails // Fallback to primary relay if rotation fails
usedRelayUrl = getPrimaryRelaySync() usedRelayUrl = getPrimaryRelaySync()
sub = createSubscription(pool, [usedRelayUrl], filters) sub = createSubscription(pool, [usedRelayUrl], filters)
@ -322,7 +322,7 @@ async function fetchAndCachePurchases(
5000 // 5 second timeout per relay 5000 // 5 second timeout per relay
) )
sub = result sub = result
} catch (rotationError) { } catch (_rotationError) {
// Fallback to primary relay if rotation fails // Fallback to primary relay if rotation fails
usedRelayUrl = getPrimaryRelaySync() usedRelayUrl = getPrimaryRelaySync()
sub = createSubscription(pool, [usedRelayUrl], filters) sub = createSubscription(pool, [usedRelayUrl], filters)
@ -423,7 +423,7 @@ async function fetchAndCacheSponsoring(
5000 // 5 second timeout per relay 5000 // 5 second timeout per relay
) )
sub = result sub = result
} catch (rotationError) { } catch (_rotationError) {
// Fallback to primary relay if rotation fails // Fallback to primary relay if rotation fails
usedRelayUrl = getPrimaryRelaySync() usedRelayUrl = getPrimaryRelaySync()
sub = createSubscription(pool, [usedRelayUrl], filters) sub = createSubscription(pool, [usedRelayUrl], filters)
@ -524,7 +524,7 @@ async function fetchAndCacheReviewTips(
5000 // 5 second timeout per relay 5000 // 5 second timeout per relay
) )
sub = result sub = result
} catch (rotationError) { } catch (_rotationError) {
// Fallback to primary relay if rotation fails // Fallback to primary relay if rotation fails
usedRelayUrl = getPrimaryRelaySync() usedRelayUrl = getPrimaryRelaySync()
sub = createSubscription(pool, [usedRelayUrl], filters) sub = createSubscription(pool, [usedRelayUrl], filters)
@ -644,7 +644,7 @@ async function fetchAndCachePaymentNotes(
5000 // 5 second timeout per relay 5000 // 5 second timeout per relay
) )
subscriptions = result.flat() subscriptions = result.flat()
} catch (rotationError) { } catch (_rotationError) {
// Fallback to primary relay if rotation fails // Fallback to primary relay if rotation fails
usedRelayUrl = getPrimaryRelaySync() usedRelayUrl = getPrimaryRelaySync()
subscriptions = filters.map((filter) => createSubscription(pool, [usedRelayUrl], [filter])) subscriptions = filters.map((filter) => createSubscription(pool, [usedRelayUrl], [filter]))