@softistx/pulsarix-widget 0.0.0-stage → 0.3.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 +266 -2
- package/dist/index.js +98 -0
- package/dist/types/config.d.ts +62 -0
- package/dist/types/element.d.ts +69 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +65 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Steve Tsala
|
|
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,267 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @softistx/pulsarix-widget
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An intake widget that lets your users report a problem to your pulsarix project:
|
|
4
|
+
a title, a description and an optional e-mail, with no account. It renders inside a
|
|
5
|
+
Shadow DOM, so your page's styles and the widget's never touch.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
The package is published on npmjs (public), no registry setup needed:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @softistx/pulsarix-widget
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The `mount()` route below is for apps that install the package. Third-party sites use the
|
|
16
|
+
script tag served by the pulsarix host and install nothing. The package has no dependencies and
|
|
17
|
+
ships its own types. The bundle is about 1 MB un-gzipped (about 270 KB gzipped): React is inlined
|
|
18
|
+
and isolated in the widget's shadow root, so it never clashes with the page's own React.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Script tag
|
|
23
|
+
|
|
24
|
+
```html
|
|
25
|
+
<script src="https://<pulsarix-host>/widget/v1/loader.js" async
|
|
26
|
+
data-project-key="pk_live_xxx"></script>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Attributes (all optional but the key): `data-locale` (`en` default, `fr`), `data-theme`
|
|
30
|
+
(`light`, `dark`, `auto` default), `data-position` (`bottom-right` default, `bottom-left`),
|
|
31
|
+
`data-accent-color` (a hex seed for the theme; without it the widget wears material's built-in `lavande` theme), `data-api-base` (the
|
|
32
|
+
pulsarix origin; defaults to the host that served the loader), `data-launcher="false"` (no
|
|
33
|
+
floating button; open it with `window.PulsarixWidget.open()`), `data-mask-text="true"` (the
|
|
34
|
+
"Mask the text on the page" screenshot option starts on; see "Screenshots"), `data-attachments="false"`
|
|
35
|
+
(no screenshot and no file controls; see "Attached files"), `data-privacy-url` (an http(s) link to your
|
|
36
|
+
own privacy page, shown after the privacy line), `data-prefill-email` and `data-prefill-title` (starting
|
|
37
|
+
values of the form), `data-metadata` (a JSON object of strings stored with each report: at most 20 entries,
|
|
38
|
+
keys of 64 characters, values of 512, 2 KB in all; the rest is dropped).
|
|
39
|
+
|
|
40
|
+
`data-identity` (the signed token of the signed-in user, see "Identified reporters"), changed later with
|
|
41
|
+
`PulsarixWidget.identify(token)` and `PulsarixWidget.identify(null)` at sign-out.
|
|
42
|
+
|
|
43
|
+
In script, the same are `identity`, `privacyUrl`, `prefill: { email, title }` and `metadata: { plan: "pro" }`.
|
|
44
|
+
What the reporter typed is kept when the dialog is closed by accident (a click outside, Escape) and comes
|
|
45
|
+
back at the next opening; a sent report clears it.
|
|
46
|
+
|
|
47
|
+
Without the attributes, drive it from script. Calls made before the bundle has loaded are queued, and a second `init` while loaded is ignored:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
PulsarixWidget.init({ projectKey: "pk_live_xxx", locale: "fr" });
|
|
51
|
+
const off = PulsarixWidget.on("pulsarix:submit", (e) => console.log(e.detail.reportId));
|
|
52
|
+
PulsarixWidget.open();
|
|
53
|
+
// later
|
|
54
|
+
off();
|
|
55
|
+
PulsarixWidget.destroy();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### npm
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { mount } from "@softistx/pulsarix-widget";
|
|
62
|
+
|
|
63
|
+
const widget = mount({
|
|
64
|
+
projectKey: "pk_live_xxx",
|
|
65
|
+
apiBase: "https://<pulsarix-host>", // required on the npm route
|
|
66
|
+
accentColor: "#0b7a75",
|
|
67
|
+
});
|
|
68
|
+
widget.on("pulsarix:open", () => console.log("opened"));
|
|
69
|
+
widget.open();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`apiBase` is required here: only the script tag can infer it (from where the loader was
|
|
73
|
+
served). Without it the form reports a configuration error instead of sending.
|
|
74
|
+
|
|
75
|
+
The module is browser-only. Importing it registers `<pulsarix-widget>` and needs `HTMLElement`
|
|
76
|
+
and `customElements`, so in an SSR framework import it on the client only:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const { mount } = await import("@softistx/pulsarix-widget"); // inside an effect, never at module top level
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
One widget per page: a second `mount` while one is attached warns and returns the first
|
|
83
|
+
handle. To mount again, destroy first:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
widget.destroy();
|
|
87
|
+
const next = mount({ projectKey: "pk_live_xxx", apiBase: "https://<pulsarix-host>", locale: "fr" });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
A script-tag loader and an npm import are two separate instances: use one route per page.
|
|
91
|
+
|
|
92
|
+
### Exports
|
|
93
|
+
|
|
94
|
+
`mount`, `defineWidget` (registers the element; `mount` calls it), `PulsarixWidgetElement`,
|
|
95
|
+
`TAG_NAME` (`"pulsarix-widget"`), and the types `MountOptions`,
|
|
96
|
+
`WidgetHandle`, `WidgetEvent`, `WidgetConfig`, `Locale`, `Position`, `ThemeMode`.
|
|
97
|
+
|
|
98
|
+
| `MountOptions` | Type | Default |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| `projectKey` | `string` | required; missing reports `pulsarix:error` `config` |
|
|
101
|
+
| `apiBase` | `string` | none; required on the npm route |
|
|
102
|
+
| `locale` | `"en" \| "fr"` | `"en"` |
|
|
103
|
+
| `theme` | `"light" \| "dark" \| "auto"` | `"auto"` |
|
|
104
|
+
| `position` | `"bottom-right" \| "bottom-left"` | `"bottom-right"` |
|
|
105
|
+
| `accentColor` | hex string | none: the built-in `lavande` theme |
|
|
106
|
+
| `launcher` | `boolean` | `true` (`false` hides the floating button) |
|
|
107
|
+
| `identity` | `string \| null` | none: today's form only (see "Identified reporters") |
|
|
108
|
+
| `target` | `Element` | `document.body` |
|
|
109
|
+
|
|
110
|
+
`WidgetHandle`: `open()`, `close()`, `destroy()`, `identify(token \| null)`, `on(name, callback)` (returns the function that
|
|
111
|
+
unsubscribes) and `element`, the `<pulsarix-widget>` (`element.isOpen`, `element.config`).
|
|
112
|
+
|
|
113
|
+
## The report form
|
|
114
|
+
|
|
115
|
+
The launcher opens a dialog with a title, a description and an optional e-mail. With an e-mail,
|
|
116
|
+
the reporter is mailed a link to follow the report. The dialog traps focus, closes on Escape
|
|
117
|
+
and returns focus to the launcher (or to whatever opened it).
|
|
118
|
+
|
|
119
|
+
- The form posts the persisted `submitClientReport` operation to `<apiBase>/public/graphql`.
|
|
120
|
+
The script tag fills `apiBase` with the origin that served the loader; override it with
|
|
121
|
+
`data-api-base` (or `apiBase` in `init` / `mount`, `api-base` on the element). Without one
|
|
122
|
+
(an npm `mount` that gives none), the form reports a configuration error instead of sending.
|
|
123
|
+
- The project key must allow the page's origin (plain `http` only on `localhost`). A form sent
|
|
124
|
+
faster than 3 seconds after it opened waits out the difference, because the API refuses it.
|
|
125
|
+
- Failures are shown in the dialog and the text is kept: the service busy (503), a rejected key
|
|
126
|
+
(404, or a readable 403: sending stops), a rate limit (429, with the wait), a refused report
|
|
127
|
+
(400), a network failure, a missing key or base. A page whose origin the key does not allow
|
|
128
|
+
gets an answer without CORS headers, which the browser hides from the widget: it shows as a
|
|
129
|
+
network failure (`pulsarix:error` with `network`), and the text tells the reader to ask the
|
|
130
|
+
site owner whether reports are enabled there.
|
|
131
|
+
- Locales: English (default) and French, from `locale`. The page address (origin and path only,
|
|
132
|
+
never the query string or the fragment), the browser and the e-mail (if given) are sent with
|
|
133
|
+
the report; the form says so.
|
|
134
|
+
|
|
135
|
+
## Identified reporters
|
|
136
|
+
|
|
137
|
+
Give the widget the token your server signed for the signed-in user (`data-identity`,
|
|
138
|
+
`identity` in `init` / `mount`, or `PulsarixWidget.identify(token)` after sign-in; call
|
|
139
|
+
`identify(null)` at sign-out). The secret that signs the token stays on your server and never
|
|
140
|
+
reaches the browser; the widget only sends the token, in the `x-pulsarix-identity` header, and
|
|
141
|
+
never in a URL. A malformed token is ignored. A token given with `identify()` or `mount({ identity })`
|
|
142
|
+
is kept in the widget's memory and is not written to the page; a token in `data-identity` is an
|
|
143
|
+
attribute of the element, so it is visible in the DOM (prefer `identify()` when that matters).
|
|
144
|
+
|
|
145
|
+
- Without a token the dialog is today's form, with no tabs.
|
|
146
|
+
- With one, the dialog has two tabs, New request and My requests. My requests is one list with
|
|
147
|
+
filter chips and their counts (Open by default, Resolved, Declined, All); requests with
|
|
148
|
+
unread replies come first, and the list is read again each time the dialog opens.
|
|
149
|
+
- The launcher and the My requests tab show the unread count.
|
|
150
|
+
- Opening a request shows its thread: the original message, then the replies of the team (plain
|
|
151
|
+
text, with their file names). The reporter can reply, with up to three files sent the same way as
|
|
152
|
+
a report's (the ticket upload below), resolve the request, and reopen a resolved one for 30 days.
|
|
153
|
+
A declined request is read-only and shows its reason. Opening a thread marks it read.
|
|
154
|
+
- While a thread is open the widget reads `GET /public/live/requests` with `fetch` (the identity in
|
|
155
|
+
the header; an `EventSource` cannot send one) so a team reply appears at once, and stops reading
|
|
156
|
+
when the thread closes. The page's CSP needs `connect-src` for the widget's API origin only.
|
|
157
|
+
- **Expired or refused token**: when the API refuses the token (a 401 on a read, a 401 or 403 on
|
|
158
|
+
the live stream) or the stream ends with `expired`, the list or the open thread shows the session-expired message and the page hears `pulsarix:error` once with the code
|
|
159
|
+
(`intake.errors.identity-invalid`,
|
|
160
|
+
`intake.errors.identity-expired` or `http-<status>`). Call `identify(newToken)` to sign in again.
|
|
161
|
+
The live stream reconnects after a drop with a pause that doubles up to 30 s, and never after
|
|
162
|
+
`expired`, a 401, 403, 404 or 429.
|
|
163
|
+
- **E-mails about my requests**: a switch at the foot of My requests, on or off as the API
|
|
164
|
+
says (`emailsOn`). It flips at once and is sent to the API (`setRequestEmails`); if that fails it
|
|
165
|
+
goes back with a message. The choice applies to every request of the reporter under your key.
|
|
166
|
+
- **Delete my data**: a button at the foot of My requests opens a confirmation (Cancel on the
|
|
167
|
+
left, Delete on the right). Confirming erases every request of the reporter under your key
|
|
168
|
+
(`eraseMyData`), with their replies and files; the list is emptied, the dialog says how many
|
|
169
|
+
were erased and the unread count goes to 0. A refusal (expired token, rate limit) keeps the
|
|
170
|
+
confirmation open with the reason. Erasing cannot be undone. The page hears
|
|
171
|
+
`pulsarix:erase` with `detail: { requests }`, the number of requests erased, followed by
|
|
172
|
+
`pulsarix:unread` with `{ count: 0 }`.
|
|
173
|
+
- A token the API refuses (expired or forged) shows a message in My requests; reload the page
|
|
174
|
+
to get a fresh one.
|
|
175
|
+
- Everyone (identified or not) can give an optional type (bug, question, suggestion) and an
|
|
176
|
+
impact (blocking, annoying, minor) in the form's Details group.
|
|
177
|
+
|
|
178
|
+
## Screenshots
|
|
179
|
+
|
|
180
|
+
A report can carry one optional screenshot, never taken without a click (and a per-report
|
|
181
|
+
choice). The right pane of the dialog offers:
|
|
182
|
+
|
|
183
|
+
- **Add a screenshot**: the browser's screen capture (`getDisplayMedia`). The widget hides itself
|
|
184
|
+
(`visibility`, not unmount, so the form keeps its text) while the frame is grabbed, then shows
|
|
185
|
+
itself again. Not offered on a phone, without the API, or under a Permissions-Policy that blocks
|
|
186
|
+
`display-capture`.
|
|
187
|
+
- **Upload an image**: always offered, and the only choice where capture is unavailable or was
|
|
188
|
+
refused. PNG, JPEG or WebP, 25 megapixels at most.
|
|
189
|
+
- **Mask the text on the page** (off by default; `data-mask-text="true"`, or `maskText: true` in `init` / `mount`, turns it on when the dialog opens): covers the
|
|
190
|
+
page's text with opaque boxes before the picture is taken. It needs the current tab to be shared;
|
|
191
|
+
otherwise the widget says it cannot and nothing is captured. Mark anything that must stay visible
|
|
192
|
+
with `data-capture-unmask`.
|
|
193
|
+
|
|
194
|
+
The picture opens in an editor (a separate chunk, fetched when first needed) with a pen, a highlighter,
|
|
195
|
+
an arrow, a box, text, a solid "Redact" box (redacted pixels are one opaque colour) and Crop, which trims the
|
|
196
|
+
picture before it is kept. Only the flattened
|
|
197
|
+
export (2560 px on its longest side at most) is kept; the raw capture is dropped, its object URLs
|
|
198
|
+
revoked and no media track stays live. Retake and Remove are offered. A report is complete without
|
|
199
|
+
any of this. No `blob:` image source is needed in your CSP (the editor draws on canvases), and a
|
|
200
|
+
`Permissions-Policy` without `display-capture` turns the capture button off.
|
|
201
|
+
|
|
202
|
+
Events, on the element and through `on(name, cb)`: `pulsarix:ready` (asynchronous, in a microtask,
|
|
203
|
+
so a listener added right after `mount()` hears it; it fires even when the key is missing, then
|
|
204
|
+
`pulsarix:error` with `config` follows), `pulsarix:open`,
|
|
205
|
+
`pulsarix:close`, `pulsarix:submit` (`detail: { reportId, files }`, one `{ name, role, type, size,
|
|
206
|
+
uploaded }` per file sent with the report), `pulsarix:reply` (`detail: { requestId }`, the team
|
|
207
|
+
replied to one of the reporter's requests), `pulsarix:unread` (`detail: { count }`, the reporter's
|
|
208
|
+
unread replies changed), `pulsarix:erase` (`detail: { requests }`, the reporter erased their
|
|
209
|
+
data) and `pulsarix:error`
|
|
210
|
+
(`detail: { code }`, the API's `intake.errors.*` code, or `network`, `config`, `http-<status>`).
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
widget.on("pulsarix:submit", (event) => console.log(event.detail.reportId));
|
|
214
|
+
widget.on("pulsarix:error", (event) => console.warn(event.detail.code));
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Attached files
|
|
218
|
+
|
|
219
|
+
Besides the screenshot, a reporter can attach up to 3 files (PNG, JPEG, WebP or PDF, 5 MB each,
|
|
220
|
+
12 MB for the report, screenshot included) by dropping them on the zone or with Browse. The
|
|
221
|
+
checks mirror the API's, so a refused file is shown with its reason and never sent; the list shows
|
|
222
|
+
each file's type icon, name, size, a thumbnail for images, a Remove button, and its progress while
|
|
223
|
+
the report goes out.
|
|
224
|
+
|
|
225
|
+
- On submit the widget declares the files to `submitClientReport`, then PUTs each one to the signed
|
|
226
|
+
single-use ticket the API answers (`/public/media/report-files/<slot>`), with progress, and one
|
|
227
|
+
retry on a network failure or a 5xx. The report itself is already saved by then: if a file
|
|
228
|
+
cannot be attached, the confirmation says "Your report was sent, but N of M files could not be
|
|
229
|
+
attached" and `pulsarix:submit` lists that file with `uploaded: false`.
|
|
230
|
+
- Off for one embed with `data-attachments="false"` (`attachments: false` in `init` / `mount`), and
|
|
231
|
+
off for a key when its project switches attachments off (`widgetConfig.attachments`); the
|
|
232
|
+
screenshot pane goes with them.
|
|
233
|
+
- The files go to the same origin as the report, so `connect-src` is unchanged. Thumbnails are
|
|
234
|
+
drawn on canvases, so no `img-src blob:` is needed. Capture needs `display-capture` in the
|
|
235
|
+
host's `Permissions-Policy` (the upload of an image works without it).
|
|
236
|
+
- The list's own labels (the "Attachments" name, "Remove") come from `@softistx/material/embed`
|
|
237
|
+
and follow the widget's locale through `I18nProvider`, like every refusal and the confirmation.
|
|
238
|
+
- An API that sends no `attachments` in `widgetConfig`, or a failed config read, shows no file
|
|
239
|
+
controls (the widget then behaves as v1).
|
|
240
|
+
|
|
241
|
+
## How it is isolated
|
|
242
|
+
|
|
243
|
+
- `<pulsarix-widget>` has an open shadow root. `@softistx/material/embed` (the lean entry for
|
|
244
|
+
Shadow DOM widgets: no globals, only the parts the form uses) and its `embed.css`, plus the
|
|
245
|
+
theme (the built-in `lavande`, or one generated from `accentColor`), are adopted into it (`adoptedStyleSheets`): no style
|
|
246
|
+
element, no `style-src 'unsafe-inline'`. Portals (the dialog) target an element inside it.
|
|
247
|
+
- The page's styles do not reach the widget. Only `color-scheme` and the root font size
|
|
248
|
+
inherit: `:host` resets `color-scheme`, and `embed.css` is already in `px` with its
|
|
249
|
+
`@property` initial values as plain declarations (a shadow root ignores `@property`). The build
|
|
250
|
+
adds the utilities the widget's own classes need, with their `@property` values copied the same way.
|
|
251
|
+
- The widget leaves the page as it found it: no global but `window.PulsarixWidget`. While the
|
|
252
|
+
modal is open, the dialog's scroll lock adds a transient style element and focus guards
|
|
253
|
+
to the document; both are removed on close.
|
|
254
|
+
- Fonts: `@font-face` is ignored in a shadow root. The widget uses the system font stack.
|
|
255
|
+
|
|
256
|
+
## Strict CSP and the requests thread
|
|
257
|
+
|
|
258
|
+
The requests thread's scroll area injects one `<style>` element into the shadow root. Under a strict
|
|
259
|
+
`style-src`, give your page a nonce: a `style` or `script` element carrying `nonce`, or
|
|
260
|
+
`<meta property="csp-nonce" content="...">`. The widget reads it and puts it on that element. The
|
|
261
|
+
form, the dialog and the screenshot editor need no nonce.
|
|
262
|
+
|
|
263
|
+
## Serving (script-tag integrators)
|
|
264
|
+
|
|
265
|
+
The pulsarix host serves `/widget/v1/loader.js` (short cache) and the hashed bundle it imports
|
|
266
|
+
(long cache). The bundle needs `Access-Control-Allow-Origin: *`. Your CSP needs `script-src` and
|
|
267
|
+
`connect-src` for the pulsarix host.
|