@everscribe/components-react 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 +104 -0
- package/dist/index.cjs +1935 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +39 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +1933 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -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,104 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/everscribe/components/main/assets/everscribe.svg" alt="Everscribe" height="64" align="middle">
|
|
3
|
+
<b>+</b>
|
|
4
|
+
<img src="https://raw.githubusercontent.com/everscribe/components/main/assets/react.svg" alt="React" height="56" align="middle">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://www.npmjs.com/package/@everscribe/components-react"><img src="https://img.shields.io/npm/v/@everscribe/components-react.svg" alt="npm"></a>
|
|
9
|
+
<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>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
# @everscribe/components-react
|
|
13
|
+
|
|
14
|
+
Embeddable React component for [Everscribe](https://everscribe.io) audit events. Drop `<AuditTrail />` into your app, hand it a short-lived embed token, and your users see a live, scoped view of their audit trail.
|
|
15
|
+
|
|
16
|
+
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).
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @everscribe/components-react @everscribe/components-styles
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Peer dependencies: `react >=18`, `react-dom >=18`. The `components-styles` package ships the default CSS theme; install it alongside.
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { AuditTrail } from '@everscribe/components-react'
|
|
30
|
+
import '@everscribe/components-styles/default.css'
|
|
31
|
+
|
|
32
|
+
export function AuditPage() {
|
|
33
|
+
return <AuditTrail tokenEndpoint="https://yourbackend.com/api/embed-token" />
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`tokenEndpoint` is a route on **your** server (not Everscribe's) that returns a freshly minted embed token. The component 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.
|
|
38
|
+
|
|
39
|
+
If your React app and backend share an origin, a relative path (`/api/embed-token`) works too.
|
|
40
|
+
|
|
41
|
+
If you'd rather control the initial fetch yourself - explicit loading states, integration with an auth context, or a token already in hand - pass it as the `token` prop:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { useEffect, useState } from 'react'
|
|
45
|
+
import { AuditTrail } from '@everscribe/components-react'
|
|
46
|
+
import '@everscribe/components-styles/default.css'
|
|
47
|
+
|
|
48
|
+
export function AuditPage() {
|
|
49
|
+
const [token, setToken] = useState<string | null>(null)
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
fetch('https://yourbackend.com/api/embed-token', { credentials: 'include' })
|
|
53
|
+
.then((r) => r.json())
|
|
54
|
+
.then(({ token }) => setToken(token))
|
|
55
|
+
}, [])
|
|
56
|
+
|
|
57
|
+
if (!token) return <div>Loading…</div>
|
|
58
|
+
return <AuditTrail token={token} tokenEndpoint="https://yourbackend.com/api/embed-token" />
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Pass `tokenEndpoint` (or `onTokenExpired`) alongside `token` so refresh on 401 still works.
|
|
63
|
+
|
|
64
|
+
If you pass none of `token`, `tokenEndpoint`, or `onTokenExpired`, the component renders a configuration error.
|
|
65
|
+
|
|
66
|
+
## Props
|
|
67
|
+
|
|
68
|
+
At least one of `token`, `tokenEndpoint`, or `onTokenExpired` is required.
|
|
69
|
+
|
|
70
|
+
| Prop | Type | Default | Notes |
|
|
71
|
+
|---|---|---|---|
|
|
72
|
+
| `token` | `string` | - | Embed JWT. If omitted, the component fetches one via `tokenEndpoint`/`onTokenExpired` on mount. |
|
|
73
|
+
| `tokenEndpoint` | `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
|
+
| `onTokenExpired` | `() => Promise<string>` | - | Custom token-fetch callback. Takes precedence over `tokenEndpoint`. |
|
|
75
|
+
| `apiBase` | `string` | `https://api.everscribe.io/v1/embed` | Base URL for read endpoints. Override for local dev or self-hosted. |
|
|
76
|
+
| `pageSize` | `number` | `25` | Events per page. |
|
|
77
|
+
| `pollInterval` | `number` | `5000` | Poll cadence in ms. `<= 0` disables polling. Below `1000` is clamped with a `console.warn`. |
|
|
78
|
+
| `theme` | `'light' \| 'dark'` | `'light'` | Switches the CSS-variable theme. |
|
|
79
|
+
| `defaultTimeRange` | `'24h' \| '7d' \| '30d' \| 'all'` | `'all'` | Initial time-range preset for the filters panel. |
|
|
80
|
+
| `className` | `string` | - | Merged onto the root element. |
|
|
81
|
+
| `style` | `CSSProperties` | - | Inline style on the root. Use to override CSS variables at runtime. |
|
|
82
|
+
| `onError` | `(err: Error) => void` | - | Observability hook for fetch errors. |
|
|
83
|
+
|
|
84
|
+
## Persistence
|
|
85
|
+
|
|
86
|
+
Column visibility and filter state are persisted to `localStorage` automatically and restored on mount. Two keys are written, both namespaced by the token's project ID (`sub` claim) and tenant ID (`tenant_id` claim, or `_` when unset):
|
|
87
|
+
|
|
88
|
+
- `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.
|
|
89
|
+
- `audit-trail:filters:{sub}:{tenant_id}` - the active filter state (`FilterValues`): time range, column filters, free-text inputs, the active DSL query, and the last NLP echo fields.
|
|
90
|
+
|
|
91
|
+
Behavior:
|
|
92
|
+
- Restored once the token bootstrap resolves and the JWT is parsed, so the first request to `/events` reflects the user's last session.
|
|
93
|
+
- Swapping the `token` prop to a different project re-restores from that project's storage; persistence picks up under the new key.
|
|
94
|
+
- localStorage failures (private browsing, quota exceeded, malformed JSON) are silently swallowed - falls through to `defaultTimeRange` and empty filters.
|
|
95
|
+
- Token claims that restrict columns (`columns` claim set) take precedence over restored hidden columns.
|
|
96
|
+
- Storage keys are identical between this package and `@everscribe/components-element`, so a customer using both adapters under the same origin shares state cleanly.
|
|
97
|
+
|
|
98
|
+
## SSR / Next.js
|
|
99
|
+
|
|
100
|
+
The component is marked `'use client'` - drop it into a Server Component tree as-is. The detail drawer mounts after hydration via a portal to `document.body`, so SSR output is unaffected. The persistence `useEffect`s only fire on the client after hydration, so they have no SSR side effects.
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT
|