@everscribe/components-element 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/LICENSE +21 -0
- package/README.md +127 -0
- package/dist/index.cjs +2255 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +2253 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Everscribe
|
|
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
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/everscribe/components/main/assets/everscribe.svg" alt="Everscribe" height="64">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/@everscribe/components-element"><img src="https://img.shields.io/npm/v/@everscribe/components-element.svg" alt="npm"></a>
|
|
7
|
+
<a href="https://github.com/everscribe/components/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
# @everscribe/components-element
|
|
11
|
+
|
|
12
|
+
Framework-agnostic `<audit-trail>` custom element for [Everscribe](https://everscribe.io) audit events. Drop the tag into any HTML, in any framework - plain JS, Vue, Svelte, Solid, Angular - and you get the same live, scoped audit trail UI you'd get from the React component.
|
|
13
|
+
|
|
14
|
+
Part of [@everscribe/components](https://github.com/everscribe/components#readme). Token minting, the refresh chain, theming, security, rate limits, and claim-driven UI are covered in the [web components guide](https://everscribe.io/docs/web-components/overview).
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @everscribe/components-element @everscribe/components-styles
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The element registers itself as `<audit-trail>` on import (idempotent - safe to import in multiple bundles). The styles package ships the CSS theme; install it alongside.
|
|
23
|
+
|
|
24
|
+
## Quick start (plain HTML)
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<link rel="stylesheet" href="https://unpkg.com/@everscribe/components-styles/default.css">
|
|
28
|
+
<script type="module">
|
|
29
|
+
import '@everscribe/components-element'
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<audit-trail token-endpoint="/api/embed-token"></audit-trail>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`token-endpoint` is a route on **your** server (not Everscribe's) that returns a freshly minted embed token. The element fetches it on mount, holds it in memory, and re-fetches from the same endpoint on 401. Your project API key never touches the browser. See [Minting tokens](https://everscribe.io/docs/web-components/prerequisites) for the backend side.
|
|
36
|
+
|
|
37
|
+
If you have a token already, pass it directly:
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<audit-trail token="eyJhbGciOi..." token-endpoint="/api/embed-token"></audit-trail>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Pass `token-endpoint` alongside `token` so refresh on 401 still works.
|
|
44
|
+
|
|
45
|
+
## Vue / Svelte / Solid
|
|
46
|
+
|
|
47
|
+
Custom elements are first-class in these frameworks. The tag works as written, attributes flow normally, and `audit-trail-error` integrates with each framework's event syntax.
|
|
48
|
+
|
|
49
|
+
```vue
|
|
50
|
+
<!-- Vue -->
|
|
51
|
+
<audit-trail token-endpoint="/api/embed-token" @audit-trail-error="handleError" />
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```svelte
|
|
55
|
+
<!-- Svelte -->
|
|
56
|
+
<audit-trail token-endpoint="/api/embed-token" on:audit-trail-error={handleError} />
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```jsx
|
|
60
|
+
{/* Solid */}
|
|
61
|
+
<audit-trail token-endpoint="/api/embed-token" on:audit-trail-error={handleError} />
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
For React 18, prefer [`@everscribe/components-react`](../react#readme) - React 18's custom-element interop has known rough edges around prop conventions and synthetic events.
|
|
65
|
+
|
|
66
|
+
## Attributes
|
|
67
|
+
|
|
68
|
+
At least one of `token`, `token-endpoint`, or the JS-only `onTokenExpired` property is required.
|
|
69
|
+
|
|
70
|
+
| Attribute | Type | Default | Notes |
|
|
71
|
+
|---|---|---|---|
|
|
72
|
+
| `token` | string | - | Embed JWT. If omitted, the element fetches one via `token-endpoint`/`onTokenExpired` on mount. |
|
|
73
|
+
| `token-endpoint` | string | - | URL on your backend that returns `{ token }` JSON. Used for the initial fetch (when `token` is omitted) and for refresh on 401. Sent with `credentials: 'include'`. |
|
|
74
|
+
| `api-base` | string | `https://api.everscribe.io/v1/embed` | Base URL for read endpoints. Override for local dev or self-hosted. |
|
|
75
|
+
| `page-size` | number | `25` | Events per page. |
|
|
76
|
+
| `poll-interval` | number | `5000` | Poll cadence in ms. `<= 0` disables polling. Below `1000` is clamped with a `console.warn`. |
|
|
77
|
+
| `theme` | `light` \| `dark` | `light` | Switches the CSS-variable theme. |
|
|
78
|
+
| `default-time-range` | `24h` \| `7d` \| `30d` \| `all` | `all` | Initial time-range preset (read at mount only). |
|
|
79
|
+
|
|
80
|
+
Style and class come from the standard `class` and `style` attributes. The element renders into its own light DOM, so the CSS in `@everscribe/components-styles/default.css` applies the same way it does for the React component.
|
|
81
|
+
|
|
82
|
+
## Persistence
|
|
83
|
+
|
|
84
|
+
Column visibility and filter state are persisted to `localStorage` automatically and restored on reload. Two keys are written, both namespaced by the token's project ID (`sub` claim) and tenant ID (`tenant_id` claim, or `_` when unset):
|
|
85
|
+
|
|
86
|
+
- `audit-trail:cols:{sub}:{tenant_id}` - the list of *hidden* columns. Stored as hidden (not visible) so future-added columns appear by default for returning users.
|
|
87
|
+
- `audit-trail:filters:{sub}:{tenant_id}` - the active filter state (`FilterValues`): time range, column filters, free-text actor/target/origin inputs, the active DSL query, and the last NLP echo fields.
|
|
88
|
+
|
|
89
|
+
Behavior:
|
|
90
|
+
- Restored after the bootstrap token fetch resolves, so the very first request to `/events` already reflects the user's last session.
|
|
91
|
+
- localStorage failures (private browsing, quota exceeded, malformed JSON) are silently swallowed - the element falls through to the default-time-range attribute and empty filters.
|
|
92
|
+
- Token claims that restrict columns (`columns` claim set) take precedence over restored hidden columns; the restored list can only narrow the claim-allowed set, never escape it.
|
|
93
|
+
- Two `<audit-trail>` instances on the same page sharing the same `sub` + `tenant_id` will share persisted state. This is a degenerate case (the same view embedded twice) and generally desirable when it does happen.
|
|
94
|
+
|
|
95
|
+
## Properties (JS only)
|
|
96
|
+
|
|
97
|
+
These can't be expressed as attributes; set them on the element directly via JS.
|
|
98
|
+
|
|
99
|
+
| Property | Type | Notes |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| `onTokenExpired` | `() => Promise<string>` | Custom token-fetch callback. Takes precedence over `token-endpoint`. |
|
|
102
|
+
| `refresh()` | `() => void` | Public method. Triggers a full re-bootstrap (fresh token fetch + fresh stores). |
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
const el = document.querySelector('audit-trail')
|
|
106
|
+
el.onTokenExpired = async () => {
|
|
107
|
+
const res = await fetch('/api/embed-token', { credentials: 'include' })
|
|
108
|
+
const { token } = await res.json()
|
|
109
|
+
return token
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Events
|
|
114
|
+
|
|
115
|
+
| Event | `detail` | Notes |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| `audit-trail-error` | `{ error: Error }` | Bubbles. Fired on fetch errors that surface from the events store (network, server, expired token after refresh chain exhausted). |
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
document.querySelector('audit-trail').addEventListener('audit-trail-error', (e) => {
|
|
121
|
+
console.error(e.detail.error)
|
|
122
|
+
})
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
MIT
|