How reneilwekeoagile061/bdap-server works
Purpose and execution modes
This Node.js batch integration exports Botswana SIMS subscriber data from BOCRA and transfers CSV extracts to BDAP. Server.js is the primary entry point: default execution performs a limited test download; node Server.js --production removes page limits and runs the full export. It also installs a weekly Monday 1 AM Botswana-time job. scheduled-test.js supports scheduled-run validation.
Bootstrap and configuration boundary
Startup validates runtime configuration, then initializes API and transfer connectivity before extraction. BDAP host, port, credentials, and remote directory are environment-supplied; env.template defines the expected contract and check-env.js validates it. No application database or web-serving layer is represented.
Paths: Server.js, check-env.js, env.template
BOCRA SIMS acquisition client
The core server uses an Axios-based HTTP client to call BOCRA SIMS endpoints with authentication, timeouts, retries, and optional SSL verification. It supports endpoint variants and response-shape variants (content, direct arrays, wrapped data/subscribers) to tolerate API differences. API calls are an external-service boundary; failures trigger retry/fallback behavior rather than persisting raw API state.
Path: Server.js
Natural-subscriber export pipeline
For each verification class—verified, failed verification, and pending verification—the service pages through natural-subscriber API results, extracts phone/document details, normalizes fields, and writes one standardized CSV. State mapping adapts API values such as ACTIVE, FAILED, and PENDING to export categories. If normal verification endpoints fail, MSISDN range scanning is an alternative acquisition route.
Paths: Server.js, resources/verified_natural-subscriber_2025-04-29T12-54-14-442Z.csv, resources/pending_verification_natural-subscriber_2025-04-29T12-54-11-970Z.csv
Juristic-subscriber enrichment pipeline
Juristic exports follow a distinct flow: list subscribers, request each subscriber’s detail and contact-person data, retrieve associated phone numbers, consolidate those records, then emit a single standardized CSV. This per-subscriber fan-out is the principal control-flow difference from paginated natural exports.
Path: Server.js
Local artifact boundary
CSV output is the durable handoff artifact between extraction and delivery. Output is date/timestamp partitioned and existing resources/ files demonstrate separate natural-subscriber exports by state and run time. Text cleanup and field normalization occur before file writes, preserving a consistent downstream schema.
Paths: resources/, resources/failed_verification_natural-subscriber_2025-04-29T12-53-44-481Z.csv
BDAP delivery and scheduling
After each completed CSV is generated, the service tests BDAP reachability and transfers artifacts using password-authenticated SCP to the configured remote directory. Transfer is an infrastructure boundary independent of BOCRA acquisition. A cron-driven weekly full run and an explicit one-time push function orchestrate automated versus ad hoc delivery; logging and optional notifications expose failures.
Paths: Server.js, scheduled-test.js
Main entry points: Server.js Server entry point · check-env.js Runtime config validation · scheduled-test.js Scheduled-run validator · env.template Environment contract
Components 14
Batch Runtime
- Server entry point · Runs limited exports by default and full exports with --production.
Server.js - Scheduled-run validator
scheduled-test.js - Environment contract · Defines BDAP connection and destination variables.
env.template - Runtime config validation
check-env.js - Weekly Monday schedule · Triggers a 1 AM Botswana-time full export.
Server.js
BOCRA Acquisition
- BOCRA SIMS API
- Authenticated SIMS client · Handles endpoint variants, retries, timeouts, and response shapes.
Server.js - MSISDN range fallback · Scans ranges when normal verification endpoints fail.
Server.js
CSV Export
- Natural subscriber export · Exports verified, failed, and pending verification classes.
Server.js - Juristic subscriber enrichment · Fetches subscriber details, contacts, and associated phone numbers.
Server.js - Timestamped CSV artifacts · Standardized durable handoff files partitioned by export state and run.
BDAP Delivery
- BDAP SCP endpoint · Password-authenticated SCP destination configured by environment.
- CSV transfer · Tests reachability and pushes completed artifacts to the remote directory.
Server.js - Failure visibility · Logs transfer and scheduled-run failures with optional notifications.
Server.js
Connections 19
- Environment contract → Runtime config validation: defines required values
- Runtime config validation → Server entry point: validates at startup
- Server entry point → Authenticated SIMS client: initializes
- Authenticated SIMS client → BOCRA SIMS API: authenticated HTTP calls
- Server entry point → Natural subscriber export: runs export classes
- BOCRA SIMS API → Natural subscriber export: paged natural records
- Natural subscriber export → MSISDN range fallback: endpoint failure
- MSISDN range fallback → BOCRA SIMS API: range queries
- Server entry point → Juristic subscriber enrichment: runs enrichment
- BOCRA SIMS API → Juristic subscriber enrichment: subscriber, contact, phone data
- Natural subscriber export → Timestamped CSV artifacts: writes standardized CSV
- Juristic subscriber enrichment → Timestamped CSV artifacts: writes standardized CSV
- Timestamped CSV artifacts → CSV transfer: completed files
- Server entry point → CSV transfer: orchestrates one-time push
- CSV transfer → BDAP SCP endpoint: SCP upload
- Server entry point → Weekly Monday schedule: installs
- Weekly Monday schedule → Server entry point: full production run
- Scheduled-run validator → Server entry point: validates scheduled execution
- CSV transfer → Failure visibility: reports failures