✅ ID バリデーター
ID ルートは 2 つの共通アクセスファクトリーを合成し、isSelf はローカルで再利用可能な所有権バリデーターです。バリデーターはルートペイロードを受け取り、正常に完了するか NodeblocksError をスローします。Express ミドルウェアではなく SDK ガードです。
一覧
| バリデーター | 読み取る値 | 成功条件 | 失敗 / エラー | 利用箇所 |
|---|---|---|---|---|
isSelf | context.authenticate またはベアラーへのフォールバック。設定済みペイロードパス | 対象値が有効なユーザートークンの identityId と一致する | 401: 無効なトークン。403: 対象値の欠落または不一致 | 認証、プロフィール、注文、組織、通知、チャットのルート |
isAuthenticated() | context.authenticate またはベアラーへのフォールバック | 選択されたアダプターが正常終了する | アダプターのエラーをそのまま伝播する | 検索、取得、更新、削除、ロック、ロック解除 |
checkIdentityType(['admin']) | 認証アダプター、db.identities、configuration.identity.typeIds | 有効なユーザートークンから取得したアイデンティティが設定済みの admin 種別 ID を持つ | 500: 設定。401: 無効なトークン。403: アイデンティティ/種別 | 検索、取得、更新、削除、ロック、ロック解除 |
詳細
isSelf
実装
シグネチャは isSelf<T extends string>(identityIdPathInPayload: [T, ...T[]]): Validator です。このファクトリーは context.authenticate または getBearerTokenInfo を選択してルートペイロードで呼び出し、isValidUserAccessToken(tokenInfo) を要求した後、ramda で path(identityIdPathInPayload, payload) を読み取ります。identityId という名前とは限らない設定済みの対象値を、tokenInfo.identityId と比較します。
ユーザートークンでない場合は NodeblocksError(401, 'Invalid token', 'isSelf')、設定済みパスに値がない場合は NodeblocksError(403, 'Identity ID is required', 'isSelf')、値が異なる場合は NodeblocksError(403, 'Identity ID does not match', 'isSelf') をスローします。
利用箇所: isSelf(...) は、認証サービスの deleteRefreshTokensRoute、sendVerificationEmailRoute、changeEmailRoute、changePasswordRoute、deactivateRoute で使われる some(checkIdentityType(['admin']), isSelf(...)) の本人分岐です。無効化以外では ['params', 'requestParams', 'identityId']、無効化では ['params', 'requestBody', 'identityId'] を使用します。ほかに、本文 identityId を使うプロフィールの createProfileRoute、注文の createOrderRoute とクエリ identityId を使う findOrdersRoute、パス identityId を使う組織の findOrganizationsForMemberRoute、チャットの createChatChannelRoute、findChatChannelsRoute、createChatSubscriptionRoute、findChatSubscriptionsRoute でも使われます。プロフィールの findProfilesByIdentityIdRoute、通知の findNotificationsRoute と updateNotificationToReadBatchRoute、チャットの createChatMessageRoute、findChatMessagesRoute、upsertChatChannelReadStateRoute では直接実行されます。チャットではそれぞれ ownerId、subscribedId、senderId を使用し、残りの直接ルートでは記載の本文、パス、またはクエリ位置の identityId を使用します。
アイデンティティルートは isSelf を合成せず、以下の管理者チェックを使用します。
isAuthenticated()
実装
この共有ファクトリーの正規ドキュメントは 共通バリデーター にあります。シグネチャは isAuthenticated(): Validator です。バリデーターは context.authenticate または getBearerTokenInfo を選択し、選択したアダプターをペイロードで一度呼び出します。戻り値は検査せず、アダプターのエラーはそのまま伝播します。
利用箇所: アイデンティティは findIdentitiesRoute、getIdentityRoute、updateIdentityRoute、deleteIdentityRoute、lockIdentityRoute、unlockIdentityRoute で最初に isAuthenticated() を呼び出します。ほかの直接利用先は、住所 findAddressRoute、属性 createAttributeRoute、updateAttributeRoute、deleteAttributeRoute、組織のルートリファレンスに記載されたすべての組織ルート、すべてのプロフィールルート、すべての注文ルート、ロケーションの createLocationRoute、updateLocationRoute、deleteLocationRoute、認証の logoutRoute、deleteRefreshTokensRoute、generateOnetimeTokenRoute、restoreOnetimeTokenRoute、invalidateOnetimeTokenRoute、sendVerificationEmailRoute、changeEmailRoute、changePasswordRoute、deactivateRoute、activateRoute、通知の updateNotificationToReadRoute、findNotificationsRoute、updateNotificationToReadBatchRoute、製品の作成、一括、更新、削除、コピー、画像、バリアント、組織一覧、いいねの各ルート、すべての招待ルート、ソースコメントでストリームバリデーターとされているものを除くすべてのチャットルート、およびすべてのカテゴリルートです。
checkIdentityType(['admin'])
実装
この共有ファクトリーの正規ドキュメントは 共通バリデーター にあります。アイデンティティでの正確な呼び出しは checkIdentityType(['admin']) です。context.db.identities と context.configuration.identity.typeIds を必要とし、context.authenticate または getBearerTokenInfo を選択します。有効なユーザーアクセストークンを要求し、getIdentityById で tokenInfo.identityId を読み込んだ後、取得したアイデンティティの typeId を identityTypeIds.admin と比較します。
500 の db.identities is not set または configuration.identity.typeIds is not set、401 の Invalid token、403 の Failed to fetch identity、Invalid identity type ID、または Identity is not authorized to access this resource をスローします。
利用箇所: アイデンティティは findIdentitiesRoute、getIdentityRoute、updateIdentityRoute、deleteIdentityRoute、lockIdentityRoute、unlockIdentityRoute で、isAuthenticated() の後に checkIdentityType(['admin']) を実行します。ほかの直接の ['admin'] 利用先は、属性の createAttributeRoute、updateAttributeRoute、deleteAttributeRoute、ルートリファレンスにあるすべての組織ルート、findProfilesByIdentityIdRoute を除くすべてのプロフィールルート、findOrdersByOrganizationIdRoute を除くすべての注文ルート、ロケーションの createLocationRoute、updateLocationRoute、deleteLocationRoute、認証の deleteRefreshTokensRoute、generateOnetimeTokenRoute、restoreOnetimeTokenRoute、invalidateOnetimeTokenRoute、sendVerificationEmailRoute、changeEmailRoute、changePasswordRoute、deactivateRoute、activateRoute、すべての管理者製品ルート、すべての招待ルート、管理者向けのチャットチャネル、メッセージ、テンプレート、サブスクリプションのルート、およびすべてのカテゴリルートです。