@ownhelp/widget 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
- "name": "@ownhelp/widget",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@ownhelp/widget",
3
+ "version": "0.1.1",
4
+ "type": "module",
5
+ "description": "Embeddable chat widget for a self-hosted, multi-tenant support gateway. Use it as a <script> tag or as a React component.",
6
+ "license": "MIT",
7
+ "author": "Juan Cruz",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/ownhelp/OwnHelp.git",
11
+ "directory": "widget"
12
+ },
13
+ "homepage": "https://github.com/ownhelp/OwnHelp/tree/main/widget#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/ownhelp/OwnHelp/issues"
16
+ },
17
+ "keywords": ["chat", "widget", "support", "customer-support", "react", "sse", "self-hosted"],
18
+ "main": "./dist/lib/index.js",
19
+ "module": "./dist/lib/index.js",
20
+ "types": "./types/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./types/index.d.ts",
24
+ "import": "./dist/lib/index.js"
25
+ },
26
+ "./widget.js": "./dist/widget.js",
27
+ "./package.json": "./package.json"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "types",
32
+ "README.md",
33
+ "LICENSE",
34
+ "API_CONTRACT.md"
35
+ ],
36
+ "sideEffects": false,
37
+ "scripts": {
38
+ "dev": "vite",
39
+ "build": "vite build && vite build --mode lib",
40
+ "build:embed": "vite build",
41
+ "build:lib": "vite build --mode lib",
42
+ "mock": "node mock/mock_gateway.js",
43
+ "test": "node --test tests/*.test.js",
44
+ "prepublishOnly": "npm test && npm run build"
45
+ },
46
+ "peerDependencies": {
47
+ "react": ">=18",
48
+ "react-dom": ">=18"
49
+ },
50
+ "devDependencies": {
51
+ "@vitejs/plugin-react": "^5.0.0",
52
+ "cors": "^2.8.5",
53
+ "express": "^4.21.2",
54
+ "react": "19.3.0",
55
+ "react-dom": "19.3.0",
56
+ "vite": "^7.0.0"
57
+ },
58
+ "publishConfig": {
59
+ "access": "public"
60
+ }
61
+ }
@@ -0,0 +1,67 @@
1
+ import type { ComponentType } from "react";
2
+
3
+ export interface ChatWidgetProps {
4
+ /** Base URL of the gateway, e.g. "https://support.example.com". The widget posts to `{apiUrl}/api/chat`. */
5
+ apiUrl: string;
6
+ /** Tenant the visitor is chatting with. */
7
+ tenantId: string;
8
+ title?: string;
9
+ greeting?: string;
10
+ position?: "left" | "right";
11
+ /** Any CSS colour, e.g. "#0b6e4f". */
12
+ accentColor?: string;
13
+ defaultOpen?: boolean;
14
+ /** Override `fetch` (tests, custom auth proxies). */
15
+ fetchImpl?: typeof fetch;
16
+ }
17
+
18
+ export const ChatWidget: ComponentType<ChatWidgetProps>;
19
+
20
+ /** Error thrown by `streamChat` and `submitContact`. Show visitors a fixed message, not `message`. */
21
+ export class ChatError extends Error {
22
+ /** Gateway code (e.g. "rate_limited") or client code ("network_error", "timeout", "aborted", ...). */
23
+ code: string;
24
+ /** HTTP status, when the error came from a response. */
25
+ status?: number;
26
+ /** Seconds from the `Retry-After` header of a 429, when present. */
27
+ retryAfterSec?: number;
28
+ constructor(code: string, message: string, status?: number, retryAfterSec?: number);
29
+ }
30
+
31
+ export interface StreamChatOptions {
32
+ apiUrl: string;
33
+ tenantId: string;
34
+ message: string;
35
+ sessionId: string;
36
+ signal?: AbortSignal;
37
+ onToken?: (text: string) => void;
38
+ idleTimeoutMs?: number;
39
+ fetchImpl?: typeof fetch;
40
+ }
41
+
42
+ export interface FollowUp {
43
+ available: true;
44
+ token: string;
45
+ contactEmail?: string;
46
+ contactPhone?: string;
47
+ }
48
+ /** Sends one message and streams the reply; `onToken` receives text deltas. Rejects with `ChatError`. */
49
+ export function streamChat(options: StreamChatOptions): Promise<{ answer: string; sessionId: string; followUp?: FollowUp }>;
50
+ export interface ContactOptions {
51
+ apiUrl: string;
52
+ tenantId: string;
53
+ sessionId: string;
54
+ followUpToken: string;
55
+ name: string;
56
+ email: string;
57
+ signal?: AbortSignal;
58
+ fetchImpl?: typeof fetch;
59
+ }
60
+ /** Saves visitor contact details for staff follow-up (persisted, not emailed). */
61
+ export function submitContact(options: ContactOptions): Promise<{ status: "saved" }>;
62
+
63
+ /** Stable per-tenant visitor session id (localStorage, in-memory fallback). */
64
+ export function getSessionId(tenantId: string, storage?: Pick<Storage, "getItem" | "setItem"> | null): string;
65
+
66
+ /** Creates and persists a fresh session id for the tenant (used by "New chat"). */
67
+ export function newSessionId(tenantId: string, storage?: Pick<Storage, "getItem" | "setItem"> | null): string;