Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev 3800 Privacy Plugin race condition when listening on enabled features #53

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { Analytics, AnalyticsInstance } from 'analytics';
import { PLUGIN_NAME as NINETAILED_CORE_PLUGIN_NAME } from '@ninetailed/experience.js';
import {
FEATURES,
PLUGIN_NAME as NINETAILED_CORE_PLUGIN_NAME,
SET_ENABLED_FEATURES,
} from '@ninetailed/experience.js-shared';
} from '@ninetailed/experience.js';
import { FEATURES } from '@ninetailed/experience.js-shared';
import {
DEFAULT_ACCEPTED_CONSENT_CONFIG,
DEFAULT_PRIVACY_CONFIG,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/privacy/src/NinetailedPrivacyPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
CONSENT,
COMPONENT,
COMPONENT_START,
SET_ENABLED_FEATURES,
PLUGIN_NAME as NINETAILED_CORE_PLUGIN_NAME,
SET_ENABLED_FEATURES,
} from '@ninetailed/experience.js';
import wildCardMatch from 'wildcard-match';
import { isEqual } from 'radash';
Expand Down
19 changes: 10 additions & 9 deletions packages/sdks/javascript/src/lib/Ninetailed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
}
}

type GetItem<T = any> = (key: string) => T;

Check warning on line 78 in packages/sdks/javascript/src/lib/Ninetailed.ts

View workflow job for this annotation

GitHub Actions / Lint 🎨

Unexpected any. Specify a different type

Check warning on line 78 in packages/sdks/javascript/src/lib/Ninetailed.ts

View workflow job for this annotation

GitHub Actions / Lint 🎨

Unexpected any. Specify a different type

type SetItem<T = any> = (key: string, value: T) => void;

Check warning on line 80 in packages/sdks/javascript/src/lib/Ninetailed.ts

View workflow job for this annotation

GitHub Actions / Lint 🎨

Unexpected any. Specify a different type

Check warning on line 80 in packages/sdks/javascript/src/lib/Ninetailed.ts

View workflow job for this annotation

GitHub Actions / Lint 🎨

Unexpected any. Specify a different type

type RemoveItem = (key: string) => void;

Expand Down Expand Up @@ -177,6 +177,16 @@
useSDKEvaluation = false,
}: Options = {}
) {
if (typeof onLog === 'function') {
logger.addSink(new OnLogLogSink(onLog));
}

if (typeof onError === 'function') {
logger.addSink(new OnErrorLogSink(onError));
}

this.logger = logger;

this.useSDKEvaluation = useSDKEvaluation;

if (ninetailedApiClientInstanceOrOptions instanceof NinetailedApiClient) {
Expand Down Expand Up @@ -220,17 +230,8 @@
from: 'api',
};

if (typeof onLog === 'function') {
logger.addSink(new OnLogLogSink(onLog));
}

if (typeof onError === 'function') {
logger.addSink(new OnErrorLogSink(onError));
}

this.eventBuilder = new EventBuilder(buildClientContext);

this.logger = logger;
this.ninetailedCorePlugin = new NinetailedCorePlugin({
apiClient: this.apiClient,
locale,
Expand Down Expand Up @@ -480,7 +481,7 @@

if (!(element instanceof Element)) {
const isObject = typeof element === 'object' && element !== null;
const constructorName = isObject ? (element as any).constructor.name : '';

Check warning on line 484 in packages/sdks/javascript/src/lib/Ninetailed.ts

View workflow job for this annotation

GitHub Actions / Lint 🎨

Unexpected any. Specify a different type

Check warning on line 484 in packages/sdks/javascript/src/lib/Ninetailed.ts

View workflow job for this annotation

GitHub Actions / Lint 🎨

Unexpected any. Specify a different type
const isConstructorNameNotObject =
constructorName && constructorName !== 'Object';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@

export const PLUGIN_NAME = 'ninetailed:core';

type EventFn = { payload: any; instance: InternalAnalyticsInstance };

Check warning on line 58 in packages/sdks/javascript/src/lib/NinetailedCorePlugin/NinetailedCorePlugin.ts

View workflow job for this annotation

GitHub Actions / Lint 🎨

Unexpected any. Specify a different type

Check warning on line 58 in packages/sdks/javascript/src/lib/NinetailedCorePlugin/NinetailedCorePlugin.ts

View workflow job for this annotation

GitHub Actions / Lint 🎨

Unexpected any. Specify a different type

type AbortableFnParams = { abort: () => void; payload: unknown };

const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

type InternalAnalyticsInstance = AnalyticsInstance & {
dispatch: (action: any) => void;

Check warning on line 65 in packages/sdks/javascript/src/lib/NinetailedCorePlugin/NinetailedCorePlugin.ts

View workflow job for this annotation

GitHub Actions / Lint 🎨

Unexpected any. Specify a different type

Check warning on line 65 in packages/sdks/javascript/src/lib/NinetailedCorePlugin/NinetailedCorePlugin.ts

View workflow job for this annotation

GitHub Actions / Lint 🎨

Unexpected any. Specify a different type
};

export interface NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
Expand Down Expand Up @@ -143,16 +143,13 @@
}
}

instance.on(
SET_ENABLED_FEATURES,
({ payload }: { payload: { features: Feature[] } }) => {
this.enabledFeatures = payload.features || [];
}
);

logger.debug('Ninetailed Core plugin initialized.');
}

public [SET_ENABLED_FEATURES] = async ({ payload }: EventFn) => {
this.enabledFeatures = payload.features || [];
};

public pageStart(params: AbortableFnParams) {
return this.abortNonClientEvents(params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const PROFILE_CHANGE = 'profile-change';
export const PROFILE_RESET = 'profile-reset';

export const CONSENT = '__nt-consent__';
export const SET_ENABLED_FEATURES = 'set-enabled-features';

export const SET_ENABLED_FEATURES = 'setEnabledFeatures';

export const EMPTY_MERGE_ID = 'nt:empty-merge-id';
1 change: 0 additions & 1 deletion packages/sdks/shared/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const PROFILE_CHANGE = 'profile-change';
export const PROFILE_RESET = 'profile-reset';

export const CONSENT = '__nt-consent__';
export const SET_ENABLED_FEATURES = 'set-enabled-features';

export const EMPTY_MERGE_ID = 'nt:empty-merge-id';

Expand Down
Loading