@visitorquery/react 0.0.10 → 0.0.13

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 CHANGED
@@ -1 +1 @@
1
- export * from "./provider.tsx";
1
+ export * from './provider.tsx';
package/dist/index.js CHANGED
@@ -1,122 +1,89 @@
1
- // src/provider.tsx
2
- import { createContext, useContext, useState as useState2, useEffect as useEffect2, useMemo } 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);
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);
14
11
  return;
15
12
  }
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();
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);
26
21
  };
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;
22
+ e.addEventListener("load", o), e.addEventListener("error", r);
23
+ const c = a.current.removeOnUnmount;
39
24
  return () => {
40
- if (removeOnUnmount === true) {
41
- script?.remove();
42
- removeEventListeners();
43
- }
25
+ c === !0 && (e == null || e.remove(), u());
44
26
  };
45
- } else {
46
- setStatus("unknown");
47
- }
48
- }, [src]);
49
- return status;
27
+ } else
28
+ n("unknown");
29
+ }, [t]), d;
50
30
  }
51
-
52
- // src/provider.tsx
53
- import { jsxDEV } from "react/jsx-dev-runtime";
54
- var VisitorQueryContext = createContext(null);
55
- function VisitorQueryProvider({
56
- apiKey,
57
- sessionId,
58
- endpoint,
59
- children
31
+ const f = v(null);
32
+ function x({
33
+ apiKey: t,
34
+ sessionId: i,
35
+ endpoint: d,
36
+ children: n
60
37
  }) {
61
- const defaultEndpoint = "main.check.visitorquery.com";
62
- const clientScript = useScript("https://cdn.visitorquery.com/visitorquery.js", {
63
- removeOnUnmount: false
64
- });
65
- const [state, setState] = useState2({
66
- Started: false,
67
- Ended: false
68
- });
69
- const params = useMemo(() => ({
70
- ApiKey: apiKey,
71
- SessionId: sessionId,
72
- Endpoint: endpoint || defaultEndpoint
73
- }), [apiKey, sessionId, endpoint, defaultEndpoint]);
74
- useEffect2(() => {
75
- if (typeof window.VisitorQuery !== "undefined") {
76
- window.VisitorQuery.run({
77
- ApiKey: params.ApiKey,
78
- Endpoint: params.Endpoint,
79
- SessionId: params.SessionId,
80
- onOpen: () => {
81
- setState({
82
- Started: true,
83
- Ended: false
84
- });
85
- },
86
- onClose: () => {
87
- setState({
88
- Started: true,
89
- Ended: true
90
- });
91
- },
92
- onError: (err) => {
93
- setState({
94
- Started: true,
95
- Ended: true,
96
- Errored: true
97
- });
98
- console.error(err);
99
- }
100
- });
101
- }
102
- }, [params, clientScript]);
103
- const contextValue = useMemo(() => ({
104
- ...state,
105
- isLoading: clientScript === "loading"
106
- }), [state, clientScript]);
107
- return /* @__PURE__ */ jsxDEV(VisitorQueryContext.Provider, {
108
- value: contextValue,
109
- children
110
- }, undefined, false, undefined, this);
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 });
111
79
  }
112
- function useVisitorQuery() {
113
- const context = useContext(VisitorQueryContext);
114
- if (!context) {
80
+ function A() {
81
+ const t = p(f);
82
+ if (!t)
115
83
  throw new Error("useVisitorQuery must be used within a VisitorQueryProvider");
116
- }
117
- return context;
84
+ return t;
118
85
  }
119
86
  export {
120
- useVisitorQuery,
121
- VisitorQueryProvider
87
+ x as VisitorQueryProvider,
88
+ A as useVisitorQuery
122
89
  };
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import { default as React } from 'react';
2
2
  declare global {
3
3
  interface Window {
4
4
  VisitorQuery: any;
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
1
  {
2
- "version": "0.0.10",
3
- "name": "@visitorquery/react",
4
- "module": "src/index.tsx",
5
- "type": "module",
6
- "devDependencies": {
7
- "@types/bun": "latest"
8
- },
9
- "access": "public",
10
- "main": "dist/index.ts",
11
- "types": "dist/index.d.ts",
12
- "scripts": {
13
- "build": "bun build --target=node ./src/index.ts --outfile=dist/index.js --external react --external react-dom && bun run build:declaration",
14
- "build:declaration": "tsc --emitDeclarationOnly --project tsconfig.types.json",
15
- "postbuild": "rimraf tsconfig.types.tsbuildinfo",
16
- "push": "git fetch --tags -f && standard-version && git push --follow-tags origin master && bun publish --access public",
17
- "release": "pnpm run build && pnpm run build:declaration && pnpm run push"
18
- },
19
- "peerDependencies": {
20
- "@types/react": "^19.0.10",
21
- "react": "^19.0.0",
22
- "react-dom": "^19.0.0",
23
- "typescript": "^5.0.0"
24
- },
25
- "repository": {
26
- "type": "git",
27
- "url": "https://github.com/visitorquery/react-hook.git"
28
- },
29
- "keywords": [
30
- "fraud",
31
- "antifraud",
32
- "chargeback",
33
- "proxy",
34
- "visitorquery",
35
- "vpn",
36
- "detect"
37
- ],
38
- "author": "VisitorQuery",
39
- "license": "MIT",
40
- "files": [
41
- "dist/*.js",
42
- "dist/*.jsx",
43
- "dist/*.d.ts"
44
- ]
45
- }
2
+ "version": "0.0.13",
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
+ }