Skip to content

Commit

Permalink
chore: deprecate property_blacklist in favor of property_denylist (#1044
Browse files Browse the repository at this point in the history
)
  • Loading branch information
marandaneto authored Feb 27, 2024
1 parent eaf4505 commit c0578e3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
15 changes: 12 additions & 3 deletions src/__tests__/posthog-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('posthog core', () => {

given('config', () => ({
api_host: 'https://app.posthog.com',
property_denylist: [],
property_blacklist: [],
_onCapture: jest.fn(),
get_device_id: jest.fn().mockReturnValue('device-id'),
Expand Down Expand Up @@ -95,6 +96,7 @@ describe('posthog core', () => {

it('calls update_campaign_params and update_referrer_info on sessionPersistence', () => {
given('config', () => ({
property_denylist: [],
property_blacklist: [],
_onCapture: jest.fn(),
store_google: true,
Expand Down Expand Up @@ -151,6 +153,7 @@ describe('posthog core', () => {

given('config', () => ({
opt_out_useragent_filter: true,
property_denylist: [],
property_blacklist: [],
_onCapture: jest.fn(),
}))
Expand All @@ -172,6 +175,7 @@ describe('posthog core', () => {
it('truncates long properties', () => {
given('config', () => ({
properties_string_max_length: 1000,
property_denylist: [],
property_blacklist: [],
_onCapture: jest.fn(),
}))
Expand All @@ -185,6 +189,7 @@ describe('posthog core', () => {
it('keeps long properties if null', () => {
given('config', () => ({
properties_string_max_length: null,
property_denylist: [],
property_blacklist: [],
_onCapture: jest.fn(),
}))
Expand Down Expand Up @@ -219,6 +224,7 @@ describe('posthog core', () => {

it('updates persisted person properties for feature flags if $set is present', () => {
given('config', () => ({
property_denylist: [],
property_blacklist: [],
_onCapture: jest.fn(),
}))
Expand Down Expand Up @@ -361,9 +367,11 @@ describe('posthog core', () => {

given('config', () => ({
token: 'testtoken',
property_denylist: given.property_denylist,
property_blacklist: given.property_blacklist,
sanitize_properties: given.sanitize_properties,
}))
given('property_denylist', () => [])
given('property_blacklist', () => [])

beforeEach(() => {
Expand All @@ -382,11 +390,11 @@ describe('posthog core', () => {
})
})

it('respects property_blacklist', () => {
given('property_blacklist', () => ['$lib', 'persistent'])
it('respects property_denylist and property_blacklist', () => {
given('property_denylist', () => ['$lib', 'persistent'])
given('property_blacklist', () => ['token'])

expect(given.subject).toEqual({
token: 'testtoken',
event: 'prop',
distinct_id: 'abc',
$window_id: 'windowId',
Expand Down Expand Up @@ -880,6 +888,7 @@ describe('posthog core', () => {
given('config', () => ({
request_batching: true,
persistence: 'memory',
property_denylist: [],
property_blacklist: [],
_onCapture: jest.fn(),
}))
Expand Down
26 changes: 20 additions & 6 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ export const defaultConfig = (): PostHogConfig => ({
opt_out_capturing_persistence_type: 'localStorage',
opt_out_capturing_cookie_prefix: null,
opt_in_site_apps: false,
// Deprecated, use property_denylist instead.
property_blacklist: [],
property_denylist: [],
respect_dnt: false,
sanitize_properties: null,
request_headers: {}, // { header: value, header2: value }
Expand Down Expand Up @@ -1036,13 +1038,20 @@ export class PostHog {
properties
)

const property_blacklist = this.config.property_blacklist
if (_isArray(property_blacklist)) {
_each(property_blacklist, function (blacklisted_prop) {
delete properties[blacklisted_prop]
if (_isArray(this.config.property_denylist) && _isArray(this.config.property_blacklist)) {
// since property_blacklist is deprecated in favor of property_denylist, we merge both of them here
// TODO: merge this only once, requires refactoring tests
const property_denylist = [...this.config.property_blacklist, ...this.config.property_denylist]
_each(property_denylist, function (denylisted_prop) {
delete properties[denylisted_prop]
})
} else {
logger.error('Invalid value for property_blacklist config: ' + property_blacklist)
logger.error(
'Invalid value for property_denylist config: ' +
this.config.property_denylist +
' or property_blacklist config: ' +
this.config.property_blacklist
)
}

const sanitize_properties = this.config.sanitize_properties
Expand Down Expand Up @@ -1690,10 +1699,15 @@ export class PostHog {
* // name for super properties persistent store
* persistence_name: ''
*
* // deprecated, use property_denylist instead.
* // names of properties/superproperties which should never
* // be sent with capture() calls
* // be sent with capture() calls.
* property_blacklist: []
*
* // names of properties/superproperties which should never
* // be sent with capture() calls.
* property_denylist: []
*
* // if this is true, posthog cookies will be marked as
* // secure, meaning they will only be transmitted over https
* secure_cookie: false
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ export interface PostHogConfig {
opt_out_capturing_cookie_prefix: string | null
opt_in_site_apps: boolean
respect_dnt: boolean
/** @deprecated - use `property_denylist` instead */
property_blacklist: string[]
property_denylist: string[]
request_headers: { [header_name: string]: string }
on_request_error: (error: MinimalHTTPResponse) => void
/** @deprecated - use `request_headers` instead */
Expand Down

0 comments on commit c0578e3

Please sign in to comment.