satyamark-react 0.0.5 → 0.0.6

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