@ninetailed/experience.js 7.6.0-beta.1 → 7.6.0-beta.3

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.
Files changed (28) hide show
  1. package/index.cjs.d.ts +1 -0
  2. package/{index.cjs → index.cjs.js} +276 -244
  3. package/{index.js → index.esm.js} +411 -383
  4. package/package.json +13 -9
  5. package/src/index.d.ts +1 -1
  6. package/src/lib/ElementSeenObserver.d.ts +1 -1
  7. package/src/lib/Ninetailed.d.ts +4 -2
  8. package/src/lib/NinetailedCorePlugin/NinetailedCorePlugin.d.ts +69 -0
  9. package/src/lib/{ninetailedCorePlugin → NinetailedCorePlugin}/index.d.ts +1 -1
  10. package/src/lib/constants.d.ts +0 -2
  11. package/src/lib/experience/makeExperienceSelectMiddleware.d.ts +1 -1
  12. package/src/lib/guards/hasComponentViewTrackingThreshold.d.ts +3 -0
  13. package/src/lib/plugins/selectPluginsHavingExperienceSelectionMiddleware.d.ts +1 -1
  14. package/src/lib/plugins/selectPluginsHavingOnChangeEmitter.d.ts +1 -1
  15. package/src/lib/types/index.d.ts +2 -8
  16. package/src/lib/types/interfaces/HasComponentViewTrackingThreshold.d.ts +3 -0
  17. package/src/lib/types/interfaces/InterestedInHiddenPage.d.ts +1 -1
  18. package/src/lib/types/interfaces/InterestedInProfileChange.d.ts +1 -1
  19. package/src/lib/types/interfaces/InterestedInSeenElements.d.ts +1 -3
  20. package/src/lib/ninetailedCorePlugin/ninetailedCorePlugin.d.ts +0 -17
  21. package/src/lib/types/ElementSeenPayload.d.ts +0 -82
  22. package/src/lib/types/EventHandler.d.ts +0 -6
  23. package/src/lib/types/NinetailedPlugin.d.ts +0 -11
  24. package/src/lib/types/TrackingProperties.d.ts +0 -35
  25. /package/src/lib/{ninetailedCorePlugin → NinetailedCorePlugin}/Events/build-context.d.ts +0 -0
  26. /package/src/lib/{ninetailedCorePlugin → NinetailedCorePlugin}/Events/build-locale.d.ts +0 -0
  27. /package/src/lib/{ninetailedCorePlugin → NinetailedCorePlugin}/Events/index.d.ts +0 -0
  28. /package/src/lib/{ninetailedCorePlugin → NinetailedCorePlugin}/constants.d.ts +0 -0
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js",
3
- "version": "7.6.0-beta.1",
4
- "license": "BSL-1.1",
5
- "module": "./index.js",
6
- "main": "./index.cjs",
3
+ "version": "7.6.0-beta.3",
7
4
  "type": "module",
8
- "types": "./src/index.d.ts",
5
+ "description": "Ninetailed SDK for javascript",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/ninetailed-inc/experience.js.git",
10
+ "directory": "packages/sdks/javascript"
11
+ },
9
12
  "dependencies": {
10
- "@ninetailed/experience.js-shared": "7.6.0-beta.1",
11
13
  "analytics": "0.8.1",
12
- "uuid": "9.0.0",
13
- "zod": "3.21.4"
14
+ "@ninetailed/experience.js-plugin-analytics": "*",
15
+ "@ninetailed/experience.js-shared": "*",
16
+ "uuid": "9.0.0"
14
17
  },
15
- "peerDependencies": {}
18
+ "module": "./index.esm.js",
19
+ "main": "./index.cjs.js"
16
20
  }
package/src/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './lib/constants';
2
- export * from './lib/ninetailedCorePlugin';
2
+ export * from './lib/NinetailedCorePlugin';
3
3
  export * from './lib/Ninetailed';
4
4
  export * from './lib/selectVariant';
5
5
  export * from './lib/types';
@@ -1,5 +1,5 @@
1
1
  export type ElementSeenObserverOptions = {
2
- onElementSeen: (element: Element) => void;
2
+ onElementSeen: (element: Element, delay?: number) => void;
3
3
  };
4
4
  export type ObserveOptions = {
5
5
  delay?: number;
@@ -1,9 +1,10 @@
1
1
  /// <reference types="analytics" />
2
2
  import { Locale, Traits, OnLogHandler, OnErrorHandler, Logger, PageviewProperties, Properties, NinetailedApiClient, NinetailedApiClientOptions, NinetailedRequestContext, Reference, Event } from '@ninetailed/experience.js-shared';
3
- import { OnInitProfileId } from './ninetailedCorePlugin';
4
- import { EventFunctionOptions, NinetailedInstance, NinetailedPlugin, OnIsInitializedCallback, OnProfileChangeCallback, ProfileState, TrackHasSeenComponent, ElementSeenPayload, TrackComponentView } from './types';
3
+ import { OnInitProfileId } from './NinetailedCorePlugin';
4
+ import { EventFunctionOptions, NinetailedInstance, OnIsInitializedCallback, OnProfileChangeCallback, ProfileState, TrackHasSeenComponent, TrackComponentView } from './types';
5
5
  import { ObserveOptions } from './ElementSeenObserver';
6
6
  import { OnSelectVariantArgs, OnSelectVariantCallback } from './types/OnSelectVariant';
7
+ import { ElementSeenPayload, NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
7
8
  import { EventBuilder } from './utils/EventBuilder';
8
9
  declare global {
9
10
  interface Window {
@@ -68,6 +69,7 @@ export declare class Ninetailed implements NinetailedInstance {
68
69
  */
69
70
  trackHasSeenComponent: TrackHasSeenComponent;
70
71
  trackComponentView: TrackComponentView;
72
+ private get pluginsWithCustomComponentViewThreshold();
71
73
  observeElement: (payload: ElementSeenPayload, options?: ObserveOptions) => void;
72
74
  unobserveElement: (element: Element) => void;
73
75
  private onElementSeen;
@@ -0,0 +1,69 @@
1
+ import { AnalyticsInstance } from 'analytics';
2
+ import { Locale, NinetailedApiClient, NinetailedRequestContext } from '@ninetailed/experience.js-shared';
3
+ import { NinetailedAnalyticsPlugin, NinetailedPlugin, SanitizedElementSeenPayload } from '@ninetailed/experience.js-plugin-analytics';
4
+ import { NinetailedInstance, FlushResult } from '../types';
5
+ import { HAS_SEEN_STICKY_COMPONENT } from '../constants';
6
+ import { HasComponentViewTrackingThreshold } from '../types/interfaces/HasComponentViewTrackingThreshold';
7
+ export type OnInitProfileId = (profileId?: string) => Promise<string | undefined> | string | undefined;
8
+ type AnalyticsPluginNinetailedConfig = {
9
+ apiClient: NinetailedApiClient;
10
+ locale?: Locale;
11
+ requestTimeout?: number;
12
+ onInitProfileId?: OnInitProfileId;
13
+ buildClientContext?: () => NinetailedRequestContext;
14
+ ninetailed: NinetailedInstance;
15
+ };
16
+ export declare const PLUGIN_NAME = "ninetailed:core";
17
+ type EventFn = {
18
+ payload: any;
19
+ instance: InternalAnalyticsInstance;
20
+ };
21
+ type AbortableFnParams = {
22
+ abort: () => void;
23
+ payload: unknown;
24
+ };
25
+ type InternalAnalyticsInstance = AnalyticsInstance & {
26
+ dispatch: (action: any) => void;
27
+ };
28
+ export interface NinetailedCorePlugin extends NinetailedPlugin {
29
+ flush: (args: void) => Promise<FlushResult>;
30
+ }
31
+ export declare class NinetailedCorePlugin extends NinetailedAnalyticsPlugin implements NinetailedCorePlugin, HasComponentViewTrackingThreshold {
32
+ name: string;
33
+ private _instance?;
34
+ private queue;
35
+ private enabledFeatures;
36
+ private readonly buildContext;
37
+ private readonly onInitProfileId?;
38
+ private readonly apiClient;
39
+ private readonly locale?;
40
+ private readonly ninetailed;
41
+ constructor({ apiClient, locale, ninetailed, onInitProfileId, buildClientContext, }: AnalyticsPluginNinetailedConfig);
42
+ initialize({ instance, }: {
43
+ instance: InternalAnalyticsInstance;
44
+ }): Promise<void>;
45
+ pageStart(params: AbortableFnParams): unknown;
46
+ page({ payload }: EventFn): Promise<void>;
47
+ trackStart(params: AbortableFnParams): unknown;
48
+ track({ payload }: EventFn): Promise<void>;
49
+ identifyStart(params: AbortableFnParams): unknown;
50
+ identify({ payload }: EventFn): Promise<void>;
51
+ getComponentViewTrackingThreshold(): number;
52
+ protected onTrackExperience(properties: SanitizedElementSeenPayload): Promise<void>;
53
+ protected onTrackComponent(): Promise<void>;
54
+ [HAS_SEEN_STICKY_COMPONENT]: ({ payload }: EventFn) => Promise<void>;
55
+ setItemStart({ abort, payload }: {
56
+ abort: any;
57
+ payload: any;
58
+ }): any;
59
+ methods: {
60
+ reset: (...args: any[]) => Promise<void>;
61
+ debug: (...args: any[]) => Promise<void>;
62
+ };
63
+ private enqueueEvent;
64
+ private abortNonClientEvents;
65
+ private get instance();
66
+ flush: (args: void) => Promise<FlushResult>;
67
+ private _flush;
68
+ }
69
+ export {};
@@ -1,3 +1,3 @@
1
- export * from './ninetailedCorePlugin';
1
+ export * from './NinetailedCorePlugin';
2
2
  export * from './constants';
3
3
  export * from './Events';
@@ -1,5 +1,3 @@
1
- export declare const HAS_SEEN_COMPONENT = "has_seen_component";
2
- export declare const HAS_SEEN_ELEMENT = "has_seen_element";
3
1
  export declare const COMPONENT = "component";
4
2
  export declare const COMPONENT_START = "componentStart";
5
3
  export declare const PAGE_HIDDEN = "page_hidden";
@@ -1,5 +1,5 @@
1
1
  import { ExperienceConfiguration, Profile, Reference } from '@ninetailed/experience.js-shared';
2
- import { NinetailedPlugin } from '../types/NinetailedPlugin';
2
+ import { NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
3
3
  import { ExperienceSelectionMiddleware, ExperienceSelectionMiddlewareArg } from '../types/interfaces/HasExperienceSelectionMiddleware';
4
4
  type MakeExperienceSelectMiddlewareArg<Baseline extends Reference, Variant extends Reference> = {
5
5
  plugins: NinetailedPlugin[];
@@ -0,0 +1,3 @@
1
+ import { NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
2
+ import type { HasComponentViewTrackingThreshold } from '../types/interfaces/HasComponentViewTrackingThreshold';
3
+ export declare const hasComponentViewTrackingThreshold: (arg: NinetailedPlugin) => arg is NinetailedPlugin & HasComponentViewTrackingThreshold;
@@ -1,4 +1,4 @@
1
1
  import { Reference } from '@ninetailed/experience.js-shared';
2
+ import { NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
2
3
  import { HasExperienceSelectionMiddleware } from '../types/interfaces/HasExperienceSelectionMiddleware';
3
- import { NinetailedPlugin } from '../types/NinetailedPlugin';
4
4
  export declare const selectPluginsHavingExperienceSelectionMiddleware: <Baseline extends Reference, Variant extends Reference>(plugins: NinetailedPlugin[]) => HasExperienceSelectionMiddleware<Baseline, Variant>[];
@@ -1,3 +1,3 @@
1
- import { NinetailedPlugin } from '../types/NinetailedPlugin';
1
+ import { NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
2
2
  import { HasOnChangeEmitter } from '../types/interfaces/HasOnChangeEmitter';
3
3
  export declare const selectPluginsHavingOnChangeEmitter: (plugins: NinetailedPlugin[]) => HasOnChangeEmitter[];
@@ -1,9 +1,7 @@
1
- import { Logger, PageviewProperties, Profile, Properties, Traits, SelectedVariantInfo, Reference, Event } from '@ninetailed/experience.js-shared';
2
1
  import { DetachListeners } from 'analytics';
3
- import { TrackComponentProperties } from './TrackingProperties';
4
- import { NinetailedPlugin } from './NinetailedPlugin';
2
+ import { Logger, PageviewProperties, Profile, Properties, Traits, SelectedVariantInfo, Reference, Event } from '@ninetailed/experience.js-shared';
3
+ import { ElementSeenPayload, NinetailedPlugin, TrackComponentProperties } from '@ninetailed/experience.js-plugin-analytics';
5
4
  import { type Ninetailed } from '../Ninetailed';
6
- import { ElementSeenPayload } from './ElementSeenPayload';
7
5
  import { OnSelectVariant } from './OnSelectVariant';
8
6
  import { EventBuilder } from '../utils/EventBuilder';
9
7
  type Loading = {
@@ -72,10 +70,6 @@ export interface NinetailedInstance<TBaseline extends Reference = Reference, TVa
72
70
  unobserveElement: UnObserveElement;
73
71
  onSelectVariant: OnSelectVariant<TBaseline, TVariant>;
74
72
  }
75
- export { NinetailedPlugin, TrackComponentProperties };
76
- export type { EventHandler } from './EventHandler';
77
73
  export type { AnalyticsInstance } from './AnalyticsInstance';
78
- export { ElementSeenPayloadSchema } from './ElementSeenPayload';
79
- export type { ElementSeenPayload } from './ElementSeenPayload';
80
74
  export type { ProfileChangedPayload } from './ProfileChangedPayload';
81
75
  export type { Credentials } from './Credentials';
@@ -0,0 +1,3 @@
1
+ export interface HasComponentViewTrackingThreshold {
2
+ getComponentViewTrackingThreshold: () => number;
3
+ }
@@ -1,5 +1,5 @@
1
1
  import { PAGE_HIDDEN } from '../../constants';
2
- import { EventHandler } from '../EventHandler';
2
+ import { EventHandler } from '@ninetailed/experience.js-plugin-analytics';
3
3
  export interface InterestedInHiddenPage {
4
4
  [PAGE_HIDDEN]: EventHandler<void>;
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import { PROFILE_CHANGE } from '@ninetailed/experience.js-shared';
2
- import { EventHandler } from '../EventHandler';
2
+ import { EventHandler } from '@ninetailed/experience.js-plugin-analytics';
3
3
  import { ProfileChangedPayload } from '../ProfileChangedPayload';
4
4
  export interface InterestedInProfileChange {
5
5
  [PROFILE_CHANGE]: EventHandler<ProfileChangedPayload>;
@@ -1,6 +1,4 @@
1
- import { HAS_SEEN_ELEMENT } from '../../constants';
2
- import { ElementSeenPayload } from '../ElementSeenPayload';
3
- import { EventHandler } from '../EventHandler';
1
+ import { EventHandler, ElementSeenPayload, HAS_SEEN_ELEMENT } from '@ninetailed/experience.js-plugin-analytics';
4
2
  export interface InterestedInSeenElements {
5
3
  [HAS_SEEN_ELEMENT]: EventHandler<ElementSeenPayload>;
6
4
  }
@@ -1,17 +0,0 @@
1
- import { Locale, NinetailedApiClient, NinetailedRequestContext } from '@ninetailed/experience.js-shared';
2
- import { NinetailedInstance, FlushResult, NinetailedPlugin } from '../types';
3
- export type OnInitProfileId = (profileId?: string) => Promise<string | undefined> | string | undefined;
4
- type AnalyticsPluginNinetailedConfig = {
5
- apiClient: NinetailedApiClient;
6
- locale?: Locale;
7
- requestTimeout?: number;
8
- onInitProfileId?: OnInitProfileId;
9
- buildClientContext?: () => NinetailedRequestContext;
10
- ninetailed: NinetailedInstance;
11
- };
12
- export declare const PLUGIN_NAME = "ninetailed";
13
- export interface NinetailedCorePlugin extends NinetailedPlugin {
14
- flush: () => Promise<FlushResult>;
15
- }
16
- export declare const ninetailedCorePlugin: ({ apiClient, locale, ninetailed, onInitProfileId, buildClientContext, }: AnalyticsPluginNinetailedConfig) => NinetailedCorePlugin;
17
- export {};
@@ -1,82 +0,0 @@
1
- import { z } from 'zod';
2
- export declare const ElementSeenPayloadSchema: z.ZodObject<{
3
- element: z.ZodAny;
4
- experience: z.ZodNullable<z.ZodOptional<z.ZodObject<{
5
- id: z.ZodString;
6
- type: z.ZodUnion<[z.ZodLiteral<"nt_experiment">, z.ZodLiteral<"nt_personalization">]>;
7
- name: z.ZodOptional<z.ZodString>;
8
- description: z.ZodOptional<z.ZodString>;
9
- }, "strip", z.ZodTypeAny, {
10
- id: string;
11
- type: "nt_experiment" | "nt_personalization";
12
- name?: string | undefined;
13
- description?: string | undefined;
14
- }, {
15
- id: string;
16
- type: "nt_experiment" | "nt_personalization";
17
- name?: string | undefined;
18
- description?: string | undefined;
19
- }>>>;
20
- audience: z.ZodDefault<z.ZodNullable<z.ZodOptional<z.ZodObject<{
21
- id: z.ZodString;
22
- name: z.ZodOptional<z.ZodString>;
23
- description: z.ZodOptional<z.ZodString>;
24
- }, "strip", z.ZodTypeAny, {
25
- id: string;
26
- name?: string | undefined;
27
- description?: string | undefined;
28
- }, {
29
- id: string;
30
- name?: string | undefined;
31
- description?: string | undefined;
32
- }>>>>;
33
- variant: z.ZodObject<{
34
- id: z.ZodString;
35
- }, "strip", z.ZodUnknown, z.objectOutputType<{
36
- id: z.ZodString;
37
- }, z.ZodUnknown, "strip">, z.objectInputType<{
38
- id: z.ZodString;
39
- }, z.ZodUnknown, "strip">>;
40
- variantIndex: z.ZodNumber;
41
- }, "strip", z.ZodTypeAny, {
42
- audience: {
43
- id: string;
44
- name?: string | undefined;
45
- description?: string | undefined;
46
- } | null;
47
- variant: {
48
- id: string;
49
- } & {
50
- [k: string]: unknown;
51
- };
52
- variantIndex: number;
53
- element?: any;
54
- experience?: {
55
- id: string;
56
- type: "nt_experiment" | "nt_personalization";
57
- name?: string | undefined;
58
- description?: string | undefined;
59
- } | null | undefined;
60
- }, {
61
- variant: {
62
- id: string;
63
- } & {
64
- [k: string]: unknown;
65
- };
66
- variantIndex: number;
67
- element?: any;
68
- experience?: {
69
- id: string;
70
- type: "nt_experiment" | "nt_personalization";
71
- name?: string | undefined;
72
- description?: string | undefined;
73
- } | null | undefined;
74
- audience?: {
75
- id: string;
76
- name?: string | undefined;
77
- description?: string | undefined;
78
- } | null | undefined;
79
- }>;
80
- export type ElementSeenPayload = Omit<z.input<typeof ElementSeenPayloadSchema>, 'element'> & {
81
- element: Element;
82
- };
@@ -1,6 +0,0 @@
1
- import { AnalyticsInstance } from './AnalyticsInstance';
2
- export type EventHandlerParams<T = unknown> = {
3
- payload: T;
4
- instance: AnalyticsInstance;
5
- };
6
- export type EventHandler<T = unknown> = (params: EventHandlerParams<T>) => void;
@@ -1,11 +0,0 @@
1
- import { AnalyticsPlugin } from 'analytics';
2
- import { AnalyticsInstance } from './AnalyticsInstance';
3
- export type EventHandlerParams<T = unknown> = {
4
- payload: T;
5
- instance: AnalyticsInstance;
6
- };
7
- export type EventHandler<T = unknown> = (params: EventHandlerParams<T>) => void;
8
- export declare abstract class NinetailedPlugin implements AnalyticsPlugin {
9
- [x: string]: unknown;
10
- abstract readonly name: string;
11
- }
@@ -1,35 +0,0 @@
1
- import { z } from 'zod';
2
- export declare const TrackComponentProperties: z.ZodObject<{
3
- variant: z.ZodObject<{
4
- id: z.ZodString;
5
- }, "strip", z.ZodTypeAny, {
6
- id: string;
7
- }, {
8
- id: string;
9
- }>;
10
- audience: z.ZodObject<{
11
- id: z.ZodString;
12
- }, "strip", z.ZodTypeAny, {
13
- id: string;
14
- }, {
15
- id: string;
16
- }>;
17
- isPersonalized: z.ZodBoolean;
18
- }, "strip", z.ZodTypeAny, {
19
- variant: {
20
- id: string;
21
- };
22
- audience: {
23
- id: string;
24
- };
25
- isPersonalized: boolean;
26
- }, {
27
- variant: {
28
- id: string;
29
- };
30
- audience: {
31
- id: string;
32
- };
33
- isPersonalized: boolean;
34
- }>;
35
- export type TrackComponentProperties = z.infer<typeof TrackComponentProperties>;