@ninetailed/experience.js 7.11.0 → 7.12.0-beta.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 +226 -116
- package/index.esm.js +232 -117
- package/package.json +3 -3
- package/src/lib/Ninetailed.d.ts +18 -2
- package/src/lib/NinetailedCorePlugin/NinetailedCorePlugin.d.ts +21 -5
- package/src/lib/NinetailedCorePlugin/actions.d.ts +59 -0
- package/src/lib/NinetailedCorePlugin/constants.d.ts +1 -0
- package/src/lib/experience/makeExperienceSelectMiddleware.d.ts +15 -10
- package/src/lib/types/index.d.ts +34 -10
- package/src/lib/utils/EventBuilder.d.ts +10 -4
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { HAS_SEEN_COMPONENT, HAS_SEEN_ELEMENT } from '@ninetailed/experience.js-plugin-analytics';
|
|
2
|
+
import { PROFILE_CHANGE, Profile, SelectedVariantInfo, PROFILE_RESET, Change } from '@ninetailed/experience.js-shared';
|
|
3
|
+
import { HAS_SEEN_STICKY_COMPONENT, PAGE_HIDDEN } from '../constants';
|
|
4
|
+
type ReadyAction = {
|
|
5
|
+
type: 'ready';
|
|
6
|
+
};
|
|
7
|
+
type HasSeenElementAction = {
|
|
8
|
+
type: typeof HAS_SEEN_ELEMENT;
|
|
9
|
+
seenFor: number | undefined;
|
|
10
|
+
element: Element;
|
|
11
|
+
};
|
|
12
|
+
type PageHiddenAction = {
|
|
13
|
+
type: typeof PAGE_HIDDEN;
|
|
14
|
+
};
|
|
15
|
+
type ProfileChangeAction = {
|
|
16
|
+
type: typeof PROFILE_CHANGE;
|
|
17
|
+
profile: Profile;
|
|
18
|
+
experiences: SelectedVariantInfo[];
|
|
19
|
+
changes: Change[];
|
|
20
|
+
error: undefined | null;
|
|
21
|
+
} | {
|
|
22
|
+
type: typeof PROFILE_CHANGE;
|
|
23
|
+
profile: Profile | null;
|
|
24
|
+
experiences: SelectedVariantInfo[];
|
|
25
|
+
changes: Change[];
|
|
26
|
+
error: Error;
|
|
27
|
+
};
|
|
28
|
+
type ProfileResetAction = {
|
|
29
|
+
type: typeof PROFILE_RESET;
|
|
30
|
+
};
|
|
31
|
+
type ProfileHasSeenStickyComponentAction = {
|
|
32
|
+
type: typeof HAS_SEEN_STICKY_COMPONENT;
|
|
33
|
+
componentId: string;
|
|
34
|
+
experienceId: string | undefined;
|
|
35
|
+
variantIndex: number | undefined;
|
|
36
|
+
};
|
|
37
|
+
type ProfileHasSeenComponentAction = {
|
|
38
|
+
type: typeof HAS_SEEN_COMPONENT;
|
|
39
|
+
variant: {
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
42
|
+
audience: {
|
|
43
|
+
id: string;
|
|
44
|
+
};
|
|
45
|
+
isPersonalized: boolean;
|
|
46
|
+
};
|
|
47
|
+
export type DispatchAction = ReadyAction | ProfileChangeAction | ProfileResetAction | ProfileHasSeenStickyComponentAction | HasSeenElementAction | ProfileHasSeenComponentAction | PageHiddenAction;
|
|
48
|
+
type RemoveTypeField<Type> = {
|
|
49
|
+
[Property in keyof Type as Exclude<Property, 'type'>]: Type[Property];
|
|
50
|
+
};
|
|
51
|
+
export type ExtractPayload<T extends {
|
|
52
|
+
type: string;
|
|
53
|
+
}> = {
|
|
54
|
+
payload: RemoveTypeField<T>;
|
|
55
|
+
};
|
|
56
|
+
export type ActionPayloadMap = {
|
|
57
|
+
[A in DispatchAction as A['type']]: ExtractPayload<A>;
|
|
58
|
+
};
|
|
59
|
+
export {};
|
|
@@ -3,6 +3,7 @@ export declare const ANONYMOUS_ID = "__nt_anonymous_id__";
|
|
|
3
3
|
export declare const DEBUG_FLAG = "__nt_debug__";
|
|
4
4
|
export declare const PROFILE_FALLBACK_CACHE = "__nt_profile__";
|
|
5
5
|
export declare const EXPERIENCES_FALLBACK_CACHE = "__nt_experiences__";
|
|
6
|
+
export declare const CHANGES_FALLBACK_CACHE = "__nt_changes__";
|
|
6
7
|
export declare const PROFILE_CHANGE = "profile-change";
|
|
7
8
|
export declare const PROFILE_RESET = "profile-reset";
|
|
8
9
|
export declare const CONSENT = "__nt-consent__";
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { ExperienceConfiguration, Profile, Reference } from '@ninetailed/experience.js-shared';
|
|
2
2
|
import { NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
|
|
3
|
-
import { ExperienceSelectionMiddleware
|
|
4
|
-
|
|
3
|
+
import { ExperienceSelectionMiddleware } from '../types/interfaces/HasExperienceSelectionMiddleware';
|
|
4
|
+
/**
|
|
5
|
+
* Args for creating an experience selection middleware
|
|
6
|
+
*/
|
|
7
|
+
type CreateExperienceSelectionMiddlewareArg<Baseline extends Reference, Variant extends Reference> = {
|
|
5
8
|
plugins: NinetailedPlugin[];
|
|
6
9
|
experiences: ExperienceConfiguration<Variant>[];
|
|
7
|
-
baseline:
|
|
10
|
+
baseline: Baseline;
|
|
8
11
|
profile: Profile | null;
|
|
12
|
+
};
|
|
13
|
+
type MakeExperienceSelectMiddlewareArg<Baseline extends Reference, Variant extends Reference> = CreateExperienceSelectionMiddlewareArg<Baseline, Variant> & {
|
|
9
14
|
onChange: (middleware: ExperienceSelectionMiddleware<Baseline, Variant>) => void;
|
|
10
15
|
};
|
|
11
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Result of creating an experience selection middleware
|
|
18
|
+
*/
|
|
19
|
+
interface ExperienceSelectMiddlewareResult<Baseline extends Reference, Variant extends Reference> {
|
|
12
20
|
addListeners: () => void;
|
|
13
21
|
removeListeners: () => void;
|
|
14
|
-
middleware:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
variantIndex: number;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
22
|
+
middleware: ExperienceSelectionMiddleware<Baseline, Variant>;
|
|
23
|
+
}
|
|
24
|
+
export declare const makeExperienceSelectMiddleware: <Baseline extends Reference, Variant extends Reference>({ plugins, onChange, experiences, baseline, profile, }: MakeExperienceSelectMiddlewareArg<Baseline, Variant>) => ExperienceSelectMiddlewareResult<Baseline, Variant>;
|
|
20
25
|
export {};
|
package/src/lib/types/index.d.ts
CHANGED
|
@@ -1,30 +1,44 @@
|
|
|
1
1
|
import { DetachListeners } from 'analytics';
|
|
2
|
-
import { Logger, PageviewProperties, Profile, Properties, Traits, SelectedVariantInfo, Reference, Event } from '@ninetailed/experience.js-shared';
|
|
2
|
+
import { Logger, PageviewProperties, Profile, Properties, Traits, SelectedVariantInfo, Reference, Event, Change } from '@ninetailed/experience.js-shared';
|
|
3
3
|
import { ElementSeenPayload, NinetailedPlugin, TrackComponentProperties } from '@ninetailed/experience.js-plugin-analytics';
|
|
4
4
|
import { type Ninetailed } from '../Ninetailed';
|
|
5
5
|
import { OnSelectVariant } from './OnSelectVariant';
|
|
6
6
|
import { EventBuilder } from '../utils/EventBuilder';
|
|
7
|
-
type
|
|
7
|
+
export type ProfileState = {
|
|
8
8
|
status: 'loading';
|
|
9
9
|
profile: null;
|
|
10
10
|
experiences: null;
|
|
11
|
+
changes: null;
|
|
11
12
|
error: null;
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
from: 'api' | 'hydrated';
|
|
14
|
+
} | {
|
|
14
15
|
status: 'success';
|
|
15
16
|
profile: Profile;
|
|
16
17
|
experiences: SelectedVariantInfo[];
|
|
18
|
+
changes: Change[];
|
|
17
19
|
error: null;
|
|
20
|
+
from: 'api' | 'hydrated';
|
|
21
|
+
} | {
|
|
22
|
+
status: 'error';
|
|
23
|
+
profile: Profile | null;
|
|
24
|
+
experiences: SelectedVariantInfo[] | null;
|
|
25
|
+
changes: Change[] | null;
|
|
26
|
+
error: Error;
|
|
27
|
+
from: 'api' | 'hydrated';
|
|
18
28
|
};
|
|
19
|
-
type
|
|
29
|
+
export type ChangesState = {
|
|
30
|
+
status: 'loading';
|
|
31
|
+
changes: null;
|
|
32
|
+
error: null;
|
|
33
|
+
} | {
|
|
34
|
+
status: 'success';
|
|
35
|
+
changes: Change[];
|
|
36
|
+
error: null;
|
|
37
|
+
} | {
|
|
20
38
|
status: 'error';
|
|
21
|
-
|
|
22
|
-
experiences: null;
|
|
39
|
+
changes: null;
|
|
23
40
|
error: Error;
|
|
24
41
|
};
|
|
25
|
-
export type ProfileState = {
|
|
26
|
-
from: 'api' | 'hydrated';
|
|
27
|
-
} & (Loading | Success | Fail);
|
|
28
42
|
export type OnIsInitializedCallback = () => void;
|
|
29
43
|
export type OnIsInitialized = (cb: OnIsInitializedCallback) => void;
|
|
30
44
|
export type EventFunctionOptions = {
|
|
@@ -36,7 +50,15 @@ export type EventFunctionOptions = {
|
|
|
36
50
|
export type FlushResult = {
|
|
37
51
|
success: boolean;
|
|
38
52
|
};
|
|
53
|
+
export type Result<T> = {
|
|
54
|
+
success: true;
|
|
55
|
+
data: T;
|
|
56
|
+
} | {
|
|
57
|
+
success: false;
|
|
58
|
+
error: Error;
|
|
59
|
+
};
|
|
39
60
|
export type OnProfileChangeCallback = (profile: ProfileState) => void;
|
|
61
|
+
export type OnChangesChangeCallback = (changesState: ChangesState) => void;
|
|
40
62
|
export type Page = (data?: Partial<PageviewProperties>, options?: EventFunctionOptions) => Promise<FlushResult>;
|
|
41
63
|
export type Track = (event: string, properties?: Properties, options?: EventFunctionOptions) => Promise<FlushResult>;
|
|
42
64
|
export type TrackHasSeenComponent = (properties: TrackComponentProperties) => Promise<void>;
|
|
@@ -46,6 +68,7 @@ export type Batch = (events: Event[]) => Promise<FlushResult>;
|
|
|
46
68
|
export type Reset = () => void;
|
|
47
69
|
export type Debug = (enable: boolean) => void;
|
|
48
70
|
export type OnProfileChange = (cb: OnProfileChangeCallback) => DetachListeners;
|
|
71
|
+
export type OnChangesChange = (cb: OnChangesChangeCallback) => DetachListeners;
|
|
49
72
|
type ObserveElement = Ninetailed['observeElement'];
|
|
50
73
|
type UnObserveElement = Ninetailed['unobserveElement'];
|
|
51
74
|
export interface NinetailedInstance<TBaseline extends Reference = Reference, TVariant extends Reference = Reference> {
|
|
@@ -62,6 +85,7 @@ export interface NinetailedInstance<TBaseline extends Reference = Reference, TVa
|
|
|
62
85
|
debug: Debug;
|
|
63
86
|
profileState: ProfileState;
|
|
64
87
|
onProfileChange: OnProfileChange;
|
|
88
|
+
onChangesChange: OnChangesChange;
|
|
65
89
|
plugins: NinetailedPlugin[];
|
|
66
90
|
logger: Logger;
|
|
67
91
|
eventBuilder: EventBuilder;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { BuildPageEventArgs, BuildTrackEventArgs, IdentifyEventArgs, NinetailedRequestContext, Properties } from '@ninetailed/experience.js-shared';
|
|
2
|
+
type PageData = Partial<Omit<BuildPageEventArgs, 'ctx' | 'properties'>>;
|
|
3
|
+
type TrackData = Partial<Omit<BuildTrackEventArgs, 'ctx' | 'event' | 'properties'>>;
|
|
4
|
+
type IdentifyData = Partial<Omit<IdentifyEventArgs, 'ctx' | 'userId' | 'traits'>>;
|
|
5
|
+
type ComponentData = Partial<Omit<BuildPageEventArgs, 'ctx' | 'componentId' | 'experienceId' | 'variantIndex'>>;
|
|
2
6
|
export declare class EventBuilder {
|
|
3
7
|
private readonly buildRequestContext;
|
|
4
8
|
constructor(buildRequestContext?: () => NinetailedRequestContext);
|
|
5
|
-
|
|
9
|
+
private buildEventBase;
|
|
10
|
+
page(properties?: Properties, data?: PageData): {
|
|
6
11
|
channel: import("@ninetailed/experience.js-shared").EventChanel;
|
|
7
12
|
context: {
|
|
8
13
|
app?: {
|
|
@@ -56,7 +61,7 @@ export declare class EventBuilder {
|
|
|
56
61
|
name?: string | undefined;
|
|
57
62
|
properties: import("@ninetailed/experience.js-shared").PageviewProperties;
|
|
58
63
|
};
|
|
59
|
-
track(event: string, properties?: Properties, data?:
|
|
64
|
+
track(event: string, properties?: Properties, data?: TrackData): {
|
|
60
65
|
channel: import("@ninetailed/experience.js-shared").EventChanel;
|
|
61
66
|
context: {
|
|
62
67
|
app?: {
|
|
@@ -110,7 +115,7 @@ export declare class EventBuilder {
|
|
|
110
115
|
event: string;
|
|
111
116
|
properties: Properties;
|
|
112
117
|
};
|
|
113
|
-
identify(userId: string, traits?: Properties, data?:
|
|
118
|
+
identify(userId: string, traits?: Properties, data?: IdentifyData): {
|
|
114
119
|
channel: import("@ninetailed/experience.js-shared").EventChanel;
|
|
115
120
|
context: {
|
|
116
121
|
app?: {
|
|
@@ -163,7 +168,7 @@ export declare class EventBuilder {
|
|
|
163
168
|
userId?: string | undefined;
|
|
164
169
|
traits: Properties;
|
|
165
170
|
};
|
|
166
|
-
component(componentId: string, experienceId?: string, variantIndex?: number, data?:
|
|
171
|
+
component(componentId: string, experienceId?: string, variantIndex?: number, data?: ComponentData): {
|
|
167
172
|
channel: import("@ninetailed/experience.js-shared").EventChanel;
|
|
168
173
|
context: {
|
|
169
174
|
app?: {
|
|
@@ -219,3 +224,4 @@ export declare class EventBuilder {
|
|
|
219
224
|
variantIndex?: number | undefined;
|
|
220
225
|
};
|
|
221
226
|
}
|
|
227
|
+
export {};
|