From dec7359dcd4c76adcca1c93f4ba02e703b0edab3 Mon Sep 17 00:00:00 2001 From: Nicolas Cantu Date: Tue, 6 Jan 2026 23:07:30 +0100 Subject: [PATCH] lint fix wip --- lib/articleMutations.ts | 14 +++--- lib/articlePublisherHelpersEncryption.ts | 2 +- lib/articlePublisherHelpersVerification.ts | 4 +- lib/articlePublisherPublish.ts | 2 +- lib/automaticTransfer.ts | 2 +- lib/paymentPollingTracking.ts | 8 ++-- lib/platformSync.ts | 55 +++++++++++++++++++--- lib/platformTracking.ts | 4 +- lib/relayRotation.ts | 4 +- lib/relaySessionManager.ts | 2 +- lib/reviewRewardUpdate.ts | 4 +- lib/sponsoringPayment.ts | 2 +- lib/sponsoringPaymentTracking.ts | 2 +- lib/sponsoringTracking.ts | 6 +-- lib/userContentSync.ts | 12 ++--- 15 files changed, 84 insertions(+), 39 deletions(-) diff --git a/lib/articleMutations.ts b/lib/articleMutations.ts index 2d34d4f..608602b 100644 --- a/lib/articleMutations.ts +++ b/lib/articleMutations.ts @@ -66,9 +66,10 @@ export async function publishSeries(params: { throw new Error('Failed to publish series') } const parsed = parseObjectId(published.id) - const hash = parsed.hash ?? published.id - const version = parsed.version ?? 0 - const index = parsed.index ?? 0 + const {hash: parsedHash, version: parsedVersion, index: parsedIndex} = parsed + const hash = parsedHash ?? published.id + const version = parsedVersion ?? 0 + const index = parsedIndex ?? 0 return { id: published.id, hash, @@ -171,9 +172,10 @@ export async function publishReview(params: { throw new Error('Failed to publish review') } const parsed = parseObjectId(published.id) - const hash = parsed.hash ?? published.id - const version = parsed.version ?? 0 - const index = parsed.index ?? 0 + const {hash: parsedHash, version: parsedVersion, index: parsedIndex} = parsed + const hash = parsedHash ?? published.id + const version = parsedVersion ?? 0 + const index = parsedIndex ?? 0 return { id: published.id, hash, diff --git a/lib/articlePublisherHelpersEncryption.ts b/lib/articlePublisherHelpersEncryption.ts index 7518b79..d95c168 100644 --- a/lib/articlePublisherHelpersEncryption.ts +++ b/lib/articlePublisherHelpersEncryption.ts @@ -49,7 +49,7 @@ async function publishEncryptedMessage( return null } - console.log('Private message published', { + console.warn('Private message published', { messageEventId: publishedEvent.id, articleId, recipientPubkey, diff --git a/lib/articlePublisherHelpersVerification.ts b/lib/articlePublisherHelpersVerification.ts index e5d00ce..d960d6b 100644 --- a/lib/articlePublisherHelpersVerification.ts +++ b/lib/articlePublisherHelpersVerification.ts @@ -30,7 +30,7 @@ export function handleMessageVerificationEvent( authorPubkey: string, finalize: (value: boolean) => void ): void { - console.log('Private message verified on relay', { + console.warn('Private message verified on relay', { messageEventId: event.id, articleId, recipientPubkey, @@ -157,7 +157,7 @@ export async function publishAndVerifyMessage( ): Promise { const verified = await verifyPrivateMessagePublished(messageEventId, authorPubkey, recipientPubkey, articleId) if (verified) { - console.log('Private message verified on relay', { messageEventId, articleId, recipientPubkey }) + console.warn('Private message verified on relay', { messageEventId, articleId, recipientPubkey }) } else { console.warn('Private message published but not yet verified on relay', { messageEventId, articleId, recipientPubkey }) } diff --git a/lib/articlePublisherPublish.ts b/lib/articlePublisherPublish.ts index a875209..5497947 100644 --- a/lib/articlePublisherPublish.ts +++ b/lib/articlePublisherPublish.ts @@ -57,7 +57,7 @@ export async function encryptAndPublish( } 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, authorPubkey, timestamp: new Date().toISOString(), diff --git a/lib/automaticTransfer.ts b/lib/automaticTransfer.ts index 2d0177f..6a6198c 100644 --- a/lib/automaticTransfer.ts +++ b/lib/automaticTransfer.ts @@ -137,7 +137,7 @@ export class AutomaticTransferService { // 2. Trigger automatic transfer via platform's Lightning node // 3. Update tracking when transfer is complete - console.log('Transfer requirement tracked', { + console.warn('Transfer requirement tracked', { type, id, recipientPubkey, diff --git a/lib/paymentPollingTracking.ts b/lib/paymentPollingTracking.ts index 78c0343..1edb234 100644 --- a/lib/paymentPollingTracking.ts +++ b/lib/paymentPollingTracking.ts @@ -81,7 +81,7 @@ export function logPaymentSuccess( verified: boolean ): void { const expectedSplit = calculateArticleSplit() - console.log('Article payment processed with commission', { + console.warn('Article payment processed with commission', { articleId, totalAmount: amount, authorPortion: expectedSplit.author, @@ -91,7 +91,7 @@ export function logPaymentSuccess( }) if (verified) { - console.log('Private content sent and verified on relay', { + console.warn('Private content sent and verified on relay', { articleId, recipientPubkey, messageEventId, @@ -116,7 +116,7 @@ export function logPaymentResult( if (result.success && result.messageEventId) { logPaymentSuccess(articleId, recipientPubkey, amount, result.messageEventId, result.verified ?? false) return true - } + } console.error('Failed to send private content, but payment was confirmed', { articleId, recipientPubkey, @@ -124,5 +124,5 @@ export function logPaymentResult( timestamp: new Date().toISOString(), }) return false - + } diff --git a/lib/platformSync.ts b/lib/platformSync.ts index ba2e17b..e8ac80a 100644 --- a/lib/platformSync.ts +++ b/lib/platformSync.ts @@ -18,7 +18,7 @@ class PlatformSyncService { private syncSubscription: { unsub: () => void } | null = null private lastSyncTime: number = 0 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 @@ -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 { syncProgressManager } = await import('./syncProgressManager') const activeRelays = await relaySessionManager.getActiveRelays() @@ -114,6 +117,7 @@ class PlatformSyncService { const relayEvents: Event[] = [] let resolved = false + let eventCount = 0 const finalize = (): void => { 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((resolve) => { 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 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, created_at: event.created_at, created_at_date: new Date(event.created_at * 1000).toISOString(), @@ -173,15 +182,18 @@ class PlatformSyncService { }) sub.on('eose', (): void => { + console.warn(`[PlatformSync] Relay ${relayUrl} sent EOSE signal`) finalize() resolve() }) // Timeout after SYNC_TIMEOUT_MS - setTimeout((): void => { + const timeoutId = setTimeout((): void => { + console.warn(`[PlatformSync] Relay ${relayUrl} timeout after ${this.SYNC_TIMEOUT_MS}ms`) finalize() resolve() - }, this.SYNC_TIMEOUT_MS).unref?.() + }, this.SYNC_TIMEOUT_MS) + timeoutId.unref?.() this.syncSubscription = sub }) @@ -235,16 +247,47 @@ class PlatformSyncService { private async processEvent(event: Event): Promise { 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 if (tags.hidden) { + if (event.id === '527d83e0af20bf23c3e104974090ccc21536ece72c24eb784b3642890f63b763') { + console.warn(`[PlatformSync] Target event skipped: hidden=${tags.hidden}`) + } return } // Try to parse and cache by type if (tags.type === 'author') { + if (event.id === '527d83e0af20bf23c3e104974090ccc21536ece72c24eb784b3642890f63b763') { + console.warn(`[PlatformSync] Attempting to parse target event as author presentation`) + } 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) { 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') { const parsed = await parseSeriesFromEvent(event) diff --git a/lib/platformTracking.ts b/lib/platformTracking.ts index 26e08a6..59c8efc 100644 --- a/lib/platformTracking.ts +++ b/lib/platformTracking.ts @@ -34,7 +34,7 @@ export class PlatformTrackingService { await Promise.all(pubs) } else { // 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) // 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) await this.publishTrackingEvent(event) - console.log('Platform tracking event published', { + console.warn('Platform tracking event published', { eventId: event.id, articleId: tracking.articleId, recipientPubkey: tracking.recipientPubkey, diff --git a/lib/relayRotation.ts b/lib/relayRotation.ts index e7af6e8..14973a2 100644 --- a/lib/relayRotation.ts +++ b/lib/relayRotation.ts @@ -50,7 +50,7 @@ export async function tryWithRelayRotation( // We continue to use it but it's lower priority 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) const { syncProgressManager } = await import('./syncProgressManager') @@ -70,7 +70,7 @@ export async function tryWithRelayRotation( 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 } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error) diff --git a/lib/relaySessionManager.ts b/lib/relaySessionManager.ts index efca688..2671e55 100644 --- a/lib/relaySessionManager.ts +++ b/lib/relaySessionManager.ts @@ -15,7 +15,7 @@ class RelaySessionManager { */ public async initialize(): Promise { this.failedRelays.clear() - console.log('[RelaySessionManager] Session initialized - all relays active') + console.warn('[RelaySessionManager] Session initialized - all relays active') } /** diff --git a/lib/reviewRewardUpdate.ts b/lib/reviewRewardUpdate.ts index 58e53eb..72efdc6 100644 --- a/lib/reviewRewardUpdate.ts +++ b/lib/reviewRewardUpdate.ts @@ -63,7 +63,7 @@ export function buildRewardEvent(originalEvent: Event, reviewId: string): { export function checkIfAlreadyRewarded(originalEvent: Event, reviewId: string): boolean { const alreadyRewarded = originalEvent.tags.some((tag) => tag[0] === 'rewarded' && tag[1] === 'true') if (alreadyRewarded) { - console.log('Review already marked as rewarded', { + console.warn('Review already marked as rewarded', { reviewId, timestamp: new Date().toISOString(), }) @@ -82,7 +82,7 @@ export async function publishRewardEvent( ): Promise { const publishedEvent = await nostrService.publishEvent(updatedEvent) if (publishedEvent) { - console.log('Review updated with reward tag', { + console.warn('Review updated with reward tag', { reviewId, updatedEventId: publishedEvent.id, timestamp: new Date().toISOString(), diff --git a/lib/sponsoringPayment.ts b/lib/sponsoringPayment.ts index 9c2c7af..2d66c0f 100644 --- a/lib/sponsoringPayment.ts +++ b/lib/sponsoringPayment.ts @@ -39,7 +39,7 @@ export class SponsoringPaymentService { return buildErrorResult('Invalid author Bitcoin address', request) } - console.log('Sponsoring payment request created', { + console.warn('Sponsoring payment request created', { authorPubkey: request.authorPubkey, authorAddress: request.authorMainnetAddress, platformAddress: PLATFORM_BITCOIN_ADDRESS, diff --git a/lib/sponsoringPaymentTracking.ts b/lib/sponsoringPaymentTracking.ts index dd96850..b0d8155 100644 --- a/lib/sponsoringPaymentTracking.ts +++ b/lib/sponsoringPaymentTracking.ts @@ -63,7 +63,7 @@ export function logTrackingSuccess( split: { authorSats: number; platformSats: number }, verification: { confirmed: boolean; confirmations: number } ): void { - console.log('Sponsoring payment tracked', { + console.warn('Sponsoring payment tracked', { transactionId, authorPubkey, authorAmount: split.authorSats, diff --git a/lib/sponsoringTracking.ts b/lib/sponsoringTracking.ts index 5d246b4..63083f7 100644 --- a/lib/sponsoringTracking.ts +++ b/lib/sponsoringTracking.ts @@ -86,7 +86,7 @@ export class SponsoringTrackingService { await Promise.all(pubs) } else { // 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) // Track failed relays and mark them inactive for the session @@ -125,7 +125,7 @@ export class SponsoringTrackingService { const event = this.buildSponsoringTrackingEvent(tracking, authorPubkey, authorPrivateKey) await this.publishSponsoringTrackingEvent(event) - console.log('Sponsoring payment tracked', { + console.warn('Sponsoring payment tracked', { eventId: event.id, transactionId: tracking.transactionId, authorPubkey: tracking.authorPubkey, @@ -160,7 +160,7 @@ export class SponsoringTrackingService { // 2. Update the total_sponsoring tag // 3. Publish updated event - console.log('Presentation sponsoring updated', { + console.warn('Presentation sponsoring updated', { presentationArticleId, newTotalSponsoring, timestamp: new Date().toISOString(), diff --git a/lib/userContentSync.ts b/lib/userContentSync.ts index f316e1e..976eb91 100644 --- a/lib/userContentSync.ts +++ b/lib/userContentSync.ts @@ -64,7 +64,7 @@ async function fetchAndCachePublications( 5000 // 5 second timeout per relay ) sub = result - } catch (rotationError) { + } catch (_rotationError) { // Fallback to primary relay if rotation fails usedRelayUrl = getPrimaryRelaySync() sub = createSubscription(pool, [usedRelayUrl], filters) @@ -192,7 +192,7 @@ async function fetchAndCacheSeries( 5000 // 5 second timeout per relay ) sub = result - } catch (rotationError) { + } catch (_rotationError) { // Fallback to primary relay if rotation fails usedRelayUrl = getPrimaryRelaySync() sub = createSubscription(pool, [usedRelayUrl], filters) @@ -322,7 +322,7 @@ async function fetchAndCachePurchases( 5000 // 5 second timeout per relay ) sub = result - } catch (rotationError) { + } catch (_rotationError) { // Fallback to primary relay if rotation fails usedRelayUrl = getPrimaryRelaySync() sub = createSubscription(pool, [usedRelayUrl], filters) @@ -423,7 +423,7 @@ async function fetchAndCacheSponsoring( 5000 // 5 second timeout per relay ) sub = result - } catch (rotationError) { + } catch (_rotationError) { // Fallback to primary relay if rotation fails usedRelayUrl = getPrimaryRelaySync() sub = createSubscription(pool, [usedRelayUrl], filters) @@ -524,7 +524,7 @@ async function fetchAndCacheReviewTips( 5000 // 5 second timeout per relay ) sub = result - } catch (rotationError) { + } catch (_rotationError) { // Fallback to primary relay if rotation fails usedRelayUrl = getPrimaryRelaySync() sub = createSubscription(pool, [usedRelayUrl], filters) @@ -644,7 +644,7 @@ async function fetchAndCachePaymentNotes( 5000 // 5 second timeout per relay ) subscriptions = result.flat() - } catch (rotationError) { + } catch (_rotationError) { // Fallback to primary relay if rotation fails usedRelayUrl = getPrimaryRelaySync() subscriptions = filters.map((filter) => createSubscription(pool, [usedRelayUrl], [filter]))