Skip to content

API Events

@nx/search is a CDC consumer. It subscribes to 18 Debezium topics and produces only to a dead-letter queue. No outbound business events, no WebSocket, no BullMQ. Topic naming follows Debezium {prefix}.{schema}.{table} with prefix nx.seller.

1. Inbound — Kafka (CDC)

All topics defined in SearchCollections.CDC (src/common/kafka-topics.ts); the consumer subscribes to ALL_CDC_TOPICS. Handler is CDCService.handleBatch() for every topic.

Direct document sources (mapped in TableToCollectionMap)

TopicSchema.Table→ Collection
nx.seller.public.Organizerpublic.Organizerorganizers
nx.seller.public.Merchantpublic.Merchantmerchants
nx.seller.public.Categorypublic.Categorycategories
nx.seller.public.Devicepublic.Devicedevices
nx.seller.public.SaleChannelpublic.SaleChannelsale-channels
nx.seller.public.Productpublic.Productproducts
nx.seller.public.ProductInfopublic.ProductInfoproducts (i18n partial)
nx.seller.public.ProductVariantpublic.ProductVariantproduct-variants
nx.seller.inventory.InventoryStockinventory.InventoryStockinventories

Cascade-only sources (not direct doc sources — fan out via CDCCascadeService)

TopicSchema.TableRecomputes
nx.seller.public.ProductCategorypublic.ProductCategoryproducts + product-variants categoryIds
nx.seller.public.MetaLinkpublic.MetaLinkproduct → variant productMetaLinks; variant metaLinks
nx.seller.pricing.FareSetpricing.FareSetvariant fareSet + defaultPrice
nx.seller.pricing.Farepricing.Farevariant fareSet + defaultPrice
nx.seller.public.ProductBundlerpublic.ProductBundlervariant comboItems
nx.seller.inventory.InventoryIteminventory.InventoryIteminventories item group
nx.seller.inventory.InventoryLocationinventory.InventoryLocationinventories location group
nx.seller.inventory.InventoryIdentifierinventory.InventoryIdentifierinventories identifiers[]
nx.seller.inventory.Materialinventory.Materialinventories item (Material-typed)

Debezium op codes

OpMeaningAction
ccreateupsert doc
uupdateupsert doc
ddeletedelete doc
rsnapshot readupsert doc (initial load)

Any op where the mapper returns null (soft-deleted) becomes a Typesense delete.

2. Outbound — Kafka

TopicTriggerConsumersPayload
nx.seller.cdc.dlq (default, override via APP_ENV_CDC_DLQ_TOPIC)A CDC message fails processing after retriesOps / manual replay toolingOriginal CDC message + failure metadata

3. Inbound — BullMQ

N/A — no BullMQ consumer. (The selection report's embedding-queue design is a future option, not implemented.)

4. Outbound — BullMQ

N/A — no BullMQ producer.

5. WebSocket Emissions

N/A — the library emits no WebSocket events. Real-time UI updates are the host service's concern.

6. Payload Schemas

CDC payloads are Debezium envelopes, decoded with avsc. Search does not own these schemas — they mirror the source tables. Shape (abridged):

ts
// Debezium change event (Avro-decoded)
interface DebeziumEnvelope<TBefore, TAfter> {
  op: 'c' | 'u' | 'd' | 'r';
  before: TBefore | null;
  after: TAfter | null;
  source: {
    schema: string;     // public | pricing | inventory
    table: string;      // e.g. "Product"
    lsn: number;        // → guards out-of-order replays (SearchVersionFields.SOURCE_LSN)
    ts_ms: number;
  };
}

Search query params (consumer-facing, ISearchParams):

ts
interface ISearchParams {
  q?: string;                    // default '*'
  limit?: number;                // default 10, max 250
  offset?: number;
  where?: unknown;               // Ignis-style → filter_by
  order?: string | string[];     // "createdAt DESC" → sort_by
  include?: IIncludeSpec[];      // relation hydration / native join
  useCache?: boolean;
  cacheTtl?: number;
  disableSemanticSearch?: boolean; // drop embedding from query_by (strict keyword)
}

7. Idempotency & Ordering

Topic classDeliveryOrderingRecovery
All CDC topicsat-least-once (auto-commit off; commit after batch)per-key via Debezium; LSN guard rejects stale eventsre-read uncommitted offsets after restart / circuit-breaker close
DLQfire-and-forgetmanual replay
GuardFieldEffect
LSNsource_lsn (SearchVersionFields.SOURCE_LSN)Skip event if its LSN ≤ stored doc LSN
Tombstonedeleted_at (SearchVersionFields.DELETED_AT)Compared to keep deletes from being undone by stale upserts

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