Skip to main content
Version: 0.14.0 (Latest)

✅ Notification validators

Notification routes compose one local ownership wrapper and two shared validator factories; no route composes checkIdentityType.

Inventory

ValidatorReadsSuccess conditionFailure / errorConsumers
isAuthenticated()context.authenticate(payload)Selected adapter accepts the request token.Propagates the selected adapter error.updateNotificationToReadRoute, findNotificationsRoute, updateNotificationToReadBatchRoute
ownsNotificationcontext.authenticate, db.notifications, path notification IDNotification receiverId equals token identity ID.400, 401, 403, or 500.updateNotificationToReadRoute
isSelf(['params', 'requestParams', 'identityId'])context.authenticate and route path identity IDTarget ID equals token identity ID.401 Invalid token; 403 missing/mismatch.findNotificationsRoute, updateNotificationToReadBatchRoute

Details

isAuthenticated()

Implementation

Signature: isAuthenticated(): Validator. Its returned validator reads context.authenticate and awaits authenticate(payload); absent that context entry, the shared factory falls back to the Bearer adapter. It neither inspects the returned token information nor queries a collection, so any rejection is propagated unchanged.

notificationService supplies the Bearer adapter unless configuration.authMode is 'cookie', in which case it supplies the cookie adapter. Those adapters are the source of their request reads and authentication 401 errors; see the Notification service setup and the canonical shared contract.

Consumers: updateNotificationToReadRoute, findNotificationsRoute, and updateNotificationToReadBatchRoute.

ownsNotification

Implementation

Local partial(ownsResource, ['notifications', ['receiverId']]) wrapper. updateNotificationToReadRoute invokes the resulting factory second as ownsNotification(['params', 'requestParams', 'notificationId']). Its returned validator authenticates again through context.authenticate (or the Bearer fallback), requires a valid user access token, reads db.notifications, loads a document by the exact path ID, and compares document receiverId with tokenInfo.identityId.

It throws 401 Invalid token for a token that is not a user access token, 500 Resource does not exist when that collection is absent, and 400 Invalid resource ID when the path has no value. A rejected lookup is 403 Failed to fetch resource; an absent document also reaches 403 Invalid owner ID because it has no receiverId; a document with no receiver has that same error; a different receiver is 403 Identity is not the owner of the resource. See the canonical ownsResource contract.

Consumers: updateNotificationToReadRoute.

isSelf(['params', 'requestParams', 'identityId'])

Implementation

Shared factory invoked second by findNotificationsRoute and updateNotificationToReadBatchRoute. It authenticates again through context.authenticate (or the Bearer fallback), requires a valid user access token, reads payload.params.requestParams.identityId through the supplied Ramda path, and compares it with tokenInfo.identityId.

It throws 401 Invalid token for a token that is not a user access token, 403 Identity ID is required when that path has no value, and 403 Identity ID does not match when the target is another identity. See the canonical shared contract.

Consumers: findNotificationsRoute and updateNotificationToReadBatchRoute.