@ninetailed/experience.js 7.8.1 → 7.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js CHANGED
@@ -527,7 +527,7 @@ const makeExperienceSelectMiddleware = ({
527
527
  const middlewareFunctions = pluginsWithMiddleware.map(plugin => plugin.getExperienceSelectionMiddleware({
528
528
  experiences,
529
529
  baseline
530
- }));
530
+ })).filter(result => typeof result !== 'undefined');
531
531
  return experience_jsShared.pipe(...middlewareFunctions);
532
532
  };
533
533
  const middleware = prepareMiddleware();
@@ -595,6 +595,10 @@ class EventBuilder {
595
595
  }
596
596
  }
597
597
 
598
+ const requiresEventBuilder = plugin => {
599
+ return typeof plugin === 'object' && plugin !== null && 'setEventBuilder' in plugin && typeof plugin.setEventBuilder === 'function';
600
+ };
601
+
598
602
  const buildOverrideMiddleware = experienceSelectionMiddleware => _a => {
599
603
  var {
600
604
  experience: originalExperience,
@@ -1067,6 +1071,7 @@ class Ninetailed {
1067
1071
  });
1068
1072
  }
1069
1073
  this.plugins = (plugins !== null && plugins !== void 0 ? plugins : []).flat();
1074
+ this.eventBuilder = new EventBuilder(buildClientContext);
1070
1075
  this.plugins.forEach(plugin => {
1071
1076
  if (acceptsCredentials(plugin) && this.clientId && this.environment) {
1072
1077
  plugin.setCredentials({
@@ -1077,6 +1082,9 @@ class Ninetailed {
1077
1082
  if (experience_jsPluginAnalytics.hasComponentViewTrackingThreshold(plugin)) {
1078
1083
  plugin.setComponentViewTrackingThreshold(componentViewTrackingThreshold);
1079
1084
  }
1085
+ if (requiresEventBuilder(plugin)) {
1086
+ plugin.setEventBuilder(this.eventBuilder);
1087
+ }
1080
1088
  });
1081
1089
  this._profileState = {
1082
1090
  status: 'loading',
@@ -1085,7 +1093,6 @@ class Ninetailed {
1085
1093
  error: null,
1086
1094
  from: 'api'
1087
1095
  };
1088
- this.eventBuilder = new EventBuilder(buildClientContext);
1089
1096
  this.ninetailedCorePlugin = new NinetailedCorePlugin({
1090
1097
  apiClient: this.apiClient,
1091
1098
  locale,
@@ -1280,6 +1287,7 @@ exports.CONSENT = CONSENT;
1280
1287
  exports.DEBUG_FLAG = DEBUG_FLAG;
1281
1288
  exports.EMPTY_MERGE_ID = EMPTY_MERGE_ID;
1282
1289
  exports.EXPERIENCES_FALLBACK_CACHE = EXPERIENCES_FALLBACK_CACHE;
1290
+ exports.EventBuilder = EventBuilder;
1283
1291
  exports.HAS_SEEN_STICKY_COMPONENT = HAS_SEEN_STICKY_COMPONENT;
1284
1292
  exports.LEGACY_ANONYMOUS_ID = LEGACY_ANONYMOUS_ID;
1285
1293
  exports.Ninetailed = Ninetailed;
package/index.esm.js CHANGED
@@ -491,7 +491,7 @@ const makeExperienceSelectMiddleware = ({
491
491
  const middlewareFunctions = pluginsWithMiddleware.map(plugin => plugin.getExperienceSelectionMiddleware({
492
492
  experiences,
493
493
  baseline
494
- }));
494
+ })).filter(result => typeof result !== 'undefined');
495
495
  return pipe(...middlewareFunctions);
496
496
  };
497
497
  const middleware = prepareMiddleware();
@@ -560,6 +560,10 @@ class EventBuilder {
560
560
  }
561
561
  }
562
562
 
563
+ const requiresEventBuilder = plugin => {
564
+ return typeof plugin === 'object' && plugin !== null && 'setEventBuilder' in plugin && typeof plugin.setEventBuilder === 'function';
565
+ };
566
+
563
567
  const _excluded = ["experience", "variant", "variantIndex"],
564
568
  _excluded2 = ["element"];
565
569
  const buildOverrideMiddleware = experienceSelectionMiddleware => _ref => {
@@ -1049,6 +1053,7 @@ class Ninetailed {
1049
1053
  });
1050
1054
  }
1051
1055
  this.plugins = (plugins != null ? plugins : []).flat();
1056
+ this.eventBuilder = new EventBuilder(buildClientContext);
1052
1057
  this.plugins.forEach(plugin => {
1053
1058
  if (acceptsCredentials(plugin) && this.clientId && this.environment) {
1054
1059
  plugin.setCredentials({
@@ -1059,6 +1064,9 @@ class Ninetailed {
1059
1064
  if (hasComponentViewTrackingThreshold(plugin)) {
1060
1065
  plugin.setComponentViewTrackingThreshold(componentViewTrackingThreshold);
1061
1066
  }
1067
+ if (requiresEventBuilder(plugin)) {
1068
+ plugin.setEventBuilder(this.eventBuilder);
1069
+ }
1062
1070
  });
1063
1071
  this._profileState = {
1064
1072
  status: 'loading',
@@ -1067,7 +1075,6 @@ class Ninetailed {
1067
1075
  error: null,
1068
1076
  from: 'api'
1069
1077
  };
1070
- this.eventBuilder = new EventBuilder(buildClientContext);
1071
1078
  this.ninetailedCorePlugin = new NinetailedCorePlugin({
1072
1079
  apiClient: this.apiClient,
1073
1080
  locale,
@@ -1221,4 +1228,4 @@ const selectVariant = (baseline, variants, {
1221
1228
  };
1222
1229
  };
1223
1230
 
1224
- export { ANONYMOUS_ID, COMPONENT, COMPONENT_START, CONSENT, DEBUG_FLAG, EMPTY_MERGE_ID, EXPERIENCES_FALLBACK_CACHE, HAS_SEEN_STICKY_COMPONENT, LEGACY_ANONYMOUS_ID, Ninetailed, NinetailedCorePlugin, OnChangeEmitter, PAGE_HIDDEN, PLUGIN_NAME, PROFILE_CHANGE, PROFILE_FALLBACK_CACHE, PROFILE_RESET, SET_ENABLED_FEATURES, buildClientNinetailedRequestContext, decodeExperienceVariantsMap, makeExperienceSelectMiddleware, selectPluginsHavingExperienceSelectionMiddleware, selectPluginsHavingOnChangeEmitter, selectVariant };
1231
+ export { ANONYMOUS_ID, COMPONENT, COMPONENT_START, CONSENT, DEBUG_FLAG, EMPTY_MERGE_ID, EXPERIENCES_FALLBACK_CACHE, EventBuilder, HAS_SEEN_STICKY_COMPONENT, LEGACY_ANONYMOUS_ID, Ninetailed, NinetailedCorePlugin, OnChangeEmitter, PAGE_HIDDEN, PLUGIN_NAME, PROFILE_CHANGE, PROFILE_FALLBACK_CACHE, PROFILE_RESET, SET_ENABLED_FEATURES, buildClientNinetailedRequestContext, decodeExperienceVariantsMap, makeExperienceSelectMiddleware, selectPluginsHavingExperienceSelectionMiddleware, selectPluginsHavingOnChangeEmitter, selectVariant };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js",
3
- "version": "7.8.1",
3
+ "version": "7.9.1",
4
4
  "description": "Ninetailed SDK for javascript",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -9,8 +9,8 @@
9
9
  "directory": "packages/sdks/javascript"
10
10
  },
11
11
  "dependencies": {
12
- "@ninetailed/experience.js-plugin-analytics": "7.8.1",
13
- "@ninetailed/experience.js-shared": "7.8.1",
12
+ "@ninetailed/experience.js-plugin-analytics": "7.9.1",
13
+ "@ninetailed/experience.js-shared": "7.9.1",
14
14
  "analytics": "0.8.1",
15
15
  "uuid": "9.0.0"
16
16
  },
package/src/index.d.ts CHANGED
@@ -6,10 +6,12 @@ export * from './lib/types';
6
6
  export * from './lib/experience';
7
7
  export * from './lib/plugins/selectPluginsHavingExperienceSelectionMiddleware';
8
8
  export * from './lib/plugins/selectPluginsHavingOnChangeEmitter';
9
+ export * from './lib/types/interfaces/RequiresEventBuilder';
9
10
  export * from './lib/types/interfaces/HasExperienceSelectionMiddleware';
10
11
  export * from './lib/types/interfaces/InterestedInSeenElements';
11
12
  export * from './lib/types/interfaces/InterestedInProfileChange';
12
13
  export * from './lib/types/interfaces/InterestedInHiddenPage';
13
14
  export * from './lib/types/interfaces/AcceptsCredentials';
14
15
  export * from './lib/utils/OnChangeEmitter';
16
+ export * from './lib/utils/EventBuilder';
15
17
  export type { Profile } from '@ninetailed/experience.js-shared';
@@ -0,0 +1,2 @@
1
+ import { RequiresEventBuilder } from '../types/interfaces/RequiresEventBuilder';
2
+ export declare const requiresEventBuilder: (plugin: unknown) => plugin is RequiresEventBuilder;
@@ -1,4 +1,4 @@
1
1
  import { type Profile } from '@ninetailed/experience.js-shared';
2
2
  export type ProfileChangedPayload = {
3
- profile: Profile;
3
+ profile: Profile | null;
4
4
  };
@@ -9,7 +9,7 @@ type BuildExperienceSelectionMiddlewareArg<TVariant extends Reference> = {
9
9
  experiences: ExperienceConfiguration<TVariant>[];
10
10
  baseline: Reference;
11
11
  };
12
- export type BuildExperienceSelectionMiddleware<TBaseline extends Reference, TVariant extends Reference> = (arg: BuildExperienceSelectionMiddlewareArg<TVariant>) => ExperienceSelectionMiddleware<TBaseline, TVariant>;
12
+ export type BuildExperienceSelectionMiddleware<TBaseline extends Reference, TVariant extends Reference> = (arg: BuildExperienceSelectionMiddlewareArg<TVariant>) => ExperienceSelectionMiddleware<TBaseline, TVariant> | undefined;
13
13
  export interface HasExperienceSelectionMiddleware<TBaseline extends Reference, TVariant extends Reference> {
14
14
  getExperienceSelectionMiddleware: BuildExperienceSelectionMiddleware<TBaseline, TVariant>;
15
15
  }
@@ -0,0 +1,4 @@
1
+ import { EventBuilder } from '../../utils/EventBuilder';
2
+ export interface RequiresEventBuilder {
3
+ setEventBuilder(eventBuilder: EventBuilder): void;
4
+ }