メインコンテンツまでスキップ
バージョン: 🚧 Canary

✅ Identity validators

Identity routes compose two shared access factories, while isSelf is the local reusable ownership validator. Validators receive the route payload, either complete normally or throw NodeblocksError; they are SDK guards, not Express middleware.

Inventory

ValidatorReadsSuccess conditionFailure / errorConsumers
isSelfcontext.authenticate or Bearer fallback; configured payload pathTarget value equals the valid user token’s identityId401 invalid token; 403 missing or mismatched targetAuthentication, Profile, Order, Organization, Notification, and Chat routes.
isAuthenticated()context.authenticate or Bearer fallbackSelected adapter resolvesAdapter error propagatesfind, get, update, delete, lock, unlock
checkIdentityType(['admin'])auth adapter, db.identities, configuration.identity.typeIdsValid user token’s loaded identity has configured admin type ID500 setup; 401 invalid token; 403 identity/typefind, get, update, delete, lock, unlock

Details

isSelf

Implementation

Signature: isSelf<T extends string>(identityIdPathInPayload: [T, ...T[]]): Validator. This factory selects context.authenticate or getBearerTokenInfo, calls it with the route payload, requires isValidUserAccessToken(tokenInfo), then reads path(identityIdPathInPayload, payload) with ramda. It compares that configured target value—not necessarily a field named identityId—with tokenInfo.identityId.

It throws NodeblocksError(401, 'Invalid token', 'isSelf') for a non-user token, NodeblocksError(403, 'Identity ID is required', 'isSelf') when the configured path has no value, and NodeblocksError(403, 'Identity ID does not match', 'isSelf') when the values differ.

Consumers: isSelf(...) is the self branch of some(checkIdentityType(['admin']), isSelf(...)) on Authentication’s deleteRefreshTokensRoute, sendVerificationEmailRoute, changeEmailRoute, changePasswordRoute, and deactivateRoute, each with ['params', 'requestParams', 'identityId'] except deactivation’s ['params', 'requestBody', 'identityId']; Profile’s createProfileRoute with body identityId; Order’s createOrderRoute with body identityId and findOrdersRoute with query identityId; Organization’s findOrganizationsForMemberRoute with path identityId; and Chat’s createChatChannelRoute, findChatChannelsRoute, createChatSubscriptionRoute, and findChatSubscriptionsRoute. It runs directly on Profile’s findProfilesByIdentityIdRoute (path identityId; see Profile routes), Notification’s findNotificationsRoute and updateNotificationToReadBatchRoute, Chat’s createChatMessageRoute, findChatMessagesRoute, and upsertChatChannelReadStateRoute. Chat uses ownerId, subscribedId, and senderId respectively; the remaining direct routes use identityId at the stated body, path, or query location.

Identity routes do not compose isSelf; they use the administrator check below.

isAuthenticated()

Implementation

checkIdentityType(['admin'])

Implementation

This shared factory is documented canonically in Common validators. Identity’s exact invocation is checkIdentityType(['admin']). It requires context.db.identities and context.configuration.identity.typeIds, selects context.authenticate or getBearerTokenInfo, requires a valid user access token, loads tokenInfo.identityId using getIdentityById, then compares the retrieved identity’s typeId with identityTypeIds.admin.

It throws 500 db.identities is not set or 500 configuration.identity.typeIds is not set; 401 Invalid token; 403 Failed to fetch identity, 403 Invalid identity type ID, or 403 Identity is not authorized to access this resource.

Consumers: Identity invokes checkIdentityType(['admin']) after isAuthenticated() on findIdentitiesRoute, getIdentityRoute, updateIdentityRoute, deleteIdentityRoute, lockIdentityRoute, and unlockIdentityRoute. Other direct ['admin'] consumers are Attribute createAttributeRoute, updateAttributeRoute, deleteAttributeRoute; all Organization routes in the route reference; all Profile routes except findProfilesByIdentityIdRoute; all Order routes except findOrdersByOrganizationIdRoute; Location createLocationRoute, updateLocationRoute, deleteLocationRoute; Authentication deleteRefreshTokensRoute, generateOnetimeTokenRoute, restoreOnetimeTokenRoute, invalidateOnetimeTokenRoute, sendVerificationEmailRoute, changeEmailRoute, changePasswordRoute, deactivateRoute, activateRoute; all administrator Product routes; all Invitation routes; the administrator Chat channel, message, template, and subscription routes; and all Category routes.