satyamark-react 0.0.5 → 0.0.7

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.
Files changed (2) hide show
  1. package/README.md +406 -136
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,224 +1,494 @@
1
- <p align="center">
2
- <img src="https://raw.githubusercontent.com/DhirajKarangale/SatyaMark/main/Assets/NpmCover/NpmCover_2.png" alt="SatyaMark React" width="100%" />
3
- </p>
4
-
5
1
  # satyamark-react
6
2
 
7
- **satyamark-react** is the official React client library for **SatyaMark** — a real-time, AI-powered content verification infrastructure that surfaces clear, evidence-backed trust signals directly inside your UI.
3
+ > Real-time content verification library for React applications
8
4
 
9
- It extracts text and images from rendered DOM elements, submits them for verification, and renders standardized credibility icons that update live as results arrive.
5
+ SatyaMark is a React library that provides real-time verification for text and image content through AI-powered fact-checking and deepfake detection. Display transparent trust signals directly in your UI to help users distinguish between reliable and unreliable information.
10
6
 
11
- SatyaMark is built as **trust infrastructure**, not a fact-checking oracle.
7
+ [![npm version](https://badge.fury.io/js/satyamark-react.svg)](https://www.npmjs.com/package/satyamark-react)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
12
9
 
13
- <p align="center">
14
- <a href="https://github.com/DhirajKarangale/SatyaMark/tree/main/Frontend/satyamark-react" target="_blank" rel="noopener noreferrer">
15
- GitHub Repository
16
- </a>
17
- ·
18
- <a href="https://www.npmjs.com/package/satyamark-react" target="_blank" rel="noopener noreferrer">
19
- npm Package
20
- </a>
21
- </p>
10
+ ## Features
22
11
 
23
- ---
24
-
25
- ## What This Library Does
12
+ - ✅ **Real-time verification** of text content through fact-checking APIs
13
+ - 🤖 **AI-generated media detection** for images
14
+ - 🔄 **Live status updates** via WebSocket connection
15
+ - 🎨 **Automatic UI injection** with verification marks
16
+ - ⚡ **Lightweight integration** - minimal code required
17
+ - 🔗 **Interactive results** - click through to detailed evidence
18
+ - 📱 **Framework agnostic** - works with any React setup
26
19
 
27
- - Connects your React app to the SatyaMark verification network
28
- - Extracts visible text and images from DOM elements
29
- - Submits content for real-time verification
30
- - Displays standardized trust icons inside your UI
31
- - Updates verification status live
32
- - Allows users to open detailed verification explanations
20
+ ## Table of Contents
33
21
 
34
- This library prioritizes **transparency over certainty**.
35
-
36
- ---
22
+ - [Installation](#installation)
23
+ - [Quick Start](#quick-start)
24
+ - [Core Concepts](#core-concepts)
25
+ - [API Reference](#api-reference)
26
+ - [Usage Examples](#usage-examples)
27
+ - [Best Practices](#best-practices)
28
+ - [Verification Marks](#verification-marks)
29
+ - [Troubleshooting](#troubleshooting)
30
+ - [Limitations](#limitations)
31
+ - [Contributing](#contributing)
37
32
 
38
33
  ## Installation
39
34
 
35
+ Install via npm:
36
+
40
37
  ```bash
41
38
  npm install satyamark-react
42
39
  ```
43
40
 
44
- ---
41
+ **Peer Dependencies:**
42
+ - React 18+ (compatible with React 19)
45
43
 
46
44
  ## Quick Start
47
45
 
48
- ### 1. Initialize the SatyaMark connection (once)
46
+ ### 1. Initialize Connection
47
+
48
+ Call `init()` once when your app loads to establish the WebSocket connection:
49
49
 
50
50
  ```tsx
51
51
  import { useEffect } from "react";
52
- import { init, onConnected } from "satyamark-react";
52
+ import { init } from "satyamark-react";
53
+
54
+ function App() {
55
+ useEffect(() => {
56
+ init({
57
+ app_id: "your-app-id",
58
+ user_id: "unique-user-id",
59
+ });
60
+ }, []);
61
+
62
+ return <YourAppContent />;
63
+ }
64
+ ```
53
65
 
54
- useEffect(() => {
55
- init({
56
- app_id: "YOUR_APP_ID",
57
- user_id: "USER_ID",
58
- });
59
- }, []);
66
+ ### 2. Create a Verified Component
67
+
68
+ ```tsx
69
+ import { useRef, useEffect, useState } from "react";
70
+ import { process, registerStatus } from "satyamark-react";
71
+
72
+ function PostCard({ post }) {
73
+ const contentRef = useRef(null);
74
+ const [jobId, setJobId] = useState(null);
75
+
76
+ // Process content after render
77
+ useEffect(() => {
78
+ if (!contentRef.current) return;
79
+
80
+ process(contentRef.current, post.id)
81
+ .then(setJobId)
82
+ .catch(console.error);
83
+ }, [post.id]);
84
+
85
+ // Register status display
86
+ useEffect(() => {
87
+ if (!jobId || !contentRef.current) return;
88
+ registerStatus(jobId, contentRef.current);
89
+ }, [jobId]);
90
+
91
+ return (
92
+ <div ref={contentRef}>
93
+ <p>{post.text}</p>
94
+ {post.image && <img src={post.image} alt="Post" />}
95
+
96
+ {/* Verification mark appears here */}
97
+ <div data-satyamark-status-container />
98
+ </div>
99
+ );
100
+ }
101
+ ```
102
+
103
+ That's it! The verification mark will automatically appear and update.
104
+
105
+ ## Core Concepts
106
+
107
+ SatyaMark consists of three core modules that work together:
108
+
109
+ ### 1. Connection Layer (`satyamark_connect`)
110
+
111
+ Manages the WebSocket connection to the verification server.
112
+
113
+ - Authenticates with your `app_id` and `user_id`
114
+ - Maintains persistent connection
115
+ - Handles incoming verification results
116
+ - Supports connection callbacks
117
+
118
+ ### 2. Processing Layer (`satyamark_process`)
119
+
120
+ Extracts content from rendered DOM elements for verification.
121
+
122
+ - Walks the DOM tree to extract all visible text
123
+ - Finds and validates images
124
+ - Sends content to verification service
125
+ - Returns a unique `jobId` for tracking
126
+
127
+ ### 3. Status Layer (`satyamark_status_controller`)
128
+
129
+ Manages visual display of verification status.
130
+
131
+ - Injects verification icons into your UI
132
+ - Updates status in real-time
133
+ - Provides tooltips on hover
134
+ - Makes icons clickable for detailed results
60
135
 
136
+ ### Lifecycle Flow
137
+
138
+ ```
139
+ 1. init() → Establish connection
140
+ 2. render → Display content normally
141
+ 3. process() → Extract and send for verification
142
+ 4. registerStatus() → Attach status display
143
+ 5. Auto-update → Marks appear and update automatically
144
+ ```
145
+
146
+ <p align="center">
147
+ <img src="https://raw.githubusercontent.com/DhirajKarangale/SatyaMark/main/Assets/NpmCover/NpmCover_1.png" alt="SatyaMark Architecture" width="100%" />
148
+ </p>
149
+
150
+ ## API Reference
151
+
152
+ ### Connection API
153
+
154
+ #### `init(connectionData, options?)`
155
+
156
+ Establishes WebSocket connection to the SatyaMark server.
157
+
158
+ **Parameters:**
159
+ - `connectionData` (SatyaMarkConnectionData) - **Required**
160
+ - `app_id` (string): Your application's unique identifier
161
+ - `user_id` (string): Current user's unique identifier
162
+ - `options` (object) - Optional
163
+ - `onConnected` (function): Callback when connection succeeds
164
+
165
+ **Returns:** `void`
166
+
167
+ **Example:**
168
+ ```tsx
169
+ init({
170
+ app_id: "my-social-app",
171
+ user_id: "user_12345",
172
+ });
173
+ ```
174
+
175
+ #### `onConnected(callback)`
176
+
177
+ Register a callback for when the connection is established.
178
+
179
+ **Parameters:**
180
+ - `callback` (ConnectedCallback): Function receiving connection data
181
+
182
+ **Returns:** `void`
183
+
184
+ **Example:**
185
+ ```tsx
61
186
  onConnected((data) => {
62
- console.log("Connected to SatyaMark:", data);
187
+ console.log("Connected:", data);
63
188
  });
64
189
  ```
65
190
 
191
+ #### `onReceive(callback)`
192
+
193
+ Subscribe to incoming verification updates. Used internally by status controller.
194
+
195
+ **Parameters:**
196
+ - `callback` (ReceiveCallback): Function receiving verification data
197
+
198
+ **Returns:** Unsubscribe function
199
+
66
200
  ---
67
201
 
68
- ### 2. Process content from a DOM element
202
+ ### Processing API
69
203
 
70
- `satyamark-react` works directly on **rendered UI**, not raw strings.
204
+ #### `process(divRef, dataId)`
71
205
 
72
- ```tsx
73
- import { useRef, useEffect, useState } from "react";
74
- import { process, registerStatus } from "satyamark-react";
206
+ Extracts content from a DOM element and submits for verification.
75
207
 
76
- const cardRef = useRef<HTMLDivElement>(null);
77
- const [jobId, setJobId] = useState<string | null>(null);
208
+ **Parameters:**
209
+ - `divRef` (HTMLDivElement): The DOM element containing content
210
+ - `dataId` (string): Unique identifier for this content (e.g., post ID)
78
211
 
79
- useEffect(() => {
80
- if (!cardRef.current) return;
212
+ **Returns:** `Promise<string>` - Resolves with `jobId` for tracking
81
213
 
82
- process(cardRef.current, "POST_ID")
83
- .then(setJobId)
84
- .catch(console.error);
85
- }, []);
214
+ **Throws:**
215
+ - `"Invalid root element"` - if divRef is null/undefined
216
+ - `"dataId is required"` - if dataId is empty
217
+ - `"No valid text or image found"` - if element has no content
218
+ - `"Extracted text is too short"` - if text is less than 3 characters
219
+
220
+ **Example:**
221
+ ```tsx
222
+ process(ref.current, "post_123")
223
+ .then((jobId) => registerStatus(jobId, ref.current))
224
+ .catch((error) => console.error(error.message));
86
225
  ```
87
226
 
88
227
  ---
89
228
 
90
- ### 3. Display verification status
229
+ ### Status API
91
230
 
92
- Add a container where the status icon should appear:
231
+ #### `registerStatus(jobId, rootElement, options?)`
93
232
 
233
+ Registers a DOM element to display verification status.
234
+
235
+ **Parameters:**
236
+ - `jobId` (string): Job ID returned from `process()`
237
+ - `rootElement` (HTMLElement): Element containing status container
238
+ - `options` (StatusOptions) - Optional
239
+ - `iconSize` (number): Icon size in pixels (default: 20)
240
+
241
+ **Returns:** `void`
242
+
243
+ **Requirements:**
244
+ - Root element must contain a child with `data-satyamark-status-container` attribute
245
+
246
+ **Example:**
94
247
  ```tsx
95
- <div data-satyamark-status-container />
248
+ registerStatus(jobId, contentRef.current, {
249
+ iconSize: 24,
250
+ });
251
+ ```
252
+
253
+ **HTML Structure:**
254
+ ```tsx
255
+ <div ref={contentRef}>
256
+ {/* Your content */}
257
+ <div data-satyamark-status-container />
258
+ </div>
259
+ ```
260
+
261
+ ## Usage Examples
262
+
263
+ ### Basic Setup
264
+
265
+ ```tsx
266
+ import { useEffect } from "react";
267
+ import { init, onConnected } from "satyamark-react";
268
+
269
+ function App() {
270
+ useEffect(() => {
271
+ init({
272
+ app_id: "my-app",
273
+ user_id: getCurrentUserId(),
274
+ });
275
+
276
+ onConnected((data) => {
277
+ console.log("SatyaMark connected:", data);
278
+ });
279
+ }, []);
280
+
281
+ return <div>{/* Your app */}</div>;
282
+ }
283
+ ```
284
+
285
+ ### Complete Component with Error Handling
286
+
287
+ ```tsx
288
+ import { useRef, useEffect, useState } from "react";
289
+ import { process, registerStatus } from "satyamark-react";
290
+
291
+ function VerifiedPost({ post }) {
292
+ const contentRef = useRef(null);
293
+ const [status, setStatus] = useState("idle");
294
+ const [error, setError] = useState("");
295
+
296
+ useEffect(() => {
297
+ if (!contentRef.current) return;
298
+
299
+ setStatus("processing");
300
+
301
+ process(contentRef.current, post.id)
302
+ .then((jobId) => {
303
+ setStatus("success");
304
+ registerStatus(jobId, contentRef.current);
305
+ })
306
+ .catch((err) => {
307
+ setStatus("error");
308
+ setError(err.message);
309
+ });
310
+ }, [post.id]);
311
+
312
+ return (
313
+ <div ref={contentRef} className="post-card">
314
+ <div className="content">
315
+ <p>{post.text}</p>
316
+ {post.image && <img src={post.image} alt="" />}
317
+ </div>
318
+
319
+ {status === "success" && (
320
+ <div data-satyamark-status-container />
321
+ )}
322
+
323
+ {status === "error" && (
324
+ <div className="error-badge">{error}</div>
325
+ )}
326
+ </div>
327
+ );
328
+ }
96
329
  ```
97
330
 
98
- Register the status handler:
331
+ ### List of Posts
332
+
333
+ ```tsx
334
+ function PostFeed({ posts }) {
335
+ return (
336
+ <div className="feed">
337
+ {posts.map((post) => (
338
+ <VerifiedPost key={post.id} post={post} />
339
+ ))}
340
+ </div>
341
+ );
342
+ }
343
+ ```
344
+
345
+ ### Custom Icon Size
99
346
 
100
347
  ```tsx
101
348
  useEffect(() => {
102
- if (!jobId || !cardRef.current) return;
349
+ if (!jobId || !ref.current) return;
103
350
 
104
- registerStatus(jobId, cardRef.current);
351
+ registerStatus(jobId, ref.current, {
352
+ iconSize: 32, // Larger icon
353
+ });
105
354
  }, [jobId]);
106
355
  ```
107
356
 
108
- ---
357
+ ## Best Practices
109
358
 
110
- ## How It Works
359
+ ### Do
111
360
 
112
- <p align="center">
113
- <img src="https://raw.githubusercontent.com/DhirajKarangale/SatyaMark/main/Assets/NpmCover/NpmCover_1.png" alt="SatyaMark Architecture" width="90%" />
114
- </p>
361
+ - **Initialize once** at app startup in your root component
362
+ - **Use unique dataIds** for each piece of content (post ID, comment ID, etc.)
363
+ - **Process after render** - ensure content exists in DOM before calling `process()`
364
+ - **Handle errors gracefully** - short or empty content will throw errors
365
+ - **Use refs correctly** - pass actual DOM elements, not null
366
+ - **Test with real content** - minimum 3 characters or valid image required
115
367
 
116
- 1. Extracts visible text + first valid image
117
- 2. Sends content via WebSocket
118
- 3. Receives live verification updates
119
- 4. Updates icons automatically
120
- 5. Click icon → open detailed verification page
368
+ ### Don't
121
369
 
122
- ---
370
+ - **Don't call init() multiple times** - creates duplicate connections
371
+ - **Don't process before render** - ref.current will be null
372
+ - **Don't reuse dataIds** - each content piece needs unique identifier
373
+ - **Don't forget status container** - `data-satyamark-status-container` is required
374
+ - **Don't manually update icons** - library handles it automatically
375
+ - **Don't process empty content** - ensure content exists first
376
+
377
+ ### ⚡ Performance Tips
378
+
379
+ - **Debounce rapid updates** - don't re-process on every keystroke
380
+ - **Process only visible content** - use Intersection Observer for long lists
381
+ - **Cache jobIds** - avoid re-processing identical content
382
+ - **Lazy load verification** - process when content enters viewport
123
383
 
124
384
  ## Verification Marks
125
385
 
126
- - `correct`
127
- - `incorrect`
128
- - `verifyable`
129
- - `unverifyable`
130
- - `insufficient`
131
- - `pending`
132
- - `ai`
133
- - `nonai`
386
+ SatyaMark displays different marks based on verification results:
134
387
 
135
- ---
388
+ | Mark | Meaning |
389
+ |------|---------|
390
+ | ✅ **Verifiable** | Content contains factual claims that can be verified |
391
+ | ❌ **Unverifiable** | Cannot be verified (opinions, random data, etc.) |
392
+ | ⚠️ **Insufficient** | Verifiable but not enough reliable sources available |
393
+ | ✔️ **Correct** | Factually correct based on evidence |
394
+ | ❗ **Incorrect** | Factually incorrect or contradicts sources |
395
+ | ⏳ **Pending** | Verification in progress |
396
+ | 🤖 **AI-Generated** | Media appears to be AI-generated |
397
+ | 👤 **Human-Generated** | Media appears to be human-created |
398
+ | ❓ **Uncertain** | Cannot confidently determine AI vs human origin |
136
399
 
137
- ## API Reference
400
+ **Interactive:** After verification completes, clicking the mark opens a detailed results page with sources and evidence.
138
401
 
139
- ### `init()`
402
+ ## Troubleshooting
140
403
 
141
- ```ts
142
- init({
143
- app_id: string;
144
- user_id: string;
145
- });
404
+ ### "Invalid root element"
405
+
406
+ **Cause:** Calling `process()` with null/undefined ref.
407
+
408
+ **Solution:** Check ref exists before processing:
409
+ ```tsx
410
+ if (!contentRef.current) return;
411
+ process(contentRef.current, post.id);
146
412
  ```
147
413
 
148
- ---
414
+ ### "No valid text or image found"
149
415
 
150
- ### `process()`
416
+ **Cause:** Element contains no extractable content or all images fail to load.
151
417
 
152
- ```ts
153
- process(
154
- rootElement: HTMLDivElement,
155
- dataId: string
156
- ): Promise<string>
157
- ```
418
+ **Solution:** Ensure content has visible text (3+ chars) or valid image URLs.
158
419
 
159
- ---
420
+ ### Status icon not appearing
160
421
 
161
- ### `registerStatus()`
422
+ **Cause:** Missing `data-satyamark-status-container` or `registerStatus()` not called.
162
423
 
163
- ```ts
164
- registerStatus(
165
- jobId: string,
166
- rootElement: HTMLElement,
167
- options?: {
168
- iconSize?: number;
169
- }
170
- );
424
+ **Solution:** Add status container and call `registerStatus()` with correct jobId:
425
+ ```tsx
426
+ <div data-satyamark-status-container />
427
+ // ...
428
+ registerStatus(jobId, contentRef.current);
171
429
  ```
172
430
 
173
- ---
431
+ ### Connection fails or times out
174
432
 
175
- ### `onReceive()`
433
+ **Cause:** Network issues, invalid credentials, or server unavailable.
176
434
 
177
- ```ts
178
- onReceive((data) => {
179
- console.log(data);
180
- });
181
- ```
435
+ **Solution:** Check console for WebSocket errors. Verify `app_id` and `user_id` are correct.
182
436
 
183
- ---
437
+ ### Multiple verification requests
184
438
 
185
- ### `onConnected()`
439
+ **Cause:** useEffect dependency array causing re-renders.
186
440
 
187
- ```ts
188
- onConnected((connection) => {
189
- console.log("Connected:", connection);
190
- });
441
+ **Solution:** Use stable identifiers in dependency array:
442
+ ```tsx
443
+ useEffect(() => {
444
+ // Process logic
445
+ }, [post.id]); // Stable dependency
191
446
  ```
192
447
 
193
- ---
448
+ ### Verification stuck on "Pending"
194
449
 
195
- ## Design Principles
450
+ **Cause:** Server processing or jobId mismatch.
196
451
 
197
- - Transparency over certainty
198
- - Trust signals, not guarantees
199
- - Privacy-first
200
- - Incremental accuracy
452
+ **Solution:** Verification can take 5-30 seconds. Ensure jobId is correctly passed to `registerStatus()`.
201
453
 
202
- ---
454
+ ## Limitations
203
455
 
204
- ## Current Limitations
456
+ SatyaMark is actively developed. Current limitations:
205
457
 
206
- - Text verification is most reliable
207
- - Image verification is experimental
208
- - Video & audio not yet supported
209
- - Results are not absolute truth
458
+ - **Minimum content:** Text must be at least 3 characters
459
+ - **Single image:** Only first valid image is processed per element
460
+ - **No offline support:** Requires active WebSocket connection
461
+ - **No local caching:** Content sent to server every time (caching planned)
462
+ - **Single connection:** Multiple tabs share connection state
463
+ - **Limited retry logic:** Manual refresh required if connection drops
464
+ - **No client rate limiting:** Apps should implement own throttling
210
465
 
211
- ---
466
+ These are being addressed in future releases. Check the [GitHub repository](https://github.com/DhirajKarangale/SatyaMark) for updates.
212
467
 
213
- ## Privacy Notes
468
+ ## Contributing
214
469
 
215
- - Original text is not stored
216
- - Short AI-generated summaries may be retained
217
- - Images may be temporarily cached
218
- - No advertising or profiling
470
+ SatyaMark is fully open-source and welcomes contributions!
219
471
 
220
- ---
472
+ ### How to Contribute
473
+
474
+ - **Report bugs** on [GitHub Issues](https://github.com/DhirajKarangale/SatyaMark/issues)
475
+ - **Request features** that align with the project's mission
476
+ - **Improve documentation** - submit PRs for clarity improvements
477
+ - **Contribute code** - follow the contributing guidelines in the repository
478
+ - **Share feedback** on library design and API
479
+
480
+ ### Project Links
481
+
482
+ - **Main Repository:** [github.com/DhirajKarangale/SatyaMark](https://github.com/DhirajKarangale/SatyaMark)
483
+ - **npm Package:** [npmjs.com/package/satyamark-react](https://www.npmjs.com/package/satyamark-react)
484
+ - **Demo Application:** [Live Demo](https://satyamark.vercel.app)
221
485
 
222
- ## Summary
486
+ All contributions are reviewed for alignment with SatyaMark's principles: transparency, evidence-based verification, and accessibility.
487
+
488
+ ## License
489
+
490
+ MIT © SatyaMark Contributors
491
+
492
+ ---
223
493
 
224
- **satyamark-react lets React apps surface real-time, evidence-backed credibility signals directly inside the UI.**
494
+ **Need help?** Open an issue on [GitHub](https://github.com/DhirajKarangale/SatyaMark) or check the [live demo](https://satyamark.vercel.app) for examples.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satyamark-react",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "Official React SDK for SatyaMark — a lightweight UI library to embed transparent content verification marks, confidence indicators, and trust signals into React applications.",
5
5
  "license": "MIT",
6
6
  "author": "DK",