@lifelands/callcenter (0.1.0)
Installation
@lifelands:registry=https://git.lifelands.ir/api/packages/lifelands/npm/npm install @lifelands/callcenter@0.1.0"@lifelands/callcenter": "0.1.0"About this package
@lifelands/callcenter
Typed HTTP and session event client for Callcenter. Every service uses the shared
CALLCENTER_API_KEY and its registered CALLCENTER_CONSUMER_ID.
HTTP client
import { CallcenterHttpClient } from '@lifelands/callcenter';
const client = new CallcenterHttpClient({
baseUrl: process.env.CALLCENTER_URL!,
apiKey: process.env.CALLCENTER_API_KEY!,
consumerId: process.env.CALLCENTER_CONSUMER_ID!,
});
const session = await client.createSession(
{ type: 'private', externalReference: 'booking-42' },
'booking-42:create-session',
);
The client exposes typed session create/list/detail, token, participant grant, leave, mute, remove, screen-share stop, message, lock and end methods. Mutating operations accept an idempotency key. API and broker credentials must come from the consumer's secret manager; never pass either credential to a browser or mobile client.
Durable event subscriber
The consumer owns its inbox schema and implementation. Persist each envelope
idempotently by eventId before returning from persist. The adapter's
dispatchPending implementation must claim and dispatch events in ascending
sequence for each sessionId, mark completion only after all handlers
succeed, and leave unknown event versions in an unsupported state. A database
failure rejects persist, so the broker delivery stays unacknowledged and is
redelivered. Handler effects should be idempotent because a process can stop
after an effect and before the consumer marks it complete.
import {
DurableSessionEventSubscriber,
RabbitMqSubscriberTransport,
SessionCreated,
SessionEventName,
} from '@lifelands/callcenter';
import { backendEventInbox } from './event-inbox.js';
const events = new DurableSessionEventSubscriber({
consumerId: process.env.CALLCENTER_CONSUMER_ID!,
transport: new RabbitMqSubscriberTransport(
process.env.CALLCENTER_EVENTS_URL!,
process.env.CALLCENTER_CONSUMER_ID!,
),
inbox: backendEventInbox,
onUnsupported: (event) => alertUnsupportedEvent(event),
onDispatchError: (error) => logInboxFailure(error),
});
events.subscribe(SessionEventName.SessionCreated, async (event) => {
await recordSessionCreated(event.sessionId, event.data.type);
});
const stop = await events.start();
SessionEventName.SessionCreated and the named constant SessionCreated both
represent session.created. subscribe also returns an async iterator when
called without a handler. Both styles can be used on the same subscriber; each
event is delivered in sequence to the matching handlers and iterator:
import {
DurableSessionEventSubscriber,
ParticipantJoined,
} from '@lifelands/callcenter';
events.subscribe(ParticipantJoined, async (event) => {
await recordJoin(event.data.userId, event.sessionId);
});
for await (const event of events.subscribe(ParticipantJoined)) {
await updatePresence(event.data.userId, event.sessionId);
}
The provisioned queue is durable and uses RabbitMQ single-active-consumer so
multiple instances of one service share one ordered consumer stream with
failover. The package does not declare exchanges, queues or bindings; consumer
credentials can only read the pre-provisioned callcenter.<consumerId> queue.
To add a service, register its consumer ID in session_consumers, then call
POST /v1/admin/consumers/refresh with the shared API key. Configure the new
service with that ID; no Callcenter source change is needed.
Unknown event versions/types are persisted, alerted, and not passed to typed handlers. They can be replayed after the consumer adds support. Malformed envelopes are rejected to the configured broker dead-letter exchange.
Build and install locally
npm run build
npm pack --workspace @lifelands/callcenter --pack-destination ./artifacts
The package publishes to the LifeLands Gitea npm registry. Publishing needs a package write token supplied at release time; no registry credential belongs in this repository.
Dependencies
Dependencies
| ID | Version |
|---|---|
| amqplib | ^2.3.3 |
| joi | ^18.3.2 |