@amora95/commons
v2.0.92
Published
Amora95 commons packages and dependencies used in microservices
Readme
@amora95/commons
Shared utilities, constants, middleware, and service clients for the Aure Games backend.
Installation
npm install @amora95/commons
# or
yarn add @amora95/commonsContents
Constants
| Module | Description |
| ----------------------------- | ------------------------------------------------------------------------ |
| dbConstants | Database status values (pending, done) |
| httpCodes / responseCodes | Standard HTTP status codes and response code strings |
| webErrors | Pre-defined error objects with id and msg for auth and server errors |
| loggerConstants | Logger categories, levels, and types |
| webConstants | General web-related constants |
| websocketConstants | WebSocket-related constants |
| serviceConstants | Service-level constants (e.g. S3 signed URL expiry) |
Middleware
checkTokenMiddleware
Express middleware that validates a Bearer token by calling the auth service's check-session-token
endpoint. Requires AUTH_SERVICE_URL to be set in the environment.
import { checkTokenMiddleware } from '@amora95/commons';
router.get('/protected', checkTokenMiddleware, handler);Utils
Logger (logData, logDBRegistry, sendOkResponse, sendClientError, sendServerError)
Log4js-based logger that writes to file and console. Optionally ships log entries to a remote logger
service when LOGGER_STATUS=ON.
| Function | Description |
| ----------------- | --------------------------------------------------- |
| logData | Writes a log entry at the given level and category |
| logDBRegistry | Posts a structured log to the remote logger service |
| sendOkResponse | Sends a 200 JSON response |
| sendClientError | Sends a 4xx JSON error response |
| sendServerError | Sends a 500 JSON error response |
Environment variables:
LOG_PATH— directory for log filesLOGGER_STATUS— set toONto enable remote loggingLOGGER_URL— URL of the remote logger service
RSA Manager (encrypt, decrypt, sign, verifySign, verifySpkiSignature)
Wrappers around Node's crypto module for RSA encryption, decryption, signing, and signature
verification. Supports XML-format public keys (converts to PEM internally).
Tokenizer (createJWT, getTokenInfo, getTokenData)
JWT helpers that retrieve signing secrets from OpenBao/Vault at runtime.
| Function | Description |
| -------------- | -------------------------------------------------------- |
| createJWT | Signs and returns a JWT using the secret stored in Vault |
| getTokenInfo | Verifies a JWT and returns its decoded payload |
| getTokenData | Decodes a JWT without verification |
String Utils (getNewCode, getSafeMail, avoidNanParseInt, avoidNanParseFloat)
Miscellaneous string helpers.
Thread Utils (sleep)
Async sleep helper.
Services
OpenbaoVaultClient
Singleton client for OpenBao (Vault-compatible). Handles token-based authentication with wrapping token support and automatic re-authentication.
import { OpenbaoVaultClient } from '@amora95/commons';
const vault = OpenbaoVaultClient.getInstance();
const secret = await vault.getSecret<MySecretType>('secret/path');Environment variables:
VAULT_ADDR— Vault URL (default:http://localhost:8200)DOCKER_SHARED_FOLDER— path to shared volume for wrapping tokens
S3ClientService
AWS S3 client wrapper with presigned URL support. Credentials are fetched from Vault at init time.
import { S3ClientService } from '@amora95/commons';
const s3 = await new S3ClientService().init(bucketId, secretPath);
const url = await s3.getPresignedUrl('path/to/object');Environment variables:
S3_REGIONS3_URLS3_SHOULD_FORCE_PATHAWS_DEFAULT_MODE
Types
GenericObject—{ [key: string]: any }S3ValidDefaultsMode— valid values for the AWS SDKdefaultsModeoptionErrorType—{ msg: string; id: string }
Controllers
Base controller class/interface shared across backend services.
Development
# Build (TypeScript + esbuild bundle)
yarn build
# Build in watch mode
yarn compileBuild output is placed in dist/ and supports both ESM (dist/index.js) and CJS
(dist/index.cjs).
License
MIT
