Skip to main content
Version: 0.14.0 (Latest)

🔄 Common

Common documents cross-domain blocks, utility blocks, validators, and schemas that SDK services and custom route compositions reuse for normalization, access checks, pagination, and responses.

Start here

Import shared contracts from the SDK namespace that owns the export:

import {blocks, schemas, validators} from '@nodeblocks/backend-sdk';

const normalized = blocks.normalizeRawDocument({
_id: 'database-id',
id: 'public-id',
});

const requireAdmin = validators.checkIdentityType(['admin']);
const paginationParameters = schemas.paginationQueryParametersSchema;

normalizeRawDocument returns an infallible Result without MongoDB's _id; checkIdentityType returns a route validator; and paginationQueryParametersSchema is an array of reusable OpenAPI query parameters.

Common is not a mountable service and does not define features, handlers, or routes. Consumers import its public exports through blocks, schemas, and validators, then compose them into a domain service or custom route. Blocks provide errors, response normalization, redirects, and secure password generation. The first group is exported by blocks/common; redirect and password helpers are exported by blocks/utils. Schemas provide shared JSON Schema and OpenAPI definitions. Address-specific schemas are documented in Address. Validators authenticate, authorize, combine checks, and validate ownership. Validator factories receive configuration through the route payload. Authentication-aware validators use context.authenticate when supplied and otherwise fall back to Bearer-token authentication. Database-backed validators also require the named collection in context.db.

Common tasks

TaskStart withContract
Remove MongoDB _id before returning datanormalizeRawDocumentnormalizeRawDocument or normalizeDocuments
Produce a consistent empty response bodynormalizeEmptyBodynormalizeEmptyBody
Validate a notification timestamp anchorassertHasCreatedAtassertHasCreatedAt
Redirect an OAuth responseredirectToredirectTo
Generate an OAuth fallback passwordgenerateRandomPasswordgenerateRandomPassword
Add standard page and limit query parameterspaginationQueryParametersSchemapaginationQueryParametersSchema
Require every or any access checkall or someall or some
Restrict access by identity type or ownershipcheckIdentityType, isSelf, or ownsResourcecheckIdentityType, isSelf, or ownsResource

Reference map

PagePurpose
Common blocksShared errors, normalizers, redirect behavior, and password generation.
Common schemasPagination, response, file, audit, and contact definitions.
Common validatorsAuthentication, identity type, ownership, and validator composition contracts.

Authentication composes the shared authentication and authorization validators and uses empty-body normalization. OAuth consumes redirects and generated passwords during provider flows. Chat consumes shared pagination schemas, document normalization, and ownership composition. Product uses shared document normalizers and access validators for variant routes. Address owns address data schemas and postal-code lookup contracts. Backend types, schemas, and validators define the route payload and composition contracts these exports use.