@ninetailed/experience.js 1.0.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.
@@ -0,0 +1,47 @@
1
+ import { PageData, AnalyticsPlugin, DetachListeners } from 'analytics';
2
+ import { Locale, Traits, Profile } from '@ninetailed/experience.js-shared';
3
+ import { ProfileState } from './types';
4
+ declare type Options = {
5
+ url?: string;
6
+ locale?: Locale;
7
+ plugins?: AnalyticsPlugin[];
8
+ profile?: Profile;
9
+ };
10
+ declare type EventFunctionOptions = {
11
+ plugins?: {
12
+ all: boolean;
13
+ [key: string]: boolean;
14
+ };
15
+ };
16
+ declare type OnProfileChangeCallback = (profile: ProfileState) => void;
17
+ export declare type Page = (data?: PageData, options?: EventFunctionOptions) => Promise<void>;
18
+ export declare type Track = (event: string, payload?: unknown, options?: EventFunctionOptions) => Promise<void>;
19
+ export declare type Identify = (uid: string, traits?: Traits, options?: EventFunctionOptions) => Promise<void>;
20
+ export declare type Reset = () => void;
21
+ export declare type Debug = (enable: boolean) => void;
22
+ export declare type OnProfileChange = (cb: OnProfileChangeCallback) => DetachListeners;
23
+ export interface NinetailedInstance {
24
+ page: Page;
25
+ track: Track;
26
+ identify: Identify;
27
+ reset: Reset;
28
+ debug: Debug;
29
+ profileState: ProfileState;
30
+ onProfileChange: OnProfileChange;
31
+ }
32
+ export declare class Ninetailed implements NinetailedInstance {
33
+ private readonly instance;
34
+ private readonly plugins;
35
+ private _profileState;
36
+ constructor(apiKey: string, { plugins, url, profile, locale }: Options);
37
+ page: (data?: PageData, options?: EventFunctionOptions) => Promise<any>;
38
+ track: (event: string, payload?: unknown, options?: EventFunctionOptions) => Promise<any>;
39
+ identify: (uid: string, traits?: Traits, options?: EventFunctionOptions) => Promise<any>;
40
+ reset: () => any;
41
+ debug: (enabled: boolean) => any;
42
+ onProfileChange: (cb: OnProfileChangeCallback) => DetachListeners;
43
+ get profileState(): ProfileState;
44
+ private buildOptions;
45
+ private registerWindowHandlers;
46
+ }
47
+ export {};
@@ -0,0 +1,11 @@
1
+ import { AnalyticsInstance } from 'analytics';
2
+ import { Cache } from '@ninetailed/experience.js-shared';
3
+ declare type CacheOptions = {
4
+ instance: AnalyticsInstance;
5
+ };
6
+ export declare const initialize: ({ instance }: CacheOptions, data?: Partial<Cache>) => Cache;
7
+ export declare const get: ({ instance }: CacheOptions) => Cache | null;
8
+ export declare const set: (cache: Cache, { instance }: CacheOptions) => Cache;
9
+ export declare const remove: ({ instance }: CacheOptions) => void;
10
+ export declare const reset: ({ instance }: CacheOptions) => Cache;
11
+ export {};
@@ -0,0 +1 @@
1
+ export * from './cache';
@@ -0,0 +1,2 @@
1
+ import { NinetailedRequestContext } from '@ninetailed/experience.js-shared';
2
+ export declare const buildClientNinetailedRequestContext: () => NinetailedRequestContext;
@@ -0,0 +1 @@
1
+ export declare const buildClientLocale: () => string;
@@ -0,0 +1 @@
1
+ export * from './build-context';
@@ -0,0 +1,22 @@
1
+ import { AnalyticsPlugin } from 'analytics';
2
+ import { Profile, Locale } from '@ninetailed/experience.js-shared';
3
+ declare global {
4
+ interface Window {
5
+ ninetailed?: any;
6
+ }
7
+ }
8
+ declare type AnalyticsPluginNinetailedConfig = {
9
+ apiKey: string;
10
+ url?: string;
11
+ profile?: Profile;
12
+ locale?: Locale;
13
+ };
14
+ export declare const NINETAILED_TRACKER_EVENTS: {
15
+ /**
16
+ * `profile` - Fires when the profile is returned by the cdp API.
17
+ */
18
+ profile: string;
19
+ };
20
+ export declare const PLUGIN_NAME = "ninetailed";
21
+ export declare const ninetailedPlugin: ({ apiKey, url, profile, locale, }: AnalyticsPluginNinetailedConfig) => AnalyticsPlugin;
22
+ export {};
@@ -0,0 +1 @@
1
+ export * from './get-analytics-plugin';
@@ -0,0 +1,19 @@
1
+ import { AudienceSignals, IngestProfileEventsRequestBody, Profile, Session } from '@ninetailed/experience.js-shared';
2
+ declare type NinetailedApiClientOptions = {
3
+ apiKey: string;
4
+ url?: string;
5
+ };
6
+ declare type ProfileOptions = IngestProfileEventsRequestBody;
7
+ declare type ProfileResponse = {
8
+ profile: Profile;
9
+ signals: AudienceSignals;
10
+ traitsUpdatedAt: string;
11
+ sessions: Session[];
12
+ };
13
+ export declare class NinetailedApiClient {
14
+ private readonly apiKey;
15
+ private readonly url;
16
+ constructor({ apiKey, url }: NinetailedApiClientOptions);
17
+ profile(options: ProfileOptions): Promise<ProfileResponse>;
18
+ }
19
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const log: any;
2
+ export declare const enable: () => void;
3
+ export declare const disable: () => any;
@@ -0,0 +1,2 @@
1
+ export * from './apiClient';
2
+ export * from './debug';
@@ -0,0 +1,34 @@
1
+ import { ProfileState, Variant } from './types';
2
+ declare type Options = {
3
+ holdout?: number;
4
+ };
5
+ declare type Loading<T> = {
6
+ loading: true;
7
+ variant: T;
8
+ audience: {
9
+ id: 'baseline';
10
+ };
11
+ isPersonalized: false;
12
+ error: null;
13
+ };
14
+ declare type Success<T> = {
15
+ loading: false;
16
+ variant: T;
17
+ audience: {
18
+ id: string;
19
+ };
20
+ isPersonalized: boolean;
21
+ error: null;
22
+ };
23
+ declare type Fail<T> = {
24
+ loading: false;
25
+ variant: T;
26
+ audience: {
27
+ id: 'baseline';
28
+ };
29
+ isPersonalized: false;
30
+ error: Error;
31
+ };
32
+ declare type Result<T> = Loading<T> | Success<T> | Fail<T>;
33
+ export declare const selectVariant: <T>(baseline: T, variants: Variant<T>[], { loading, profile, error }: ProfileState, options?: Options) => Result<T>;
34
+ export {};
package/lib/types.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { Profile } from "@ninetailed/experience.js-shared";
2
+ export declare type Variant<P> = {
3
+ audience: {
4
+ id: string;
5
+ };
6
+ } & P;
7
+ export declare type ProfileState = {
8
+ loading: boolean;
9
+ profile?: Profile;
10
+ error?: Error;
11
+ from: 'api' | 'hydrated';
12
+ };
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@ninetailed/experience.js",
3
+ "version": "1.0.0-beta.0",
4
+ "main": "./index.umd.js",
5
+ "module": "./index.esm.js",
6
+ "typings": "./index.d.ts",
7
+ "dependencies": {
8
+ "analytics": "^0.8.0",
9
+ "@ninetailed/experience.js-shared": "1.0.0-beta.0",
10
+ "uuid": "^8.3.2",
11
+ "ts-toolbelt": "^9.6.0",
12
+ "locale-enum": "^1.1.1",
13
+ "i18n-iso-countries": "^7.3.0",
14
+ "lodash": "^4.17.21"
15
+ },
16
+ "peerDependencies": {}
17
+ }