Pillar 1. Security, Multi-Tenant Isolation & Anti-Abuse
Enterprise Multi-Tenant Context, SHA-256 Hash-Chain Audit Trails, 64-Bit SimHash Anti-Spam & Zalo Mini App Authentication.
Pillar 1. Security, Multi-Tenant Isolation & Anti-Abuse
4 Domain Combo Suites (18+ Isolated Slices)
Enforcing zero data leakage across multi-tenant SaaS environments, cryptographically verifiable audit trails, anti-bot defenses, and Zalo OAuth verification.
📦 Package Catalog
| Package Name | Dedicated Guide | Architecture Paradigm & Key Exports |
|---|---|---|
@kido/tenant-guard | Deep Dive & API Reference | Multi-Tenant Context + RLS Filter + ABAC Guard + Surgical Snapshot: • TenantContextStore, injectTenantFilter, injectPrismaTenantArgs• AuthorizationGuard, evaluateAbacPolicy• SurgicalSnapshotEngine, resolveDemoPersona |
@kido/audit-trail | Deep Dive & API Reference | Immutable SHA-256 Hash-Chain Audit Trail + Mutation Logger: • AuditTrailEngine, computeAuditHash, verifyAuditChain• ApiAuditService, honoAuditMiddleware, sanitizePayload |
@kido/anti-spam | Deep Dive & API Reference | Multi-Signal Anti-Spam + 64-Bit SimHash Deduplication: • createAntiSpamGuard, analyzeFingerprint, scorePurchaseReview• computeSimHash, hammingDistance, isNearDuplicate, NearDuplicateIndex |
@kido/zalo-mini-auth | Deep Dive & API Reference | Zalo Mini App OAuth2, HMAC-SHA256 Proof & Phone Token Decoder: • ZaloMiniAuthClient, calculateAppSecretProof, verifyWebhookSignature |
🔍 Deep-Dive: Architecture & Slices
1. @kido/tenant-guard
Enterprise B2B applications must prevent cross-tenant data leaks. tenant-guard isolates tenants transparently using Node.js AsyncLocalStorage:
src/tenant-context.ts: Zero-overhead context store providingTenantContextStore.getTenantId().src/rls-query-filter.ts&src/orm-cache-interceptor.ts: Automatically injects tenant filters into Prisma queries and prefixes Redis cache keys (tenant:{id}:{key}).src/team-rbac/: Attribute-based access control engine evaluating complex permission matrices.src/snapshot/&src/sandbox/: Creates cryptographically verified database snapshots and powers safe public demo environments with sanitized data.
2. @kido/audit-trail
Regulatory compliance (SOC2, ISO 27001, HIPAA) requires tamper-proof records of critical mutations:
src/hash-chain.ts&src/merkle-tree.ts: Implements a cryptographic SHA-256 blockchain-style hash chain (currentHash = sha256(prevHash + timestamp + payload)). Any modification to past entries breaks verification immediately.src/api-audit/: High-performance HTTP middleware with PII auto-redaction for Hono and Express.
3. @kido/anti-spam
Defends platforms against automated comment spam, fake purchase reviews, and duplicate promotional abuse:
src/dedupe/: Fast 64-bit SimHash near-duplicate detector with Hamming distance matching. Detects paraphrased or slightly edited spam in< 0.1ms.src/heuristics.ts: Multi-signal scoring engine combining velocity checks, account age, and textual entropy.
4. @kido/zalo-mini-auth
Connects Vietnam market mini-apps to backend APIs with strict HMAC verification:
- Decodes encrypted phone tokens (
phoneToken) into verified phone numbers. - Computes
appsecret_proofto prevent replay attacks and man-in-the-middle tampering.
💻 Code Example: Multi-Tenant Context & Hash-Chain Audit
import { TenantContextStore } from '@kido/tenant-guard';
import { AuditTrailEngine } from '@kido/audit-trail';
const auditEngine = new AuditTrailEngine();
export async function updateUserRole(targetUserId: string, newRole: string) {
const tenantId = TenantContextStore.getTenantId();
if (!tenantId) throw new Error('Unauthenticated tenant context');
// Perform database mutation...
// Record tamper-proof audit entry
const entry = await auditEngine.recordEntry({
tenantId,
actorId: 'admin_user_42',
action: 'USER_ROLE_UPDATED',
entityId: targetUserId,
diff: { previousRole: 'MEMBER', newRole },
});
return { success: true, auditHash: entry.hash };
}12. WMS Smart Warehouse Putaway & S-Shape 2-Opt Pick Wave
GS1 Barcode Parser + Multi-Level Recipe BOM + FEFO Expiry Alert + Traveling Salesperson S-Shape 2-Opt Pick Routing reducing warehouse walking by 35%.
@kido/tenant-guard
Enterprise Multi-Tenant Row-Level Security (RLS), AsyncLocalStorage Context Isolation, and Dynamic RBAC/ABAC Guard for Franchise & POS Architectures.