メインコンテンツまでスキップ
バージョン: 0.14.0 (最新)

✅ ID バリデーター

ID ルートは 2 つの共通アクセスファクトリーを合成し、isSelf はローカルで再利用可能な所有権バリデーターです。バリデーターはルートペイロードを受け取り、正常に完了するか NodeblocksError をスローします。Express ミドルウェアではなく SDK ガードです。

一覧

バリデーター読み取る値成功条件失敗 / エラー利用箇所
isSelfcontext.authenticate またはベアラーへのフォールバック。設定済みペイロードパス対象値が有効なユーザートークンの identityId と一致する401: 無効なトークン。403: 対象値の欠落または不一致認証プロフィール注文組織通知チャットのルート
isAuthenticated()context.authenticate またはベアラーへのフォールバック選択されたアダプターが正常終了するアダプターのエラーをそのまま伝播する検索取得更新削除ロックロック解除
checkIdentityType(['admin'])認証アダプター、db.identitiesconfiguration.identity.typeIds有効なユーザートークンから取得したアイデンティティが設定済みの admin 種別 ID を持つ500: 設定。401: 無効なトークン。403: アイデンティティ/種別検索取得更新削除ロックロック解除

詳細

isSelf

実装

シグネチャは isSelf<T extends string>(identityIdPathInPayload: [T, ...T[]]): Validator です。このファクトリーは context.authenticate または getBearerTokenInfo を選択してルートペイロードで呼び出し、isValidUserAccessToken(tokenInfo) を要求した後、ramdapath(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(...) は、認証サービスの deleteRefreshTokensRoutesendVerificationEmailRoutechangeEmailRoutechangePasswordRoutedeactivateRoute で使われる some(checkIdentityType(['admin']), isSelf(...)) の本人分岐です。無効化以外では ['params', 'requestParams', 'identityId']、無効化では ['params', 'requestBody', 'identityId'] を使用します。ほかに、本文 identityId を使うプロフィールの createProfileRoute、注文の createOrderRoute とクエリ identityId を使う findOrdersRoute、パス identityId を使う組織の findOrganizationsForMemberRoute、チャットの createChatChannelRoutefindChatChannelsRoutecreateChatSubscriptionRoutefindChatSubscriptionsRoute でも使われます。プロフィールの findProfilesByIdentityIdRoute、通知の findNotificationsRouteupdateNotificationToReadBatchRoute、チャットの createChatMessageRoutefindChatMessagesRouteupsertChatChannelReadStateRoute では直接実行されます。チャットではそれぞれ ownerIdsubscribedIdsenderId を使用し、残りの直接ルートでは記載の本文、パス、またはクエリ位置の identityId を使用します。

アイデンティティルートは isSelf を合成せず、以下の管理者チェックを使用します。

isAuthenticated()

実装

この共有ファクトリーの正規ドキュメントは 共通バリデーター にあります。シグネチャは isAuthenticated(): Validator です。バリデーターは context.authenticate または getBearerTokenInfo を選択し、選択したアダプターをペイロードで一度呼び出します。戻り値は検査せず、アダプターのエラーはそのまま伝播します。

利用箇所: アイデンティティは findIdentitiesRoutegetIdentityRouteupdateIdentityRoutedeleteIdentityRoutelockIdentityRouteunlockIdentityRoute で最初に isAuthenticated() を呼び出します。ほかの直接利用先は、住所 findAddressRoute属性 createAttributeRouteupdateAttributeRoutedeleteAttributeRoute組織のルートリファレンスに記載されたすべての組織ルートすべてのプロフィールルートすべての注文ルートロケーションの createLocationRouteupdateLocationRoutedeleteLocationRoute認証の logoutRoutedeleteRefreshTokensRoutegenerateOnetimeTokenRouterestoreOnetimeTokenRouteinvalidateOnetimeTokenRoutesendVerificationEmailRoutechangeEmailRoutechangePasswordRoutedeactivateRouteactivateRoute通知の updateNotificationToReadRoutefindNotificationsRouteupdateNotificationToReadBatchRoute製品の作成、一括、更新、削除、コピー、画像、バリアント、組織一覧、いいねの各ルートすべての招待ルートソースコメントでストリームバリデーターとされているものを除くすべてのチャットルート、およびすべてのカテゴリルートです。

checkIdentityType(['admin'])

実装

この共有ファクトリーの正規ドキュメントは 共通バリデーター にあります。アイデンティティでの正確な呼び出しは checkIdentityType(['admin']) です。context.db.identitiescontext.configuration.identity.typeIds を必要とし、context.authenticate または getBearerTokenInfo を選択します。有効なユーザーアクセストークンを要求し、getIdentityByIdtokenInfo.identityId を読み込んだ後、取得したアイデンティティの typeIdidentityTypeIds.admin と比較します。

500db.identities is not set または configuration.identity.typeIds is not set401Invalid token403Failed to fetch identityInvalid identity type ID、または Identity is not authorized to access this resource をスローします。

利用箇所: アイデンティティは findIdentitiesRoutegetIdentityRouteupdateIdentityRoutedeleteIdentityRoutelockIdentityRouteunlockIdentityRoute で、isAuthenticated() の後に checkIdentityType(['admin']) を実行します。ほかの直接の ['admin'] 利用先は、属性の createAttributeRouteupdateAttributeRoutedeleteAttributeRouteルートリファレンスにあるすべての組織ルートfindProfilesByIdentityIdRoute を除くすべてのプロフィールルートfindOrdersByOrganizationIdRoute を除くすべての注文ルートロケーションの createLocationRouteupdateLocationRoutedeleteLocationRoute認証の deleteRefreshTokensRoutegenerateOnetimeTokenRouterestoreOnetimeTokenRouteinvalidateOnetimeTokenRoutesendVerificationEmailRoutechangeEmailRoutechangePasswordRoutedeactivateRouteactivateRouteすべての管理者製品ルートすべての招待ルート管理者向けのチャットチャネル、メッセージ、テンプレート、サブスクリプションのルート、およびすべてのカテゴリルートです。