|
@ -188,6 +188,7 @@ class MockPollingManager { |
|
|
await this.storage.set(`polling_config_${scheduleId}`, config); |
|
|
await this.storage.set(`polling_config_${scheduleId}`, config); |
|
|
|
|
|
|
|
|
// Simulate scheduling
|
|
|
// Simulate scheduling
|
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log(`Scheduled poll: ${scheduleId}`); |
|
|
console.log(`Scheduled poll: ${scheduleId}`); |
|
|
|
|
|
|
|
|
return scheduleId; |
|
|
return scheduleId; |
|
@ -196,6 +197,7 @@ class MockPollingManager { |
|
|
|
|
|
|
|
|
// Main example
|
|
|
// Main example
|
|
|
async function runHelloPollExample(): Promise<void> { |
|
|
async function runHelloPollExample(): Promise<void> { |
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log('🚀 Starting Hello Poll Example'); |
|
|
console.log('🚀 Starting Hello Poll Example'); |
|
|
|
|
|
|
|
|
// 1. Set up dependencies
|
|
|
// 1. Set up dependencies
|
|
@ -252,40 +254,50 @@ async function runHelloPollExample(): Promise<void> { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const scheduleId = await pollingManager.schedulePoll(scheduleConfig); |
|
|
const scheduleId = await pollingManager.schedulePoll(scheduleConfig); |
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log(`✅ Scheduled poll: ${scheduleId}`); |
|
|
console.log(`✅ Scheduled poll: ${scheduleId}`); |
|
|
|
|
|
|
|
|
// 4. Execute initial poll
|
|
|
// 4. Execute initial poll
|
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log('📡 Executing initial poll...'); |
|
|
console.log('📡 Executing initial poll...'); |
|
|
const result = await pollingManager.executePoll(request); |
|
|
const result = await pollingManager.executePoll(request); |
|
|
|
|
|
|
|
|
if (result.success && result.data) { |
|
|
if (result.success && result.data) { |
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log(`✅ Found ${result.data.data.length} changes`); |
|
|
console.log(`✅ Found ${result.data.data.length} changes`); |
|
|
|
|
|
|
|
|
if (result.data.data.length > 0) { |
|
|
if (result.data.data.length > 0) { |
|
|
// 5. Generate notifications
|
|
|
// 5. Generate notifications
|
|
|
const changes = result.data.data; |
|
|
const changes = result.data.data; |
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log('🔔 Generating notifications...'); |
|
|
console.log('🔔 Generating notifications...'); |
|
|
|
|
|
|
|
|
if (changes.length === 1) { |
|
|
if (changes.length === 1) { |
|
|
const project = changes[0].planSummary; |
|
|
const project = changes[0].planSummary; |
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log(`📱 Notification: "${project.name} has been updated"`); |
|
|
console.log(`📱 Notification: "${project.name} has been updated"`); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log(`📱 Notification: "You have ${changes.length} new updates in your starred projects"`); |
|
|
console.log(`📱 Notification: "You have ${changes.length} new updates in your starred projects"`); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 6. Update watermark with CAS
|
|
|
// 6. Update watermark with CAS
|
|
|
const latestJwtId = changes[changes.length - 1].planSummary.jwtId; |
|
|
const latestJwtId = changes[changes.length - 1].planSummary.jwtId; |
|
|
await storage.set('lastAckedStarredPlanChangesJwtId', latestJwtId); |
|
|
await storage.set('lastAckedStarredPlanChangesJwtId', latestJwtId); |
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log(`💾 Updated watermark: ${latestJwtId}`); |
|
|
console.log(`💾 Updated watermark: ${latestJwtId}`); |
|
|
|
|
|
|
|
|
// 7. Acknowledge changes (simulate)
|
|
|
// 7. Acknowledge changes (simulate)
|
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log('✅ Acknowledged changes with server'); |
|
|
console.log('✅ Acknowledged changes with server'); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log('❌ Poll failed:', result.error?.message); |
|
|
console.log('❌ Poll failed:', result.error?.message); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 8. Simulate new data and poll again
|
|
|
// 8. Simulate new data and poll again
|
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log('\n🔄 Adding new data and polling again...'); |
|
|
console.log('\n🔄 Adding new data and polling again...'); |
|
|
server.addNewData('1704153600_new123_0badf00d', 'Updated Hello Project'); |
|
|
server.addNewData('1704153600_new123_0badf00d', 'Updated Hello Project'); |
|
|
|
|
|
|
|
@ -295,25 +307,30 @@ async function runHelloPollExample(): Promise<void> { |
|
|
const result2 = await pollingManager.executePoll(request); |
|
|
const result2 = await pollingManager.executePoll(request); |
|
|
|
|
|
|
|
|
if (result2.success && result2.data) { |
|
|
if (result2.success && result2.data) { |
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log(`✅ Found ${result2.data.data.length} new changes`); |
|
|
console.log(`✅ Found ${result2.data.data.length} new changes`); |
|
|
|
|
|
|
|
|
if (result2.data.data.length > 0) { |
|
|
if (result2.data.data.length > 0) { |
|
|
const project = result2.data.data[0].planSummary; |
|
|
const project = result2.data.data[0].planSummary; |
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log(`📱 New notification: "${project.name} has been updated"`); |
|
|
console.log(`📱 New notification: "${project.name} has been updated"`); |
|
|
|
|
|
|
|
|
// Update watermark
|
|
|
// Update watermark
|
|
|
const latestJwtId = result2.data.data[result2.data.data.length - 1].planSummary.jwtId; |
|
|
const latestJwtId = result2.data.data[result2.data.data.length - 1].planSummary.jwtId; |
|
|
await storage.set('lastAckedStarredPlanChangesJwtId', latestJwtId); |
|
|
await storage.set('lastAckedStarredPlanChangesJwtId', latestJwtId); |
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log(`💾 Updated watermark: ${latestJwtId}`); |
|
|
console.log(`💾 Updated watermark: ${latestJwtId}`); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
console.log('\n🎉 Hello Poll Example completed successfully!'); |
|
|
console.log('\n🎉 Hello Poll Example completed successfully!'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Run the example
|
|
|
// Run the example
|
|
|
if (require.main === module) { |
|
|
if (require.main === module) { |
|
|
runHelloPollExample().catch(console.error); |
|
|
runHelloPollExample().catch(// eslint-disable-next-line no-console
|
|
|
|
|
|
console.error); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export { runHelloPollExample }; |
|
|
export { runHelloPollExample }; |
|
|