@ninetailed/experience.js 2.0.2 → 2.1.1-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.
@@ -2,6 +2,8 @@ import { PageData, AnalyticsPlugin, DetachListeners } from 'analytics';
2
2
  import { Locale, Traits, Profile, Variant } from '@ninetailed/experience.js-shared';
3
3
  import { ProfileState } from './types';
4
4
  import { ExperienceConfiguration } from './experience';
5
+ import { Logger, OnLogHandler, OnErrorHandler } from './logger';
6
+ export type { OnErrorHandler, OnLogHandler } from './logger';
5
7
  declare global {
6
8
  interface Window {
7
9
  ninetailed?: {
@@ -11,12 +13,16 @@ declare global {
11
13
  } & unknown;
12
14
  }
13
15
  }
16
+ declare type OnIsInitializedCallback = () => void;
17
+ export declare type OnIsInitialized = (cb: OnIsInitializedCallback) => void;
14
18
  declare type Options = {
15
19
  url?: string;
16
20
  locale?: Locale;
17
21
  plugins?: (AnalyticsPlugin | AnalyticsPlugin[])[];
18
22
  profile?: Profile;
19
23
  requestTimeout?: number;
24
+ onLog?: OnLogHandler;
25
+ onError?: OnErrorHandler;
20
26
  };
21
27
  declare type EventFunctionOptions = {
22
28
  plugins?: {
@@ -57,26 +63,31 @@ export interface NinetailedInstance {
57
63
  profileState: ProfileState;
58
64
  onProfileChange: OnProfileChange;
59
65
  plugins: AnalyticsPlugin[];
66
+ logger: Logger;
67
+ onIsInitialized: OnIsInitialized;
60
68
  }
61
69
  export declare class Ninetailed implements NinetailedInstance {
62
70
  private readonly instance;
63
71
  private _profileState;
72
+ private isInitialized;
64
73
  readonly plugins: AnalyticsPlugin[];
65
- constructor({ clientId, environment, preview }: {
74
+ readonly logger: Logger;
75
+ constructor({ clientId, environment, preview, }: {
66
76
  clientId: string;
67
77
  environment?: string;
68
78
  preview?: boolean;
69
- }, { plugins, url, profile, locale, requestTimeout }?: Options);
79
+ }, { plugins, url, profile, locale, requestTimeout, onLog, onError, }?: Options);
70
80
  page: (data?: PageData, options?: EventFunctionOptions) => Promise<any>;
71
81
  track: (event: string, payload?: unknown, options?: EventFunctionOptions) => Promise<any>;
72
82
  trackHasSeenComponent: TrackHasSeenComponent;
73
83
  trackExperience: TrackExperience;
74
84
  identify: (uid: string, traits?: Traits, options?: EventFunctionOptions) => Promise<any>;
75
- reset: () => any;
76
- debug: (enabled: boolean) => any;
85
+ reset: () => void;
86
+ debug: (enabled: boolean) => void;
77
87
  onProfileChange: (cb: OnProfileChangeCallback) => DetachListeners;
88
+ onIsInitialized: (onIsInitialized: OnIsInitializedCallback) => void;
89
+ private waitUntilInitialized;
78
90
  get profileState(): ProfileState;
79
91
  private buildOptions;
80
92
  private registerWindowHandlers;
81
93
  }
82
- export {};
@@ -1,2 +1 @@
1
1
  export * from './apiClient';
2
- export * from './debug';
@@ -0,0 +1,10 @@
1
+ import { LogSink } from './LogSink';
2
+ export declare class ConsoleLogSink implements LogSink {
3
+ name: string;
4
+ debug(message: string, ...args: unknown[]): void;
5
+ info(message: string, ...args: unknown[]): void;
6
+ log(message: string, ...args: unknown[]): void;
7
+ warn(message: string, ...args: unknown[]): void;
8
+ error(message: string | Error, ...args: unknown[]): void;
9
+ fatal(message: string | Error, ...args: unknown[]): void;
10
+ }
@@ -0,0 +1,10 @@
1
+ import { LogFn, LogFnAsError } from 'diary';
2
+ export interface LogSink {
3
+ name: string;
4
+ debug?: LogFn;
5
+ info?: LogFn;
6
+ log?: LogFn;
7
+ warn?: LogFn;
8
+ error?: LogFnAsError;
9
+ fatal?: LogFnAsError;
10
+ }
@@ -0,0 +1,17 @@
1
+ import { LogSink } from './LogSink';
2
+ export declare class Logger {
3
+ readonly name = "@ninetailed/experience.js";
4
+ private readonly diary;
5
+ private sinks;
6
+ constructor();
7
+ addSink(sink: LogSink): void;
8
+ removeSink(name: string): void;
9
+ debug(message: string, ...args: unknown[]): void;
10
+ info(message: string, ...args: unknown[]): void;
11
+ log(message: string, ...args: unknown[]): void;
12
+ warn(message: string, ...args: unknown[]): void;
13
+ error(message: string | Error, ...args: unknown[]): void;
14
+ fatal(message: string | Error, ...args: unknown[]): void;
15
+ private onLogEvent;
16
+ }
17
+ export declare const logger: Logger;
@@ -0,0 +1,10 @@
1
+ import { LogFnAsError } from 'diary';
2
+ import { LogSink } from './LogSink';
3
+ export declare type OnErrorHandler = LogFnAsError;
4
+ export declare class OnErrorLogSink implements LogSink {
5
+ private readonly onError;
6
+ name: string;
7
+ constructor(onError: OnErrorHandler);
8
+ error(message: string | Error, ...args: unknown[]): void;
9
+ fatal(message: string | Error, ...args: unknown[]): void;
10
+ }
@@ -0,0 +1,12 @@
1
+ import { LogFnAsError } from 'diary';
2
+ import { LogSink } from './LogSink';
3
+ export declare type OnLogHandler = LogFnAsError;
4
+ export declare class OnLogLogSink implements LogSink {
5
+ private readonly onLog;
6
+ name: string;
7
+ constructor(onLog: OnLogHandler);
8
+ debug(message: string, ...args: unknown[]): void;
9
+ info(message: string, ...args: unknown[]): void;
10
+ log(message: string, ...args: unknown[]): void;
11
+ warn(message: string, ...args: unknown[]): void;
12
+ }
@@ -0,0 +1,7 @@
1
+ export { Logger, logger } from './Logger';
2
+ export { ConsoleLogSink } from './ConsoleLogSink';
3
+ export { OnLogLogSink } from './OnLogLogSink';
4
+ export { OnErrorLogSink } from './OnErrorLogSink';
5
+ export type { LogSink } from './LogSink';
6
+ export type { OnLogHandler } from './OnLogLogSink';
7
+ export type { OnErrorHandler } from './OnErrorLogSink';
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js",
3
- "version": "2.0.2",
3
+ "version": "2.1.1-beta.0",
4
4
  "main": "./index.umd.js",
5
5
  "module": "./index.esm.js",
6
6
  "typings": "./index.d.ts",
7
7
  "dependencies": {
8
8
  "analytics": "^0.8.0",
9
- "@ninetailed/experience.js-shared": "2.0.2",
9
+ "@ninetailed/experience.js-shared": "2.1.1-beta.0",
10
10
  "uuid": "^8.3.2",
11
11
  "ts-toolbelt": "^9.6.0",
12
12
  "locale-enum": "^1.1.1",
13
13
  "i18n-iso-countries": "^7.3.0",
14
14
  "lodash": "^4.17.21",
15
- "loglevel": "^1.8.0",
16
- "murmurhash-js": "^1.0.0"
15
+ "murmurhash-js": "^1.0.0",
16
+ "diary": "^0.3.1"
17
17
  },
18
18
  "peerDependencies": {}
19
19
  }
@@ -1,3 +0,0 @@
1
- export declare const enable: () => void;
2
- export declare const disable: () => void;
3
- export declare const log: (...msg: any[]) => void;