@ninetailed/experience.js 7.8.0 → 7.9.0

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
@@ -214,7 +214,7 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
214
214
  });
215
215
  }
216
216
  pageStart(params) {
217
- return this.abortNonClientEvents(params);
217
+ return NinetailedCorePlugin.abortNonClientEvents(params);
218
218
  }
219
219
  page({
220
220
  payload
@@ -231,7 +231,7 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
231
231
  });
232
232
  }
233
233
  trackStart(params) {
234
- return this.abortNonClientEvents(params);
234
+ return NinetailedCorePlugin.abortNonClientEvents(params);
235
235
  }
236
236
  track({
237
237
  payload
@@ -249,7 +249,7 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
249
249
  });
250
250
  }
251
251
  identifyStart(params) {
252
- return this.abortNonClientEvents(params);
252
+ return NinetailedCorePlugin.abortNonClientEvents(params);
253
253
  }
254
254
  identify({
255
255
  payload
@@ -301,7 +301,7 @@ class NinetailedCorePlugin extends experience_jsPluginAnalytics.NinetailedAnalyt
301
301
  this.queue = experience_jsShared.unionBy([event], this.queue, 'messageId');
302
302
  });
303
303
  }
304
- abortNonClientEvents({
304
+ static abortNonClientEvents({
305
305
  abort,
306
306
  payload
307
307
  }) {
@@ -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
@@ -175,7 +175,7 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
175
175
  logger.debug('Ninetailed Core plugin initialized.');
176
176
  }
177
177
  pageStart(params) {
178
- return this.abortNonClientEvents(params);
178
+ return NinetailedCorePlugin.abortNonClientEvents(params);
179
179
  }
180
180
  async page({
181
181
  payload
@@ -190,7 +190,7 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
190
190
  }));
191
191
  }
192
192
  trackStart(params) {
193
- return this.abortNonClientEvents(params);
193
+ return NinetailedCorePlugin.abortNonClientEvents(params);
194
194
  }
195
195
  async track({
196
196
  payload
@@ -206,7 +206,7 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
206
206
  }));
207
207
  }
208
208
  identifyStart(params) {
209
- return this.abortNonClientEvents(params);
209
+ return NinetailedCorePlugin.abortNonClientEvents(params);
210
210
  }
211
211
  async identify({
212
212
  payload
@@ -252,7 +252,7 @@ class NinetailedCorePlugin extends NinetailedAnalyticsPlugin {
252
252
  async enqueueEvent(event) {
253
253
  this.queue = unionBy([event], this.queue, 'messageId');
254
254
  }
255
- abortNonClientEvents({
255
+ static abortNonClientEvents({
256
256
  abort,
257
257
  payload
258
258
  }) {
@@ -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.0",
3
+ "version": "7.9.0",
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.0",
13
- "@ninetailed/experience.js-shared": "7.8.0",
12
+ "@ninetailed/experience.js-plugin-analytics": "7.9.0",
13
+ "@ninetailed/experience.js-shared": "7.9.0",
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';
@@ -62,7 +62,7 @@ export declare class NinetailedCorePlugin extends NinetailedAnalyticsPlugin impl
62
62
  debug: (...args: any[]) => Promise<void>;
63
63
  };
64
64
  private enqueueEvent;
65
- private abortNonClientEvents;
65
+ private static abortNonClientEvents;
66
66
  private get instance();
67
67
  flush: (args: void) => Promise<FlushResult>;
68
68
  private _flush;
@@ -0,0 +1,2 @@
1
+ import { RequiresEventBuilder } from '../types/interfaces/RequiresEventBuilder';
2
+ export declare const requiresEventBuilder: (plugin: unknown) => plugin is RequiresEventBuilder;
@@ -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
+ }