Skip to content

Cấu hình

1. Biến môi trường

Nguồn: EnvironmentKeys trong @nx/core/src/common/environments.ts. Service đọc qua applicationEnvironment.get<T>(key).

Core runtime

TênKiểuMặc địnhBắt buộcMô tả
APP_ENV_PORTnumber3000Port HTTP listen (container)
APP_ENV_HOSTstring0.0.0.0Bind address
APP_ENV_BASE_PATHstring/v1/api/inventoryTiền tố route
APP_ENV_NODE_IDnumberSnowflake worker ID (phải là 5 cho inventory)
APP_ENV_LOG_LEVELinfo|debug|warn|errorinfoMức logger
APP_ENV_NODE_ENVstringdevelopmentLoad qua dotenv-flow
RUN_MODEmigrate|servermigrate chuyển sang entry migration

Database

TênKiểuMặc địnhBắt buộcMô tả
APP_ENV_DB_URLstringURL kết nối PostgreSQL
APP_ENV_DB_POOL_MAXnumber10Kích thước pool tối đa

Redis (chỉ auth cache)

TênKiểuMặc địnhBắt buộcMô tả
APP_ENV_REDIS_HOSTstringTùy chọn — nếu không set, auth cache bị tắt
APP_ENV_REDIS_PORTnumber6379
APP_ENV_REDIS_PASSWORDstring
APP_ENV_REDIS_DBnumber0

Kafka

TênKiểuMặc địnhBắt buộcMô tả
APP_ENV_KAFKA_BROKERScsvDanh sách broker phân tách bằng dấu phẩy — service từ chối khởi động nếu rỗng
APP_ENV_KAFKA_CLIENT_IDstringSVC-00050-INVENTORY_PRODUCER / _CONSUMEROverride producer/consumer
APP_ENV_KAFKA_GROUP_IDstringSVC-00050-INVENTORY_CONSUMER_GROUPConsumer group
APP_ENV_KAFKA_SASL_ENABLE'true'|'false'falseBật/tắt SASL auth
APP_ENV_KAFKA_SASL_MECHANISMenumNAKhi bật SASL
APP_ENV_KAFKA_SASL_USERNAMEstringNAKhi bật SASL
APP_ENV_KAFKA_SASL_PASSWORDstringNAKhi bật SASL

Authentication

TênKiểuMặc địnhBắt buộcMô tả
APP_ENV_JWKS_URLurlEndpoint JWKS của Identity service (/jw-certs)
APP_ENV_BASIC_AUTH_*stringCredentials basic cho service-to-service (nếu bật)

2. Feature Flags

CờLưu ởMặc địnhMô tả
metadata.inventory.allowOversellrow MaterialfalseKhi true, adjustStock bỏ qua guard forceNonNegative cho material đó
metadata.inventory.isInventoryTrackedrow MaterialtrueKhi false, material không được seed vào InventoryItem lúc tạo

Hôm nay chưa có service feature-flag toàn cục. Chỉ có cờ metadata theo từng row.

3. Dữ liệu Seed

Migration process trong src/migrations/processes/. Tất cả idempotent. Chạy lúc bootstrap (prestartbun run rebuildmigrate.ts).

FilePhạm viIdempotency KeySố row xấp xỉGhi chú
inventory-0002-seed-permissions.tsPermission (catalog RBAC)code~131Tổng hợp InventoryPermissions từ 15 nhóm controller (controllers/permissions.ts)
inventory-0003-seed-unit-of-measures.tsUnitOfMeasure (toàn hệ thống, merchantId=NULL)code~40Categories: COUNT (unit, pair, pack, dozen…), WEIGHT (kg, g, lb…), VOLUME (L, ml, gal…), TIME (sec, min, hr, day…); base unit mỗi category có ratio=1
inventory-0004-seed-discrimination-types.tsDiscriminationType (reference data)(scope, type)~100Scopes: tracking_reason, tracking_reference_type, tracking_type, location_type, identifier_scheme, ticket_partner_type, material_type, material_identifier_scheme, uom_category, costing_method
inventory-0005-backfill-vendor-item.tsMaterialize VendorItem từ lịch sử PO(merchantId, vendorId, itemType, itemId)one-shotSnapshot dòng PO non-cancelled mới nhất theo từng nhóm
inventory-0006-backfill-merchant-id.tsBackfill denorm InventoryStock.merchantIdmỗi row thiếu merchantIdone-shotLấy từ InventoryItem.merchantId

Mỗi file seed extends MigrationProcess từ @nx/core và tôn trọng cờ alwaysRun. Backfill (0005, 0006) là one-shot — chạy lại là no-op.

4. Lưu trữ Cấu hình (bảng Configuration)

N/A. Inventory không dùng bảng Configuration per-merchant cho cấu hình runtime (không có credential mã hóa, không có feature toggle per-merchant trong package này).

5. Boot Order

6. Trang liên quan

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