(
namespace: string,
subscription: StoredSubscription,
body: string
)
| 49 | } |
| 50 | |
| 51 | private async sendToSubscription( |
| 52 | namespace: string, |
| 53 | subscription: StoredSubscription, |
| 54 | body: string |
| 55 | ): Promise<void> { |
| 56 | const pushSubscription: PushSubscription = { |
| 57 | endpoint: subscription.endpoint, |
| 58 | keys: { |
| 59 | p256dh: subscription.p256dh, |
| 60 | auth: subscription.auth |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | try { |
| 65 | await webPush.sendNotification(pushSubscription, body) |
| 66 | } catch (error) { |
| 67 | const statusCode = typeof (error as { statusCode?: unknown }).statusCode === 'number' |
| 68 | ? (error as { statusCode: number }).statusCode |
| 69 | : null |
| 70 | |
| 71 | if (statusCode === 410) { |
| 72 | this.store.push.removePushSubscription(namespace, subscription.endpoint) |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | console.error('[PushService] Failed to send notification:', error) |
| 77 | } |
| 78 | } |
| 79 | } |
no test coverage detected