@honeypot-run/core
Advanced tools
Comparing version
@@ -13,2 +13,4 @@ import { IFlow, IHoneypot, IdentityType } from "."; | ||
callbacks: Record<string, Function[]>; | ||
geofenced: boolean; | ||
geofence(): void; | ||
ensureHoneypot(): void; | ||
@@ -21,3 +23,3 @@ identify(id: string, props?: Record<string, any>, type?: IdentityType): Promise<void>; | ||
load(url: string): Promise<IHoneypot>; | ||
get(): Promise<any>; | ||
get(timeoutMilliseconds?: number): Promise<any>; | ||
} | ||
@@ -24,0 +26,0 @@ declare const honeypot: Honeypot; |
@@ -1,3 +0,50 @@ | ||
class Honeypot { | ||
constructor() { | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
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 __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var Honeypot = (function () { | ||
function Honeypot() { | ||
this.honey = null; | ||
@@ -8,27 +55,35 @@ this.id = []; | ||
this.callbacks = {}; | ||
this.geofenced = false; | ||
} | ||
ensureHoneypot() { | ||
Honeypot.prototype.geofence = function () { | ||
this.geofenced = true; | ||
}; | ||
Honeypot.prototype.ensureHoneypot = function () { | ||
if (!window.honeypot) { | ||
window.honeypot = {}; | ||
} | ||
} | ||
async identify(id, props, type) { | ||
this.ensureHoneypot(); | ||
if (window.honeypot?.identify) { | ||
window.honeypot.identify(id, props, type); | ||
} | ||
else { | ||
let _id = { | ||
id, | ||
...(props ? { properties: props } : {}), | ||
...(type ? { type } : {}), | ||
}; | ||
if (!Array.isArray(window.honeypot.id)) { | ||
window.honeypot.id = []; | ||
} | ||
window.honeypot.id.push(_id); | ||
} | ||
} | ||
on(eventName, fn) { | ||
}; | ||
Honeypot.prototype.identify = function (id, props, type) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _id; | ||
return __generator(this, function (_b) { | ||
this.ensureHoneypot(); | ||
if ((_a = window.honeypot) === null || _a === void 0 ? void 0 : _a.identify) { | ||
window.honeypot.identify(id, props, type); | ||
} | ||
else { | ||
_id = __assign(__assign({ id: id }, (props ? { properties: props } : {})), (type ? { type: type } : {})); | ||
if (!Array.isArray(window.honeypot.id)) { | ||
window.honeypot.id = []; | ||
} | ||
window.honeypot.id.push(_id); | ||
} | ||
return [2]; | ||
}); | ||
}); | ||
}; | ||
Honeypot.prototype.on = function (eventName, fn) { | ||
var _a; | ||
var _b; | ||
this.ensureHoneypot(); | ||
@@ -39,66 +94,89 @@ if (window.honeypot.on) { | ||
else { | ||
((_a = window.honeypot.callbacks)[eventName] ?? (_a[eventName] = [])).push(fn); | ||
((_a = (_b = window.honeypot.callbacks)[eventName]) !== null && _a !== void 0 ? _a : (_b[eventName] = [])).push(fn); | ||
} | ||
} | ||
async flow(flowId, instanceId) { | ||
this.ensureHoneypot(); | ||
return new Promise((resolve, reject) => { | ||
let t = Date.now(); | ||
const e = () => { | ||
if (window && window.honeypot && this.didInit) { | ||
resolve(window.honeypot.flow(flowId, instanceId)); | ||
}; | ||
Honeypot.prototype.flow = function (flowId, instanceId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
this.ensureHoneypot(); | ||
return [2, new Promise(function (resolve, reject) { | ||
var t = Date.now(); | ||
var e = function () { | ||
if (window && window.honeypot && _this.didInit) { | ||
resolve(window.honeypot.flow(flowId, instanceId)); | ||
} | ||
else if (Date.now() - t >= 5000) { | ||
reject(new Error("Flow could not be created. Did you call the load() method first?")); | ||
} | ||
else { | ||
setTimeout(e, 100); | ||
} | ||
}; | ||
e(); | ||
})]; | ||
}); | ||
}); | ||
}; | ||
Honeypot.prototype.track = function (eventType, eventProperties) { | ||
if (eventProperties === void 0) { eventProperties = {}; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
this.ensureHoneypot(); | ||
if (window.honeypot.track) { | ||
window.honeypot.track(eventType, eventProperties); | ||
} | ||
else if (Date.now() - t >= 5000) { | ||
reject(new Error("Flow could not be created. Did you call the load() method first?")); | ||
} | ||
else { | ||
setTimeout(e, 100); | ||
window.honeypot.q.push([eventType, eventProperties]); | ||
} | ||
}; | ||
e(); | ||
return [2]; | ||
}); | ||
}); | ||
} | ||
async track(eventType, eventProperties = {}) { | ||
this.ensureHoneypot(); | ||
if (window.honeypot.track) { | ||
window.honeypot.track(eventType, eventProperties); | ||
} | ||
else { | ||
window.honeypot.q.push([eventType, eventProperties]); | ||
} | ||
} | ||
async init() { | ||
} | ||
load(url) { | ||
return new Promise((resolve) => { | ||
const script = document.createElement('script'); | ||
}; | ||
Honeypot.prototype.init = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2]; | ||
}); | ||
}); | ||
}; | ||
Honeypot.prototype.load = function (url) { | ||
var _this = this; | ||
return new Promise(function (resolve) { | ||
var script = document.createElement('script'); | ||
script.async = true; | ||
script.src = url; | ||
document.head.appendChild(script); | ||
script.onload = () => { | ||
this.didInit = true; | ||
script.onload = function () { | ||
_this.didInit = true; | ||
resolve(window.honeypot); | ||
}; | ||
}); | ||
} | ||
async get() { | ||
return new Promise((resolve, reject) => { | ||
let t = Date.now(); | ||
const e = () => { | ||
if (window.honeypot && window.honeypot.honey) { | ||
resolve(window.honeypot.honey); | ||
} | ||
else if (Date.now() - t >= 5000) { | ||
reject(new Error("Honey not found")); | ||
} | ||
else { | ||
setTimeout(e, 100); | ||
} | ||
}; | ||
e(); | ||
}; | ||
Honeypot.prototype.get = function (timeoutMilliseconds) { | ||
if (timeoutMilliseconds === void 0) { timeoutMilliseconds = 5000; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2, new Promise(function (resolve, reject) { | ||
var t = Date.now(); | ||
var e = function () { | ||
if (window.honeypot && window.honeypot.honey) { | ||
resolve(window.honeypot.honey); | ||
} | ||
else if (Date.now() - t >= timeoutMilliseconds) { | ||
reject(new Error("Honey not found")); | ||
} | ||
else { | ||
setTimeout(e, 100); | ||
} | ||
}; | ||
e(); | ||
})]; | ||
}); | ||
}); | ||
} | ||
} | ||
const honeypot = new Honeypot(); | ||
}; | ||
return Honeypot; | ||
}()); | ||
var honeypot = new Honeypot(); | ||
export { honeypot }; | ||
export default honeypot; |
@@ -8,3 +8,4 @@ import { honeypot } from "./Honeypot"; | ||
track(eventType: string, eventProperties?: Record<string, any> | null): Promise<any>; | ||
get(): Promise<any>; | ||
get(timeoutMilliseconds: number): Promise<any>; | ||
geofence(): void; | ||
} | ||
@@ -11,0 +12,0 @@ export type FlowState = "empty" | "not started" | "started" | "completed" | "force completed" | "cleared"; |
@@ -5,3 +5,3 @@ { | ||
"author": "https://honeypot.run", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"license": "BUSL-1.1", | ||
@@ -25,4 +25,6 @@ "keywords": [ | ||
], | ||
"main": "dist/src/public/index.js", | ||
"typings": "dist/src/public/index.d.ts", | ||
"main": "./dist/cjs/src/public/index.js", | ||
"module": "./dist/esm/src/public/index.js", | ||
"types": "dist/esm/src/public/index.d.ts", | ||
"typings": "dist/esm/src/public/index.d.ts", | ||
"files": [ | ||
@@ -37,3 +39,5 @@ "dist/src/public" | ||
"update-version": "./scripts/update-version", | ||
"build": "npm run test && tsc", | ||
"build:cjs": "tsc --project tsconfig.cjs.json", | ||
"build:esm": "tsc --project tsconfig.esm.json", | ||
"build": "npm run test && npm run build:cjs && npm run build:esm", | ||
"build-api": "npm run update-version && npm run test && esbuild src/index.js --bundle --minify --outfile=../../../honeypot-fastapi/static/js-template.js", | ||
@@ -45,3 +49,3 @@ "build-worker": "esbuild ./creepjs/src/creep_worker.js --bundle --minify --outfile=../../../honeypot-fastapi/static/js-worker.js", | ||
"devDependencies": { | ||
"@fingerprintjs/botd": "1.7.0", | ||
"@fingerprintjs/botd": "1.5.0", | ||
"@fingerprintjs/fingerprintjs-pro": "^3.8.6", | ||
@@ -48,0 +52,0 @@ "axios": "^1.6.2", |
17226
131.25%9
80%289
60.56%