@visitorquery/react 0.0.9 → 0.0.12
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/dist/index.d.ts +1 -17
- package/dist/provider.d.ts +23 -0
- package/dist/react.js +89 -0
- package/package.json +44 -43
- package/dist/index.js +0 -95
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
interface Window {
|
|
3
|
-
VisitorQuery: any;
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
type Params = {
|
|
7
|
-
ApiKey: string;
|
|
8
|
-
SessionId: string;
|
|
9
|
-
Endpoint?: string;
|
|
10
|
-
};
|
|
11
|
-
type State = {
|
|
12
|
-
Started: boolean;
|
|
13
|
-
Ended: boolean;
|
|
14
|
-
Errored?: boolean;
|
|
15
|
-
};
|
|
16
|
-
export declare function useVisitorQuery(p: Params): State;
|
|
17
|
-
export {};
|
|
1
|
+
export * from './provider.tsx';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
VisitorQuery: any;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
type VisitorQueryState = {
|
|
8
|
+
Started: boolean;
|
|
9
|
+
Ended: boolean;
|
|
10
|
+
Errored?: boolean;
|
|
11
|
+
};
|
|
12
|
+
type VisitorQueryContextType = VisitorQueryState & {
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
};
|
|
15
|
+
type VisitorQueryProviderProps = {
|
|
16
|
+
apiKey: string;
|
|
17
|
+
sessionId: string;
|
|
18
|
+
endpoint?: string;
|
|
19
|
+
children: React.ReactNode;
|
|
20
|
+
};
|
|
21
|
+
export declare function VisitorQueryProvider({ apiKey, sessionId, endpoint, children }: VisitorQueryProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export declare function useVisitorQuery(): VisitorQueryContextType;
|
|
23
|
+
export {};
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { jsx as E } from "react/jsx-runtime";
|
|
2
|
+
import * as m from "react";
|
|
3
|
+
import { createContext as v, useState as y, useMemo as l, useEffect as S, useContext as p } from "react";
|
|
4
|
+
function w(t, i = {}) {
|
|
5
|
+
const [d, n] = m.useState("loading"), a = m.useRef(i);
|
|
6
|
+
return m.useEffect(() => {
|
|
7
|
+
let e = document.querySelector(`script[src="${t}"]`);
|
|
8
|
+
const s = e == null ? void 0 : e.getAttribute("data-status");
|
|
9
|
+
if (s) {
|
|
10
|
+
n(s);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (e === null) {
|
|
14
|
+
e = document.createElement("script"), e.src = t, e.async = !0, e.setAttribute("data-status", "loading"), document.body.appendChild(e);
|
|
15
|
+
const o = () => {
|
|
16
|
+
e == null || e.setAttribute("data-status", "ready"), n("ready"), u();
|
|
17
|
+
}, r = () => {
|
|
18
|
+
e == null || e.setAttribute("data-status", "error"), n("error"), u();
|
|
19
|
+
}, u = () => {
|
|
20
|
+
e == null || e.removeEventListener("load", o), e == null || e.removeEventListener("error", r);
|
|
21
|
+
};
|
|
22
|
+
e.addEventListener("load", o), e.addEventListener("error", r);
|
|
23
|
+
const c = a.current.removeOnUnmount;
|
|
24
|
+
return () => {
|
|
25
|
+
c === !0 && (e == null || e.remove(), u());
|
|
26
|
+
};
|
|
27
|
+
} else
|
|
28
|
+
n("unknown");
|
|
29
|
+
}, [t]), d;
|
|
30
|
+
}
|
|
31
|
+
const f = v(null);
|
|
32
|
+
function x({
|
|
33
|
+
apiKey: t,
|
|
34
|
+
sessionId: i,
|
|
35
|
+
endpoint: d,
|
|
36
|
+
children: n
|
|
37
|
+
}) {
|
|
38
|
+
const a = "main.check.visitorquery.com", e = w("https://cdn.visitorquery.com/visitorquery.js", {
|
|
39
|
+
removeOnUnmount: !1
|
|
40
|
+
}), [s, o] = y({
|
|
41
|
+
Started: !1,
|
|
42
|
+
Ended: !1
|
|
43
|
+
}), r = l(() => ({
|
|
44
|
+
ApiKey: t,
|
|
45
|
+
SessionId: i,
|
|
46
|
+
Endpoint: d || a
|
|
47
|
+
}), [t, i, d, a]);
|
|
48
|
+
S(() => {
|
|
49
|
+
typeof window.VisitorQuery < "u" && window.VisitorQuery.run({
|
|
50
|
+
ApiKey: r.ApiKey,
|
|
51
|
+
Endpoint: r.Endpoint,
|
|
52
|
+
SessionId: r.SessionId,
|
|
53
|
+
onOpen: () => {
|
|
54
|
+
o({
|
|
55
|
+
Started: !0,
|
|
56
|
+
Ended: !1
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
onClose: () => {
|
|
60
|
+
o({
|
|
61
|
+
Started: !0,
|
|
62
|
+
Ended: !0
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
onError: (c) => {
|
|
66
|
+
o({
|
|
67
|
+
Started: !0,
|
|
68
|
+
Ended: !0,
|
|
69
|
+
Errored: !0
|
|
70
|
+
}), console.error(c);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}, [r, e]);
|
|
74
|
+
const u = l(() => ({
|
|
75
|
+
...s,
|
|
76
|
+
isLoading: e === "loading"
|
|
77
|
+
}), [s, e]);
|
|
78
|
+
return /* @__PURE__ */ E(f.Provider, { value: u, children: n });
|
|
79
|
+
}
|
|
80
|
+
function A() {
|
|
81
|
+
const t = p(f);
|
|
82
|
+
if (!t)
|
|
83
|
+
throw new Error("useVisitorQuery must be used within a VisitorQueryProvider");
|
|
84
|
+
return t;
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
x as VisitorQueryProvider,
|
|
88
|
+
A as useVisitorQuery
|
|
89
|
+
};
|
package/package.json
CHANGED
|
@@ -1,44 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
2
|
+
"version": "0.0.12",
|
|
3
|
+
"name": "@visitorquery/react",
|
|
4
|
+
"module": "src/index.tsx",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"devDependencies": {
|
|
7
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
8
|
+
"vite": "^6.2.1",
|
|
9
|
+
"vite-plugin-dts": "^4.5.3"
|
|
10
|
+
},
|
|
11
|
+
"access": "public",
|
|
12
|
+
"main": "dist/index.ts",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@types/react": "^19.0.10",
|
|
16
|
+
"react": "^19.0.0",
|
|
17
|
+
"react-dom": "^19.0.0",
|
|
18
|
+
"typescript": "^5.0.0"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/visitorquery/react-hook.git"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"fraud",
|
|
26
|
+
"antifraud",
|
|
27
|
+
"chargeback",
|
|
28
|
+
"proxy",
|
|
29
|
+
"visitorquery",
|
|
30
|
+
"vpn",
|
|
31
|
+
"detect"
|
|
32
|
+
],
|
|
33
|
+
"author": "VisitorQuery",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"files": [
|
|
36
|
+
"dist/*.js",
|
|
37
|
+
"dist/*.jsx",
|
|
38
|
+
"dist/*.d.ts"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc --p ./tsconfig.build.json && vite build",
|
|
42
|
+
"push": "git fetch --tags -f && standard-version && git push --follow-tags origin master && pnpm publish --access public",
|
|
43
|
+
"release": "pnpm run build && pnpm run push"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/dist/index.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import { useState as useState2, useEffect as useEffect2 } from "react";
|
|
3
|
-
|
|
4
|
-
// src/hooks.ts
|
|
5
|
-
import * as React from "react";
|
|
6
|
-
function useScript(src, options = {}) {
|
|
7
|
-
const [status, setStatus] = React.useState("loading");
|
|
8
|
-
const optionsRef = React.useRef(options);
|
|
9
|
-
React.useEffect(() => {
|
|
10
|
-
let script = document.querySelector(`script[src="${src}"]`);
|
|
11
|
-
const domStatus = script?.getAttribute("data-status");
|
|
12
|
-
if (domStatus) {
|
|
13
|
-
setStatus(domStatus);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (script === null) {
|
|
17
|
-
script = document.createElement("script");
|
|
18
|
-
script.src = src;
|
|
19
|
-
script.async = true;
|
|
20
|
-
script.setAttribute("data-status", "loading");
|
|
21
|
-
document.body.appendChild(script);
|
|
22
|
-
const handleScriptLoad = () => {
|
|
23
|
-
script?.setAttribute("data-status", "ready");
|
|
24
|
-
setStatus("ready");
|
|
25
|
-
removeEventListeners();
|
|
26
|
-
};
|
|
27
|
-
const handleScriptError = () => {
|
|
28
|
-
script?.setAttribute("data-status", "error");
|
|
29
|
-
setStatus("error");
|
|
30
|
-
removeEventListeners();
|
|
31
|
-
};
|
|
32
|
-
const removeEventListeners = () => {
|
|
33
|
-
script?.removeEventListener("load", handleScriptLoad);
|
|
34
|
-
script?.removeEventListener("error", handleScriptError);
|
|
35
|
-
};
|
|
36
|
-
script.addEventListener("load", handleScriptLoad);
|
|
37
|
-
script.addEventListener("error", handleScriptError);
|
|
38
|
-
const removeOnUnmount = optionsRef.current.removeOnUnmount;
|
|
39
|
-
return () => {
|
|
40
|
-
if (removeOnUnmount === true) {
|
|
41
|
-
script?.remove();
|
|
42
|
-
removeEventListeners();
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
} else {
|
|
46
|
-
setStatus("unknown");
|
|
47
|
-
}
|
|
48
|
-
}, [src]);
|
|
49
|
-
return status;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// src/index.ts
|
|
53
|
-
function useVisitorQuery(p) {
|
|
54
|
-
const defaultEndpoint = "main.check.visitorquery.com";
|
|
55
|
-
const clientScript = useScript("https://cdn.visitorquery.com/visitorquery.js", {
|
|
56
|
-
removeOnUnmount: false
|
|
57
|
-
});
|
|
58
|
-
const [state, setState] = useState2({
|
|
59
|
-
Started: false,
|
|
60
|
-
Ended: false
|
|
61
|
-
});
|
|
62
|
-
useEffect2(() => {
|
|
63
|
-
if (typeof window.VisitorQuery !== "undefined") {
|
|
64
|
-
window.VisitorQuery.run({
|
|
65
|
-
ApiKey: p.ApiKey,
|
|
66
|
-
Endpoint: p.Endpoint || defaultEndpoint,
|
|
67
|
-
SessionId: p.SessionId,
|
|
68
|
-
onOpen: () => {
|
|
69
|
-
setState({
|
|
70
|
-
Started: true,
|
|
71
|
-
Ended: false
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
onClose: () => {
|
|
75
|
-
setState({
|
|
76
|
-
Started: true,
|
|
77
|
-
Ended: true
|
|
78
|
-
});
|
|
79
|
-
},
|
|
80
|
-
onError: (err) => {
|
|
81
|
-
setState({
|
|
82
|
-
Started: true,
|
|
83
|
-
Ended: true,
|
|
84
|
-
Errored: true
|
|
85
|
-
});
|
|
86
|
-
console.error(err);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}, [p, clientScript]);
|
|
91
|
-
return state;
|
|
92
|
-
}
|
|
93
|
-
export {
|
|
94
|
-
useVisitorQuery
|
|
95
|
-
};
|