@honeypot-run/core
Advanced tools
Comparing version 0.2.54 to 0.2.55
import { IFlow, HoneypotConfig, IHoneypot, IHoneypotLite, IdentityType } from "./types"; | ||
import { HoneypotBase } from "./models/HoneypotBase"; | ||
import { AmplitudePluginConfig } from './types'; | ||
import { EnrichmentPlugin } from '@amplitude/analytics-types'; | ||
declare global { | ||
@@ -8,3 +9,3 @@ interface Window { | ||
} | ||
declare class Honeypot extends HoneypotBase implements IHoneypot { | ||
declare class Honeypot implements IHoneypot { | ||
config: HoneypotConfig | null; | ||
@@ -19,2 +20,3 @@ honey: any; | ||
setup(config: HoneypotConfig): void; | ||
amplitudePlugin(pluginConfig?: AmplitudePluginConfig): EnrichmentPlugin; | ||
geofence(): void; | ||
@@ -21,0 +23,0 @@ ensureHoneypot(): void; |
@@ -13,6 +13,5 @@ "use strict"; | ||
exports.honeypot = void 0; | ||
const HoneypotBase_1 = require("./models/HoneypotBase"); | ||
class Honeypot extends HoneypotBase_1.HoneypotBase { | ||
const AmplitudePlugin_1 = require("./plugins/AmplitudePlugin"); | ||
class Honeypot { | ||
constructor() { | ||
super(...arguments); | ||
this.config = null; | ||
@@ -30,2 +29,5 @@ this.honey = null; | ||
} | ||
amplitudePlugin(pluginConfig) { | ||
return (0, AmplitudePlugin_1.createAmplitudePlugin)(this.track.bind(this), this.get.bind(this), pluginConfig); | ||
} | ||
geofence() { | ||
@@ -32,0 +34,0 @@ var _a; |
@@ -20,22 +20,18 @@ "use strict"; | ||
execute: (event) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _a, _b; | ||
var _a; | ||
try { | ||
const { user_id, event_type } = event; | ||
const cleanedEventType = event_type.startsWith('[Amplitude] ') | ||
const isInternal = event_type.startsWith('[Amplitude] '); | ||
const cleanedEventType = isInternal | ||
? event_type.replace('[Amplitude] ', '') | ||
: event_type; | ||
const isEventDisabled = ((_a = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.disableEvents) === null || _a === void 0 ? void 0 : _a.includes(cleanedEventType)) || | ||
(((_b = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.enableEvents) === null || _b === void 0 ? void 0 : _b.length) && !(pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.enableEvents.includes(cleanedEventType))); | ||
if (isEventDisabled) { | ||
return null; | ||
const shouldIgnore = (_a = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.ignoreEvents) === null || _a === void 0 ? void 0 : _a.includes(cleanedEventType); | ||
if (shouldIgnore) { | ||
return event; | ||
} | ||
yield track(event_type, event.event_properties); | ||
const honey = yield get(); | ||
if ((honey === null || honey === void 0 ? void 0 : honey.geofenced) && !user_id && (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.dropAnonymousGeofenceEvents)) { | ||
return null; | ||
if (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.enrichEventProperties) { | ||
event.event_properties = Object.assign(Object.assign({}, event.event_properties), { honey }); | ||
} | ||
if ((honey === null || honey === void 0 ? void 0 : honey.geofenced) && (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.dropGeofenceEvents)) { | ||
return null; | ||
} | ||
event.event_properties = Object.assign(Object.assign({}, event.event_properties), { honey }); | ||
return event; | ||
@@ -42,0 +38,0 @@ } |
@@ -23,7 +23,3 @@ "use strict"; | ||
const pluginConfig = { | ||
disableEvents: ['excluded_event'], | ||
enableEvents: [], | ||
dropAnonymousGeofenceEvents: false, | ||
dropGeofenceEvents: false, | ||
enrichEvents: true, | ||
ignoreEvents: ['excluded_event'], | ||
}; | ||
@@ -38,18 +34,14 @@ plugin = (0, AmplitudePlugin_1.createAmplitudePlugin)(track, get, pluginConfig); | ||
const result = yield plugin.execute(event); | ||
expect(result).toBeNull(); | ||
expect(track).not.toHaveBeenCalled(); | ||
expect(get).not.toHaveBeenCalled(); | ||
expect(result === null || result === void 0 ? void 0 : result.event_properties).not.toHaveProperty('honey'); | ||
})); | ||
test('should include event if it is in enableEvents', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('should enrich event if enrichEvents is enabled', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const pluginConfig = { | ||
disableEvents: [], | ||
enableEvents: ['allowed_event'], | ||
dropAnonymousGeofenceEvents: false, | ||
dropGeofenceEvents: false, | ||
enrichEvents: true, | ||
enrichEventProperties: true, | ||
}; | ||
plugin = (0, AmplitudePlugin_1.createAmplitudePlugin)(track, get, pluginConfig); | ||
const event = { | ||
event_type: 'allowed_event', | ||
event_properties: { initial: 'value' }, | ||
event_type: 'excluded_event', | ||
event_properties: {}, | ||
user_id: '1234', | ||
@@ -59,48 +51,22 @@ device_id: '5678', | ||
const result = yield plugin.execute(event); | ||
expect(result).not.toBeNull(); | ||
expect(track).toHaveBeenCalledWith('allowed_event', { initial: 'value' }); | ||
expect(track).toHaveBeenCalled(); | ||
expect(get).toHaveBeenCalled(); | ||
expect(result === null || result === void 0 ? void 0 : result.event_properties).toHaveProperty('honey'); | ||
})); | ||
test('should drop event if geofenced and dropAnonymousGeofenceEvents is true and no user_id', () => __awaiter(void 0, void 0, void 0, function* () { | ||
get.mockResolvedValueOnce({ geofenced: true }); | ||
test('should not enrich event if enrichEvents is disabled', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const pluginConfig = { | ||
disableEvents: [], | ||
enableEvents: [], | ||
dropAnonymousGeofenceEvents: true, | ||
dropGeofenceEvents: false, | ||
enrichEvents: true, | ||
enrichEventProperties: false, | ||
}; | ||
plugin = (0, AmplitudePlugin_1.createAmplitudePlugin)(track, get, pluginConfig); | ||
const event = { | ||
event_type: 'test_event', | ||
event_type: 'excluded_event', | ||
event_properties: {}, | ||
user_id: '', | ||
user_id: '1234', | ||
device_id: '5678', | ||
}; | ||
const result = yield plugin.execute(event); | ||
expect(result).toBeNull(); | ||
expect(track).toHaveBeenCalled(); | ||
expect(get).toHaveBeenCalled(); | ||
expect(result === null || result === void 0 ? void 0 : result.event_properties).not.toHaveProperty('honey'); | ||
})); | ||
test('should process event if not geofenced and enrich event', () => __awaiter(void 0, void 0, void 0, function* () { | ||
get.mockResolvedValueOnce({ geofenced: false, additional_data: 'honey' }); | ||
const pluginConfig = { | ||
disableEvents: [], | ||
enableEvents: [], | ||
dropAnonymousGeofenceEvents: false, | ||
dropGeofenceEvents: false, | ||
enrichEvents: true, | ||
}; | ||
plugin = (0, AmplitudePlugin_1.createAmplitudePlugin)(track, get, pluginConfig); | ||
const event = { | ||
event_type: 'test_event', | ||
event_properties: { initial: 'value' }, | ||
user_id: '1234', | ||
device_id: '5678', | ||
}; | ||
const result = yield plugin.execute(event); | ||
expect(result).not.toBeNull(); | ||
expect(track).toHaveBeenCalledWith('test_event', { initial: 'value' }); | ||
expect(get).toHaveBeenCalled(); | ||
})); | ||
}); |
import { EnrichmentPlugin } from '@amplitude/analytics-types'; | ||
export type IdentityType = "account" | "email" | "merchant_id" | "partner_id" | "web3_wallet" | "geofence_ref"; | ||
export interface AmplitudePluginConfig { | ||
disableEvents?: string[]; | ||
enableEvents?: string[]; | ||
dropAnonymousGeofenceEvents?: boolean; | ||
dropGeofenceEvents?: boolean; | ||
enrichEvents?: boolean; | ||
ignoreEvents?: string[]; | ||
enrichEventProperties?: boolean; | ||
} | ||
@@ -10,0 +7,0 @@ export interface HoneypotConfig { |
import { IFlow, HoneypotConfig, IHoneypot, IHoneypotLite, IdentityType } from "./types"; | ||
import { HoneypotBase } from "./models/HoneypotBase"; | ||
import { AmplitudePluginConfig } from './types'; | ||
import { EnrichmentPlugin } from '@amplitude/analytics-types'; | ||
declare global { | ||
@@ -8,3 +9,3 @@ interface Window { | ||
} | ||
declare class Honeypot extends HoneypotBase implements IHoneypot { | ||
declare class Honeypot implements IHoneypot { | ||
config: HoneypotConfig | null; | ||
@@ -19,2 +20,3 @@ honey: any; | ||
setup(config: HoneypotConfig): void; | ||
amplitudePlugin(pluginConfig?: AmplitudePluginConfig): EnrichmentPlugin; | ||
geofence(): void; | ||
@@ -21,0 +23,0 @@ ensureHoneypot(): void; |
@@ -10,6 +10,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { HoneypotBase } from "./models/HoneypotBase"; | ||
class Honeypot extends HoneypotBase { | ||
import { createAmplitudePlugin } from './plugins/AmplitudePlugin'; | ||
class Honeypot { | ||
constructor() { | ||
super(...arguments); | ||
this.config = null; | ||
@@ -27,2 +26,5 @@ this.honey = null; | ||
} | ||
amplitudePlugin(pluginConfig) { | ||
return createAmplitudePlugin(this.track.bind(this), this.get.bind(this), pluginConfig); | ||
} | ||
geofence() { | ||
@@ -29,0 +31,0 @@ var _a; |
@@ -17,22 +17,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
execute: (event) => __awaiter(void 0, void 0, void 0, function* () { | ||
var _a, _b; | ||
var _a; | ||
try { | ||
const { user_id, event_type } = event; | ||
const cleanedEventType = event_type.startsWith('[Amplitude] ') | ||
const isInternal = event_type.startsWith('[Amplitude] '); | ||
const cleanedEventType = isInternal | ||
? event_type.replace('[Amplitude] ', '') | ||
: event_type; | ||
const isEventDisabled = ((_a = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.disableEvents) === null || _a === void 0 ? void 0 : _a.includes(cleanedEventType)) || | ||
(((_b = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.enableEvents) === null || _b === void 0 ? void 0 : _b.length) && !(pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.enableEvents.includes(cleanedEventType))); | ||
if (isEventDisabled) { | ||
return null; | ||
const shouldIgnore = (_a = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.ignoreEvents) === null || _a === void 0 ? void 0 : _a.includes(cleanedEventType); | ||
if (shouldIgnore) { | ||
return event; | ||
} | ||
yield track(event_type, event.event_properties); | ||
const honey = yield get(); | ||
if ((honey === null || honey === void 0 ? void 0 : honey.geofenced) && !user_id && (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.dropAnonymousGeofenceEvents)) { | ||
return null; | ||
if (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.enrichEventProperties) { | ||
event.event_properties = Object.assign(Object.assign({}, event.event_properties), { honey }); | ||
} | ||
if ((honey === null || honey === void 0 ? void 0 : honey.geofenced) && (pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.dropGeofenceEvents)) { | ||
return null; | ||
} | ||
event.event_properties = Object.assign(Object.assign({}, event.event_properties), { honey }); | ||
return event; | ||
@@ -39,0 +35,0 @@ } |
@@ -21,7 +21,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
const pluginConfig = { | ||
disableEvents: ['excluded_event'], | ||
enableEvents: [], | ||
dropAnonymousGeofenceEvents: false, | ||
dropGeofenceEvents: false, | ||
enrichEvents: true, | ||
ignoreEvents: ['excluded_event'], | ||
}; | ||
@@ -36,18 +32,14 @@ plugin = createAmplitudePlugin(track, get, pluginConfig); | ||
const result = yield plugin.execute(event); | ||
expect(result).toBeNull(); | ||
expect(track).not.toHaveBeenCalled(); | ||
expect(get).not.toHaveBeenCalled(); | ||
expect(result === null || result === void 0 ? void 0 : result.event_properties).not.toHaveProperty('honey'); | ||
})); | ||
test('should include event if it is in enableEvents', () => __awaiter(void 0, void 0, void 0, function* () { | ||
test('should enrich event if enrichEvents is enabled', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const pluginConfig = { | ||
disableEvents: [], | ||
enableEvents: ['allowed_event'], | ||
dropAnonymousGeofenceEvents: false, | ||
dropGeofenceEvents: false, | ||
enrichEvents: true, | ||
enrichEventProperties: true, | ||
}; | ||
plugin = createAmplitudePlugin(track, get, pluginConfig); | ||
const event = { | ||
event_type: 'allowed_event', | ||
event_properties: { initial: 'value' }, | ||
event_type: 'excluded_event', | ||
event_properties: {}, | ||
user_id: '1234', | ||
@@ -57,48 +49,22 @@ device_id: '5678', | ||
const result = yield plugin.execute(event); | ||
expect(result).not.toBeNull(); | ||
expect(track).toHaveBeenCalledWith('allowed_event', { initial: 'value' }); | ||
expect(track).toHaveBeenCalled(); | ||
expect(get).toHaveBeenCalled(); | ||
expect(result === null || result === void 0 ? void 0 : result.event_properties).toHaveProperty('honey'); | ||
})); | ||
test('should drop event if geofenced and dropAnonymousGeofenceEvents is true and no user_id', () => __awaiter(void 0, void 0, void 0, function* () { | ||
get.mockResolvedValueOnce({ geofenced: true }); | ||
test('should not enrich event if enrichEvents is disabled', () => __awaiter(void 0, void 0, void 0, function* () { | ||
const pluginConfig = { | ||
disableEvents: [], | ||
enableEvents: [], | ||
dropAnonymousGeofenceEvents: true, | ||
dropGeofenceEvents: false, | ||
enrichEvents: true, | ||
enrichEventProperties: false, | ||
}; | ||
plugin = createAmplitudePlugin(track, get, pluginConfig); | ||
const event = { | ||
event_type: 'test_event', | ||
event_type: 'excluded_event', | ||
event_properties: {}, | ||
user_id: '', | ||
user_id: '1234', | ||
device_id: '5678', | ||
}; | ||
const result = yield plugin.execute(event); | ||
expect(result).toBeNull(); | ||
expect(track).toHaveBeenCalled(); | ||
expect(get).toHaveBeenCalled(); | ||
expect(result === null || result === void 0 ? void 0 : result.event_properties).not.toHaveProperty('honey'); | ||
})); | ||
test('should process event if not geofenced and enrich event', () => __awaiter(void 0, void 0, void 0, function* () { | ||
get.mockResolvedValueOnce({ geofenced: false, additional_data: 'honey' }); | ||
const pluginConfig = { | ||
disableEvents: [], | ||
enableEvents: [], | ||
dropAnonymousGeofenceEvents: false, | ||
dropGeofenceEvents: false, | ||
enrichEvents: true, | ||
}; | ||
plugin = createAmplitudePlugin(track, get, pluginConfig); | ||
const event = { | ||
event_type: 'test_event', | ||
event_properties: { initial: 'value' }, | ||
user_id: '1234', | ||
device_id: '5678', | ||
}; | ||
const result = yield plugin.execute(event); | ||
expect(result).not.toBeNull(); | ||
expect(track).toHaveBeenCalledWith('test_event', { initial: 'value' }); | ||
expect(get).toHaveBeenCalled(); | ||
})); | ||
}); |
import { EnrichmentPlugin } from '@amplitude/analytics-types'; | ||
export type IdentityType = "account" | "email" | "merchant_id" | "partner_id" | "web3_wallet" | "geofence_ref"; | ||
export interface AmplitudePluginConfig { | ||
disableEvents?: string[]; | ||
enableEvents?: string[]; | ||
dropAnonymousGeofenceEvents?: boolean; | ||
dropGeofenceEvents?: boolean; | ||
enrichEvents?: boolean; | ||
ignoreEvents?: string[]; | ||
enrichEventProperties?: boolean; | ||
} | ||
@@ -10,0 +7,0 @@ export interface HoneypotConfig { |
@@ -5,3 +5,3 @@ { | ||
"author": "https://honeypot.run", | ||
"version": "0.2.54", | ||
"version": "0.2.55", | ||
"license": "BUSL-1.1", | ||
@@ -8,0 +8,0 @@ "keywords": [ |
44777
1050