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/README.md +46 -3
- package/dist/coveoua.browser.js +1 -1
- package/dist/coveoua.browser.js.map +1 -1
- package/dist/coveoua.js +1 -1
- package/dist/coveoua.js.map +1 -1
- package/dist/definitions/client/analytics.d.ts +1 -0
- package/dist/definitions/react-native/index.d.ts +2 -2
- package/dist/definitions/react-native/react-native-runtime.d.ts +12 -3
- package/dist/definitions/react-native/react-native-utils.d.ts +1 -1
- package/dist/definitions/src/react-native/index.d.ts +2 -2
- package/dist/definitions/src/react-native/react-native-runtime.d.ts +12 -3
- package/dist/library.es.js +7 -14
- package/dist/library.js +11 -5
- package/dist/react-native.es.js +2135 -14
- package/package.json +5 -4
- package/react-native/package.json +9 -0
- package/src/client/analytics.ts +6 -3
- package/src/react-native/index.ts +2 -3
- package/src/react-native/react-native-runtime.ts +36 -8
- package/src/react-native/react-native-utils.ts +2 -11
- package/src/react-native/react-native.spec.ts +5 -2
- package/dist/definitions/react-native/react-native-storage.d.ts +0 -6
- package/dist/definitions/src/react-native/react-native-storage.d.ts +0 -6
- package/src/react-native/react-native-storage.ts +0 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coveo.analytics",
|
|
3
|
-
"version": "2.
|
|
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
|
-
"
|
|
55
|
+
"stylelint": "^13.6.1",
|
|
56
56
|
"ts-jest": "^25.2.0",
|
|
57
|
-
"tsjs": "
|
|
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
|
+
}
|
package/src/client/analytics.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
2
|
-
export
|
|
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 {
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
|
|
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
|
|
4
|
-
|
|
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
|
-
|
|
11
|
-
|
|
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,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
|
-
}
|