@dorsk/hmm 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/LICENSE +21 -0
- package/README.md +162 -2
- package/dist/Hmm.svelte +650 -0
- package/dist/Hmm.svelte.d.ts +11 -0
- package/dist/core.d.ts +33 -0
- package/dist/core.js +50 -0
- package/dist/draft.d.ts +12 -0
- package/dist/draft.js +44 -0
- package/dist/envelope.d.ts +103 -0
- package/dist/envelope.js +218 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +32 -0
- package/dist/inspect.d.ts +4 -0
- package/dist/inspect.js +75 -0
- package/dist/labels.d.ts +36 -0
- package/dist/labels.js +35 -0
- package/dist/picker.d.ts +2 -0
- package/dist/picker.js +4 -0
- package/dist/redact.d.ts +5 -0
- package/dist/redact.js +64 -0
- package/dist/shot.d.ts +10 -0
- package/dist/shot.js +61 -0
- package/dist/transport.d.ts +11 -0
- package/dist/transport.js +71 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/package.json +82 -5
- package/schema/envelope.v1.json +163 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dorsk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,163 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dorsk/hmm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A feedback panel for Svelte 5 apps built on [tsumikit](https://github.com/DorskFR/tsumikit). The
|
|
4
|
+
user opens "Send feedback", selects elements on the page, comments on them, adds screenshots,
|
|
5
|
+
reviews exactly what will be sent, and sends it to an endpoint you own.
|
|
6
|
+
|
|
7
|
+
The panel is made of tsumikit components (`Card`, `Button`, `Textarea`, `SegmentedControl`, …), so
|
|
8
|
+
it has no palette, font or control shapes of its own: it looks like the app it is in and follows
|
|
9
|
+
its theme.
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @dorsk/hmm
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`svelte` (^5) and `@dorsk/tsumikit` (>=0.82.0 <1) are peer dependencies: the panel is rendered by
|
|
20
|
+
the copies your app already has. The app must load tsumikit's stylesheet, as any tsumikit app does.
|
|
21
|
+
|
|
22
|
+
```svelte
|
|
23
|
+
<script lang="ts">
|
|
24
|
+
import { Hmm } from '@dorsk/hmm';
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<Hmm
|
|
28
|
+
projectKey="my-app"
|
|
29
|
+
endpoint="https://feedback.example.com"
|
|
30
|
+
context={() => ({ appVersion: '1.4.2', route: currentRouteName() })}
|
|
31
|
+
/>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Render it once, near the root of the app. To open it from your own button, hide the floating one
|
|
35
|
+
and bind `open`:
|
|
36
|
+
|
|
37
|
+
```svelte
|
|
38
|
+
<Button onclick={() => (feedbackOpen = true)}>Feedback</Button>
|
|
39
|
+
<Hmm projectKey="my-app" endpoint="…" launcher={false} bind:open={feedbackOpen} />
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Outside a Svelte tree, `init` mounts the same component on `<body>`:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { init } from '@dorsk/hmm';
|
|
46
|
+
|
|
47
|
+
const feedback = init({ projectKey: 'my-app', endpoint: 'https://feedback.example.com' });
|
|
48
|
+
feedback.open();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`init` returns `{ open(), close(), destroy(), isOpen }`. Calling it again replaces the previous
|
|
52
|
+
instance.
|
|
53
|
+
|
|
54
|
+
## Props
|
|
55
|
+
|
|
56
|
+
`init` takes the same fields as an object.
|
|
57
|
+
|
|
58
|
+
| Prop | Type | Purpose |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| `projectKey` | `string` | Required. Public identifier of the project, sent with every report. Letters, digits, `.`, `_` and `-`. |
|
|
61
|
+
| `endpoint` | `string` | Base URL of the ingest server. Required unless `transport` is set. |
|
|
62
|
+
| `transport` | `(envelope) => Promise<void>` | Replaces the HTTP POST, for hosts that relay reports through their own backend. Throw an error with `retryable: false` to mark a permanent failure. |
|
|
63
|
+
| `context` | `() => object` | Extra data added to every report. May be async. |
|
|
64
|
+
| `beforeSend` | `(envelope) => envelope \| null` | Change a report, or drop it by returning `null`. Runs before the review, so the user sees the result. |
|
|
65
|
+
| `launcher` | `boolean` | `false` hides the floating button. |
|
|
66
|
+
| `position` | `'bottom-right' \| 'bottom-left'` | Corner for the button and the panel. |
|
|
67
|
+
| `labels` | `Partial<Labels>` | Override any text. The defaults are exported as `LABELS`. |
|
|
68
|
+
| `onSent` | `(envelope) => void` | Called after a report is delivered. |
|
|
69
|
+
| `open` | `boolean` | Bindable. Whether the panel is shown. |
|
|
70
|
+
|
|
71
|
+
## Styling
|
|
72
|
+
|
|
73
|
+
Colours, spacing, radii and type come from the tsumikit tokens in scope where `Hmm` is rendered, so
|
|
74
|
+
a `data-theme` switch or a token override on an ancestor applies to the panel too. The panel sits
|
|
75
|
+
at `--z-toast`; set `--hmm-z-index` on an ancestor to move it.
|
|
76
|
+
|
|
77
|
+
## What is sent
|
|
78
|
+
|
|
79
|
+
One JSON document, the envelope, described by
|
|
80
|
+
[`schema/envelope.v1.json`](schema/envelope.v1.json) and by the `Envelope` type.
|
|
81
|
+
|
|
82
|
+
```jsonc
|
|
83
|
+
{
|
|
84
|
+
"v": 1,
|
|
85
|
+
"id": "b6f0c9a2-…",
|
|
86
|
+
"kind": "feedback", // "error" and "alert" are reserved for non-widget clients
|
|
87
|
+
"category": "idea", // idea | problem | question | other
|
|
88
|
+
"project": "my-app",
|
|
89
|
+
"createdAt": "2026-11-12T08:00:00.000Z",
|
|
90
|
+
"client": { "name": "@dorsk/hmm", "version": "0.1.0" },
|
|
91
|
+
"page": { "url": "…", "title": "…", "viewport": { "width": 1280, "height": 800 }, "userAgent": "…", "language": "en" },
|
|
92
|
+
"context": { "appVersion": "1.4.2" },
|
|
93
|
+
"comment": "What about a dark mode?",
|
|
94
|
+
"items": [
|
|
95
|
+
{ "id": "…", "type": "element", "url": "…", "comment": "…", "target": { "selector": "#buy", "tag": "button", "text": "…", "html": "…", "attrs": {}, "rect": {} }, "attachment": "…" },
|
|
96
|
+
{ "id": "…", "type": "screenshot", "url": "…", "comment": "", "attachment": "…" }
|
|
97
|
+
],
|
|
98
|
+
"attachments": [{ "id": "…", "mime": "image/png", "width": 1280, "height": 800, "data": "<base64>" }]
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Limits: 20 items, 10 attachments, about 2 MB per image, 5,000 characters per comment, 16,000
|
|
103
|
+
characters of serialised context. They are exported as `LIMITS`.
|
|
104
|
+
|
|
105
|
+
## HTTP contract
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
POST <endpoint>/v1/reports
|
|
109
|
+
content-type: application/json
|
|
110
|
+
x-hmm-key: <projectKey>
|
|
111
|
+
|
|
112
|
+
<envelope>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
- Any `2xx` answer counts as delivered.
|
|
116
|
+
- `408`, `429`, `5xx` and network errors are retried: the report is stored in `localStorage` and
|
|
117
|
+
sent on the next page load or when the browser comes back online. At most five reports wait.
|
|
118
|
+
- Any other `4xx` is a permanent failure. The user sees an error and keeps the draft.
|
|
119
|
+
- The server must answer the CORS preflight and allow the `content-type` and `x-hmm-key` headers.
|
|
120
|
+
- No cookies or credentials are sent.
|
|
121
|
+
|
|
122
|
+
Servers can reuse the validator without pulling in any DOM code:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { validateEnvelope } from '@dorsk/hmm/envelope';
|
|
126
|
+
|
|
127
|
+
const result = validateEnvelope(JSON.parse(body));
|
|
128
|
+
if (!result.ok) return reject(result.errors);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Treat every field as untrusted input. The validator checks structure and size only; it does not
|
|
132
|
+
make the text safe to render or to hand to an agent, and it does not decode the images.
|
|
133
|
+
|
|
134
|
+
## Privacy
|
|
135
|
+
|
|
136
|
+
- Nothing leaves the page until the user presses Send on the review screen, which lists every
|
|
137
|
+
field and image, with the raw JSON one click away.
|
|
138
|
+
- Before the review, all text is scrubbed of JWTs, bearer tokens, common API key formats, private
|
|
139
|
+
keys and `password=`-style pairs. URLs lose their credentials and secret-looking query
|
|
140
|
+
parameters. `redactText`, `redactUrl` and `redactEnvelope` are exported.
|
|
141
|
+
- The HTML of an element is not recorded when it is, or contains, a password field.
|
|
142
|
+
- Screenshots cannot be scrubbed. They are shown in the review and each one can be removed.
|
|
143
|
+
|
|
144
|
+
## Limitations
|
|
145
|
+
|
|
146
|
+
- Svelte 5 and tsumikit only. A page without tsumikit's stylesheet renders the panel unstyled.
|
|
147
|
+
- An open `<dialog>` modal makes the rest of the page inert, the panel included.
|
|
148
|
+
- Screenshots are rendered from the DOM, not captured from the screen. Cross-origin images without
|
|
149
|
+
CORS, `<video>`, and canvases tainted by cross-origin content come out blank.
|
|
150
|
+
- A strict Content Security Policy must allow `data:` in `img-src` for the thumbnails.
|
|
151
|
+
- Elements inside iframes or closed shadow roots cannot be selected.
|
|
152
|
+
|
|
153
|
+
## Development
|
|
154
|
+
|
|
155
|
+
```sh
|
|
156
|
+
npm install
|
|
157
|
+
npm run demo # demo shop on http://localhost:4188 with an in-memory receiver
|
|
158
|
+
npm test # unit tests and Chromium browser tests
|
|
159
|
+
npm run lint # biome and tsumikit-lint
|
|
160
|
+
npm run check # svelte-check
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
MIT licensed.
|