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

✅ Order validators

Order routes compose the local ownsOrder ownership validator with shared authentication, access-alternative, identity-type, self, and organization-role validators. There is no validateOrderAccess export in the SDK.

Inventory

ValidatorReadsSuccess conditionFailure / errorConsumers
isAuthenticated()context.authenticate, or default Bearer contextAuthentication function resolves.Authentication function error; default Bearer authentication throws 401.create, get, find, update, delete, organization list
some(...)The supplied validator functionsAt least one branch fulfills.First collected NodeblocksError, or 500 Unknown error.create, get, find, update, delete
checkIdentityType(['admin'])db.identities, configuration.identity.typeIds, authentication resultUser access token identity has configured admin type ID.500, 401, or 403.create, get, find, update, delete
isSelf(...)Authentication result and provided payload pathTarget ID equals user-token identityId.401 or 403.create, find
ownsOrderdb.orders, authentication result, order-ID payload pathStored order identityId equals user-token identityId.400, 401, 403, or 500.get, update, delete
hasOrgRole(...)db.organizations, configuration.organization.roles, authentication result, organization-ID payload pathCaller is a member with configured owner/admin/member role.400, 401, 403, or 500.organization list

Details

isAuthenticated()

Implementation

Signature: isAuthenticated(): Validator. Invokes context.authenticate(payload) when supplied; otherwise it invokes getBearerTokenInfo(payload). The default reads the Authorization Bearer token, request host/fingerprint/IP/user-agent, configuration.authSecrets, and configuration.checkIp (default true). Any selected authentication error is propagated; the default emits 401 for an invalid or unsuitable access token or failed token security check. See the canonical contract.

Consumers: This factory is first in every Order route's validator array: createOrderRoute, getOrderRoute, findOrdersRoute, updateOrderRoute, deleteOrderRoute, and findOrdersByOrganizationIdRoute.

some(...)

Implementation

Signature: some(...args: Validator[]): Validator. Direct validator composer placed second after isAuthenticated(); runs both supplied branches concurrently with Promise.allSettled and succeeds when either fulfills. If both fail, it throws the first collected NodeblocksError in argument/result order. A non-NodeblocksError rejection is replaced by 500 Unknown error with source validator. See the canonical contract.

Consumers: createOrderRoute, getOrderRoute, findOrdersRoute, updateOrderRoute, and deleteOrderRoute.

checkIdentityType(['admin'])

Implementation

Signature: checkIdentityType(['admin']): Validator. Requires context.db.identities and context.configuration.identity.typeIds, authenticates, requires a user access token, fetches the token identity from db.identities, then compares its typeId to identity.typeIds.admin. Missing collection or configuration is 500; an invalid non-user token is 401; an identity lookup failure, missing typeId, or non-admin type is 403. See the canonical contract.

Consumers: First some(...) branch on createOrderRoute, getOrderRoute, findOrdersRoute, updateOrderRoute, and deleteOrderRoute.

isSelf(...)

Implementation

Signature: isSelf<T extends string>(identityIdPathInPayload: [T, ...T[]]): Validator. Authenticates, requires a user access token, reads the target at the exact supplied payload path, and compares it with the token's identityId. An invalid non-user token is 401; a missing target identity ID or mismatch is 403. See the canonical contract.

Consumers: Second some(...) branch on createOrderRoute as isSelf(['params', 'requestBody', 'identityId']), and on findOrdersRoute as isSelf(['params', 'requestQuery', 'identityId']).

ownsOrder

Implementation

ownsOrder is the local partial(ownsResource, ['orders', ['identityId']]) export. The resulting validator authenticates and requires a user access token; reads context.db.orders; reads orderId from the supplied payload path; loads the order by public id; then compares stored identityId with the token identity ID. Invalid token is 401; no order collection is 500; missing order ID is 400; a lookup error, missing owner ID, or ownership mismatch is 403. See the shared ownsResource contract.

Consumers: getOrderRoute, updateOrderRoute, and deleteOrderRoute invoke ownsOrder(['params', 'requestParams', 'orderId']) in the second some(...) branch.

hasOrgRole(...)

Implementation

Signature: hasOrgRole(allowedRoles, organizationIdPathInPayload): Validator. Requires context.db.organizations and context.configuration.organization.roles, authenticates and requires a user access token, reads the path organization ID, fetches that organization, finds the caller in organization.members, and checks the member's role against the corresponding configured owner, admin, or member role values. Missing store/configuration is 500; invalid token is 401; missing organization ID is 400; a failed lookup, absent membership, or disallowed role is 403. See the canonical contract.

Consumers: Second after isAuthenticated() only on findOrdersByOrganizationIdRoute: hasOrgRole(['owner', 'admin', 'member'], ['params', 'requestParams', 'organizationId']).