@softistx/pulsarix-widget 0.4.0 → 0.6.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 +27 -19
- package/dist/index.js +4689 -53
- package/dist/types/config.d.ts +2 -2
- package/dist/types/mount.d.ts +9 -3
- package/docs/integration.md +99 -19
- package/package.json +3 -3
package/dist/types/config.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export type Locale = "en" | "fr";
|
|
3
3
|
export type ThemeMode = "light" | "dark" | "auto";
|
|
4
4
|
export type Position = "bottom-right" | "bottom-left";
|
|
5
|
-
/**
|
|
5
|
+
/** Every value gives the round FAB; the values are read so existing embeds keep working. */
|
|
6
6
|
export type LauncherMode = "auto" | "pill" | "icon";
|
|
7
7
|
/** A launcher offset: a number is pixels, a string is any CSS length (`"2rem"`, `"env(...)"`). */
|
|
8
8
|
export interface LauncherOffset {
|
|
@@ -14,7 +14,7 @@ export interface WidgetConfig {
|
|
|
14
14
|
locale: Locale;
|
|
15
15
|
theme: ThemeMode;
|
|
16
16
|
position: Position;
|
|
17
|
-
/**
|
|
17
|
+
/** Read for compatibility (`launcher="pill"`, `"icon"`): the launcher is always the round FAB; `launcher="false"` is read by the element. */
|
|
18
18
|
launcherMode: LauncherMode;
|
|
19
19
|
/** The launcher's offsets (`offset-bottom`, `offset-side`), as CSS lengths, or null. */
|
|
20
20
|
offset: {
|
package/dist/types/mount.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export interface MountOptions {
|
|
|
14
14
|
inheritTheme?: boolean;
|
|
15
15
|
/** Origin of the pulsarix host (`https://pulsarix.example.com`); the loader fills it in. */
|
|
16
16
|
apiBase?: string;
|
|
17
|
-
/** The floating button: `"auto"`
|
|
17
|
+
/** The floating button: `"auto"`, `"pill"` and `"icon"` all give the round FAB (kept for compatibility), or `false` for none. */
|
|
18
18
|
launcher?: boolean | LauncherMode;
|
|
19
19
|
/** Launcher distance from the bottom and its side (16 px default): pixels, or a CSS length. */
|
|
20
20
|
offset?: LauncherOffset;
|
|
@@ -45,14 +45,20 @@ export interface WidgetHandle {
|
|
|
45
45
|
close(): void;
|
|
46
46
|
/** Shows or hides the launcher only; an open dialog is never closed or hidden by it. */
|
|
47
47
|
setLauncherVisible(visible: boolean): void;
|
|
48
|
+
/**
|
|
49
|
+
* Hides the launcher until the returned function is called, for a host's own sticky bar.
|
|
50
|
+
* Ref-counted: the launcher stays hidden while any hold is open, and shows again once every
|
|
51
|
+
* hold is released and `setLauncherVisible` is not `false`. Releasing twice does nothing.
|
|
52
|
+
*/
|
|
53
|
+
holdLauncher(): () => void;
|
|
48
54
|
/** Signs the reporter in with a signed identity token, or out with `null`. */
|
|
49
55
|
identify(token: string | null): void;
|
|
50
56
|
/** Light or dark now, without a remount; `"auto"` follows the OS, not the host page. */
|
|
51
57
|
setTheme(theme: ThemeMode): void;
|
|
52
58
|
/**
|
|
53
59
|
* Switches the language. The widget's strings change at once; `@softistx/material`'s built-in labels
|
|
54
|
-
* follow when the form is idle (typed fields, type
|
|
55
|
-
* during a send, on the confirmation or on the requests
|
|
60
|
+
* follow when the form is idle (typed fields, type and impact kept, attachments dropped), never
|
|
61
|
+
* during a send, on the confirmation or on the requests view.
|
|
56
62
|
*/
|
|
57
63
|
setLocale(locale: Locale): void;
|
|
58
64
|
/** Replaces the metadata sent with the next report (`null` clears it). */
|
package/docs/integration.md
CHANGED
|
@@ -6,6 +6,7 @@ and "My requests" working. Reference for every option and event: the [README](..
|
|
|
6
6
|
1. [Get a project and a widget key](#1-get-a-project-and-a-widget-key)
|
|
7
7
|
2. [Add the widget](#2-add-the-widget)
|
|
8
8
|
3. [Identify your signed-in users](#3-identify-your-signed-in-users)
|
|
9
|
+
- [Signing from a root loader with an optional viewer](#signing-from-a-root-loader-with-an-optional-viewer)
|
|
9
10
|
4. [Content Security Policy](#4-content-security-policy)
|
|
10
11
|
5. [Options and metadata](#5-options-and-metadata)
|
|
11
12
|
6. [Events](#6-events)
|
|
@@ -14,6 +15,7 @@ and "My requests" working. Reference for every option and event: the [README](..
|
|
|
14
15
|
9. [Inheriting the host app's theme](#9-inheriting-the-host-apps-theme)
|
|
15
16
|
10. [Changing theme, locale and metadata at run time](#10-changing-theme-locale-and-metadata-at-run-time)
|
|
16
17
|
11. [The launcher: look, position and visibility](#11-the-launcher-look-position-and-visibility)
|
|
18
|
+
- [Sticky bottom bars: `holdLauncher()`](#sticky-bottom-bars-holdlauncher)
|
|
17
19
|
|
|
18
20
|
## 1. Get a project and a widget key
|
|
19
21
|
|
|
@@ -27,7 +29,7 @@ A key has:
|
|
|
27
29
|
or `https://*.example.com`. A request from any other origin, or with no `Origin`, is refused;
|
|
28
30
|
- an optional **identity secret** for signed-in users (section 3): in the key's "Signed-in users" card,
|
|
29
31
|
press "Generate secret". It is **shown once**: copy it into your server's environment right away
|
|
30
|
-
(for example `PULSARIX_IDENTITY_SECRET`)
|
|
32
|
+
(for example `PULSARIX_IDENTITY_SECRET`), with the public key beside it as `PULSARIX_PROJECT_KEY`. It cannot be read again; "Regenerate" makes a new one and
|
|
31
33
|
the old one stops working at once.
|
|
32
34
|
|
|
33
35
|
The key also has a switch (disabled keys refuse everything) and a "Screenshots and files" switch.
|
|
@@ -75,7 +77,7 @@ One widget per page: use the script tag or `mount()`, not both.
|
|
|
75
77
|
## 3. Identify your signed-in users
|
|
76
78
|
|
|
77
79
|
Without an identity the widget is the anonymous report form. With one, reports are filed under the
|
|
78
|
-
reporter, who also gets a "My requests"
|
|
80
|
+
reporter, who also gets a "My requests" view (threads, replies, unread counts, "Delete my data").
|
|
79
81
|
|
|
80
82
|
Your server signs a short-lived token for the signed-in user with the key's identity secret; the browser
|
|
81
83
|
only carries the token. The helper does the signing:
|
|
@@ -91,7 +93,7 @@ export function pulsarixTokenFor(user: {
|
|
|
91
93
|
}) {
|
|
92
94
|
return signPulsarixIdentity({
|
|
93
95
|
secret: process.env.PULSARIX_IDENTITY_SECRET as string,
|
|
94
|
-
publicKey: process.env.
|
|
96
|
+
publicKey: process.env.PULSARIX_PROJECT_KEY as string, // pk_live_xxx
|
|
95
97
|
sub: user.id,
|
|
96
98
|
email: user.email,
|
|
97
99
|
name: user.name,
|
|
@@ -103,7 +105,7 @@ export function pulsarixTokenFor(user: {
|
|
|
103
105
|
Import the signer only in server code (a loader, or a `*.server.ts` file), never in the browser. Then hand
|
|
104
106
|
the token to the widget, and clear it at sign-out. In a strict-TypeScript host the script tag's global is
|
|
105
107
|
not typed: declare it once with
|
|
106
|
-
`declare global { interface Window { PulsarixWidget?: { identify(token: string | null): void } } }`,
|
|
108
|
+
`declare global { interface Window { PulsarixWidget?: { identify(token: string | null): void; holdLauncher(): () => void } } }`,
|
|
107
109
|
or use the npm route's typed handle:
|
|
108
110
|
|
|
109
111
|
```ts
|
|
@@ -154,7 +156,7 @@ export async function loader({ request }: Route.LoaderArgs) {
|
|
|
154
156
|
return {
|
|
155
157
|
pulsarixIdentity: signPulsarixIdentity({
|
|
156
158
|
secret: process.env.PULSARIX_IDENTITY_SECRET as string,
|
|
157
|
-
publicKey: process.env.
|
|
159
|
+
publicKey: process.env.PULSARIX_PROJECT_KEY as string,
|
|
158
160
|
sub: user.id,
|
|
159
161
|
email: user.email,
|
|
160
162
|
name: user.name,
|
|
@@ -171,6 +173,50 @@ export default function Layout() {
|
|
|
171
173
|
}
|
|
172
174
|
```
|
|
173
175
|
|
|
176
|
+
### Signing from a root loader with an optional viewer
|
|
177
|
+
|
|
178
|
+
The loader above sits under a layout that already requires a signed-in user. When the viewer is
|
|
179
|
+
optional (a public site with an account), sign from the root loader instead and give `identify()`
|
|
180
|
+
`null` for a visitor. Drive it from the loader data, so it also covers sign-out: the loader reruns,
|
|
181
|
+
the token becomes `null` and the widget drops "My requests", with no sign-out hook in your app.
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
// app/root.tsx
|
|
185
|
+
import { signPulsarixIdentity } from "@softistx/pulsarix-widget/server";
|
|
186
|
+
import { useEffect } from "react";
|
|
187
|
+
import { Outlet, useLoaderData } from "react-router";
|
|
188
|
+
|
|
189
|
+
export async function loader({ request }: Route.LoaderArgs) {
|
|
190
|
+
const user = await getUser(request); // your own session; `null` for a visitor
|
|
191
|
+
return {
|
|
192
|
+
pulsarixIdentity: user
|
|
193
|
+
? signPulsarixIdentity({
|
|
194
|
+
secret: process.env.PULSARIX_IDENTITY_SECRET as string,
|
|
195
|
+
publicKey: process.env.PULSARIX_PROJECT_KEY as string,
|
|
196
|
+
sub: user.id,
|
|
197
|
+
email: user.email,
|
|
198
|
+
name: user.name,
|
|
199
|
+
})
|
|
200
|
+
: null,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export default function Root() {
|
|
205
|
+
const { pulsarixIdentity } = useLoaderData<typeof loader>();
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
window.PulsarixWidget?.identify(pulsarixIdentity);
|
|
208
|
+
}, [pulsarixIdentity]);
|
|
209
|
+
return <Outlet />;
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
The cost: a root loader runs on every document request and on every revalidation, so a signed-in
|
|
214
|
+
viewer is signed once per request (an HMAC, microseconds) and the token in the page changes each
|
|
215
|
+
time, which makes the response differ per user: do not cache it in a shared cache. Keep the life
|
|
216
|
+
short (the default hour) and `identify()` again with the fresh token on each run, as the effect does.
|
|
217
|
+
To sign less often, give the loader `shouldRevalidate` so it reruns only after a sign-in or sign-out,
|
|
218
|
+
and re-sign before expiry (see above). A visitor costs nothing: no signature, and `identify(null)`.
|
|
219
|
+
|
|
174
220
|
A token given with `identify()` stays in the widget's memory; one in `data-identity` is an attribute of
|
|
175
221
|
the element and visible in the DOM, so prefer `identify()`.
|
|
176
222
|
|
|
@@ -188,6 +234,10 @@ Content-Security-Policy:
|
|
|
188
234
|
- Nothing else is needed for images or capture: thumbnails and the screenshot editor draw on canvases,
|
|
189
235
|
so there is no `img-src blob:`. Screen capture needs `display-capture` in your `Permissions-Policy`
|
|
190
236
|
(uploading an image works without it).
|
|
237
|
+
- Lazy chunks come from the same pulsarix host, so no extra `script-src` entry: the screenshot editor
|
|
238
|
+
(fetched on the first capture) and the markdown renderer of the team's replies (`chat-markdown-*.js`,
|
|
239
|
+
about 740 KB, 221 KB gzipped, fetched when a thread opens; plain text shows until it arrives). Serve
|
|
240
|
+
every file of the widget's folder beside the entry, with the bundle's cache headers.
|
|
191
241
|
- The widget's styles are adopted into its shadow root: no `style-src 'unsafe-inline'`. The requests
|
|
192
242
|
thread injects one `<style>` element; under a strict `style-src` give your page a nonce, which the
|
|
193
243
|
widget reads from a `nonce` attribute on a `style` or `script` element or from this tag:
|
|
@@ -208,7 +258,7 @@ Script-tag attributes and `init` / `mount` options (all optional except the key)
|
|
|
208
258
|
| `data-theme` / `theme` | `light`, `dark` or `auto` (default) |
|
|
209
259
|
| `data-position` / `position` | `bottom-right` (default) or `bottom-left` |
|
|
210
260
|
| `data-accent-color` / `accentColor` | a hex seed for the theme |
|
|
211
|
-
| `data-launcher` / `launcher` | `
|
|
261
|
+
| `data-launcher` / `launcher` | `false` for none; any other value gives the round FAB (section 11) |
|
|
212
262
|
| `data-offset-bottom`, `data-offset-side` / `offset` | launcher distance from the bottom and its side (section 11) |
|
|
213
263
|
| `data-attachments="false"` | no screenshot and no file controls |
|
|
214
264
|
| `data-mask-text="true"` | "Mask the text on the page" starts on |
|
|
@@ -218,7 +268,9 @@ Script-tag attributes and `init` / `mount` options (all optional except the key)
|
|
|
218
268
|
| `data-metadata` / `metadata` | a JSON object of strings stored with each report |
|
|
219
269
|
|
|
220
270
|
`metadata` carries facts about the session that help triage: at most 20 entries, keys of 64 characters,
|
|
221
|
-
values of 512, 2 KB in all; the rest is dropped.
|
|
271
|
+
values of 512, 2 KB in all; the rest is dropped. The keys `capture-N-page` are reserved: the widget
|
|
272
|
+
writes one per screenshot (the page it was taken on, origin and path), drops a host entry of that shape,
|
|
273
|
+
and drops the host's last entries first when the whole would pass these limits.
|
|
222
274
|
|
|
223
275
|
```html
|
|
224
276
|
<script src="https://<pulsarix-host>/widget/v1/loader.js" async
|
|
@@ -313,6 +365,11 @@ mount({ projectKey: "pk_live_xxx", inheritTheme: false }); // the widget's own l
|
|
|
313
365
|
|
|
314
366
|
Script tag: `data-inherit-theme="false"`. Element attribute: `inherit-theme="false"`.
|
|
315
367
|
|
|
368
|
+
**`theme` at mount does not turn host inheritance off.** On a host that provides tokens, the widget
|
|
369
|
+
keeps wearing the host's colours and its light or dark mode; the `theme` option (`light`, `dark`,
|
|
370
|
+
`auto`) only decides the mode when the host does not say. To keep the widget's own look, pass
|
|
371
|
+
`inheritTheme: false`; to force the mode at run time, call `setTheme("light" | "dark")`.
|
|
372
|
+
|
|
316
373
|
### How it works
|
|
317
374
|
|
|
318
375
|
The widget lives in a shadow root and declares its own tokens there, so the page's custom
|
|
@@ -388,8 +445,8 @@ Rules:
|
|
|
388
445
|
`prefers-color-scheme`, never the host page's class or attribute. A host with its own mode switch passes the
|
|
389
446
|
resolved `"light"` or `"dark"` to `setTheme` on each change.
|
|
390
447
|
- `setTheme` is independent of `inheritTheme` (section 9). With `inheritTheme`, the widget follows the host's
|
|
391
|
-
mode
|
|
392
|
-
|
|
448
|
+
mode when the host provides tokens, and the `theme` given at mount (or written later as the `theme`
|
|
449
|
+
attribute) decides only when it does not. `setTheme("light")` or `setTheme("dark")` wins over the
|
|
393
450
|
host's mode until the `theme` attribute is written again (that gives the mode back to the host);
|
|
394
451
|
`setTheme("auto")` gives it back at once. An inherited token still wins for its colour value.
|
|
395
452
|
- `setTheme` only sets the widget's own mode. The accent (`accentColor`) is a mount option and does not change.
|
|
@@ -397,9 +454,9 @@ Rules:
|
|
|
397
454
|
64 characters, values of 512, 2 KB in all). A report already sent is not changed.
|
|
398
455
|
- `setLocale` changes the widget's own strings at once. The built-in labels of `@softistx/material` (the close
|
|
399
456
|
button, the file list, ...) are read once by its i18n context, so they change when the form is next idle:
|
|
400
|
-
- On an idle form, the typed fields, the chosen type and impact
|
|
457
|
+
- On an idle form, the typed fields, the chosen type and impact are kept; files and a
|
|
401
458
|
screenshot already attached are dropped.
|
|
402
|
-
- While a report is being sent, on the confirmation screen, or
|
|
459
|
+
- While a report is being sent, on the confirmation screen, or in the "My requests" view, nothing is rebuilt:
|
|
403
460
|
those built-in labels switch when the reporter returns to the form (or the dialog closes), and no
|
|
404
461
|
attachment is lost.
|
|
405
462
|
- `setTheme` and `setMetadata` drop nothing.
|
|
@@ -414,15 +471,14 @@ attribute and a `mount()` option.
|
|
|
414
471
|
|
|
415
472
|
### Look: `launcher`
|
|
416
473
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
| `"pill"` | Always the text pill (the 0.3 look). |
|
|
421
|
-
| `"icon"` | Always a 48 px round button with a speech-bubble icon. |
|
|
422
|
-
| `false` | No launcher; open the dialog with `open()`. |
|
|
474
|
+
The launcher is one round floating action button (FAB) with the pulsarix mark, at every width. The
|
|
475
|
+
`launcher` option no longer changes its look: `"auto"`, `"pill"` and `"icon"` all give the FAB (they
|
|
476
|
+
are still read so existing embeds keep working), and `false` removes it (open the dialog with `open()`).
|
|
423
477
|
|
|
424
|
-
|
|
425
|
-
|
|
478
|
+
Without a token the FAB opens the report form directly. With a token it opens a small menu anchored
|
|
479
|
+
to it with two items, "Report a problem" and "My requests" (with its unread badge); each opens one
|
|
480
|
+
view, never tabs. The FAB keeps the localized label as its accessible name and carries the unread
|
|
481
|
+
count in it ("Report a problem, 3"), with a visible focus ring.
|
|
426
482
|
|
|
427
483
|
```html
|
|
428
484
|
<script src="https://<pulsarix-host>/widget/v1/loader.js" async
|
|
@@ -473,3 +529,27 @@ widget.setLauncherVisible(true);
|
|
|
473
529
|
An open dialog is never hidden or closed by it, and `open()` still works while the launcher is hidden.
|
|
474
530
|
With the script tag: `window.PulsarixWidget.setLauncherVisible(false)`. `launcher: false` still
|
|
475
531
|
removes the launcher for good.
|
|
532
|
+
|
|
533
|
+
### Sticky bottom bars: `holdLauncher()`
|
|
534
|
+
|
|
535
|
+
A host's own sticky bottom bar (a checkout bar, a cookie banner, an editor toolbar) can sit under the
|
|
536
|
+
launcher. `holdLauncher()` hides the launcher while the bar is on screen and returns a function that
|
|
537
|
+
gives it back. It is ref-counted, so two bars at once keep it hidden until both are released, and the
|
|
538
|
+
returned function is safe to call more than once.
|
|
539
|
+
|
|
540
|
+
```tsx
|
|
541
|
+
import { useEffect } from "react";
|
|
542
|
+
|
|
543
|
+
function StickyCheckoutBar() {
|
|
544
|
+
useEffect(() => {
|
|
545
|
+
// The script tag's global queues the call until the bundle has loaded.
|
|
546
|
+
const release = window.PulsarixWidget?.holdLauncher();
|
|
547
|
+
return () => release?.();
|
|
548
|
+
}, []);
|
|
549
|
+
return <div className="sticky bottom-0">…</div>;
|
|
550
|
+
}
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
With the npm route, `const release = widget.holdLauncher()`. It combines with `setLauncherVisible`: the
|
|
554
|
+
launcher shows only when `setLauncherVisible` is not `false` and no hold is open. Like it, a hold never
|
|
555
|
+
closes or hides an open dialog, and `launcher: false` still removes the launcher for good.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softistx/pulsarix-widget",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Embeddable client-issue intake widget for pulsarix, rendered in a Shadow DOM",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@graphql-codegen/typescript": "^7.0.1",
|
|
19
19
|
"@graphql-codegen/typescript-operations": "^7.0.1",
|
|
20
20
|
"@happy-dom/global-registrator": "^21.0.4",
|
|
21
|
-
"@softistx/material": "^3.
|
|
21
|
+
"@softistx/material": "^3.279.0",
|
|
22
22
|
"@softistx/material-core": "^0.96.1",
|
|
23
23
|
"@tailwindcss/cli": "^4.3.3",
|
|
24
24
|
"@testing-library/dom": "^10.4.2",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"generate:check": "bun scripts/generate.ts --check",
|
|
48
48
|
"schema:sync": "bun scripts/schema-sync.ts",
|
|
49
49
|
"schema:check": "bun scripts/schema-sync.ts --check",
|
|
50
|
-
"test:browser": "bun scripts/leak-test.ts && bun scripts/screenshot-test.ts && bun scripts/files-test.ts && bun scripts/thread-test.ts && bun scripts/privacy-test.ts",
|
|
50
|
+
"test:browser": "bun scripts/leak-test.ts && bun scripts/screenshot-test.ts && bun scripts/files-test.ts && bun scripts/thread-test.ts && bun scripts/privacy-test.ts && bun scripts/contrast-test.ts",
|
|
51
51
|
"fixture": "bun scripts/serve-fixture.ts",
|
|
52
52
|
"verify": "bun run lint && bun run schema:check && bun run generate:check && bun run build && bun run typecheck && bun run test && bun run check:deps && bun run size",
|
|
53
53
|
"release": "bun scripts/publish.ts",
|