@inso_web/els-react 0.1.1 → 0.3.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.
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "els-react-vite-example",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "tsc && vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "dependencies": {
12
+ "@inso_web/els-client": "^0.2.0",
13
+ "@inso_web/els-react": "^0.1.0",
14
+ "react": "^18.2.0",
15
+ "react-dom": "^18.2.0"
16
+ },
17
+ "devDependencies": {
18
+ "@types/react": "^18.2.0",
19
+ "@types/react-dom": "^18.2.0",
20
+ "@vitejs/plugin-react": "^4.2.0",
21
+ "typescript": "^5.3.0",
22
+ "vite": "^5.0.0"
23
+ }
24
+ }
@@ -0,0 +1,19 @@
1
+ import { ELSErrorBoundary } from '@inso_web/els-react';
2
+ import ErrorTrigger from './ErrorTrigger';
3
+
4
+ export default function App() {
5
+ return (
6
+ <main>
7
+ <h1>@inso_web/els-react — Vite example</h1>
8
+ <p>
9
+ Этот пример демонстрирует <code>ELSProvider</code>,{' '}
10
+ <code>useErrorReporter</code> и <code>ELSErrorBoundary</code>.
11
+ </p>
12
+ <ELSErrorBoundary
13
+ fallback={<div className="err">Что-то сломалось (поймал ELSErrorBoundary)</div>}
14
+ >
15
+ <ErrorTrigger />
16
+ </ELSErrorBoundary>
17
+ </main>
18
+ );
19
+ }
@@ -0,0 +1,29 @@
1
+ import { useState } from 'react';
2
+ import { useErrorReporter } from '@inso_web/els-react';
3
+
4
+ export default function ErrorTrigger() {
5
+ const [crash, setCrash] = useState(false);
6
+ const report = useErrorReporter();
7
+
8
+ if (crash) throw new Error('Manual crash for ELSErrorBoundary demo');
9
+
10
+ return (
11
+ <div className="card">
12
+ <button
13
+ onClick={() => {
14
+ try {
15
+ throw new Error('Manual error from useErrorReporter');
16
+ } catch (e) {
17
+ report(e as Error);
18
+ alert('Sent to ELS!');
19
+ }
20
+ }}
21
+ >
22
+ Send error via useErrorReporter()
23
+ </button>
24
+ <button onClick={() => setCrash(true)}>
25
+ Crash component (caught by ELSErrorBoundary)
26
+ </button>
27
+ </div>
28
+ );
29
+ }
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom/client';
3
+ import { ELSProvider } from '@inso_web/els-react';
4
+ import App from './App';
5
+ import './styles.css';
6
+
7
+ ReactDOM.createRoot(document.getElementById('root')!).render(
8
+ <React.StrictMode>
9
+ <ELSProvider
10
+ config={{
11
+ endpoint: import.meta.env.VITE_ELS_URL || 'https://api.insoweb.ru/els',
12
+ apiKey: import.meta.env.VITE_ELS_API_KEY || 'els_live_xxxxxxxx',
13
+ appSlug: 'examples',
14
+ deploymentEnv: 'DEV',
15
+ serviceName: 'vite-react-example',
16
+ }}
17
+ >
18
+ <App />
19
+ </ELSProvider>
20
+ </React.StrictMode>,
21
+ );
@@ -0,0 +1,40 @@
1
+ body {
2
+ font-family: system-ui, -apple-system, sans-serif;
3
+ max-width: 720px;
4
+ margin: 2rem auto;
5
+ padding: 0 1rem;
6
+ color: #222;
7
+ }
8
+
9
+ h1 {
10
+ font-size: 1.6rem;
11
+ }
12
+
13
+ button {
14
+ padding: 0.5rem 1rem;
15
+ margin-right: 0.5rem;
16
+ margin-top: 0.5rem;
17
+ cursor: pointer;
18
+ border: 1px solid #888;
19
+ background: #fff;
20
+ border-radius: 4px;
21
+ }
22
+
23
+ button:hover {
24
+ background: #f0f0f0;
25
+ }
26
+
27
+ .card {
28
+ border: 1px solid #ddd;
29
+ border-radius: 6px;
30
+ padding: 1rem;
31
+ margin-top: 1rem;
32
+ }
33
+
34
+ .err {
35
+ background: #ffecec;
36
+ border: 1px solid #f88;
37
+ padding: 1rem;
38
+ border-radius: 6px;
39
+ color: #900;
40
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+ "moduleResolution": "bundler",
9
+ "allowImportingTsExtensions": true,
10
+ "resolveJsonModule": true,
11
+ "isolatedModules": true,
12
+ "noEmit": true,
13
+ "jsx": "react-jsx",
14
+ "strict": true,
15
+ "noUnusedLocals": true,
16
+ "noUnusedParameters": true,
17
+ "noFallthroughCasesInSwitch": true,
18
+ "types": ["vite/client"]
19
+ },
20
+ "include": ["src"],
21
+ "references": [{ "path": "./tsconfig.node.json" }]
22
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "skipLibCheck": true,
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "allowSyntheticDefaultImports": true,
8
+ "strict": true
9
+ },
10
+ "include": ["vite.config.ts"]
11
+ }
@@ -0,0 +1,6 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+
4
+ export default defineConfig({
5
+ plugins: [react()],
6
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inso_web/els-react",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "React‑обёртка для Error Logs Service (ELS): Provider, hooks, ErrorBoundary и HOC для автоматического репорта ошибок компонентов.",
5
5
  "homepage": "https://api.insoweb.ru/els",
6
6
  "author": "INSOWEB",
@@ -17,6 +17,7 @@
17
17
  },
18
18
  "files": [
19
19
  "dist",
20
+ "examples",
20
21
  "README.md",
21
22
  "LICENSE"
22
23
  ],
@@ -49,7 +50,7 @@
49
50
  "react": ">=17.0.0"
50
51
  },
51
52
  "dependencies": {
52
- "@inso_web/els-client": "^0.2.1"
53
+ "@inso_web/els-client": "^0.3.0"
53
54
  },
54
55
  "devDependencies": {
55
56
  "@testing-library/react": "^14.1.2",