Skip to content

Operations

1. Triển khai

Thuộc tínhGiá trị
Dev port1190 ⚠️ (anh em dùng 310x0)
Local nginx upstreaminvoice_upstream → 127.0.0.1:31140 (packages/gateway/local/nginx.conf)
Base path/v1/api (không có segment riêng cho service)
Run modesapi, worker (BullMQ issuance + claim-expiry), migrate
Migrationbun run migrate:dev (seed dữ liệu hành chính VN, configs, webhooks, permissions)
Snowflake ID range⚠️ chưa đặt (APP_ENV_..._WORKER_ID chưa cấu hình)
Service codeSVC-00150-INVOICE (đã có trong ServiceCodes của core); Kafka id mặc định SVC-00150-INVOICE_CONSUMER

⚠️ Đối chiếu trước production (từ AGENTS của package): gán một SVC code duy nhất, một snowflake worker id, và một port 310x0; giải quyết va chạm SVC-00050 với inventory trước khi deploy production.

Build & run

bash
bun run rebuild      # clean + build (deps: core, iiapi, t-van, mq-pay)
bun run lint:fix     # ESLint + Prettier
bun run server:dev   # chạy với .env.development
bun run migrate:dev  # migrations / seeds

2. Observability

Tín hiệuNguồnXem ở đâu
Logsstdout (key-value có cấu trúc)kubectl logs <pod> / Loki
Audit phát hànhinvoice.InvoiceAuditTracingvết sự kiện theo từng hoá đơn (eventType/outcome/before-after)
Healthroute health mặc định của IGNISportal gateway

Marker log chính

MarkerÝ nghĩa
[handlePaymentSuccess]quyết định phát hành theo thanh toán
[handleMerchantCDC] op=u tax unchanged, SKIPshort-circuit khi diff CDC
[enqueueIssuance] ... partition: %sđịnh tuyến partition
[_handleIssuanceFailure] Scheduling retryretry tạm thời với backoff
[DLQ] invoice-issuancejob cạn lượt → hoá đơn FAILED + audit

3. Bảo mật

Mối quan tâmGiảm thiểu
AuthNJWT (ES256, JWKS từ identity); VerifierApplication
AuthZController có cổng permission + AuthorizationService (cấp merchant)
Credential providerAES-256-GCM, khoá = đúng 32 byte / 64 hex (APP_ENV_INVOICE_CREDENTIALS_KEY)
Tin cậy webhookHai HMAC secret: WEBHOOK_SECRET (merchant→platform), WEBHOOK_INTERNAL_SECRET (iiapi/commerce→platform, xác minh HMAC-SHA256)
Token claim người muaUUID ngẫu nhiên, partial-unique, có thời hạn (claimDeadline)
Secretsenv / bảng Configuration (mã hoá); không bao giờ trong code
Soft-deletedeletedAt — mặc định không hard-delete

4. Runbook

4.1 Lớp cảnh báo

Cảnh báoKích hoạtKiểm traKhắc phụcLeo thang
Tăng vọt lỗi phát hànhtỷ lệ FAILED InvoiceAuditTracinglogs [_handleIssuanceFailure] / provider 4xxxem response payload của provider; sửa config/credentialinvoice-team
BullMQ DLQ phìnhlogs [DLQ] invoice-issuanceđộ sâu queue Redis theo từng partitionre-enqueue sau khi sửa nguyên nhân gốcon-call SRE
Lệch TaxInfo CDCFE hiển thị thuế merchant cũso metadata.tax vs TaxInfokích hoạt cập nhật merchant (re-CDC); kiểm logic diffinvoice-team
Webhook bị từ chối401 trên /webhookssai chữ kýxoay/đồng bộ lại secret WEBHOOK_*invoice-team

4.2 Thao tác thường gặp

Thao tácCách làm
Tail logskubectl logs -n <ns> -f deploy/invoice
Xem trạng thái hoá đơnquery invoice.Invoice + InvoiceIssuance + InvoiceAuditTracing theo sourceId
Replay phát hành kẹtre-enqueue qua luồng phát hành (jobId = orderId); idempotent trên hoá đơn active
Re-sync thuế merchantre-emit/replay Merchant CDC; op=u diff-skip nếu không đổi
Xem partition của một orderpartition = getPartitionByKey(orderId) (hashCode mod 3)

4.3 Gotcha đã biết / nợ kỹ thuật

MụcChi tiết
Không có một transactionTạo Invoice + InvoiceRequest không nguyên tử (payment-success có thể đến trước request)
Snapshot config bất biếnprovider config được copy lúc tạo hoá đơn; sửa config giữa vòng đời không áp dụng
Lệch định danh servicecode/worker-id/port chưa đặt (xem Triển khai ⚠️)

Sự cố xuyên service: xem /runbook/.

5. Trang liên quan

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