splp-nodejs
v1.0.2
Published
SPLP Node.js - Government Service Integration with Kafka, Encryption & Tracing
Downloads
293
Maintainers
Readme
splp-nodejs
SPLP Node.js is a Node.js library for Government Service Integration. It provides robust tools for working with Kafka, payload encryption/decryption, request tracing (via OpenTelemetry), and built-in error handling like Circuit Breakers and Retry Managers.
Features
- Kafka Wrapper: Easy connection, consuming, and producing to Kafka.
- Payload Encryption: Highly secure
JsonEncryptorto easily encrypt and decrypt JSON data for communication. - Tracing: Built-in OpenTelemetry tracing utilities (
initTracing,getTracer,withSpan, etc.). - Security: Prevent XSS and Injection, sanitize objects, validate inputs securely.
- Resilience: Integrated
CircuitBreakerandRetryManagerfor robust microservices. - Programmatic Config:
configure()API to set all options in code — no.envfile required.
Installation
npm install splp-nodejsBasic Usage
Importing
import {
configure,
KafkaWrapper,
JsonEncryptor,
initTracing,
CircuitBreaker,
} from 'splp-nodejs';Programmatic Configuration
Call configure() once at startup before creating any clients. All fields are optional — omitted values fall back to environment variables or built-in defaults.
import { configure } from 'splp-nodejs';
configure({
kafka: {
hosts: 'splp-kafka.layanan.go.id:443',
clientId: 'my-service',
groupId: 'my-consumer-group',
ssl: {
enabled: true,
caPath: './certs/kafka/ca.pem',
certPath: './certs/kafka/client.crt',
keyPath: './certs/kafka/client.key',
},
},
seal: {
apiUrl: 'https://seal.example.com:2798',
publicKeys: ['-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----'],
},
tracing: {
serviceName: 'my-service',
endpoint: 'http://tempo.example.com/v1/traces',
enabled: true,
},
processing: {
maxConcurrentMessages: 10,
instanceId: 'node-1',
},
});configure() can be called multiple times — each call is deep-merged into the existing runtime config. Environment variables remain as a fallback when a field is not set programmatically.
Configuration Options
| Group | Field | Env var fallback | Default |
|---|---|---|---|
| kafka | hosts | KAFKA_HOSTS | splp-kafka.layanan.go.id:443 |
| kafka | clientId | KAFKA_CLIENT_ID | splp-service |
| kafka | groupId | KAFKA_GROUP_ID | splp-consumer-group |
| kafka | inboxTopic | KAFKA_INBOX_TOPIC | splp-inbox |
| kafka.ssl | enabled | KAFKA_SSL_ENABLED | true |
| kafka.ssl | caPath | KAFKA_CA_PATH | certs/kafka/ca.pem |
| seal | apiUrl | SEAL_API_URL | https://192.168.112.153:2798 |
| seal | timeout | SEAL_API_TIMEOUT | 30000 |
| seal | publicKeys | — | built-in key |
| seal | enableLogging | ENABLE_ENCRYPTION_LOGGING | false |
| tracing | serviceName | SERVICE_NAME | service_testing |
| tracing | endpoint | TEMPO_ENDPOINT | SPLP Tempo endpoint |
| tracing | enabled | TRACING_ENABLED | true |
| processing | maxConcurrentMessages | MAX_CONCURRENT_MESSAGES | 25 |
| processing | instanceId | INSTANCE_ID | random |
| processing | verboseLogs | VERBOSE_LOGS | false |
License
MIT
