How cookiegmvn/mbbank works
Project Type and Purpose
• This is a Node.js/TypeScript library (no UI) that wraps the Vietnam Military Bank’s HTTP API in promise‐based methods and provides optional OCR captcha‐solving via either Tesseract CLI or a WebAssembly model.
File Structure
• Top‐level “src” organizes core code:
• src/index.ts exports the MB client class
• src/MB.ts implements the main library interface (login, getBalance, getTransactions, etc.)
• src/utils contains modules for:
– Global.ts (HTTP client, session/cookies, default headers)
– LoadWasm.ts (download or load local WASM OCR model)
– OCRModel.ts (runs OCR in WASM)
– Tesseract.ts (invokes external Tesseract binary)
– Wasm.ts (low-level WASM bindings)
• src/typings define TypeScript interfaces for API payloads
• Build & config: tsup.config.ts bundles, typedoc.json generates docs, tsconfig.json for compilation, ESLint/GitHub workflows for CI.
• “dist” holds the compiled JS + type declarations, “docs” holds the generated website.
README Insights
• Describes client configuration (credentials, preferred OCR method, saveWasm), features (login, balance, transaction history), and external dependencies (tesseract-ocr CLI, optional WASM model caching).
a. Main Components
1. User Application – calls library methods
2. MB Library Core (MB class)
3. HTTP Layer (utils/Global)
4. OCR Layer (choose one based on preferredOCRMethod):
– Tesseract CLI Module (utils/Tesseract)
– WASM OCR Module (utils/OCRModel + utils/LoadWasm + utils/Wasm + local filesystem cache)
5. Remote MBBank API (login, balance, transactions endpoints)
6. Local Filesystem (optional WASM file caching)
7. External Process: Tesseract OCR executable (if selected)
b. Relationships & Data Flows
• MB Library → HTTP Layer: build requests, attach cookies/session
• HTTP Layer ↔ Remote MBBank API: request/response HTTP traffic
• When encountering a CAPTCHA challenge:
• MB Library delegates to OCR Layer
• OCR Layer uses either:
– Tesseract CLI: spawn external process → returns text
– WASM OCR: Load model (from GitHub or local FS) → run inference → returns text
• OCR result → MB Library → continues HTTP workflow
• If saveWasm=true: LoadWasm writes/reads a .wasm file on Local Filesystem
c. Architectural Patterns & Principles
• Single‐class API façade (MB.ts) that encapsulates all flows
• Strategy pattern for OCR: interchangeable implementations (default WASM, tesseract, custom)
• Separation of concerns: HTTP, OCR, configuration, and types are modular
• Promise‐based async flows
d. Key Technologies & Libraries
• Node.js HTTP (axios or fetch inside utils/Global)
• TypeScript for types and safety
• Tesseract‐OCR CLI
• WebAssembly (WASM) model loaded at runtime
• tsup for bundling, typedoc for docs, ESLint and GitHub Actions for CI