Skip to content

Integration

Ledger has no synchronous HTTP calls to sister services. All cross-service data is read directly through @nx/core repositories (shared schema, same database). It depends on @nx/asset for file storage and on identity only for JWT verification.

1. Sister Services

Direction: calls / called by / bidir.

SisterDirectionSurfaceContractAuthFailure ModeIdempotency
@nx/identityJWKS verification per requestVerifierApplicationJWKS (ES256)401 on invalid/expired JWT
@nx/assetMetaLinkService + S3 upload/downloadin-process (@nx/core repo + BunS3Helper)upload error → job REJECTEDorphaned-link cleanup pre/post run
@nx/financeDB read: FinanceTransactionRepositoryshared schemaempty result → empty ledgerread-only
@nx/saleDB read: SaleOrderRepositoryshared schemaread-only
@nx/commerceDB read: MerchantRepository, TaxInfoRepository, VnProvince/VnWardshared schemamissing merchant → validation errorread-only

Cross-package reads are S1a-HKD only (real data). S2a–S2e currently use fixture JSON via LedgerDataFixtureService (placeholder pending real integration).

2. External Systems

SystemDirectionSurfaceAuthFailure Mode
Kafkaproduce + consume ledger.generateSASL SCRAM-SHA-512 (toggle APP_ENV_KAFKA_SASL_ENABLE)broker down → enqueue throws → job REJECTED (ENQUEUE_FAILED)
S3 / Minioencrypted PDF/XLSX put/get (BunS3Helper)access/secret keysupload error → job REJECTED
Redisauth cache + WS pubsubpasswordWS emit best-effort
Typstin-procNodeCompiler PDF rendercompile error → fresh compiler, then rethrow

3. Critical Cross-Service Flows

3.1 S1a-HKD data fetch (real data)

StepDetail
1Facade LedgerDataFetcherService routes by type to S1aHkdDataFetcherService
5Worker validates with SCHEMA_MAP['S1a-HKD'].safeParse; parse failure → REJECTED

3.2 File upload via @nx/asset

StepDetail
2originalName must be a flat filenameBunS3Helper.isValidName() rejects /; path is built in normalizeNameFn
4Download reverses: getLedgerFromS3Decrypted → decrypt → stream to client

4. Contract Stability

SurfaceStabilityVersioning
HTTP /v1/api/ledger/*stableURL /v1/
Kafka ledger.generatestable (internal self-loop)payload fields additive
S3 key layout ledgers/{period}/{merchantId}/{version}/stable
S2a–S2e data sourcebeta — fixture placeholder, real fetch pending

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.