Registry / messaging / insite-subscriptions-server

insite-subscriptions-server

JSON →
library2.4.0jsnpmunverified

Server-side pub/sub layer for the inSite framework (v2.4.0). Defines publications (named data sources), subscription handles, and WebSocket integration for real-time updates. Supports two data modes: object (arbitrary data via custom fetch with manual change notification) and map (MongoDB collection with query/projection/sort that reacts to Change Streams and sends diff updates). Published weekly on npm. Key differentiators: tight integration with inSite ecosystem (insite-ws, insite-users-server-ws), low-level and WS entry points, MongoDB Change Stream support, diff-based incremental updates for map mode, TypeScript types included.

npm install insite-subscriptions-server
INSTALL
IMPORT
SIG · INSITE-SUBSCRIPTIO
I
insite-subscriptions-server
messagingjavascriptv2.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

publications
import { publications } from 'insite-subscriptions-server'
const publications = require('insite-subscriptions-server').publications
Package is ESM-only since v2. CommonJS require() will not work. 'publications' is a global Map instance.
Publication
import { Publication } from 'insite-subscriptions-server'
import { Publication } from 'insite-subscriptions-server/main'
No subpath export '/main' exists. Use default package path.
CollectionMapPublication
import { CollectionMapPublication } from 'insite-subscriptions-server'
import CollectionMapPublication from 'insite-subscriptions-server'
CollectionMapPublication is a named export, not default.
SubscriptionHandler
import { SubscriptionHandler } from 'insite-subscriptions-server/ws'
import { SubscriptionHandler } from 'insite-subscriptions-server'
SubscriptionHandler is only exported from the WS entry point (insite-subscriptions-server/ws). It is not available from the main entry.
type Projection
import type { Projection } from 'insite-subscriptions-server'
import { Projection } from 'insite-subscriptions-server'
Projection is a TypeScript type only, not a runtime value. Use 'import type' to avoid bundler issues.

Creates an object publication, subscribes to it, sets up a MongoDB-backed map publication with Change Stream updates, integrates with WebSocket server, and sends server-wide publish event.

import { Publication, CollectionMapPublication } from 'insite-subscriptions-server'; import { SubscriptionHandler } from 'insite-subscriptions-server/ws'; import { WatchedCollection } from 'insite-db'; import { WebSocketServer } from 'ws'; // Object publication const pub = new Publication('myPub', { fetch: (userId) => ({ user: userId, count: 42 }) }); setInterval(() => pub.changed('time-update'), 10000); // Subscription handle const handle = pub.subscribe({ args: ['user1'], handler: (data, reason) => console.log('Got', data, 'reason:', reason) }); // Map publication (requires insite-db) const collection = new WatchedCollection('items'); const mapPub = new CollectionMapPublication('itemsPub', { collection, query: { userId: 'user1' }, projection: { _id: 1, name: 1, price: 1 }, sort: { createdAt: -1 } }); // WS integration const wss = new WebSocketServer({ port: 8080 }); const handler = new SubscriptionHandler(wss, { authenticate: (ws, req) => ({ userId: 'user1' }) }); wss.on('connection', (ws, req) => handler.handleConnection(ws, req)); // Server-wide publish import { wss as globalWss } from 'insite-subscriptions-server/ws'; globalWss.publish('event', { message: 'Hello' });
Debug
Known issues
breakingPackage is ESM-only since v2.0.0; CommonJS require() will throw ERR_REQUIRE_ESM.
fix
Use import syntax (import/await import). If you must use CJS, downgrade to v1.x or use dynamic import().
affects: >=2.0.0
breakingSubpath exports changed in v2.0.0: '/ws' is now the only subpath for WebSocket integration. Previously '/users-server-ws' was separate.
fix
Use 'insite-subscriptions-server/ws' for all WebSocket-related imports. Remove imports from 'insite-subscriptions-server/users-server-ws'.
affects: >=2.0.0
breakingNode.js >=20.0.0 is required; older versions are unsupported.
fix
Update Node.js to 20+.
affects: >=2.0.0
deprecatedThe 'publications' global Map is deprecated in favor of using instance methods directly. It will be removed in v3.
fix
Avoid relying on 'publications' Map; instead keep references to created Publication instances.
affects: >=2.0.0
gotchaCollectionMapPublication requires a WatchedCollection from 'insite-db'. If the database connection is lost, Change Stream may silently stop producing updates.
fix
Implement reconnection logic for WatchedCollection and monitor Change Stream resume tokens.
affects: *
breakingTypeScript types are shipped but require 'strict' or 'esModuleInterop' in tsconfig for correct import resolution.
fix
Ensure tsconfig has "moduleResolution": "node" (or "bundler") and "esModuleInterop": true.
affects: >=2.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() on an ESM-only package (v2+).
fix
Change to import statement: import { Publication } from 'insite-subscriptions-server'
Cannot find module 'insite-subscriptions-server/ws'
Import path not recognized due to subpath exports misconfiguration or outdated Node.js.
fix
Update Node.js to >=20.0.0 and ensure package version is 2.x. Also verify tsconfig has proper moduleResolution.
TypeError: Publication is not a constructor
Default import instead of named import for Publication.
fix
Use named import: import { Publication } from 'insite-subscriptions-server'
Property 'publish' does not exist on type 'WebSocketServer'
Attempting to use wss.publish() on a plain WebSocketServer without insite-ws integration.
fix
Use the 'wss' exported from 'insite-subscriptions-server/ws' which extends WebSocketServer with publish().
Upgrade
Version history
2.4.0latest on npm
Audit
Dependencies
insite-dbrequiredProvides WatchedCollection for map mode publications
insite-wsoptionalRequired for WebSocket integration (entry point insite-subscriptions-server/ws)
insite-users-server-wsoptionalRequired for user-specific WebSocket middleware (entry point insite-subscriptions-server/ws)
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources