@cs124/client-id
Advanced tools
Comparing version 2021.7.2 to 2022.3.0
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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) { | ||
@@ -20,2 +24,11 @@ if (k2 === undefined) k2 = k; | ||
}; | ||
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) { | ||
@@ -29,3 +42,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const uuid_1 = require("uuid"); | ||
exports.ClientIDContext = react_1.createContext({ | ||
exports.ClientIDContext = (0, react_1.createContext)({ | ||
browserID: "", | ||
@@ -35,35 +48,27 @@ tabID: "", | ||
const ClientIDProvider = ({ IPinterval = 5 * 6 * 1000, children }) => { | ||
const [browserID, setBrowserID] = react_1.useState(); | ||
react_1.useEffect(() => { | ||
const id = localStorage.getItem("client-id") || uuid_1.v4(); | ||
localStorage.setItem("client-id", id); | ||
setBrowserID(id); | ||
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)(() => { | ||
localStorage.setItem("client-id", browser.current); | ||
sessionStorage.setItem("client-id", tab.current); | ||
}, []); | ||
const [tabID, setTabID] = react_1.useState(); | ||
react_1.useEffect(() => { | ||
const id = sessionStorage.getItem("client-id") || uuid_1.v4(); | ||
sessionStorage.setItem("client-id", id); | ||
setTabID(id); | ||
}, []); | ||
const [IPv4, setIPv4] = react_1.useState(undefined); | ||
const [IPv6, setIPv6] = react_1.useState(undefined); | ||
react_1.useEffect(() => { | ||
const checkIP = () => { | ||
public_ip_1.default | ||
.v4() | ||
.then((_ip) => { | ||
setIPv4(_ip); | ||
}) | ||
.catch(() => { | ||
setIPv4(undefined); | ||
}); | ||
public_ip_1.default | ||
.v6() | ||
.then((_ip) => { | ||
setIPv6(_ip); | ||
}) | ||
.catch(() => { | ||
setIPv6(undefined); | ||
}); | ||
}; | ||
const [ip, setIP] = (0, react_1.useState)({}); | ||
(0, react_1.useEffect)(() => { | ||
const checkIP = () => __awaiter(this, void 0, void 0, function* () { | ||
let v4; | ||
try { | ||
v4 = yield public_ip_1.default.v4(); | ||
} | ||
catch (err) { | ||
// | ||
} | ||
let v6; | ||
try { | ||
v6 = yield public_ip_1.default.v6(); | ||
} | ||
catch (err) { | ||
// | ||
} | ||
setIP({ v4, v6 }); | ||
}); | ||
const timer = setInterval(() => checkIP, IPinterval); | ||
@@ -74,8 +79,8 @@ checkIP(); | ||
}; | ||
}, [IPinterval, setIPv4, setIPv6]); | ||
return react_1.default.createElement(exports.ClientIDContext.Provider, { value: { browserID, tabID, IPv4, IPv6 } }, children); | ||
}, [IPinterval]); | ||
return (react_1.default.createElement(exports.ClientIDContext.Provider, { value: { browserID: browser.current, tabID: tab.current, IPv4: ip.v4, IPv6: ip.v6 } }, children)); | ||
}; | ||
exports.ClientIDProvider = ClientIDProvider; | ||
const useClientID = () => react_1.useContext(exports.ClientIDContext); | ||
const useClientID = () => (0, react_1.useContext)(exports.ClientIDContext); | ||
exports.useClientID = useClientID; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@cs124/client-id", | ||
"version": "2021.7.2", | ||
"version": "2022.3.0", | ||
"license": "MIT", | ||
@@ -17,4 +17,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"public-ip": "^4.0.4", | ||
"uuid": "^8.3.2" | ||
"public-ip": "5.0.0", | ||
"uuid": "8.3.2" | ||
}, | ||
@@ -25,17 +25,17 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@types/react": "17.0.14", | ||
"@types/uuid": "8.3.1", | ||
"@typescript-eslint/eslint-plugin": "4.28.3", | ||
"@typescript-eslint/parser": "4.28.3", | ||
"eslint": "7.31.0", | ||
"eslint-config-prettier": "8.3.0", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"npm-check-updates": "11.8.3", | ||
"prettier": "2.3.2", | ||
"prettier-package-json": "2.6.0", | ||
"prettier-plugin-organize-imports": "2.2.0", | ||
"@types/react": "17.0.41", | ||
"@types/uuid": "8.3.4", | ||
"@typescript-eslint/eslint-plugin": "5.15.0", | ||
"@typescript-eslint/parser": "5.15.0", | ||
"eslint": "8.11.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-react-hooks": "4.3.0", | ||
"npm-check-updates": "12.5.4", | ||
"prettier": "2.6.0", | ||
"prettier-package-json": "2.6.3", | ||
"prettier-plugin-organize-imports": "2.3.4", | ||
"react": "17.0.2", | ||
"rimraf": "3.0.2", | ||
"typescript": "4.3.5" | ||
"typescript": "4.6.2" | ||
} | ||
} |
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
10121
173
+ 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)
+ Addeddecompress-response@6.0.0(transitive)
+ Addeddefer-to-connect@2.0.1(transitive)
+ Addedform-data-encoder@2.1.4(transitive)
+ Addedget-stream@6.0.1(transitive)
+ Addedgot@12.6.1(transitive)
+ Addedhttp2-wrapper@2.2.1(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@5.0.0(transitive)
+ Addedquick-lru@5.1.1(transitive)
+ Addedresolve-alpn@1.2.1(transitive)
+ Addedresponselike@3.0.0(transitive)
- 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)
- 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)
- Removedwrappy@1.0.2(transitive)
Updatedpublic-ip@5.0.0
Updateduuid@8.3.2