Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 | 1x 1x 1x 1x 1x 1x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 33x 33x 39x 39x 5x 5x 22x 33x 33x 81x 3x 3x 3x 3x 3x 1x 1x 2x 2x 3x 3x 81x 81x 8x 8x 8x 8x 8x 8x 6x 6x 6x 6x 6x 6x 8x 8x 8x 8x 81x 81x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x 4x 3x 3x 3x 3x 3x 4x 4x 4x 4x 4x 81x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 81x 12x 12x 12x 8x 8x 8x 14x 14x 14x 14x 14x 8x 8x 6x 14x 32x 32x 32x 14x 14x 8x 8x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 8x 12x 12x 12x 12x 81x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 81x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 81x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 81x 6x 6x 6x 6x 6x 6x 6x 1x 1x 1x 1x 1x 4x 6x 3x 4x 2x 2x 2x 2x 2x 6x 6x 6x 6x 6x 81x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 2x 2x 2x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 81x 81x 4x 4x 4x 4x 3x 3x 3x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 4x 4x 4x 4x 81x 3x 3x 3x 3x 3x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 3x 3x 3x 81x 81x 81x 81x 7x 7x 7x 6x 6x 6x 6x 6x 6x 6x 7x 7x 7x 7x 81x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 81x 81x 81x 11x 11x 10x 10x 10x 11x 5x 5x 11x 11x 81x 36x 36x 36x 36x 36x 36x 81x 1x 1x 1x 1x 1x 1x 81x 81x 2x 2x 2x 2x 81x 1x | import { newsletterApi } from '@common/api/newsletterApi';
import { readingQueueApi } from '@common/api/readingQueueApi';
import { tagApi } from '@common/api/tagApi';
import {
NewsletterFilter,
NewsletterQueryParams,
NewsletterWithRelations,
PaginatedResponse,
Tag,
TagWithCount,
} from '@common/types';
import { logger } from '@common/utils/logger';
import { BaseService, NotFoundError } from '../base/BaseService';
export interface NewsletterOperationResult {
success: boolean;
newsletter?: NewsletterWithRelations;
error?: string;
}
export interface BulkNewsletterOperationResult {
success: boolean;
processedCount: number;
failedCount: number;
errors: Array<{ id: string; error: string }>;
}
export interface NewsletterServiceOptions {
enableOptimisticUpdates?: boolean;
batchSize?: number;
}
export class NewsletterService extends BaseService {
private newsletterOptions: NewsletterServiceOptions;
constructor(options: NewsletterServiceOptions = {}) {
super({
retryOptions: {
maxRetries: 3,
baseDelay: 1000,
},
timeout: 30000,
});
this.newsletterOptions = {
enableOptimisticUpdates: true,
batchSize: 50,
...options,
};
}
/**
* Get a single newsletter by ID
*/
async getNewsletter(id: string): Promise<NewsletterWithRelations | null> {
this.validateString(id, 'newsletter ID');
return this.withRetry(async () => {
const newsletter = await newsletterApi.getById(id);
if (!newsletter) {
throw new NotFoundError(`Newsletter with ID ${id} not found`);
}
return newsletter;
}, 'getNewsletter');
}
/**
* Get newsletters with filtering and pagination
*/
async getNewsletters(
params: NewsletterQueryParams = {}
): Promise<PaginatedResponse<NewsletterWithRelations>> {
return this.withRetry(async () => {
// Apply business logic for default parameters
const processedParams = this.processNewsletterParams(params);
// Handle tag filtering through the service layer
if (processedParams.tagIds && processedParams.tagIds.length > 0) {
return await this.getNewslettersByTags(processedParams.tagIds, processedParams);
}
const result = await newsletterApi.getAll(processedParams);
return result;
}, 'getNewsletters');
}
/**
* Alias for getNewsletters for backward compatibility
*/
async getAll(
params: NewsletterQueryParams = {}
): Promise<PaginatedResponse<NewsletterWithRelations>> {
return this.getNewsletters(params);
}
/**
* Get newsletters filtered by specific tags
* This method ensures newsletters have ALL the specified tags (AND logic)
*/
async getNewslettersByTags(
tagIds: string[],
params: Omit<NewsletterQueryParams, 'tagIds'> = {}
): Promise<PaginatedResponse<NewsletterWithRelations>> {
this.validateArray(tagIds, 'tag IDs', { minLength: 1 });
return this.executeWithLogging(
async () => {
// Apply business logic for default parameters
const processedParams = this.processNewsletterParams(params);
// Use the API's getByTags method which handles the complex tag intersection logic
return await this.withRetry(
() => newsletterApi.getByTags(tagIds, processedParams),
'getNewslettersByTags'
);
},
'getNewslettersByTags',
{ tagCount: tagIds.length, params }
);
}
/**
* Alias for getNewsletter for backward compatibility
*/
async getById(id: string): Promise<NewsletterWithRelations | null> {
return this.getNewsletter(id);
}
/**
* Mark newsletter as read
*/
async markAsRead(id: string): Promise<NewsletterOperationResult> {
this.validateString(id, 'newsletter ID');
return this.executeWithLogging(
async () => {
try {
const newsletter = await this.withRetry(() => newsletterApi.markAsRead(id), 'markAsRead');
// Apply business logic - update related data if needed
await this.handleReadStatusChange(id, true);
return {
success: true,
newsletter,
};
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
};
}
},
'markAsRead',
{ id }
);
}
/**
* Mark newsletter as unread
*/
async markAsUnread(id: string): Promise<NewsletterOperationResult> {
this.validateString(id, 'newsletter ID');
return this.executeWithLogging(
async () => {
try {
const newsletter = await this.withRetry(
() => newsletterApi.markAsUnread(id),
'markAsUnread'
);
// Apply business logic - update related data if needed
await this.handleReadStatusChange(id, false);
return {
success: true,
newsletter,
};
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
};
}
},
'markAsUnread',
{ id }
);
}
/**
* Bulk mark newsletters as read
*/
async bulkMarkAsRead(ids: string[]): Promise<BulkNewsletterOperationResult> {
this.validateArray(ids, 'newsletter IDs', { minLength: 1 });
return this.executeWithLogging(
async () => {
const batchProcessor = this.createBatchProcessor(
this.newsletterOptions.batchSize!,
async (batch: string[]) => {
// Use true bulk database operation instead of N individual calls
const bulkResult = await newsletterApi.bulkUpdate({
ids: batch,
updates: { is_read: true },
});
if (bulkResult.errorCount > 0) {
throw new Error(`Bulk update failed: ${bulkResult.errorCount} errors occurred`);
}
return (
bulkResult.results?.map((result: NewsletterWithRelations | null, index: number) => ({
id: batch[index],
success: result !== null,
error: result === null ? 'Update failed' : undefined,
})) || []
);
}
);
const results = await batchProcessor(ids);
const processedCount = results.filter((r) => r.success).length;
const failedCount = results.length - processedCount;
const errors = results
.filter((r) => !r.success)
.map((r) => ({ id: r.id, error: r.error || 'Unknown error' }));
// Apply business logic for successful updates
const successfulIds = results.filter((r) => r.success).map((r) => r.id);
await Promise.allSettled(successfulIds.map((id) => this.handleReadStatusChange(id, true)));
return {
success: failedCount === 0,
processedCount,
failedCount,
errors,
};
},
'bulkMarkAsRead',
{ count: ids.length }
);
}
/**
* Bulk mark newsletters as unread
*/
async bulkMarkAsUnread(ids: string[]): Promise<BulkNewsletterOperationResult> {
this.validateArray(ids, 'newsletter IDs', { minLength: 1 });
return this.executeWithLogging(
async () => {
const batchProcessor = this.createBatchProcessor(
this.newsletterOptions.batchSize!,
async (batch: string[]) => {
// Use true bulk database operation instead of N individual calls
const bulkResult = await newsletterApi.bulkUpdate({
ids: batch,
updates: { is_read: false },
});
if (bulkResult.errorCount > 0) {
throw new Error(`Bulk update failed: ${bulkResult.errorCount} errors occurred`);
}
return (
bulkResult.results?.map((result: NewsletterWithRelations | null, index: number) => ({
id: batch[index],
success: result !== null,
error: result === null ? 'Update failed' : undefined,
})) || []
);
}
);
const results = await batchProcessor(ids);
const processedCount = results.filter((r) => r.success).length;
const failedCount = results.length - processedCount;
const errors = results
.filter((r) => !r.success)
.map((r) => ({ id: r.id, error: r.error || 'Unknown error' }));
// Apply business logic for successful updates
const successfulIds = results.filter((r) => r.success).map((r) => r.id);
await Promise.allSettled(successfulIds.map((id) => this.handleReadStatusChange(id, false)));
return {
success: failedCount === 0,
processedCount,
failedCount,
errors,
};
},
'bulkMarkAsUnread',
{ count: ids.length }
);
}
/**
* Toggle like status
*/
async toggleLike(id: string): Promise<NewsletterOperationResult> {
this.validateString(id, 'newsletter ID');
return this.executeWithLogging(
async () => {
try {
// Get current newsletter to determine new like status
const currentNewsletter = await this.withRetry(
() => newsletterApi.getById(id),
'getNewsletterForToggleLike'
);
if (!currentNewsletter) {
return {
success: false,
error: 'Newsletter not found',
};
}
const newsletter = await this.withRetry(() => newsletterApi.toggleLike(id), 'toggleLike');
// Apply business logic
await this.handleLikeStatusChange(id, !currentNewsletter.is_liked);
return {
success: true,
newsletter,
};
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
};
}
},
'toggleLike',
{ id }
);
}
/**
* Toggle archive status
*/
async toggleArchive(id: string): Promise<NewsletterOperationResult> {
this.validateString(id, 'newsletter ID');
return this.executeWithLogging(
async () => {
try {
// Get current newsletter to determine new archive status
const newsletter = await this.getNewsletter(id);
if (!newsletter) {
return {
success: false,
error: 'Newsletter not found',
};
}
const updatedNewsletter = await this.withRetry(
() => newsletterApi.toggleArchive(id),
'toggleArchive'
);
if (!updatedNewsletter) {
return {
success: false,
error: 'Failed to toggle archive status',
};
}
// Apply business logic - remove from reading queue if archived
if (updatedNewsletter.is_archived) {
await this.removeFromReadingQueueIfExists(id);
}
return {
success: true,
newsletter: updatedNewsletter,
};
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
};
}
},
'toggleArchive',
{ newsletterId: id }
);
}
/**
* Add newsletter to reading queue
*/
async addToReadingQueue(id: string): Promise<NewsletterOperationResult> {
this.validateString(id, 'newsletter ID');
return this.executeWithLogging(
async () => {
try {
// Validate newsletter exists and is not archived
const newsletter = await this.getNewsletter(id);
if (!newsletter) {
return {
success: false,
error: 'Newsletter not found',
};
}
if (newsletter.is_archived) {
return {
success: false,
error: 'Cannot add archived newsletter to reading queue',
};
}
const success = await this.withRetry(() => readingQueueApi.add(id), 'addToReadingQueue');
if (!success) {
return {
success: false,
error: 'Failed to add newsletter to reading queue',
};
}
return { success: true, newsletter };
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
};
}
},
'addToReadingQueue',
{ newsletterId: id }
);
}
/**
* Remove newsletter from reading queue
*/
async removeFromReadingQueue(id: string): Promise<NewsletterOperationResult> {
this.validateString(id, 'newsletter ID');
return this.executeWithLogging(
async () => {
try {
// Get newsletter before removing
const newsletter = await this.withRetry(
() => newsletterApi.getById(id),
'getNewsletterForReadingQueueRemoval'
);
await this.withRetry(() => readingQueueApi.remove(id), 'removeFromReadingQueue');
// Apply business logic
// Future: Add any business logic for reading queue changes
return {
success: true,
newsletter: newsletter || undefined,
};
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
};
}
},
'removeFromReadingQueue',
{ id }
);
}
async deleteNewsletter(id: string): Promise<NewsletterOperationResult> {
this.validateString(id, 'newsletter ID');
return this.executeWithLogging(async () => {
try {
await this.withRetry(() => newsletterApi.delete(id), 'deleteNewsletter');
return {
success: true,
};
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : 'Failed to delete newsletter',
};
}
}, 'deleteNewsletter');
}
/**
* Update newsletter tags
*/
async updateTags(id: string, tagIds: string[]): Promise<NewsletterOperationResult> {
this.validateString(id, 'newsletter ID');
this.validateArray(tagIds, 'tag IDs');
return this.executeWithLogging(
async () => {
try {
// Validate newsletter exists
const newsletter = await this.getNewsletter(id);
if (!newsletter) {
return {
success: false,
error: 'Newsletter not found',
};
}
// Get tag objects for validation
const tags: Tag[] = [];
for (const tagId of tagIds) {
const tag = await tagApi.getById(tagId);
if (!tag) {
return {
success: false,
error: `Tag with ID ${tagId} not found`,
};
}
tags.push(tag);
}
const success = await this.withRetry(
() => tagApi.updateNewsletterTags(id, tags),
'updateNewsletterTags'
);
if (!success) {
return {
success: false,
error: 'Failed to update newsletter tags',
};
}
return {
success: true,
newsletter: { ...newsletter, tags },
};
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
};
}
},
'updateTags',
{ newsletterId: id, tagCount: tagIds.length }
);
}
/**
* Search newsletters
*/
async searchNewsletters(
query: string,
filters?: NewsletterFilter
): Promise<PaginatedResponse<NewsletterWithRelations>> {
this.validateString(query, 'search query', { minLength: 1 });
return this.executeWithLogging(
async () => {
const baseParams: NewsletterQueryParams = {
search: query.trim(),
isRead: filters?.is_read,
isArchived: filters?.is_archived,
isLiked: filters?.is_liked,
tagIds: filters?.tag_ids,
sourceIds: filters?.source_id ? [filters.source_id] : undefined,
dateFrom: filters?.start_date,
dateTo: filters?.end_date,
};
const searchParams = this.processNewsletterParams(baseParams);
return await this.withRetry(() => newsletterApi.getAll(searchParams), 'searchNewsletters');
},
'searchNewsletters',
{ query, filters }
);
}
/**
* Get unread count for all newsletters or specific source
*/
async getUnreadCount(sourceId?: string | null): Promise<number> {
return this.withRetry(async () => {
return await newsletterApi.getUnreadCount(sourceId);
}, 'getUnreadCount');
}
/**
* Get unread counts grouped by source
*/
async getUnreadCountBySource(): Promise<Record<string, number>> {
return this.withRetry(async () => {
return await newsletterApi.getUnreadCountBySource();
}, 'getUnreadCountBySource');
}
/**
* Bulk update newsletters
*/
async bulkUpdate(params: {
ids: string[];
updates: any;
}): Promise<{ successCount: number; failedCount: number }> {
this.validateArray(params.ids, 'newsletter IDs', { minLength: 1 });
return this.executeWithLogging(
async () => {
const results = await Promise.allSettled(
params.ids.map(async (id) => {
if (params.updates.is_read !== undefined) {
return params.updates.is_read ? this.markAsRead(id) : this.markAsUnread(id);
}
// Add other update types as needed
throw new Error('Unsupported bulk update type');
})
);
const successCount = results.filter((r) => r.status === 'fulfilled').length;
return {
successCount,
failedCount: results.length - successCount,
};
},
'bulkUpdate',
{ count: params.ids.length }
);
}
/**
* Bulk archive newsletters
*/
async bulkArchive(ids: string[]): Promise<{ successCount: number; failedCount: number }> {
this.validateArray(ids, 'newsletter IDs', { minLength: 1 });
return this.executeWithLogging(
async () => {
const results = await Promise.allSettled(ids.map((id) => this.toggleArchive(id)));
const successCount = results.filter((r) => r.status === 'fulfilled').length;
return {
successCount,
failedCount: results.length - successCount,
};
},
'bulkArchive',
{ count: ids.length }
);
}
/**
* Bulk unarchive newsletters
*/
async bulkUnarchive(ids: string[]): Promise<{ successCount: number; failedCount: number }> {
this.validateArray(ids, 'newsletter IDs', { minLength: 1 });
return this.executeWithLogging(
async () => {
const results = await Promise.allSettled(ids.map((id) => this.toggleArchive(id)));
const successCount = results.filter((r) => r.status === 'fulfilled').length;
return {
successCount,
failedCount: results.length - successCount,
};
},
'bulkUnarchive',
{ count: ids.length }
);
}
/**
* Delete newsletter (alias for deleteNewsletter)
*/
async delete(id: string): Promise<boolean> {
const result = await this.deleteNewsletter(id);
return result.success;
}
/**
* Update newsletter
*/
async update(params: { id: string; is_archived?: boolean }): Promise<boolean> {
this.validateString(params.id, 'newsletter ID');
if (params.is_archived !== undefined) {
const result = await this.toggleArchive(params.id);
return result.success;
}
throw new Error('Unsupported update parameters');
}
/**
* Process newsletter parameters with business logic
*/
private processNewsletterParams(params: NewsletterQueryParams): NewsletterQueryParams {
const processed = { ...params };
// Apply default sorting if not specified
if (!processed.orderBy) {
processed.orderBy = 'received_at';
processed.orderDirection = 'desc';
}
// Apply default pagination if not specified or is 0
if (!processed.limit || processed.limit === 0) {
processed.limit = 50;
}
return processed;
}
/**
* Handle business logic when read status changes
*/
private async handleReadStatusChange(id: string, isRead: boolean): Promise<void> {
// Business logic: If marked as read, could trigger analytics, recommendations, etc.
logger.debug('Newsletter read status changed', {
component: 'NewsletterService',
action: 'read_status_change',
metadata: { newsletterId: id, isRead },
});
// Future: Add analytics tracking, recommendation updates, etc.
}
/**
* Handle business logic when like status changes
*/
private async handleLikeStatusChange(id: string, isLiked: boolean): Promise<void> {
// Business logic: Update recommendation algorithms, user preferences, etc.
logger.debug('Newsletter like status changed', {
component: 'NewsletterService',
action: 'like_status_change',
metadata: { newsletterId: id, isLiked },
});
// Future: Add recommendation algorithm updates, preference learning, etc.
}
/**
* Get tag usage statistics for all tags
*/
async getTagUsageStats(): Promise<TagWithCount[]> {
return this.executeWithLogging(async () => {
try {
// Use the optimized tagApi method that efficiently gets tag counts
// excluding archived newsletters with a single database query
return await this.withRetry(() => tagApi.getTagUsageStats(), 'getTagUsageStats');
} catch (error) {
logger.error('Failed to get tag usage stats', {
component: 'NewsletterService',
action: 'getTagUsageStats',
error,
});
// Return empty array on error
return [];
}
}, 'getTagUsageStats');
}
/**
* Remove newsletter from reading queue if it exists
*/
private async removeFromReadingQueueIfExists(id: string): Promise<void> {
try {
await readingQueueApi.remove(id);
} catch {
// Ignore errors - newsletter might not be in queue
logger.debug('Newsletter not in reading queue or removal failed', {
component: 'NewsletterService',
action: 'remove_from_queue_cleanup',
metadata: { newsletterId: id },
});
}
}
}
// Export singleton instance
export const newsletterService = new NewsletterService();
|