( subscription: PushSubscription )
| 49 | } |
| 50 | |
| 51 | const serializeSubscription = ( |
| 52 | subscription: PushSubscription |
| 53 | ): ISerializedSubscription => { |
| 54 | const json = subscription.toJSON(); |
| 55 | |
| 56 | return { |
| 57 | endpoint: json.endpoint ?? subscription.endpoint, |
| 58 | keys: { |
| 59 | p256dh: json.keys?.p256dh ?? "", |
| 60 | auth: json.keys?.auth ?? "" |
| 61 | }, |
| 62 | expirationTime: |
| 63 | typeof subscription.expirationTime === "number" |
| 64 | ? subscription.expirationTime |
| 65 | : null |
| 66 | }; |
| 67 | }; |
| 68 | |
| 69 | /** |
| 70 | * Single source of truth for Web Push subscription state on the client. |