@snowplow/react-native-tracker 2.1.1 → 4.0.2-dev.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.
- package/LICENSE +29 -203
- package/README.md +59 -143
- package/dist/index.cjs.d.ts +499 -0
- package/dist/index.cjs.js +2656 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.cjs.min.d.ts +499 -0
- package/dist/index.cjs.min.js +63 -0
- package/dist/index.cjs.min.js.map +1 -0
- package/dist/index.module.d.ts +499 -0
- package/dist/index.module.js +250 -0
- package/dist/index.module.js.map +1 -0
- package/package.json +48 -158
- package/.editorconfig +0 -15
- package/.eslintignore +0 -6
- package/.gitattributes +0 -3
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -29
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/actions/setup/action.yml +0 -28
- package/.github/workflows/build.yml +0 -155
- package/.github/workflows/deploy.yml +0 -97
- package/.github/workflows/e2e-android.yml +0 -121
- package/.github/workflows/e2e-ios.yml +0 -95
- package/.github/workflows/snyk.yml +0 -21
- package/.gitignore +0 -70
- package/.npmignore +0 -60
- package/.nvmrc +0 -1
- package/.watchmanconfig +0 -1
- package/.yarnrc +0 -3
- package/CHANGELOG +0 -180
- package/CONTRIBUTING.md +0 -80
- package/android/build.gradle +0 -110
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradle.properties +0 -5
- package/android/gradlew +0 -234
- package/android/gradlew.bat +0 -89
- package/android/src/main/AndroidManifest.xml +0 -3
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerModule.kt +0 -744
- package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerPackage.kt +0 -17
- package/android/src/main/java/com/snowplow/reactnativetracker/util/ConfigUtil.kt +0 -274
- package/android/src/main/java/com/snowplow/reactnativetracker/util/EventUtil.kt +0 -233
- package/android/src/main/java/com/snowplow/reactnativetracker/util/TrackerVersion.kt +0 -5
- package/babel.config.js +0 -3
- package/example/.watchmanconfig +0 -1
- package/example/Gemfile +0 -6
- package/example/android/app/build.gradle +0 -129
- package/example/android/app/debug.keystore +0 -0
- package/example/android/app/proguard-rules.pro +0 -10
- package/example/android/app/src/androidTest/java/com/reactnativetrackerexample/DetoxTest.java +0 -36
- package/example/android/app/src/androidTest/java/com/reactnativetrackerexample/DetoxTestAppJUnitRunner.java +0 -21
- package/example/android/app/src/debug/AndroidManifest.xml +0 -13
- package/example/android/app/src/debug/java/com/reactnativetrackerexample/ReactNativeFlipper.java +0 -75
- package/example/android/app/src/main/AndroidManifest.xml +0 -26
- package/example/android/app/src/main/java/com/reactnativetrackerexample/MainActivity.java +0 -32
- package/example/android/app/src/main/java/com/reactnativetrackerexample/MainApplication.java +0 -62
- package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +0 -36
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/values/strings.xml +0 -3
- package/example/android/app/src/main/res/values/styles.xml +0 -9
- package/example/android/app/src/release/java/com/reactnativetrackerexample/ReactNativeFlipper.java +0 -20
- package/example/android/build.gradle +0 -31
- package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/android/gradle/wrapper/gradle-wrapper.properties +0 -6
- package/example/android/gradle.properties +0 -44
- package/example/android/gradlew +0 -244
- package/example/android/gradlew.bat +0 -92
- package/example/android/settings.gradle +0 -4
- package/example/app.json +0 -4
- package/example/babel.config.js +0 -17
- package/example/detox.config.js +0 -92
- package/example/e2e/config.json +0 -10
- package/example/e2e/emitEvents.e2e.detox.js +0 -95
- package/example/e2e/environment.js +0 -23
- package/example/e2e/helpers/microCommands.js +0 -140
- package/example/e2e/helpers/microHelpers.js +0 -333
- package/example/e2e/helpers/microHelpers.test.js +0 -295
- package/example/e2e/helpers/schemas.js +0 -49
- package/example/e2e/jest.config.js +0 -16
- package/example/e2e/setup.js +0 -4
- package/example/e2e/testEvents.micro.test.js +0 -287
- package/example/index.js +0 -5
- package/example/ios/.xcode.env +0 -11
- package/example/ios/Podfile +0 -62
- package/example/ios/Podfile.lock +0 -730
- package/example/ios/ReactNativeTrackerExample/AppDelegate.h +0 -6
- package/example/ios/ReactNativeTrackerExample/AppDelegate.mm +0 -26
- package/example/ios/ReactNativeTrackerExample/Images.xcassets/AppIcon.appiconset/Contents.json +0 -53
- package/example/ios/ReactNativeTrackerExample/Images.xcassets/Contents.json +0 -6
- package/example/ios/ReactNativeTrackerExample/Info.plist +0 -55
- package/example/ios/ReactNativeTrackerExample/LaunchScreen.storyboard +0 -47
- package/example/ios/ReactNativeTrackerExample/PrivacyInfo.xcprivacy +0 -37
- package/example/ios/ReactNativeTrackerExample/main.m +0 -10
- package/example/ios/ReactNativeTrackerExample-Bridging-Header.h +0 -3
- package/example/ios/ReactNativeTrackerExample.xcodeproj/project.pbxproj +0 -739
- package/example/ios/ReactNativeTrackerExample.xcodeproj/xcshareddata/xcschemes/ReactNativeTrackerExample.xcscheme +0 -88
- package/example/ios/ReactNativeTrackerExample.xcworkspace/contents.xcworkspacedata +0 -10
- package/example/ios/ReactNativeTrackerExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/example/ios/ReactNativeTrackerExampleTests/Info.plist +0 -24
- package/example/ios/ReactNativeTrackerExampleTests/ReactNativeTrackerExampleTests.m +0 -66
- package/example/metro.config.js +0 -45
- package/example/package.json +0 -54
- package/example/react-native.config.js +0 -10
- package/example/src/App.js +0 -566
- package/example/tsconfig.json +0 -5
- package/example/yarn.lock +0 -7703
- package/ios/ReactNativeTracker-Bridging-Header.h +0 -2
- package/ios/ReactNativeTracker.mm +0 -175
- package/ios/ReactNativeTracker.swift +0 -822
- package/ios/ReactNativeTracker.xcodeproj/project.pbxproj +0 -301
- package/ios/Util/ConfigUtils.swift +0 -209
- package/ios/Util/TrackerVersion.swift +0 -3
- package/ios/Util/Utilities.swift +0 -37
- package/lefthook.yml +0 -11
- package/lib/commonjs/api.js +0 -490
- package/lib/commonjs/api.js.map +0 -1
- package/lib/commonjs/configurations.js +0 -196
- package/lib/commonjs/configurations.js.map +0 -1
- package/lib/commonjs/constants.js +0 -77
- package/lib/commonjs/constants.js.map +0 -1
- package/lib/commonjs/events.js +0 -277
- package/lib/commonjs/events.js.map +0 -1
- package/lib/commonjs/index.js +0 -132
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/jsCore.js +0 -427
- package/lib/commonjs/jsCore.js.map +0 -1
- package/lib/commonjs/native.js +0 -16
- package/lib/commonjs/native.js.map +0 -1
- package/lib/commonjs/subject.js +0 -235
- package/lib/commonjs/subject.js.map +0 -1
- package/lib/commonjs/tracker.js +0 -248
- package/lib/commonjs/tracker.js.map +0 -1
- package/lib/commonjs/types.js +0 -2
- package/lib/commonjs/types.js.map +0 -1
- package/lib/commonjs/utils.js +0 -72
- package/lib/commonjs/utils.js.map +0 -1
- package/lib/commonjs/webViewInterface.js +0 -66
- package/lib/commonjs/webViewInterface.js.map +0 -1
- package/lib/module/api.js +0 -452
- package/lib/module/api.js.map +0 -1
- package/lib/module/configurations.js +0 -184
- package/lib/module/configurations.js.map +0 -1
- package/lib/module/constants.js +0 -72
- package/lib/module/constants.js.map +0 -1
- package/lib/module/events.js +0 -259
- package/lib/module/events.js.map +0 -1
- package/lib/module/index.js +0 -120
- package/lib/module/index.js.map +0 -1
- package/lib/module/jsCore.js +0 -424
- package/lib/module/jsCore.js.map +0 -1
- package/lib/module/native.js +0 -12
- package/lib/module/native.js.map +0 -1
- package/lib/module/subject.js +0 -222
- package/lib/module/subject.js.map +0 -1
- package/lib/module/tracker.js +0 -234
- package/lib/module/tracker.js.map +0 -1
- package/lib/module/types.js +0 -2
- package/lib/module/types.js.map +0 -1
- package/lib/module/utils.js +0 -66
- package/lib/module/utils.js.map +0 -1
- package/lib/module/webViewInterface.js +0 -62
- package/lib/module/webViewInterface.js.map +0 -1
- package/lib/typescript/__tests__/api.test.d.ts +0 -2
- package/lib/typescript/__tests__/api.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/configurations.test.d.ts +0 -2
- package/lib/typescript/__tests__/configurations.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/events.test.d.ts +0 -2
- package/lib/typescript/__tests__/events.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/index.test.d.ts +0 -2
- package/lib/typescript/__tests__/index.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/jsCore.test.d.ts +0 -2
- package/lib/typescript/__tests__/jsCore.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/utils.test.d.ts +0 -2
- package/lib/typescript/__tests__/utils.test.d.ts.map +0 -1
- package/lib/typescript/api.d.ts +0 -240
- package/lib/typescript/api.d.ts.map +0 -1
- package/lib/typescript/configurations.d.ts +0 -73
- package/lib/typescript/configurations.d.ts.map +0 -1
- package/lib/typescript/constants.d.ts +0 -64
- package/lib/typescript/constants.d.ts.map +0 -1
- package/lib/typescript/events.d.ts +0 -115
- package/lib/typescript/events.d.ts.map +0 -1
- package/lib/typescript/index.d.ts +0 -27
- package/lib/typescript/index.d.ts.map +0 -1
- package/lib/typescript/jsCore.d.ts +0 -152
- package/lib/typescript/jsCore.d.ts.map +0 -1
- package/lib/typescript/native.d.ts +0 -4
- package/lib/typescript/native.d.ts.map +0 -1
- package/lib/typescript/subject.d.ts +0 -91
- package/lib/typescript/subject.d.ts.map +0 -1
- package/lib/typescript/tracker.d.ts +0 -111
- package/lib/typescript/tracker.d.ts.map +0 -1
- package/lib/typescript/types.d.ts +0 -981
- package/lib/typescript/types.d.ts.map +0 -1
- package/lib/typescript/utils.d.ts +0 -35
- package/lib/typescript/utils.d.ts.map +0 -1
- package/lib/typescript/webViewInterface.d.ts +0 -15
- package/lib/typescript/webViewInterface.d.ts.map +0 -1
- package/scripts/bootstrap.js +0 -29
- package/snowplow-react-native-tracker.podspec +0 -42
- package/src/__mocks__/react-native.js +0 -7
- package/src/__tests__/api.test.ts +0 -21
- package/src/__tests__/configurations.test.ts +0 -608
- package/src/__tests__/events.test.ts +0 -736
- package/src/__tests__/index.test.ts +0 -14
- package/src/__tests__/jsCore.test.ts +0 -199
- package/src/__tests__/utils.test.ts +0 -10
- package/src/api.ts +0 -556
- package/src/configurations.ts +0 -325
- package/src/constants.ts +0 -97
- package/src/events.ts +0 -355
- package/src/index.ts +0 -184
- package/src/jsCore.ts +0 -603
- package/src/native.ts +0 -21
- package/src/subject.ts +0 -302
- package/src/tracker.ts +0 -377
- package/src/types.ts +0 -1162
- package/src/utils.ts +0 -65
- package/src/webViewInterface.ts +0 -92
- package/tsconfig.build.json +0 -5
- package/tsconfig.json +0 -28
- package/turbo.json +0 -34
- package/yarn.lock +0 -9398
package/src/events.ts
DELETED
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { isObject } from './utils';
|
|
4
|
-
import { logMessages } from './constants';
|
|
5
|
-
import type {
|
|
6
|
-
SelfDescribing,
|
|
7
|
-
EventContext,
|
|
8
|
-
ScreenViewProps,
|
|
9
|
-
StructuredProps,
|
|
10
|
-
PageViewProps,
|
|
11
|
-
TimingProps,
|
|
12
|
-
ConsentGrantedProps,
|
|
13
|
-
ConsentWithdrawnProps,
|
|
14
|
-
EcommerceItem,
|
|
15
|
-
EcommerceTransactionProps,
|
|
16
|
-
DeepLinkReceivedProps,
|
|
17
|
-
MessageNotificationProps,
|
|
18
|
-
ScrollChangedProps,
|
|
19
|
-
ListItemViewProps,
|
|
20
|
-
} from './types';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Validates whether an object is valid self-describing
|
|
24
|
-
*
|
|
25
|
-
* @param sd {Object} - the object to validate
|
|
26
|
-
* @returns - boolean
|
|
27
|
-
*/
|
|
28
|
-
function isValidSD(sd: SelfDescribing | EventContext): boolean {
|
|
29
|
-
return isObject(sd) && typeof sd.schema === 'string' && isObject(sd.data);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Validates whether an object is a valid array of contexts
|
|
34
|
-
*
|
|
35
|
-
* @param contexts {Object} - the object to validate
|
|
36
|
-
* @returns - boolean promise
|
|
37
|
-
*/
|
|
38
|
-
function validateContexts(contexts: EventContext[]): Promise<boolean> {
|
|
39
|
-
const isValid =
|
|
40
|
-
Object.prototype.toString.call(contexts) === '[object Array]' &&
|
|
41
|
-
contexts
|
|
42
|
-
.map((c) => isValidSD(c))
|
|
43
|
-
.reduce((acc, curr) => acc !== false && curr, true);
|
|
44
|
-
|
|
45
|
-
if (!isValid) {
|
|
46
|
-
return Promise.reject(new Error(logMessages.context));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return Promise.resolve(true);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Validates whether an object is valid self describing
|
|
54
|
-
*
|
|
55
|
-
* @param argmap {Object} - the object to validate
|
|
56
|
-
* @returns - boolean promise
|
|
57
|
-
*/
|
|
58
|
-
function validateSelfDesc(argmap: SelfDescribing): Promise<boolean> {
|
|
59
|
-
if (!isValidSD(argmap)) {
|
|
60
|
-
return Promise.reject(new Error(logMessages.selfDesc));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return Promise.resolve(true);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Validates a screen view event
|
|
68
|
-
*
|
|
69
|
-
* @param argmap {Object} - the object to validate
|
|
70
|
-
* @returns - boolean promise
|
|
71
|
-
*/
|
|
72
|
-
function validateScreenView(argmap: ScreenViewProps): Promise<boolean> {
|
|
73
|
-
// validate type
|
|
74
|
-
if (!isObject(argmap)) {
|
|
75
|
-
return Promise.reject(new Error(logMessages.evType));
|
|
76
|
-
}
|
|
77
|
-
// validate required props
|
|
78
|
-
if (typeof argmap.name !== 'string') {
|
|
79
|
-
return Promise.reject(new Error(logMessages.screenViewReq));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return Promise.resolve(true);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Validates a scroll changed event
|
|
87
|
-
*
|
|
88
|
-
* @param argmap {Object} - the object to validate
|
|
89
|
-
* @returns - boolean promise
|
|
90
|
-
*/
|
|
91
|
-
function validateScrollChanged(argmap: ScrollChangedProps): Promise<boolean> {
|
|
92
|
-
// validate type
|
|
93
|
-
if (!isObject(argmap)) {
|
|
94
|
-
return Promise.reject(new Error(logMessages.evType));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return Promise.resolve(true);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Validates a list item view event
|
|
102
|
-
*
|
|
103
|
-
* @param argmap {Object} - the object to validate
|
|
104
|
-
* @returns - boolean promise
|
|
105
|
-
*/
|
|
106
|
-
function validateListItemView(argmap: ListItemViewProps): Promise<boolean> {
|
|
107
|
-
// validate type
|
|
108
|
-
if (!isObject(argmap)) {
|
|
109
|
-
return Promise.reject(new Error(logMessages.evType));
|
|
110
|
-
}
|
|
111
|
-
// validate required props
|
|
112
|
-
if (typeof argmap.index !== 'number') {
|
|
113
|
-
return Promise.reject(new Error(logMessages.listItemViewReq));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return Promise.resolve(true);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Validates a structured event
|
|
121
|
-
*
|
|
122
|
-
* @param argmap {Object} - the object to validate
|
|
123
|
-
* @returns - boolean promise
|
|
124
|
-
*/
|
|
125
|
-
function validateStructured(argmap: StructuredProps): Promise<boolean> {
|
|
126
|
-
// validate type
|
|
127
|
-
if (!isObject(argmap)) {
|
|
128
|
-
return Promise.reject(new Error(logMessages.evType));
|
|
129
|
-
}
|
|
130
|
-
// validate required props
|
|
131
|
-
if (
|
|
132
|
-
typeof argmap.category !== 'string' ||
|
|
133
|
-
typeof argmap.action !== 'string'
|
|
134
|
-
) {
|
|
135
|
-
return Promise.reject(new Error(logMessages.structuredReq));
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return Promise.resolve(true);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Validates a page-view event
|
|
143
|
-
*
|
|
144
|
-
* @param argmap {Object} - the object to validate
|
|
145
|
-
* @returns - boolean promise
|
|
146
|
-
*/
|
|
147
|
-
function validatePageView(argmap: PageViewProps): Promise<boolean> {
|
|
148
|
-
// validate type
|
|
149
|
-
if (!isObject(argmap)) {
|
|
150
|
-
return Promise.reject(new Error(logMessages.evType));
|
|
151
|
-
}
|
|
152
|
-
// validate required props
|
|
153
|
-
if (typeof argmap.pageUrl !== 'string') {
|
|
154
|
-
return Promise.reject(new Error(logMessages.pageviewReq));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return Promise.resolve(true);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Validates a timing event
|
|
162
|
-
*
|
|
163
|
-
* @param argmap {Object} - the object to validate
|
|
164
|
-
* @returns - boolean promise
|
|
165
|
-
*/
|
|
166
|
-
function validateTiming(argmap: TimingProps): Promise<boolean> {
|
|
167
|
-
// validate type
|
|
168
|
-
if (!isObject(argmap)) {
|
|
169
|
-
return Promise.reject(new Error(logMessages.evType));
|
|
170
|
-
}
|
|
171
|
-
// validate required props
|
|
172
|
-
if (
|
|
173
|
-
typeof argmap.category !== 'string' ||
|
|
174
|
-
typeof argmap.variable !== 'string' ||
|
|
175
|
-
typeof argmap.timing !== 'number'
|
|
176
|
-
) {
|
|
177
|
-
return Promise.reject(new Error(logMessages.timingReq));
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return Promise.resolve(true);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Validates a consent-granted event
|
|
185
|
-
*
|
|
186
|
-
* @param argmap {Object} - the object to validate
|
|
187
|
-
* @returns - boolean promise
|
|
188
|
-
*/
|
|
189
|
-
function validateConsentGranted(argmap: ConsentGrantedProps): Promise<boolean> {
|
|
190
|
-
// validate type
|
|
191
|
-
if (!isObject(argmap)) {
|
|
192
|
-
return Promise.reject(new Error(logMessages.evType));
|
|
193
|
-
}
|
|
194
|
-
// validate required props
|
|
195
|
-
if (
|
|
196
|
-
typeof argmap.expiry !== 'string' ||
|
|
197
|
-
typeof argmap.documentId !== 'string' ||
|
|
198
|
-
typeof argmap.version !== 'string'
|
|
199
|
-
) {
|
|
200
|
-
return Promise.reject(new Error(logMessages.consentGReq));
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return Promise.resolve(true);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Validates a consent-withdrawn event
|
|
208
|
-
*
|
|
209
|
-
* @param argmap {Object} - the object to validate
|
|
210
|
-
* @returns - boolean promise
|
|
211
|
-
*/
|
|
212
|
-
function validateConsentWithdrawn(
|
|
213
|
-
argmap: ConsentWithdrawnProps
|
|
214
|
-
): Promise<boolean> {
|
|
215
|
-
// validate type
|
|
216
|
-
if (!isObject(argmap)) {
|
|
217
|
-
return Promise.reject(new Error(logMessages.evType));
|
|
218
|
-
}
|
|
219
|
-
// validate required props
|
|
220
|
-
if (
|
|
221
|
-
typeof argmap.all !== 'boolean' ||
|
|
222
|
-
typeof argmap.documentId !== 'string' ||
|
|
223
|
-
typeof argmap.version !== 'string'
|
|
224
|
-
) {
|
|
225
|
-
return Promise.reject(new Error(logMessages.consentWReq));
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return Promise.resolve(true);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Validates a deep link received event
|
|
233
|
-
*
|
|
234
|
-
* @param argmap {Object} - the object to validate
|
|
235
|
-
* @returns - boolean promise
|
|
236
|
-
*/
|
|
237
|
-
function validateDeepLinkReceived(
|
|
238
|
-
argmap: DeepLinkReceivedProps
|
|
239
|
-
): Promise<boolean> {
|
|
240
|
-
// validate type
|
|
241
|
-
if (!isObject(argmap)) {
|
|
242
|
-
return Promise.reject(new Error(logMessages.evType));
|
|
243
|
-
}
|
|
244
|
-
// validate required props
|
|
245
|
-
if (typeof argmap.url !== 'string') {
|
|
246
|
-
return Promise.reject(new Error(logMessages.deepLinkReq));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return Promise.resolve(true);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Validates a message notification event
|
|
254
|
-
*
|
|
255
|
-
* @param argmap {Object} - the object to validate
|
|
256
|
-
* @returns - boolean promise
|
|
257
|
-
*/
|
|
258
|
-
function validateMessageNotification(
|
|
259
|
-
argmap: MessageNotificationProps
|
|
260
|
-
): Promise<boolean> {
|
|
261
|
-
// validate type
|
|
262
|
-
if (!isObject(argmap)) {
|
|
263
|
-
return Promise.reject(new Error(logMessages.evType));
|
|
264
|
-
}
|
|
265
|
-
// validate required props
|
|
266
|
-
if (
|
|
267
|
-
typeof argmap.title !== 'string' ||
|
|
268
|
-
typeof argmap.body !== 'string' ||
|
|
269
|
-
typeof argmap.trigger !== 'string' ||
|
|
270
|
-
!['push', 'location', 'calendar', 'timeInterval', 'other'].includes(
|
|
271
|
-
argmap.trigger
|
|
272
|
-
)
|
|
273
|
-
) {
|
|
274
|
-
return Promise.reject(new Error(logMessages.messageNotificationReq));
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return Promise.resolve(true);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Validates whether an object is valid ecommerce-item
|
|
282
|
-
*
|
|
283
|
-
* @param item {Object} - the object to validate
|
|
284
|
-
* @returns - boolean
|
|
285
|
-
*/
|
|
286
|
-
function isValidEcomItem(item: EcommerceItem): boolean {
|
|
287
|
-
if (
|
|
288
|
-
isObject(item) &&
|
|
289
|
-
typeof item.sku === 'string' &&
|
|
290
|
-
typeof item.price === 'number' &&
|
|
291
|
-
typeof item.quantity === 'number'
|
|
292
|
-
) {
|
|
293
|
-
return true;
|
|
294
|
-
}
|
|
295
|
-
return false;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* Validates an array of ecommerce-items
|
|
300
|
-
*
|
|
301
|
-
* @param items {Object} - the object to validate
|
|
302
|
-
* @returns - boolean promise
|
|
303
|
-
*/
|
|
304
|
-
function validItemsArg(items: EcommerceItem[]): boolean {
|
|
305
|
-
return (
|
|
306
|
-
Object.prototype.toString.call(items) === '[object Array]' &&
|
|
307
|
-
items
|
|
308
|
-
.map((i) => isValidEcomItem(i))
|
|
309
|
-
.reduce((acc, curr) => acc !== false && curr, true)
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Validates an ecommerce-transaction event
|
|
315
|
-
*
|
|
316
|
-
* @param argmap {Object} - the object to validate
|
|
317
|
-
* @returns - boolean promise
|
|
318
|
-
*/
|
|
319
|
-
function validateEcommerceTransaction(
|
|
320
|
-
argmap: EcommerceTransactionProps
|
|
321
|
-
): Promise<boolean> {
|
|
322
|
-
// validate type
|
|
323
|
-
if (!isObject(argmap)) {
|
|
324
|
-
return Promise.reject(new Error(logMessages.evType));
|
|
325
|
-
}
|
|
326
|
-
// validate required props
|
|
327
|
-
if (
|
|
328
|
-
typeof argmap.orderId !== 'string' ||
|
|
329
|
-
typeof argmap.totalValue !== 'number' ||
|
|
330
|
-
!validItemsArg(argmap.items)
|
|
331
|
-
) {
|
|
332
|
-
return Promise.reject(new Error(logMessages.ecomReq));
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return Promise.resolve(true);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
export {
|
|
339
|
-
isValidSD,
|
|
340
|
-
validateContexts,
|
|
341
|
-
validateSelfDesc,
|
|
342
|
-
validateScreenView,
|
|
343
|
-
validateScrollChanged,
|
|
344
|
-
validateListItemView,
|
|
345
|
-
validateStructured,
|
|
346
|
-
validatePageView,
|
|
347
|
-
validateTiming,
|
|
348
|
-
validateConsentGranted,
|
|
349
|
-
validateConsentWithdrawn,
|
|
350
|
-
isValidEcomItem,
|
|
351
|
-
validItemsArg,
|
|
352
|
-
validateEcommerceTransaction,
|
|
353
|
-
validateDeepLinkReceived,
|
|
354
|
-
validateMessageNotification,
|
|
355
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import * as api from './api';
|
|
4
|
-
import { safeWait, safeWaitCallback, errorHandler } from './utils';
|
|
5
|
-
import type {
|
|
6
|
-
NetworkConfiguration,
|
|
7
|
-
TrackerControllerConfiguration,
|
|
8
|
-
ReactNativeTracker,
|
|
9
|
-
} from './types';
|
|
10
|
-
import { getWebViewCallback } from './webViewInterface';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Creates a React Native Tracker object
|
|
14
|
-
*
|
|
15
|
-
* @param namespace {string} - The tracker namespace
|
|
16
|
-
* @param networkConfig {Object} - The network configuration
|
|
17
|
-
* @param control {Array} - The tracker controller configuration
|
|
18
|
-
* @returns The tracker object
|
|
19
|
-
*/
|
|
20
|
-
function createTracker(
|
|
21
|
-
namespace: string,
|
|
22
|
-
networkConfig: NetworkConfiguration,
|
|
23
|
-
controllerConfig: TrackerControllerConfiguration = {}
|
|
24
|
-
): ReactNativeTracker {
|
|
25
|
-
// initTrackerPromise
|
|
26
|
-
const initTrackerPromise: Promise<void> = Promise.resolve(
|
|
27
|
-
api.createTracker({
|
|
28
|
-
namespace,
|
|
29
|
-
networkConfig,
|
|
30
|
-
...controllerConfig,
|
|
31
|
-
})
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
// mkMethod creates methods subscribed to the initTrackerPromise
|
|
35
|
-
const mkMethod = safeWait(initTrackerPromise, errorHandler);
|
|
36
|
-
|
|
37
|
-
// mkCallback creates callbacks subscribed to the initTrackerPromise
|
|
38
|
-
const mkCallback = safeWaitCallback(initTrackerPromise, errorHandler);
|
|
39
|
-
|
|
40
|
-
// track methods
|
|
41
|
-
const trackSelfDescribingEvent = mkMethod(
|
|
42
|
-
api.trackSelfDescribingEvent(namespace)
|
|
43
|
-
);
|
|
44
|
-
const trackScreenViewEvent = mkMethod(api.trackScreenViewEvent(namespace));
|
|
45
|
-
const trackScrollChangedEvent = mkMethod(
|
|
46
|
-
api.trackScrollChangedEvent(namespace)
|
|
47
|
-
);
|
|
48
|
-
const trackListItemViewEvent = mkMethod(
|
|
49
|
-
api.trackListItemViewEvent(namespace)
|
|
50
|
-
);
|
|
51
|
-
const trackStructuredEvent = mkMethod(api.trackStructuredEvent(namespace));
|
|
52
|
-
const trackPageViewEvent = mkMethod(api.trackPageViewEvent(namespace));
|
|
53
|
-
const trackTimingEvent = mkMethod(api.trackTimingEvent(namespace));
|
|
54
|
-
const trackConsentGrantedEvent = mkMethod(
|
|
55
|
-
api.trackConsentGrantedEvent(namespace)
|
|
56
|
-
);
|
|
57
|
-
const trackConsentWithdrawnEvent = mkMethod(
|
|
58
|
-
api.trackConsentWithdrawnEvent(namespace)
|
|
59
|
-
);
|
|
60
|
-
const trackEcommerceTransactionEvent = mkMethod(
|
|
61
|
-
api.trackEcommerceTransactionEvent(namespace)
|
|
62
|
-
);
|
|
63
|
-
const trackDeepLinkReceivedEvent = mkMethod(
|
|
64
|
-
api.trackDeepLinkReceivedEvent(namespace)
|
|
65
|
-
);
|
|
66
|
-
const trackMessageNotificationEvent = mkMethod(
|
|
67
|
-
api.trackMessageNotificationEvent(namespace)
|
|
68
|
-
);
|
|
69
|
-
// Global Contexts
|
|
70
|
-
const removeGlobalContexts = mkMethod(api.removeGlobalContexts(namespace));
|
|
71
|
-
const addGlobalContexts = mkMethod(api.addGlobalContexts(namespace));
|
|
72
|
-
// setters
|
|
73
|
-
const setUserId = mkMethod(api.setUserId(namespace));
|
|
74
|
-
const setNetworkUserId = mkMethod(api.setNetworkUserId(namespace));
|
|
75
|
-
const setDomainUserId = mkMethod(api.setDomainUserId(namespace));
|
|
76
|
-
const setIpAddress = mkMethod(api.setIpAddress(namespace));
|
|
77
|
-
const setUseragent = mkMethod(api.setUseragent(namespace));
|
|
78
|
-
const setTimezone = mkMethod(api.setTimezone(namespace));
|
|
79
|
-
const setLanguage = mkMethod(api.setLanguage(namespace));
|
|
80
|
-
const setScreenResolution = mkMethod(api.setScreenResolution(namespace));
|
|
81
|
-
const setScreenViewport = mkMethod(api.setScreenViewport(namespace));
|
|
82
|
-
const setColorDepth = mkMethod(api.setColorDepth(namespace));
|
|
83
|
-
const setSubjectData = mkMethod(api.setSubjectData(namespace));
|
|
84
|
-
|
|
85
|
-
// callbacks
|
|
86
|
-
const getSessionUserId = mkCallback(api.getSessionUserId(namespace));
|
|
87
|
-
const getSessionId = mkCallback(api.getSessionId(namespace));
|
|
88
|
-
const getSessionIndex = mkCallback(api.getSessionIndex(namespace));
|
|
89
|
-
const getIsInBackground = mkCallback(api.getIsInBackground(namespace));
|
|
90
|
-
const getBackgroundIndex = mkCallback(api.getBackgroundIndex(namespace));
|
|
91
|
-
const getForegroundIndex = mkCallback(api.getForegroundIndex(namespace));
|
|
92
|
-
|
|
93
|
-
return Object.freeze({
|
|
94
|
-
trackSelfDescribingEvent,
|
|
95
|
-
trackScreenViewEvent,
|
|
96
|
-
trackScrollChangedEvent,
|
|
97
|
-
trackListItemViewEvent,
|
|
98
|
-
trackStructuredEvent,
|
|
99
|
-
trackPageViewEvent,
|
|
100
|
-
trackTimingEvent,
|
|
101
|
-
trackConsentGrantedEvent,
|
|
102
|
-
trackConsentWithdrawnEvent,
|
|
103
|
-
trackEcommerceTransactionEvent,
|
|
104
|
-
trackDeepLinkReceivedEvent,
|
|
105
|
-
trackMessageNotificationEvent,
|
|
106
|
-
removeGlobalContexts,
|
|
107
|
-
addGlobalContexts,
|
|
108
|
-
setUserId,
|
|
109
|
-
setNetworkUserId,
|
|
110
|
-
setDomainUserId,
|
|
111
|
-
setIpAddress,
|
|
112
|
-
setUseragent,
|
|
113
|
-
setTimezone,
|
|
114
|
-
setLanguage,
|
|
115
|
-
setScreenResolution,
|
|
116
|
-
setScreenViewport,
|
|
117
|
-
setColorDepth,
|
|
118
|
-
setSubjectData,
|
|
119
|
-
getSessionUserId,
|
|
120
|
-
getSessionId,
|
|
121
|
-
getSessionIndex,
|
|
122
|
-
getIsInBackground,
|
|
123
|
-
getBackgroundIndex,
|
|
124
|
-
getForegroundIndex,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Removes a tracker given its namespace
|
|
130
|
-
*
|
|
131
|
-
* @param trackerNamespace {string}
|
|
132
|
-
* @returns - A boolean promise
|
|
133
|
-
*/
|
|
134
|
-
function removeTracker(trackerNamespace: string): Promise<boolean> {
|
|
135
|
-
return <Promise<boolean>>(
|
|
136
|
-
api.removeTracker(trackerNamespace).catch((e) => errorHandler(e))
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Removes all trackers
|
|
142
|
-
*
|
|
143
|
-
* @returns - A boolean promise
|
|
144
|
-
*/
|
|
145
|
-
function removeAllTrackers(): Promise<boolean> {
|
|
146
|
-
return <Promise<boolean>>(
|
|
147
|
-
api.removeAllTrackers().catch((e) => errorHandler(e))
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export { createTracker, removeTracker, removeAllTrackers, getWebViewCallback };
|
|
152
|
-
|
|
153
|
-
export type {
|
|
154
|
-
ReactNativeTracker,
|
|
155
|
-
TrackerControllerConfiguration,
|
|
156
|
-
NetworkConfiguration,
|
|
157
|
-
TrackerConfiguration,
|
|
158
|
-
SessionConfiguration,
|
|
159
|
-
EmitterConfiguration,
|
|
160
|
-
SubjectConfiguration,
|
|
161
|
-
GdprConfiguration,
|
|
162
|
-
GCConfiguration,
|
|
163
|
-
SelfDescribing,
|
|
164
|
-
EventContext,
|
|
165
|
-
ScreenViewProps,
|
|
166
|
-
StructuredProps,
|
|
167
|
-
PageViewProps,
|
|
168
|
-
TimingProps,
|
|
169
|
-
ConsentGrantedProps,
|
|
170
|
-
ConsentWithdrawnProps,
|
|
171
|
-
EcommerceTransactionProps,
|
|
172
|
-
DeepLinkReceivedProps,
|
|
173
|
-
MessageNotificationProps,
|
|
174
|
-
EcommerceItem,
|
|
175
|
-
ConsentDocument,
|
|
176
|
-
GlobalContext,
|
|
177
|
-
HttpMethod,
|
|
178
|
-
DevicePlatform,
|
|
179
|
-
LogLevel,
|
|
180
|
-
Basis,
|
|
181
|
-
BufferOption,
|
|
182
|
-
ScreenSize,
|
|
183
|
-
Trigger,
|
|
184
|
-
} from './types';
|