@honeypot-run/core
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -1,2 +0,2 @@ | ||
import { IFlow, IHoneypot, IdentityType } from "."; | ||
import { IFlow, HoneypotConfig, IHoneypot, IHoneypotLite, IdentityType } from "."; | ||
declare global { | ||
@@ -8,2 +8,3 @@ interface Window { | ||
declare class Honeypot implements IHoneypot { | ||
config: HoneypotConfig; | ||
honey: any; | ||
@@ -13,4 +14,6 @@ id: Record<string, any>[]; | ||
didInit: boolean; | ||
didLoad: boolean; | ||
callbacks: Record<string, Function[]>; | ||
geofenced: boolean; | ||
setup(config: HoneypotConfig): void; | ||
geofence(): void; | ||
@@ -23,8 +26,8 @@ ensureHoneypot(): void; | ||
init(): Promise<void>; | ||
load(url: string, identity?: string | null, type?: IdentityType | null): Promise<IHoneypot>; | ||
get(timeoutMilliseconds?: number): Promise<any>; | ||
maybeTime(process_name: string, end?: boolean): void; | ||
load(url: string, identity?: string | null, type?: IdentityType | null): Promise<IHoneypot | IHoneypotLite>; | ||
get(): Promise<any>; | ||
} | ||
declare const honeypot: Honeypot; | ||
declare const honeypotInit: (url: string, identity?: string | null, type?: IdentityType | null) => Promise<IHoneypot>; | ||
export { honeypot, honeypotInit }; | ||
export { honeypot }; | ||
export default honeypot; |
@@ -12,5 +12,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.honeypotInit = exports.honeypot = void 0; | ||
exports.honeypot = void 0; | ||
class Honeypot { | ||
constructor() { | ||
this.config = null; | ||
this.honey = null; | ||
@@ -20,6 +21,14 @@ this.id = []; | ||
this.didInit = false; | ||
this.didLoad = false; | ||
this.callbacks = {}; | ||
this.geofenced = false; | ||
} | ||
setup(config) { | ||
this.config = config; | ||
} | ||
geofence() { | ||
var _a; | ||
if ((_a = window.honeypot) === null || _a === void 0 ? void 0 : _a.geofence) { | ||
window.honeypot.geofence(); | ||
} | ||
this.geofenced = true; | ||
@@ -94,3 +103,15 @@ } | ||
} | ||
maybeTime(process_name, end) { | ||
var _a; | ||
if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.debug)) { | ||
return; | ||
} | ||
if (end) { | ||
console.timeEnd(process_name); | ||
return; | ||
} | ||
console.time(process_name); | ||
} | ||
load(url, identity, type) { | ||
this.didLoad = true; | ||
return new Promise((resolve) => { | ||
@@ -100,3 +121,3 @@ const script = document.createElement('script'); | ||
const scriptUrl = new URL(url); | ||
let currentURL = null, pageTitle = null, timezone = null; | ||
let currentURL = null, pageTitle = null; | ||
try { | ||
@@ -110,9 +131,4 @@ currentURL = window.location.href; | ||
catch (error) { } | ||
try { | ||
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
} | ||
catch (error) { } | ||
scriptUrl.searchParams.append('url', currentURL || 'URL not available'); | ||
scriptUrl.searchParams.append('title', pageTitle || 'Title not available'); | ||
scriptUrl.searchParams.append('tz', timezone || 'Timezone not available'); | ||
if (identity) { | ||
@@ -128,2 +144,3 @@ scriptUrl.searchParams.append('identity', identity); | ||
} | ||
this.maybeTime('load honeypot'); | ||
script.src = scriptUrl.toString(); | ||
@@ -133,2 +150,3 @@ document.head.appendChild(script); | ||
this.didInit = true; | ||
this.maybeTime('load honeypot', true); | ||
resolve(window.honeypot); | ||
@@ -138,4 +156,29 @@ }; | ||
} | ||
get(timeoutMilliseconds = 5000) { | ||
get() { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let timeoutMs = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.timeoutMs) || 600; | ||
const loadWithTimeout = (url) => __awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve, reject) => { | ||
const timeout = setTimeout(() => reject(new Error("Load timeout")), timeoutMs + 5); | ||
this.load(url).then(() => { | ||
clearTimeout(timeout); | ||
resolve(null); | ||
}).catch((error) => { | ||
clearTimeout(timeout); | ||
reject(error); | ||
}); | ||
}); | ||
}); | ||
if (!this.didLoad && ((_b = this.config) === null || _b === void 0 ? void 0 : _b.url)) { | ||
try { | ||
yield loadWithTimeout(this.config.url); | ||
if (window.honeypot) { | ||
return window.honeypot.get(); | ||
} | ||
} | ||
catch (error) { | ||
throw new Error(`Failed to load within the specified timeout: ${timeoutMs}`); | ||
} | ||
} | ||
return new Promise((resolve, reject) => { | ||
@@ -147,7 +190,7 @@ let t = Date.now(); | ||
} | ||
else if (Date.now() - t >= timeoutMilliseconds) { | ||
else if (Date.now() - t >= timeoutMs) { | ||
reject(new Error("Honey not found")); | ||
} | ||
else { | ||
setTimeout(e, 100); | ||
setTimeout(e, 50); | ||
} | ||
@@ -162,4 +205,2 @@ }; | ||
exports.honeypot = honeypot; | ||
const honeypotInit = honeypot.load; | ||
exports.honeypotInit = honeypotInit; | ||
exports.default = honeypot; |
@@ -1,3 +0,13 @@ | ||
import { honeypot, honeypotInit } from "./Honeypot"; | ||
import { honeypot } from "./Honeypot"; | ||
import { AmplitudePlugin as amplitudePlugin } from './AmplitudePlugin'; | ||
export type IdentityType = "account" | "email" | "merchant_id" | "partner_id" | "web3_wallet" | "geofence_ref"; | ||
export interface HoneypotConfig { | ||
url?: string; | ||
timeoutMs: number; | ||
debug: boolean; | ||
} | ||
export interface IHoneypotLite { | ||
get(): any; | ||
geofence(): void; | ||
} | ||
export interface IHoneypot { | ||
@@ -8,4 +18,5 @@ identify(id: string, props?: Record<string, any> | null, type?: IdentityType | null): Promise<void>; | ||
track(eventType: string, eventProperties?: Record<string, any> | null): Promise<any>; | ||
get(timeoutMilliseconds: number): Promise<any>; | ||
get(): Promise<any>; | ||
geofence(): void; | ||
setup(config: HoneypotConfig): any; | ||
} | ||
@@ -53,2 +64,2 @@ export type FlowState = "empty" | "not started" | "started" | "completed" | "force completed" | "cleared"; | ||
export default honeypot; | ||
export { honeypot, honeypotInit }; | ||
export { honeypot, amplitudePlugin }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.honeypotInit = exports.honeypot = void 0; | ||
exports.amplitudePlugin = exports.honeypot = void 0; | ||
const Honeypot_1 = require("./Honeypot"); | ||
Object.defineProperty(exports, "honeypot", { enumerable: true, get: function () { return Honeypot_1.honeypot; } }); | ||
Object.defineProperty(exports, "honeypotInit", { enumerable: true, get: function () { return Honeypot_1.honeypotInit; } }); | ||
const AmplitudePlugin_1 = require("./AmplitudePlugin"); | ||
Object.defineProperty(exports, "amplitudePlugin", { enumerable: true, get: function () { return AmplitudePlugin_1.AmplitudePlugin; } }); | ||
exports.default = Honeypot_1.honeypot; |
@@ -1,2 +0,2 @@ | ||
import { IFlow, IHoneypot, IdentityType } from "."; | ||
import { IFlow, HoneypotConfig, IHoneypot, IHoneypotLite, IdentityType } from "."; | ||
declare global { | ||
@@ -8,2 +8,3 @@ interface Window { | ||
declare class Honeypot implements IHoneypot { | ||
config: HoneypotConfig; | ||
honey: any; | ||
@@ -13,4 +14,6 @@ id: Record<string, any>[]; | ||
didInit: boolean; | ||
didLoad: boolean; | ||
callbacks: Record<string, Function[]>; | ||
geofenced: boolean; | ||
setup(config: HoneypotConfig): void; | ||
geofence(): void; | ||
@@ -23,8 +26,8 @@ ensureHoneypot(): void; | ||
init(): Promise<void>; | ||
load(url: string, identity?: string | null, type?: IdentityType | null): Promise<IHoneypot>; | ||
get(timeoutMilliseconds?: number): Promise<any>; | ||
maybeTime(process_name: string, end?: boolean): void; | ||
load(url: string, identity?: string | null, type?: IdentityType | null): Promise<IHoneypot | IHoneypotLite>; | ||
get(): Promise<any>; | ||
} | ||
declare const honeypot: Honeypot; | ||
declare const honeypotInit: (url: string, identity?: string | null, type?: IdentityType | null) => Promise<IHoneypot>; | ||
export { honeypot, honeypotInit }; | ||
export { honeypot }; | ||
export default honeypot; |
@@ -12,2 +12,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
constructor() { | ||
this.config = null; | ||
this.honey = null; | ||
@@ -17,6 +18,14 @@ this.id = []; | ||
this.didInit = false; | ||
this.didLoad = false; | ||
this.callbacks = {}; | ||
this.geofenced = false; | ||
} | ||
setup(config) { | ||
this.config = config; | ||
} | ||
geofence() { | ||
var _a; | ||
if ((_a = window.honeypot) === null || _a === void 0 ? void 0 : _a.geofence) { | ||
window.honeypot.geofence(); | ||
} | ||
this.geofenced = true; | ||
@@ -91,3 +100,15 @@ } | ||
} | ||
maybeTime(process_name, end) { | ||
var _a; | ||
if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.debug)) { | ||
return; | ||
} | ||
if (end) { | ||
console.timeEnd(process_name); | ||
return; | ||
} | ||
console.time(process_name); | ||
} | ||
load(url, identity, type) { | ||
this.didLoad = true; | ||
return new Promise((resolve) => { | ||
@@ -97,3 +118,3 @@ const script = document.createElement('script'); | ||
const scriptUrl = new URL(url); | ||
let currentURL = null, pageTitle = null, timezone = null; | ||
let currentURL = null, pageTitle = null; | ||
try { | ||
@@ -107,9 +128,4 @@ currentURL = window.location.href; | ||
catch (error) { } | ||
try { | ||
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
} | ||
catch (error) { } | ||
scriptUrl.searchParams.append('url', currentURL || 'URL not available'); | ||
scriptUrl.searchParams.append('title', pageTitle || 'Title not available'); | ||
scriptUrl.searchParams.append('tz', timezone || 'Timezone not available'); | ||
if (identity) { | ||
@@ -125,2 +141,3 @@ scriptUrl.searchParams.append('identity', identity); | ||
} | ||
this.maybeTime('load honeypot'); | ||
script.src = scriptUrl.toString(); | ||
@@ -130,2 +147,3 @@ document.head.appendChild(script); | ||
this.didInit = true; | ||
this.maybeTime('load honeypot', true); | ||
resolve(window.honeypot); | ||
@@ -135,4 +153,29 @@ }; | ||
} | ||
get(timeoutMilliseconds = 5000) { | ||
get() { | ||
var _a, _b; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let timeoutMs = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.timeoutMs) || 600; | ||
const loadWithTimeout = (url) => __awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve, reject) => { | ||
const timeout = setTimeout(() => reject(new Error("Load timeout")), timeoutMs + 5); | ||
this.load(url).then(() => { | ||
clearTimeout(timeout); | ||
resolve(null); | ||
}).catch((error) => { | ||
clearTimeout(timeout); | ||
reject(error); | ||
}); | ||
}); | ||
}); | ||
if (!this.didLoad && ((_b = this.config) === null || _b === void 0 ? void 0 : _b.url)) { | ||
try { | ||
yield loadWithTimeout(this.config.url); | ||
if (window.honeypot) { | ||
return window.honeypot.get(); | ||
} | ||
} | ||
catch (error) { | ||
throw new Error(`Failed to load within the specified timeout: ${timeoutMs}`); | ||
} | ||
} | ||
return new Promise((resolve, reject) => { | ||
@@ -144,7 +187,7 @@ let t = Date.now(); | ||
} | ||
else if (Date.now() - t >= timeoutMilliseconds) { | ||
else if (Date.now() - t >= timeoutMs) { | ||
reject(new Error("Honey not found")); | ||
} | ||
else { | ||
setTimeout(e, 100); | ||
setTimeout(e, 50); | ||
} | ||
@@ -158,4 +201,3 @@ }; | ||
const honeypot = new Honeypot(); | ||
const honeypotInit = honeypot.load; | ||
export { honeypot, honeypotInit }; | ||
export { honeypot }; | ||
export default honeypot; |
@@ -1,3 +0,13 @@ | ||
import { honeypot, honeypotInit } from "./Honeypot"; | ||
import { honeypot } from "./Honeypot"; | ||
import { AmplitudePlugin as amplitudePlugin } from './AmplitudePlugin'; | ||
export type IdentityType = "account" | "email" | "merchant_id" | "partner_id" | "web3_wallet" | "geofence_ref"; | ||
export interface HoneypotConfig { | ||
url?: string; | ||
timeoutMs: number; | ||
debug: boolean; | ||
} | ||
export interface IHoneypotLite { | ||
get(): any; | ||
geofence(): void; | ||
} | ||
export interface IHoneypot { | ||
@@ -8,4 +18,5 @@ identify(id: string, props?: Record<string, any> | null, type?: IdentityType | null): Promise<void>; | ||
track(eventType: string, eventProperties?: Record<string, any> | null): Promise<any>; | ||
get(timeoutMilliseconds: number): Promise<any>; | ||
get(): Promise<any>; | ||
geofence(): void; | ||
setup(config: HoneypotConfig): any; | ||
} | ||
@@ -53,2 +64,2 @@ export type FlowState = "empty" | "not started" | "started" | "completed" | "force completed" | "cleared"; | ||
export default honeypot; | ||
export { honeypot, honeypotInit }; | ||
export { honeypot, amplitudePlugin }; |
@@ -1,3 +0,4 @@ | ||
import { honeypot, honeypotInit } from "./Honeypot"; | ||
import { honeypot } from "./Honeypot"; | ||
import { AmplitudePlugin as amplitudePlugin } from './AmplitudePlugin'; | ||
export default honeypot; | ||
export { honeypot, honeypotInit }; | ||
export { honeypot, amplitudePlugin }; |
@@ -5,20 +5,12 @@ { | ||
"author": "https://honeypot.run", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"license": "BUSL-1.1", | ||
"keywords": [ | ||
"onboarding", | ||
"flow", | ||
"fraud", | ||
"fraud detection", | ||
"fraud prevention", | ||
"geofencing", | ||
"browser", | ||
"identification", | ||
"fingerprint", | ||
"fingerprinting", | ||
"handprint", | ||
"handprinting", | ||
"browser fingerprint", | ||
"device fingerprint", | ||
"privacy", | ||
"education" | ||
"privacy" | ||
], | ||
@@ -49,2 +41,3 @@ "main": "./dist/cjs/src/public/index.js", | ||
"devDependencies": { | ||
"@amplitude/analytics-browser": "^2.3.3", | ||
"@fingerprintjs/botd": "1.5.0", | ||
@@ -51,0 +44,0 @@ "@fingerprintjs/fingerprintjs-pro": "^3.8.6", |
26864
17
13
664