@ninetailed/experience.js 6.4.1 → 7.1.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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="analytics" />
2
- import { Locale, Traits, Profile, OnLogHandler, OnErrorHandler, Logger, PageviewProperties, Properties, NinetailedApiClient, NinetailedApiClientOptions } from '@ninetailed/experience.js-shared';
2
+ import { Locale, Traits, OnLogHandler, OnErrorHandler, Logger, PageviewProperties, Properties, NinetailedApiClient, NinetailedApiClientOptions, NinetailedRequestContext } from '@ninetailed/experience.js-shared';
3
3
  import { EventFunctionOptions, NinetailedInstance, NinetailedPlugin, OnIsInitializedCallback, OnProfileChangeCallback, ProfileState, TrackHasSeenComponent, ElementSeenPayload, TrackComponentView } from './types';
4
4
  import { ObserveOptions } from './ElementSeenObserver';
5
5
  declare global {
@@ -12,15 +12,24 @@ declare global {
12
12
  } & unknown;
13
13
  }
14
14
  }
15
+ type GetItem<T = any> = (key: string) => T;
16
+ type SetItem<T = any> = (key: string, value: T) => void;
17
+ type RemoveItem = (key: string) => void;
18
+ export type Storage = {
19
+ getItem: GetItem;
20
+ setItem: SetItem;
21
+ removeItem: RemoveItem;
22
+ };
15
23
  type Options = {
16
24
  url?: string;
17
25
  locale?: Locale;
18
26
  plugins?: (NinetailedPlugin | NinetailedPlugin[])[];
19
- profile?: Profile;
20
27
  requestTimeout?: number;
21
28
  onLog?: OnLogHandler;
22
29
  onError?: OnErrorHandler;
23
30
  componentViewTrackingThreshold?: number;
31
+ buildClientContext?: () => NinetailedRequestContext;
32
+ storageImpl?: Storage;
24
33
  };
25
34
  type NinetailedApiClientInstanceOrOptions = NinetailedApiClient | NinetailedApiClientOptions;
26
35
  export declare class Ninetailed implements NinetailedInstance {
@@ -36,7 +45,7 @@ export declare class Ninetailed implements NinetailedInstance {
36
45
  readonly plugins: NinetailedPlugin[];
37
46
  readonly logger: Logger;
38
47
  private readonly componentViewTrackingThreshold;
39
- constructor(ninetailedApiClientInstanceOrOptions: NinetailedApiClientInstanceOrOptions, { plugins, url, profile, locale, requestTimeout, onLog, onError, componentViewTrackingThreshold, }?: Options);
48
+ constructor(ninetailedApiClientInstanceOrOptions: NinetailedApiClientInstanceOrOptions, { plugins, url, locale, requestTimeout, onLog, onError, buildClientContext, componentViewTrackingThreshold, storageImpl, }?: Options);
40
49
  page: (data?: Partial<PageviewProperties>, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
41
50
  track: (event: string, properties?: Properties, options?: EventFunctionOptions) => Promise<import("./types").FlushResult>;
42
51
  /**
@@ -2,6 +2,7 @@ export declare const LEGACY_ANONYMOUS_ID = "__anon_id";
2
2
  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
+ export declare const EXPERIENCES_FALLBACK_CACHE = "__nt_experiences__";
5
6
  export declare const PROFILE_CHANGE = "profile-change";
6
7
  export declare const PROFILE_RESET = "profile-reset";
7
8
  export declare const CONSENT = "__nt-consent__";
@@ -1,16 +1,17 @@
1
1
  import { AnalyticsPlugin } from 'analytics';
2
- import { Profile, Locale, NinetailedApiClient } from '@ninetailed/experience.js-shared';
2
+ import { Profile, Locale, NinetailedApiClient, NinetailedRequestContext } from '@ninetailed/experience.js-shared';
3
3
  import { NinetailedInstance, FlushResult } from '../types';
4
4
  type AnalyticsPluginNinetailedConfig = {
5
5
  apiClient: NinetailedApiClient;
6
6
  profile?: Profile;
7
7
  locale?: Locale;
8
8
  requestTimeout?: number;
9
+ buildClientContext?: () => NinetailedRequestContext;
9
10
  ninetailed: NinetailedInstance;
10
11
  };
11
12
  export declare const PLUGIN_NAME = "ninetailed";
12
13
  export interface NinetailedEventQueue extends AnalyticsPlugin {
13
14
  flush: () => Promise<FlushResult>;
14
15
  }
15
- export declare const ninetailedPlugin: ({ apiClient, profile, locale, ninetailed, }: AnalyticsPluginNinetailedConfig) => NinetailedEventQueue;
16
+ export declare const ninetailedPlugin: ({ apiClient, profile, locale, ninetailed, buildClientContext, }: AnalyticsPluginNinetailedConfig) => NinetailedEventQueue;
16
17
  export {};
@@ -33,5 +33,5 @@ type Fail<T> = {
33
33
  type Result<T> = Loading<T> | Success<T> | Fail<T>;
34
34
  export declare const selectVariant: <T extends {
35
35
  id: string;
36
- }>(baseline: T, variants: Variant<T>[], { status, profile, error }: ProfileState, options?: Options) => Result<T>;
36
+ }>(baseline: T, variants: Variant<T>[], { status, profile, error }: Omit<ProfileState, 'experiences'>, options?: Options) => Result<T>;
37
37
  export {};
@@ -1,4 +1,4 @@
1
- import { Logger, PageviewProperties, Profile, Properties, Traits } from '@ninetailed/experience.js-shared';
1
+ import { Logger, PageviewProperties, Profile, Properties, Traits, SelectedVariantInfo } from '@ninetailed/experience.js-shared';
2
2
  import { DetachListeners } from 'analytics';
3
3
  import { TrackComponentProperties } from './TrackingProperties';
4
4
  import { NinetailedPlugin } from './NinetailedPlugin';
@@ -7,16 +7,19 @@ import { ElementSeenPayload } from './ElementSeenPayload';
7
7
  type Loading = {
8
8
  status: 'loading';
9
9
  profile: null;
10
+ experiences: null;
10
11
  error: null;
11
12
  };
12
13
  type Success = {
13
14
  status: 'success';
14
15
  profile: Profile;
16
+ experiences: SelectedVariantInfo[];
15
17
  error: null;
16
18
  };
17
19
  type Fail = {
18
20
  status: 'error';
19
21
  profile: null;
22
+ experiences: null;
20
23
  error: Error;
21
24
  };
22
25
  export type ProfileState = {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js",
3
- "version": "6.4.1",
3
+ "version": "7.1.0-beta.0",
4
4
  "module": "./index.js",
5
5
  "main": "./index.cjs",
6
6
  "type": "module",
7
7
  "types": "./index.d.ts",
8
8
  "dependencies": {
9
- "@ninetailed/experience.js-shared": "6.4.1",
9
+ "@ninetailed/experience.js-shared": "7.1.0-beta.0",
10
10
  "analytics": "0.8.1",
11
11
  "zod": "3.21.4"
12
12
  },