How bold-desk/live-chat-web-sdk works
Project type and purpose
• This is a lightweight, TypeScript-based npm SDK (a client‐side library) that wraps and exposes the BoldDesk Live Chat widget functionality to host web applications (React, Vue, Angular). Its sole purpose is to provide a smooth integration layer and full TS support, bundling the widget code and exposing a simple API.
a. SDK Source Module
• src/live-chat.ts: core wrapper that initializes the BoldDesk widget, exposes methods for showing the chat, setting visitor info, hooking into events, etc.
b. Build & Packaging Layer
• rollup.config.js + tsconfig.json: compile TS → ES5/ESNext, bundle into a single distributable .js file, generate type declarations, manage external dependencies.
c. Package Metadata
• package.json: describes entry points, dependencies, peerDependencies (e.g., framework adapters), and published bundle.
d. Host Application (Consumer)
• Any web app (React/Vue/Angular) that installs this SDK via npm/yarn, imports the module, and calls its API to embed the chat widget.
e. External BoldDesk Chat Service
• The remote BoldDesk backend (over WebSocket/HTTPS) that actually powers the chat sessions, stores transcripts, and manages agent routing.
Relationships & Data Flows
• The Host App imports the SDK bundle.
• At runtime, the SDK injects the chat widget’s JavaScript/CSS, initializes the connection to BoldDesk service.
• Data flows:
• Host App → SDK API calls (e.g., init, openWidget)
• SDK → BoldDesk service (session auth, message send/receive)
• BoldDesk service → SDK (incoming messages, events) → Host App callbacks
• Build‐time flows:
• src/ (TS) → Rollup → dist/sdk.bundle.js + .d.ts → npm registry
Key architectural patterns & principles
• Wrapper/Facade pattern: SDK provides a simplified facade over the raw widget API.
• Publish-Subscribe or Event Emitter: SDK likely exposes events (onMessage, onAgentJoined).
• Universal Module Definition: bundle configured to work in CJS/ESM/browser global.
• Strict typing: TS interfaces for configurables, responses, and events.
Technologies & frameworks
• TypeScript (tsconfig.json)
• Rollup.js (rollup.config.js) for bundling
• npm package system (package.json)
• BoldDesk REST/WebSocket APIs (external service)