@trustsig/react 1.2.1 → 1.2.8

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/README.md CHANGED
@@ -8,10 +8,9 @@ React Context Provider and hooks for TrustSig bot protection.
8
8
  npm install @trustsig/react
9
9
  ```
10
10
 
11
- ## Usage (Next.js App Router)
12
-
13
- ### 1. Root Layout
11
+ ## Usage
14
12
 
13
+ ### 1. Setup Provider
15
14
  Wrap your application or specific routes with the provider.
16
15
 
17
16
  ```tsx
@@ -20,39 +19,48 @@ import { TrustSigProvider } from '@trustsig/react';
20
19
 
21
20
  export default function RootLayout({ children }) {
22
21
  return (
23
- <TrustSigProvider siteKey="YOUR_PUBLIC_KEY" interceptRequests={true}>
22
+ <TrustSigProvider
23
+ siteKey="pk_live_..."
24
+ autoScan={true}
25
+ >
24
26
  {children}
25
27
  </TrustSigProvider>
26
28
  );
27
29
  }
28
30
  ```
29
31
 
30
- ### 2. Usage in Client Components
31
-
32
- Use the hook inside any component nested under the provider.
32
+ ### 2. Using the Hook
33
+ Use `useTrustSig` to access the analysis methods.
33
34
 
34
35
  ```tsx
35
36
  "use client";
36
37
  import { useTrustSig } from '@trustsig/react';
37
38
 
38
- export function LoginForm() {
39
- const { getResponse } = useTrustSig();
39
+ export function ActionForm() {
40
+ const { getResponse, scan, isLoaded } = useTrustSig();
40
41
 
41
42
  const handleSubmit = async (e) => {
42
43
  e.preventDefault();
43
- const token = await getResponse();
44
44
 
45
- await fetch('/api/login', {
46
- method: 'POST',
47
- headers: { 'X-TrustSig-Response': token || '' },
48
- body: JSON.stringify({ email: "user@example.com" })
49
- });
45
+ // Get the current analysis response
46
+ const response = await getResponse();
47
+
48
+ if (response?.token) {
49
+ await fetch('/api/secure-action', {
50
+ method: 'POST',
51
+ headers: {
52
+ 'Content-Type': 'application/json',
53
+ 'X-TrustSig-Response': response.token
54
+ },
55
+ body: JSON.stringify({ data: "..." })
56
+ });
57
+ }
50
58
  };
51
59
 
52
60
  return (
53
- <form onSubmit={handleSubmit}>
54
- <button type="submit">Login</button>
55
- </form>
61
+ <button onClick={handleSubmit} disabled={!isLoaded}>
62
+ Submit Secure Action
63
+ </button>
56
64
  );
57
65
  }
58
66
  ```
@@ -61,5 +69,8 @@ export function LoginForm() {
61
69
 
62
70
  | Export | Type | Description |
63
71
  | --- | --- | --- |
64
- | `TrustSigProvider` | Component | The React context provider. |
65
- | `useTrustSig` | Hook | Hook to get the response token and status. |
72
+ | `isLoaded` | `boolean` | True when the TrustSig script has loaded. |
73
+ | `getResponse()` | `Promise<TrustSigResponse>` | Returns the current analysis result. |
74
+ | `scan()` | `Promise<TrustSigResponse>` | Manually triggers a new analysis scan. |
75
+ | `setCustomData(data)` | `void` | Updates custom metadata for subsequent scans. |
76
+ | `error` | `Error \| null` | Error object if script loading failed. |
package/dist/index.cjs CHANGED
@@ -44,10 +44,9 @@ var import_client = require("@trustsig/client");
44
44
  var TrustSigContext = (0, import_react.createContext)(null);
45
45
  var TrustSigProvider = ({
46
46
  siteKey,
47
- endpoint,
48
- wasmUrl,
49
47
  scriptUrl,
50
48
  interceptRequests,
49
+ autoScan,
51
50
  debug,
52
51
  nonce,
53
52
  env,
@@ -59,16 +58,15 @@ var TrustSigProvider = ({
59
58
  const client = (0, import_react.useMemo)(
60
59
  () => new import_client.TrustSigClient({
61
60
  siteKey,
62
- endpoint,
63
- wasmUrl,
64
61
  scriptUrl,
65
62
  interceptRequests,
63
+ autoScan,
66
64
  debug,
67
65
  nonce,
68
66
  env,
69
67
  customData
70
68
  }),
71
- [siteKey, endpoint, wasmUrl, scriptUrl, interceptRequests, debug, nonce, env, JSON.stringify(customData)]
69
+ [siteKey, scriptUrl, interceptRequests, autoScan, debug, nonce, env, JSON.stringify(customData)]
72
70
  );
73
71
  (0, import_react.useEffect)(() => {
74
72
  let mounted = true;
@@ -90,6 +88,7 @@ var TrustSigProvider = ({
90
88
  isLoaded,
91
89
  error,
92
90
  getResponse: () => client.getResponse(),
91
+ scan: () => client.scan(),
93
92
  setCustomData: (data) => client.setCustomData(data)
94
93
  }),
95
94
  [isLoaded, error, client]
package/dist/index.d.cts CHANGED
@@ -1,18 +1,18 @@
1
1
  import React from 'react';
2
- import { TrustSigEnv } from '@trustsig/types';
2
+ import { TrustSigResponse, TrustSigEnv } from '@trustsig/types';
3
3
 
4
4
  interface TrustSigContextValue {
5
5
  isLoaded: boolean;
6
6
  error: Error | null;
7
- getResponse: () => Promise<string | null>;
7
+ getResponse: () => Promise<TrustSigResponse | null>;
8
+ scan: () => Promise<TrustSigResponse | null>;
8
9
  setCustomData: (data: Record<string, any>) => void;
9
10
  }
10
11
  interface TrustSigProviderProps {
11
12
  siteKey: string;
12
- endpoint?: string;
13
- wasmUrl?: string;
14
13
  scriptUrl?: string;
15
14
  interceptRequests?: boolean;
15
+ autoScan?: boolean;
16
16
  debug?: boolean;
17
17
  nonce?: string;
18
18
  env?: TrustSigEnv;
package/dist/index.d.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  import React from 'react';
2
- import { TrustSigEnv } from '@trustsig/types';
2
+ import { TrustSigResponse, TrustSigEnv } from '@trustsig/types';
3
3
 
4
4
  interface TrustSigContextValue {
5
5
  isLoaded: boolean;
6
6
  error: Error | null;
7
- getResponse: () => Promise<string | null>;
7
+ getResponse: () => Promise<TrustSigResponse | null>;
8
+ scan: () => Promise<TrustSigResponse | null>;
8
9
  setCustomData: (data: Record<string, any>) => void;
9
10
  }
10
11
  interface TrustSigProviderProps {
11
12
  siteKey: string;
12
- endpoint?: string;
13
- wasmUrl?: string;
14
13
  scriptUrl?: string;
15
14
  interceptRequests?: boolean;
15
+ autoScan?: boolean;
16
16
  debug?: boolean;
17
17
  nonce?: string;
18
18
  env?: TrustSigEnv;
package/dist/index.js CHANGED
@@ -7,10 +7,9 @@ import { TrustSigClient } from "@trustsig/client";
7
7
  var TrustSigContext = createContext(null);
8
8
  var TrustSigProvider = ({
9
9
  siteKey,
10
- endpoint,
11
- wasmUrl,
12
10
  scriptUrl,
13
11
  interceptRequests,
12
+ autoScan,
14
13
  debug,
15
14
  nonce,
16
15
  env,
@@ -22,16 +21,15 @@ var TrustSigProvider = ({
22
21
  const client = useMemo(
23
22
  () => new TrustSigClient({
24
23
  siteKey,
25
- endpoint,
26
- wasmUrl,
27
24
  scriptUrl,
28
25
  interceptRequests,
26
+ autoScan,
29
27
  debug,
30
28
  nonce,
31
29
  env,
32
30
  customData
33
31
  }),
34
- [siteKey, endpoint, wasmUrl, scriptUrl, interceptRequests, debug, nonce, env, JSON.stringify(customData)]
32
+ [siteKey, scriptUrl, interceptRequests, autoScan, debug, nonce, env, JSON.stringify(customData)]
35
33
  );
36
34
  useEffect(() => {
37
35
  let mounted = true;
@@ -53,6 +51,7 @@ var TrustSigProvider = ({
53
51
  isLoaded,
54
52
  error,
55
53
  getResponse: () => client.getResponse(),
54
+ scan: () => client.scan(),
56
55
  setCustomData: (data) => client.setCustomData(data)
57
56
  }),
58
57
  [isLoaded, error, client]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustsig/react",
3
- "version": "1.2.1",
3
+ "version": "1.2.8",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -20,8 +20,8 @@
20
20
  "build": "tsup"
21
21
  },
22
22
  "dependencies": {
23
- "@trustsig/client": "^1.1.11",
24
- "@trustsig/types": "^1.1.11"
23
+ "@trustsig/client": "^1.2.8",
24
+ "@trustsig/types": "^1.2.8"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "react": "^18.0.0 || ^19.0.0",