|
26 | 26 | * addressed to an unregistered channel are dead-lettered, not delivered. |
27 | 27 | */ |
28 | 28 | import type { NotificationChannel } from '../system/notification.zod'; |
| 29 | +import type { RegisterDeviceRequest, RegisterDeviceResponse, UnregisterDeviceResponse } from '../api/protocol.zod'; |
29 | 30 | export type { NotificationChannel } from '../system/notification.zod'; |
30 | 31 |
|
31 | 32 | /** |
@@ -207,4 +208,65 @@ export interface INotificationService { |
207 | 208 | * @param userId - Owner of the inbox |
208 | 209 | */ |
209 | 210 | markAllRead?(userId: string): Promise<MarkReadResult>; |
| 211 | + |
| 212 | + /* ------------------------------------------------------------------ */ |
| 213 | + /* Push devices — the device registry (ADR-0012 §6) */ |
| 214 | + /* ------------------------------------------------------------------ */ |
| 215 | + |
| 216 | + /* |
| 217 | + * All three are OPTIONAL, for the reason the inbox trio is: a provider |
| 218 | + * with no push channel (SMTP, an SMS gateway, the dev stub) fills this |
| 219 | + * slot legitimately with no device registry. Absence means the |
| 220 | + * capability is unavailable — the device routes answer that, not a |
| 221 | + * crash — so every implementation written before these members stays |
| 222 | + * valid. Shapes are the wire contract the device routes serialize: |
| 223 | + * `RegisterDeviceRequestSchema` / `RegisterDeviceResponseSchema` / |
| 224 | + * `UnregisterDeviceResponseSchema` (`api/protocol.zod.ts`). |
| 225 | + */ |
| 226 | + |
| 227 | + /** |
| 228 | + * Register or refresh a push device for this user. |
| 229 | + * |
| 230 | + * - **Refresh, not duplicate.** A `request.deviceId` this user already |
| 231 | + * holds refreshes that device (token, vendor, app, locale, last seen) |
| 232 | + * and re-enables it; an absent `deviceId` is minted here and answered |
| 233 | + * in the response, which the client keeps. |
| 234 | + * - **One live owner per token.** A token is delivered to one user only: |
| 235 | + * registering a token another user's device holds moves it to this |
| 236 | + * user, and the other user's device stops receiving it. A push meant |
| 237 | + * for the previous owner never reaches the phone's new user. |
| 238 | + * - An absent `request.vendor` is derived from `request.platform` |
| 239 | + * (`ios` → `apns`, `android` → `fcm`). |
| 240 | + * |
| 241 | + * @param userId - The signed-in user, from the session; never a body member |
| 242 | + * @param request - The registration body |
| 243 | + */ |
| 244 | + registerDevice?(userId: string, request: RegisterDeviceRequest): Promise<RegisterDeviceResponse>; |
| 245 | + |
| 246 | + /** |
| 247 | + * Unregister one of this user's devices (sign-out, account switch). |
| 248 | + * |
| 249 | + * A `deviceId` this user does not hold — unknown, or another user's — |
| 250 | + * answers not found (`NOT_FOUND`, 404 at the device route), never a |
| 251 | + * success and never a distinct "forbidden": a caller cannot learn that a |
| 252 | + * device id exists for somebody else, and cannot remove it. |
| 253 | + * |
| 254 | + * @param userId - The signed-in user, from the session |
| 255 | + * @param deviceId - The id {@link registerDevice} answered |
| 256 | + */ |
| 257 | + unregisterDevice?(userId: string, deviceId: string): Promise<UnregisterDeviceResponse>; |
| 258 | + |
| 259 | + /** |
| 260 | + * Retire a token the vendor reported dead (APNs `BadDeviceToken` / |
| 261 | + * `Unregistered`, FCM `UNREGISTERED`), called by the push channel's |
| 262 | + * invalid-recipient path (ADR-0012 §6, §12). |
| 263 | + * |
| 264 | + * The device row is KEPT, disabled, with the time of invalidation, so |
| 265 | + * "why did this phone stop getting pushes" stays answerable and a later |
| 266 | + * registration of the same device re-enables it. Nothing is delivered to |
| 267 | + * a disabled device. A token no device holds is a no-op. |
| 268 | + * |
| 269 | + * @param token - The vendor token as the vendor reported it |
| 270 | + */ |
| 271 | + invalidateDeviceToken?(token: string): Promise<void>; |
210 | 272 | } |
0 commit comments