@spilki/widget 0.1.0
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/README.md +99 -0
- package/dist/bootstrap.d.ts +2 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.es.js +616 -0
- package/dist/bootstrap.es.js.map +1 -0
- package/dist/bootstrap.umd.js +62 -0
- package/dist/bootstrap.umd.js.map +1 -0
- package/dist/core/jwt.d.ts +8 -0
- package/dist/core/jwt.d.ts.map +1 -0
- package/dist/core/state.d.ts +37 -0
- package/dist/core/state.d.ts.map +1 -0
- package/dist/core/transport.d.ts +40 -0
- package/dist/core/transport.d.ts.map +1 -0
- package/dist/core/utils.d.ts +27 -0
- package/dist/core/utils.d.ts.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types.d.ts +50 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/ui/bubble.d.ts +15 -0
- package/dist/ui/bubble.d.ts.map +1 -0
- package/dist/ui/panel.d.ts +38 -0
- package/dist/ui/panel.d.ts.map +1 -0
- package/dist/widget.es.js +619 -0
- package/dist/widget.es.js.map +1 -0
- package/dist/widget.umd.js +62 -0
- package/dist/widget.umd.js.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# @spilki/widget
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@spilki/widget)
|
|
4
|
+
[](#size-budget)
|
|
5
|
+
|
|
6
|
+
Embeddable chat widget that connects your website visitors with the Spilki assistant backend via a secure Web Widget channel.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- ✅ Zero runtime dependencies and <35 kB gzip UMD build
|
|
11
|
+
- ✅ Vanilla TypeScript UI with Shadow DOM isolation
|
|
12
|
+
- ✅ Automatic websocket with SSE / long-poll fallback
|
|
13
|
+
- ✅ JWT + origin validation handshake
|
|
14
|
+
- ✅ Local demo and mock backend for development
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pnpm add @spilki/widget
|
|
20
|
+
# or
|
|
21
|
+
npm install @spilki/widget
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### CDN (UMD)
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<script src="https://cdn.jsdelivr.net/npm/@spilki/widget/dist/widget.umd.js"
|
|
28
|
+
data-org="ori-bar"
|
|
29
|
+
data-assistant="main-bot"
|
|
30
|
+
data-token="<your-jwt>"></script>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### ESM
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { initSpilkiWidget } from "@spilki/widget";
|
|
37
|
+
|
|
38
|
+
initSpilkiWidget({
|
|
39
|
+
org: "ori-bar",
|
|
40
|
+
assistant: "main-bot",
|
|
41
|
+
token: "<your-jwt>"
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Options
|
|
46
|
+
|
|
47
|
+
| Option | Type | Default | Description |
|
|
48
|
+
| --- | --- | --- | --- |
|
|
49
|
+
| `org` | `string` | – | Spilki organisation identifier. |
|
|
50
|
+
| `assistant` | `string` | – | Assistant identifier. |
|
|
51
|
+
| `token` | `string?` | – | Signed JWT obtained from the admin UI or backend. |
|
|
52
|
+
| `apiBase` | `string?` | `https://api.spilki.ai` | Override API endpoint (useful for staging/local). |
|
|
53
|
+
| `position` | `"bottom-right" \| "bottom-left"` | `"bottom-right"` | Corner to anchor the bubble + panel. |
|
|
54
|
+
| `theme` | `"auto" \| "light" \| "dark"` | `"auto"` | Force light/dark or respect OS preference. |
|
|
55
|
+
| `color` | `string?` | `#6366f1` | Accent color for bubble + primary CTA. |
|
|
56
|
+
| `welcome` | `string?` | "Hi! I'm your assistant." | Greeting shown when no conversation exists. |
|
|
57
|
+
| `persist` | `boolean?` | `true` | Persist session + history in localStorage. |
|
|
58
|
+
| `allowedOriginsHint` | `string[]?` | – | List of origins expected to be in JWT allowlist. Logs warnings during misconfiguration. |
|
|
59
|
+
| `i18n` | `Partial<WidgetI18n>?` | – | Override UI strings (welcome, placeholder, sendLabel, typing, offline, title). |
|
|
60
|
+
| `hooks` | `Partial<WidgetHooks>?` | – | Telemetry callbacks for open/close/message/error/transport change. |
|
|
61
|
+
|
|
62
|
+
## Security
|
|
63
|
+
|
|
64
|
+
The widget never stores credentials. Provide a short-lived JWT (HS256) issued server-side with the following claims:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"organisation_id": "ori-bar",
|
|
69
|
+
"assistant_id": "main-bot",
|
|
70
|
+
"allowed_origins": ["https://yourdomain.com"],
|
|
71
|
+
"exp": 1760000000
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
During `POST /widget/connect` the widget sends `Origin` and the JWT for verification. Expired tokens are rejected client-side before any network call. Rotate tokens frequently and limit the allowed origins array to trusted domains only.
|
|
76
|
+
|
|
77
|
+
See [`apps/mock-server/openapi.yaml`](../apps/mock-server/openapi.yaml) for the full handshake specification.
|
|
78
|
+
|
|
79
|
+
## Size budget
|
|
80
|
+
|
|
81
|
+
The `scripts/size-check.cjs` script ensures the UMD build stays below 35 kB gzip. CI runs the check prior to publish.
|
|
82
|
+
|
|
83
|
+
## Browser support
|
|
84
|
+
|
|
85
|
+
- Last two Chrome, Edge, Firefox versions
|
|
86
|
+
- Safari 15+
|
|
87
|
+
|
|
88
|
+
## Local development
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pnpm install
|
|
92
|
+
pnpm -w dev # runs mock server + demo site
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Open [http://localhost:5174](http://localhost:5174) and use **Issue token** to obtain a development JWT. Messages are relayed via websocket by default; stop the websocket server to see SSE fallback.
|
|
96
|
+
|
|
97
|
+
## Publishing
|
|
98
|
+
|
|
99
|
+
The GitHub Actions workflow publishes on tags that match `v*`. Ensure `NPM_TOKEN` is configured in the repository secrets before tagging `v0.1.0` or later.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":""}
|