coveo.analytics 2.20.26 → 2.22.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coveo.analytics",
3
- "version": "2.20.26",
3
+ "version": "2.22.1",
4
4
  "description": "📈 Coveo analytics client (node and browser compatible) ",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.es.js",
@@ -23,7 +23,6 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "@react-native-async-storage/async-storage": "^1.17.10",
27
26
  "cross-fetch": "^3.1.5"
28
27
  },
29
28
  "devDependencies": {
@@ -51,10 +50,11 @@
51
50
  "rimraf": "^3.0.2",
52
51
  "rollup": "^2.50.6",
53
52
  "rollup-plugin-serve": "^1.0.1",
53
+ "rollup-plugin-terser": "^7.0.2",
54
54
  "rollup-plugin-typescript2": "^0.27.0",
55
- "rollup-plugin-uglify": "^6.0.4",
55
+ "stylelint": "^13.6.1",
56
56
  "ts-jest": "^25.2.0",
57
- "tsjs": "1.0.3",
57
+ "tsjs": "4.2.1",
58
58
  "typescript": "^3.8.3"
59
59
  },
60
60
  "overrides": {
@@ -65,6 +65,7 @@
65
65
  "dist/**/*.js",
66
66
  "dist/**/*.js.map",
67
67
  "src/**/*.ts",
68
+ "react-native/",
68
69
  "LICENSE"
69
70
  ],
70
71
  "husky": {
@@ -0,0 +1,9 @@
1
+ {
2
+ "private": true,
3
+ "name": "react-native",
4
+ "description": "Coveo analytics client for React Native",
5
+ "main": "../dist/react-native.es.js",
6
+ "module": "../dist/react-native.es.js",
7
+ "types": "../dist/definitions/react-native/index.d.ts",
8
+ "license": "MIT"
9
+ }
@@ -87,6 +87,11 @@ export interface BufferedRequest {
87
87
  type ProcessPayloadStep = (currentPayload: any) => any;
88
88
  type AsyncProcessPayloadStep = (currentPayload: any) => Promise<any>;
89
89
 
90
+ export function buildBaseUrl(endpoint = Endpoints.default, apiVersion = Version) {
91
+ const endpointIsCoveoProxy = endpoint.indexOf('.cloud.coveo.com') !== -1;
92
+ return `${endpoint}${endpointIsCoveoProxy ? '' : '/rest'}/${apiVersion}`;
93
+ }
94
+
90
95
  export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider {
91
96
  private get defaultOptions(): ClientOptions {
92
97
  return {
@@ -469,9 +474,7 @@ export class CoveoAnalyticsClient implements AnalyticsClient, VisitorIdProvider
469
474
  }
470
475
 
471
476
  private get baseUrl(): string {
472
- const {version, endpoint} = this.options;
473
- const endpointIsCoveoProxy = endpoint.indexOf('.cloud.coveo.com') !== -1;
474
- return `${endpoint}${endpointIsCoveoProxy ? '' : '/rest'}/${version}`;
477
+ return buildBaseUrl(this.options.endpoint, this.options.version);
475
478
  }
476
479
  }
477
480
 
@@ -1,3 +1,2 @@
1
- // TODO: v3 add in "coveo.analytics/react-native" subpackage
2
- export {ReactNativeRuntime} from './react-native-runtime';
3
- export {ReactNativeStorage} from './react-native-storage';
1
+ export {ReactNativeRuntime, ReactNativeRuntimeOptions, ReactNativeStorage} from './react-native-runtime';
2
+ export * from '../coveoua/headless';
@@ -1,17 +1,45 @@
1
1
  import {WebStorage} from '../storage';
2
2
  import {AnalyticsFetchClient} from '../client/analyticsFetchClient';
3
- import {ReactNativeStorage} from './react-native-storage';
4
3
  import {IRuntimeEnvironment} from '../client/runtimeEnvironment';
5
- import {IAnalyticsClientOptions} from '../client/analyticsRequestClient';
4
+ import {PreprocessAnalyticsRequest} from '../client/analyticsRequestClient';
5
+ import {uuidv4} from '../client/crypto';
6
+ import {buildBaseUrl} from '../client/analytics';
7
+
8
+ export type ReactNativeStorage = WebStorage;
9
+
10
+ export interface ReactNativeRuntimeOptions {
11
+ /**
12
+ * Mandatory Storage implementation.
13
+ *
14
+ * We recommend using a storage library. There are a few options presented in the readme: https://github.com/coveo/coveo.analytics.js#using-react-native
15
+ */
16
+ storage: ReactNativeStorage;
17
+ /**
18
+ * Key for storing the visitor ID value.
19
+ * @defaut visitorId
20
+ */
21
+ visitorIdKey?: string;
22
+ token?: string;
23
+ version?: string;
24
+ endpoint?: string;
25
+ preprocessRequest?: PreprocessAnalyticsRequest;
26
+ }
6
27
 
7
28
  export class ReactNativeRuntime implements IRuntimeEnvironment {
8
- public storage: WebStorage;
9
29
  public client: AnalyticsFetchClient;
30
+ public storage: ReactNativeStorage;
10
31
 
11
- // TODO: v3 switch to ClientOptions type, add default options
12
- // TODO: v3 reuse own ReactNativeStorage to implement VisitorIdProvider's getCurrentVisitorId, setCurrentVisitorId
13
- constructor(clientOptions: IAnalyticsClientOptions) {
14
- this.storage = new ReactNativeStorage();
15
- this.client = new AnalyticsFetchClient(clientOptions);
32
+ constructor(options: ReactNativeRuntimeOptions) {
33
+ const visitorIdKey = options.visitorIdKey ?? 'visitorId';
34
+ this.storage = options.storage;
35
+ this.client = new AnalyticsFetchClient({
36
+ preprocessRequest: options.preprocessRequest,
37
+ token: options.token,
38
+ baseUrl: buildBaseUrl(options.endpoint, options.version),
39
+ visitorIdProvider: {
40
+ getCurrentVisitorId: async () => (await this.storage.getItem(visitorIdKey)) || uuidv4(),
41
+ setCurrentVisitorId: (visitorId: string) => this.storage.setItem(visitorIdKey, visitorId),
42
+ },
43
+ });
16
44
  }
17
45
  }
@@ -1,16 +1,7 @@
1
1
  export const ReactNativeRuntimeWarning = `
2
2
  We've detected you're using React Native but have not provided the corresponding runtime,
3
- for an optimal experience please install @react-native-async-storage/async-storage and instantiate
4
- your analytics client as follows:
5
-
6
- import {ReactNativeRuntime} from 'coveo.analytics/src/react-native';
7
-
8
- const analytics = new CoveoAnalyticsClient({
9
- ...your options,
10
- runtimeEnvironment: new ReactNativeRuntime({
11
- baseUrl: '...',
12
- });
13
- })
3
+ for an optimal experience please use the "coveo.analytics/react-native" subpackage.
4
+ Follow the Readme on how to set it up: https://github.com/coveo/coveo.analytics.js#using-react-native
14
5
  `;
15
6
 
16
7
  export function isReactNative() {
@@ -7,8 +7,11 @@ describe('ReactNativeRuntime', () => {
7
7
 
8
8
  beforeEach(() => {
9
9
  runtimeEnvironment = new ReactNativeRuntime({
10
- baseUrl: 'https://www.coveo.com',
11
- visitorIdProvider: {getCurrentVisitorId: jest.fn(), setCurrentVisitorId: jest.fn()},
10
+ storage: {
11
+ getItem: jest.fn(),
12
+ setItem: jest.fn(),
13
+ removeItem: jest.fn(),
14
+ },
12
15
  });
13
16
  client = new CoveoAnalyticsClient({runtimeEnvironment});
14
17
  });
@@ -1,6 +0,0 @@
1
- import { WebStorage } from '../storage';
2
- export declare class ReactNativeStorage implements WebStorage {
3
- getItem(key: string): Promise<string | null>;
4
- setItem(key: string, data: string): Promise<void>;
5
- removeItem(key: string): Promise<void>;
6
- }
@@ -1,6 +0,0 @@
1
- import { WebStorage } from '../storage';
2
- export declare class ReactNativeStorage implements WebStorage {
3
- getItem(key: string): Promise<string | null>;
4
- setItem(key: string, data: string): Promise<void>;
5
- removeItem(key: string): Promise<void>;
6
- }
@@ -1,14 +0,0 @@
1
- import {WebStorage} from '../storage';
2
- import AsyncStorage from '@react-native-async-storage/async-storage';
3
-
4
- export class ReactNativeStorage implements WebStorage {
5
- async getItem(key: string) {
6
- return AsyncStorage.getItem(key);
7
- }
8
- async setItem(key: string, data: string) {
9
- return AsyncStorage.setItem(key, data);
10
- }
11
- async removeItem(key: string) {
12
- AsyncStorage.removeItem(key);
13
- }
14
- }