@cs124/client-id
Advanced tools
Comparing version 2023.8.0 to 2024.7.0
{ | ||
"reject": ["public-ip"] | ||
"reject": ["eslint"] | ||
} |
@@ -5,2 +5,3 @@ import React, { PropsWithChildren } from "react"; | ||
disableIP?: boolean; | ||
verbose?: boolean; | ||
} | ||
@@ -7,0 +8,0 @@ export interface ClientIDContext { |
@@ -1,62 +0,27 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useClientID = exports.ClientIDProvider = exports.ClientIDContext = void 0; | ||
const public_ip_1 = __importDefault(require("public-ip")); | ||
const react_1 = __importStar(require("react")); | ||
const uuid_1 = require("uuid"); | ||
exports.ClientIDContext = (0, react_1.createContext)({ | ||
import crypto from "crypto"; | ||
import { publicIpv4, publicIpv6 } from "public-ip"; | ||
import React, { createContext, useContext, useEffect, useRef, useState } from "react"; | ||
const generateRandomID = () => crypto.randomBytes(20).toString("base64"); | ||
export const ClientIDContext = createContext({ | ||
browserID: "", | ||
tabID: "", | ||
}); | ||
const ClientIDProvider = ({ IPinterval = 5 * 6 * 1000, disableIP, children, }) => { | ||
const browser = (0, react_1.useRef)((typeof window !== "undefined" && localStorage.getItem("client-id")) || (0, uuid_1.v4)()); | ||
const tab = (0, react_1.useRef)((typeof window !== "undefined" && sessionStorage.getItem("client-id")) || (0, uuid_1.v4)()); | ||
(0, react_1.useEffect)(() => { | ||
export const ClientIDProvider = ({ IPinterval = 5 * 6 * 1000, disableIP, verbose, children, }) => { | ||
const browser = useRef((typeof window !== "undefined" && localStorage.getItem("client-id")) || generateRandomID()); | ||
const tab = useRef((typeof window !== "undefined" && sessionStorage.getItem("client-id")) || generateRandomID()); | ||
useEffect(() => { | ||
verbose && console.log(`Browser: ${browser.current}, Tab: ${tab.current}`); | ||
localStorage.setItem("client-id", browser.current); | ||
sessionStorage.setItem("client-id", tab.current); | ||
}, []); | ||
const [ip, setIP] = (0, react_1.useState)({}); | ||
(0, react_1.useEffect)(() => { | ||
}, [verbose]); | ||
const [ip, setIP] = useState({}); | ||
useEffect(() => { | ||
if (disableIP) { | ||
return; | ||
} | ||
const checkIP = () => __awaiter(void 0, void 0, void 0, function* () { | ||
const checkIP = async () => { | ||
let v4; | ||
try { | ||
v4 = yield public_ip_1.default.v4(); | ||
v4 = await publicIpv4(); | ||
verbose && console.log(`IPv4: ${v4}`); | ||
} | ||
@@ -68,3 +33,4 @@ catch (err) { | ||
try { | ||
v6 = yield public_ip_1.default.v6(); | ||
v6 = await publicIpv6(); | ||
verbose && console.log(`IPv6: ${v4}`); | ||
} | ||
@@ -75,3 +41,3 @@ catch (err) { | ||
setIP({ v4, v6 }); | ||
}); | ||
}; | ||
const timer = setInterval(() => checkIP, IPinterval); | ||
@@ -82,8 +48,6 @@ checkIP(); | ||
}; | ||
}, [IPinterval, disableIP]); | ||
return (react_1.default.createElement(exports.ClientIDContext.Provider, { value: { browserID: browser.current, tabID: tab.current, IPv4: ip.v4, IPv6: ip.v6 } }, children)); | ||
}, [IPinterval, disableIP, verbose]); | ||
return (React.createElement(ClientIDContext.Provider, { value: { browserID: browser.current, tabID: tab.current, IPv4: ip.v4, IPv6: ip.v6 } }, children)); | ||
}; | ||
exports.ClientIDProvider = ClientIDProvider; | ||
const useClientID = () => (0, react_1.useContext)(exports.ClientIDContext); | ||
exports.useClientID = useClientID; | ||
export const useClientID = () => useContext(ClientIDContext); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@cs124/client-id", | ||
"version": "2023.8.0", | ||
"version": "2024.7.0", | ||
"license": "MIT", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
@@ -10,3 +11,3 @@ "scripts": { | ||
"clean": "rimraf dist", | ||
"depcheck": "depcheck --ignores=prettier-plugin-*,rimraf", | ||
"depcheck": "depcheck --ignores=prettier-plugin-*,rimraf --ignore-dirs=dist", | ||
"eslint": "eslint src/**", | ||
@@ -22,4 +23,3 @@ "ncu": "ncu", | ||
"dependencies": { | ||
"public-ip": "4.0.4", | ||
"uuid": "9.0.0" | ||
"public-ip": "7.0.1" | ||
}, | ||
@@ -30,18 +30,17 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@types/react": "18.2.20", | ||
"@types/uuid": "9.0.2", | ||
"@typescript-eslint/eslint-plugin": "6.4.0", | ||
"@typescript-eslint/parser": "6.4.0", | ||
"depcheck": "1.4.3", | ||
"@types/react": "18.3.3", | ||
"@typescript-eslint/eslint-plugin": "7.18.0", | ||
"@typescript-eslint/parser": "7.18.0", | ||
"depcheck": "1.4.7", | ||
"eslint": "8.47.0", | ||
"eslint-config-prettier": "9.0.0", | ||
"eslint-plugin-react-hooks": "4.6.0", | ||
"npm-check-updates": "16.12.2", | ||
"prettier": "3.0.2", | ||
"eslint-config-prettier": "9.1.0", | ||
"eslint-plugin-react-hooks": "4.6.2", | ||
"npm-check-updates": "17.0.0", | ||
"prettier": "3.3.3", | ||
"prettier-package-json": "2.8.0", | ||
"prettier-plugin-organize-imports": "3.2.3", | ||
"react": "18.2.0", | ||
"rimraf": "5.0.1", | ||
"typescript": "5.1.6" | ||
"prettier-plugin-organize-imports": "4.0.0", | ||
"react": "18.3.1", | ||
"rimraf": "6.0.1", | ||
"typescript": "5.5.4" | ||
} | ||
} |
@@ -5,4 +5,3 @@ { | ||
"outDir": "dist", | ||
"target": "es6", | ||
"module": "commonjs", | ||
"target": "esnext", | ||
"lib": ["es6", "DOM"], | ||
@@ -9,0 +8,0 @@ "moduleResolution": "node", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
14
Yes
9636
162
+ Added@sindresorhus/is@5.6.0(transitive)
+ Added@szmarczak/http-timer@5.0.1(transitive)
+ Added@types/http-cache-semantics@4.0.4(transitive)
+ Addedcacheable-lookup@7.0.0(transitive)
+ Addedcacheable-request@10.2.14(transitive)
+ Addedclone-regexp@3.0.0(transitive)
+ Addedconvert-hrtime@5.0.0(transitive)
+ Addeddecompress-response@6.0.0(transitive)
+ Addeddefer-to-connect@2.0.1(transitive)
+ Addedform-data-encoder@2.1.4(transitive)
+ Addedfunction-timeout@0.1.1(transitive)
+ Addedget-stream@6.0.1(transitive)
+ Addedgot@13.0.0(transitive)
+ Addedhttp2-wrapper@2.2.1(transitive)
+ Addedip-regex@5.0.0(transitive)
+ Addedis-ip@5.0.1(transitive)
+ Addedis-regexp@3.1.0(transitive)
+ Addedjson-buffer@3.0.1(transitive)
+ Addedkeyv@4.5.4(transitive)
+ Addedlowercase-keys@3.0.0(transitive)
+ Addedmimic-response@3.1.04.0.0(transitive)
+ Addednormalize-url@8.0.1(transitive)
+ Addedp-cancelable@3.0.0(transitive)
+ Addedpublic-ip@7.0.1(transitive)
+ Addedquick-lru@5.1.1(transitive)
+ Addedresolve-alpn@1.2.1(transitive)
+ Addedresponselike@3.0.0(transitive)
+ Addedsuper-regex@0.2.0(transitive)
+ Addedtime-span@5.1.0(transitive)
- Removeduuid@9.0.0
- Removed@sindresorhus/is@0.14.0(transitive)
- Removed@szmarczak/http-timer@1.1.2(transitive)
- Removedcacheable-request@6.1.0(transitive)
- Removedclone-response@1.0.3(transitive)
- Removeddecompress-response@3.3.0(transitive)
- Removeddefer-to-connect@1.1.3(transitive)
- Removedduplexer3@0.1.5(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedget-stream@4.1.05.2.0(transitive)
- Removedgot@9.6.0(transitive)
- Removedip-regex@4.3.0(transitive)
- Removedis-ip@3.1.0(transitive)
- Removedjson-buffer@3.0.0(transitive)
- Removedkeyv@3.1.0(transitive)
- Removedlowercase-keys@1.0.12.0.0(transitive)
- Removedmimic-response@1.0.1(transitive)
- Removednormalize-url@4.5.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-cancelable@1.1.0(transitive)
- Removedprepend-http@2.0.0(transitive)
- Removedpublic-ip@4.0.4(transitive)
- Removedpump@3.0.2(transitive)
- Removedresponselike@1.0.2(transitive)
- Removedto-readable-stream@1.0.0(transitive)
- Removedurl-parse-lax@3.0.0(transitive)
- Removeduuid@9.0.0(transitive)
- Removedwrappy@1.0.2(transitive)
Updatedpublic-ip@7.0.1