satyamark-react 0.0.3 → 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 -132
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,220 +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">GitHub Repository</a>
15
- ·
16
- <a href="https://www.npmjs.com/package/satyamark-react">npm Package</a>
17
- </p>
10
+ ## Features
18
11
 
19
- ---
20
-
21
- ## 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
22
19
 
23
- - Connects your React app to the SatyaMark verification network
24
- - Extracts visible text and images from DOM elements
25
- - Submits content for real-time verification
26
- - Displays standardized trust icons inside your UI
27
- - Updates verification status live
28
- - Allows users to open detailed verification explanations
20
+ ## Table of Contents
29
21
 
30
- This library prioritizes **transparency over certainty**.
31
-
32
- ---
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)
33
32
 
34
33
  ## Installation
35
34
 
35
+ Install via npm or yarn:
36
+
36
37
  ```bash
37
38
  npm install satyamark-react
38
39
  ```
39
40
 
40
- ---
41
+ ```bash
42
+ yarn add satyamark-react
43
+ ```
44
+
45
+ **Peer Dependencies:**
46
+ - React 18+ (compatible with React 19)
41
47
 
42
48
  ## Quick Start
43
49
 
44
- ### 1. Initialize the SatyaMark connection (once)
50
+ ### 1. Initialize Connection
51
+
52
+ Call `init()` once when your app loads to establish the WebSocket connection:
45
53
 
46
54
  ```tsx
47
55
  import { useEffect } from "react";
48
- 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
+ ```
49
69
 
50
- useEffect(() => {
51
- init({
52
- app_id: "YOUR_APP_ID",
53
- user_id: "USER_ID",
54
- });
55
- }, []);
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`)
56
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
57
190
  onConnected((data) => {
58
- console.log("Connected to SatyaMark:", data);
191
+ console.log("Connected:", data);
59
192
  });
60
193
  ```
61
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
+
62
204
  ---
63
205
 
64
- ### 2. Process content from a DOM element
206
+ ### Processing API
65
207
 
66
- `satyamark-react` works directly on **rendered UI**, not raw strings.
208
+ #### `process(divRef, dataId)`
67
209
 
68
- ```tsx
69
- import { useRef, useEffect, useState } from "react";
70
- import { process, registerStatus } from "satyamark-react";
210
+ Extracts content from a DOM element and submits for verification.
71
211
 
72
- const cardRef = useRef<HTMLDivElement>(null);
73
- 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)
74
215
 
75
- useEffect(() => {
76
- if (!cardRef.current) return;
216
+ **Returns:** `Promise<string>` - Resolves with `jobId` for tracking
77
217
 
78
- process(cardRef.current, "POST_ID")
79
- .then(setJobId)
80
- .catch(console.error);
81
- }, []);
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));
82
229
  ```
83
230
 
84
231
  ---
85
232
 
86
- ### 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)
87
244
 
88
- Add a container where the status icon should appear:
245
+ **Returns:** `void`
89
246
 
247
+ **Requirements:**
248
+ - Root element must contain a child with `data-satyamark-status-container` attribute
249
+
250
+ **Example:**
90
251
  ```tsx
91
- <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>
92
263
  ```
93
264
 
94
- 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
95
350
 
96
351
  ```tsx
97
352
  useEffect(() => {
98
- if (!jobId || !cardRef.current) return;
353
+ if (!jobId || !ref.current) return;
99
354
 
100
- registerStatus(jobId, cardRef.current);
355
+ registerStatus(jobId, ref.current, {
356
+ iconSize: 32, // Larger icon
357
+ });
101
358
  }, [jobId]);
102
359
  ```
103
360
 
104
- ---
361
+ ## Best Practices
105
362
 
106
- ## How It Works
363
+ ### Do
107
364
 
108
- <p align="center">
109
- <img src="https://raw.githubusercontent.com/DhirajKarangale/SatyaMark/main/Assets/NpmCover/NpmCover_1.png" alt="SatyaMark Architecture" width="90%" />
110
- </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
111
371
 
112
- 1. Extracts visible text + first valid image
113
- 2. Sends content via WebSocket
114
- 3. Receives live verification updates
115
- 4. Updates icons automatically
116
- 5. Click icon → open detailed verification page
372
+ ### Don't
117
373
 
118
- ---
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
119
387
 
120
388
  ## Verification Marks
121
389
 
122
- - `correct`
123
- - `incorrect`
124
- - `verifyable`
125
- - `unverifyable`
126
- - `insufficient`
127
- - `pending`
128
- - `ai`
129
- - `nonai`
390
+ SatyaMark displays different marks based on verification results:
130
391
 
131
- ---
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 |
132
403
 
133
- ## API Reference
404
+ **Interactive:** After verification completes, clicking the mark opens a detailed results page with sources and evidence.
134
405
 
135
- ### `init()`
406
+ ## Troubleshooting
136
407
 
137
- ```ts
138
- init({
139
- app_id: string;
140
- user_id: string;
141
- });
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);
142
416
  ```
143
417
 
144
- ---
418
+ ### "No valid text or image found"
145
419
 
146
- ### `process()`
420
+ **Cause:** Element contains no extractable content or all images fail to load.
147
421
 
148
- ```ts
149
- process(
150
- rootElement: HTMLDivElement,
151
- dataId: string
152
- ): Promise<string>
153
- ```
422
+ **Solution:** Ensure content has visible text (3+ chars) or valid image URLs.
154
423
 
155
- ---
424
+ ### Status icon not appearing
156
425
 
157
- ### `registerStatus()`
426
+ **Cause:** Missing `data-satyamark-status-container` or `registerStatus()` not called.
158
427
 
159
- ```ts
160
- registerStatus(
161
- jobId: string,
162
- rootElement: HTMLElement,
163
- options?: {
164
- iconSize?: number;
165
- }
166
- );
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);
167
433
  ```
168
434
 
169
- ---
435
+ ### Connection fails or times out
170
436
 
171
- ### `onReceive()`
437
+ **Cause:** Network issues, invalid credentials, or server unavailable.
172
438
 
173
- ```ts
174
- onReceive((data) => {
175
- console.log(data);
176
- });
177
- ```
439
+ **Solution:** Check console for WebSocket errors. Verify `app_id` and `user_id` are correct.
178
440
 
179
- ---
441
+ ### Multiple verification requests
180
442
 
181
- ### `onConnected()`
443
+ **Cause:** useEffect dependency array causing re-renders.
182
444
 
183
- ```ts
184
- onConnected((connection) => {
185
- console.log("Connected:", connection);
186
- });
445
+ **Solution:** Use stable identifiers in dependency array:
446
+ ```tsx
447
+ useEffect(() => {
448
+ // Process logic
449
+ }, [post.id]); // Stable dependency
187
450
  ```
188
451
 
189
- ---
452
+ ### Verification stuck on "Pending"
190
453
 
191
- ## Design Principles
454
+ **Cause:** Server processing or jobId mismatch.
192
455
 
193
- - Transparency over certainty
194
- - Trust signals, not guarantees
195
- - Privacy-first
196
- - Incremental accuracy
456
+ **Solution:** Verification can take 5-30 seconds. Ensure jobId is correctly passed to `registerStatus()`.
197
457
 
198
- ---
458
+ ## Limitations
199
459
 
200
- ## Current Limitations
460
+ SatyaMark is actively developed. Current limitations:
201
461
 
202
- - Text verification is most reliable
203
- - Image verification is experimental
204
- - Video & audio not yet supported
205
- - 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
206
469
 
207
- ---
470
+ These are being addressed in future releases. Check the [GitHub repository](https://github.com/DhirajKarangale/SatyaMark) for updates.
208
471
 
209
- ## Privacy Notes
472
+ ## Contributing
210
473
 
211
- - Original text is not stored
212
- - Short AI-generated summaries may be retained
213
- - Images may be temporarily cached
214
- - No advertising or profiling
474
+ SatyaMark is fully open-source and welcomes contributions!
215
475
 
216
- ---
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)
217
489
 
218
- ## One-Line 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
+ ---
219
497
 
220
- **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.3",
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",
@@ -53,4 +53,4 @@
53
53
  "tsup": "^6.7.0",
54
54
  "typescript": "^5.0.0"
55
55
  }
56
- }
56
+ }