@snowplow/react-native-tracker 1.4.0 → 2.1.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.
Files changed (240) hide show
  1. package/.editorconfig +15 -0
  2. package/.eslintignore +6 -0
  3. package/.gitattributes +3 -0
  4. package/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
  5. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. package/.github/actions/setup/action.yml +28 -0
  7. package/.github/workflows/build.yml +155 -0
  8. package/.github/workflows/deploy.yml +97 -0
  9. package/.github/workflows/e2e-android.yml +121 -0
  10. package/.github/workflows/e2e-ios.yml +95 -0
  11. package/.github/workflows/snyk.yml +21 -0
  12. package/.gitignore +70 -0
  13. package/.npmignore +60 -0
  14. package/.nvmrc +1 -0
  15. package/.watchmanconfig +1 -0
  16. package/.yarnrc +3 -0
  17. package/CHANGELOG +176 -0
  18. package/CONTRIBUTING.md +80 -0
  19. package/LICENSE +1 -1
  20. package/README.md +24 -111
  21. package/android/build.gradle +93 -37
  22. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  23. package/android/gradle/wrapper/gradle-wrapper.properties +1 -2
  24. package/android/gradle.properties +5 -2
  25. package/android/gradlew +172 -110
  26. package/android/gradlew.bat +24 -19
  27. package/android/src/main/AndroidManifest.xml +1 -3
  28. package/android/src/main/AndroidManifestNew.xml +2 -0
  29. package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerModule.kt +744 -0
  30. package/android/src/main/java/com/snowplow/reactnativetracker/ReactNativeTrackerPackage.kt +17 -0
  31. package/android/src/main/java/com/snowplow/reactnativetracker/util/ConfigUtil.kt +274 -0
  32. package/android/src/main/java/com/snowplow/reactnativetracker/util/EventUtil.kt +233 -0
  33. package/android/src/main/java/com/snowplow/reactnativetracker/util/TrackerVersion.kt +5 -0
  34. package/babel.config.js +3 -0
  35. package/example/.watchmanconfig +1 -0
  36. package/example/Gemfile +6 -0
  37. package/example/android/app/build.gradle +129 -0
  38. package/example/android/app/debug.keystore +0 -0
  39. package/example/android/app/proguard-rules.pro +10 -0
  40. package/example/android/app/src/androidTest/java/com/reactnativetrackerexample/DetoxTest.java +36 -0
  41. package/example/android/app/src/androidTest/java/com/reactnativetrackerexample/DetoxTestAppJUnitRunner.java +21 -0
  42. package/example/android/app/src/debug/AndroidManifest.xml +13 -0
  43. package/example/android/app/src/debug/java/com/reactnativetrackerexample/ReactNativeFlipper.java +75 -0
  44. package/example/android/app/src/main/AndroidManifest.xml +26 -0
  45. package/example/android/app/src/main/java/com/reactnativetrackerexample/MainActivity.java +32 -0
  46. package/example/android/app/src/main/java/com/reactnativetrackerexample/MainApplication.java +62 -0
  47. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
  48. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  49. package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  50. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  51. package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  52. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  53. package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  54. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  55. package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  56. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  57. package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  58. package/example/android/app/src/main/res/values/strings.xml +3 -0
  59. package/example/android/app/src/main/res/values/styles.xml +9 -0
  60. package/example/android/app/src/release/java/com/reactnativetrackerexample/ReactNativeFlipper.java +20 -0
  61. package/example/android/build.gradle +31 -0
  62. package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  63. package/example/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  64. package/example/android/gradle.properties +44 -0
  65. package/example/android/gradlew +244 -0
  66. package/example/android/gradlew.bat +92 -0
  67. package/example/android/settings.gradle +4 -0
  68. package/example/app.json +4 -0
  69. package/example/babel.config.js +17 -0
  70. package/example/detox.config.js +92 -0
  71. package/example/e2e/config.json +10 -0
  72. package/example/e2e/emitEvents.e2e.detox.js +95 -0
  73. package/example/e2e/environment.js +23 -0
  74. package/example/e2e/helpers/microCommands.js +140 -0
  75. package/example/e2e/helpers/microHelpers.js +333 -0
  76. package/example/e2e/helpers/microHelpers.test.js +295 -0
  77. package/example/e2e/helpers/schemas.js +49 -0
  78. package/example/e2e/jest.config.js +16 -0
  79. package/example/e2e/setup.js +4 -0
  80. package/example/e2e/testEvents.micro.test.js +287 -0
  81. package/example/index.js +5 -0
  82. package/example/ios/.xcode.env +11 -0
  83. package/example/ios/Podfile +62 -0
  84. package/example/ios/Podfile.lock +730 -0
  85. package/example/ios/ReactNativeTrackerExample/AppDelegate.h +6 -0
  86. package/example/ios/ReactNativeTrackerExample/AppDelegate.mm +26 -0
  87. package/example/ios/ReactNativeTrackerExample/Images.xcassets/AppIcon.appiconset/Contents.json +53 -0
  88. package/example/ios/ReactNativeTrackerExample/Images.xcassets/Contents.json +6 -0
  89. package/example/ios/ReactNativeTrackerExample/Info.plist +55 -0
  90. package/example/ios/ReactNativeTrackerExample/LaunchScreen.storyboard +47 -0
  91. package/example/ios/ReactNativeTrackerExample/main.m +10 -0
  92. package/example/ios/ReactNativeTrackerExample-Bridging-Header.h +3 -0
  93. package/example/ios/ReactNativeTrackerExample.xcodeproj/project.pbxproj +722 -0
  94. package/{ios/RNSnowplowTracker.xcodeproj/xcshareddata/xcschemes/RNSnowplowTracker.xcscheme → example/ios/ReactNativeTrackerExample.xcodeproj/xcshareddata/xcschemes/ReactNativeTrackerExample.xcscheme} +29 -21
  95. package/example/ios/ReactNativeTrackerExample.xcworkspace/contents.xcworkspacedata +10 -0
  96. package/example/ios/ReactNativeTrackerExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  97. package/example/ios/ReactNativeTrackerExampleTests/Info.plist +24 -0
  98. package/example/ios/ReactNativeTrackerExampleTests/ReactNativeTrackerExampleTests.m +66 -0
  99. package/example/metro.config.js +45 -0
  100. package/example/package.json +54 -0
  101. package/example/react-native.config.js +10 -0
  102. package/example/src/App.js +566 -0
  103. package/example/tsconfig.json +5 -0
  104. package/example/yarn.lock +7379 -0
  105. package/ios/ReactNativeTracker-Bridging-Header.h +2 -0
  106. package/ios/ReactNativeTracker.mm +175 -0
  107. package/ios/ReactNativeTracker.swift +822 -0
  108. package/ios/{RNSnowplowTracker.xcodeproj → ReactNativeTracker.xcodeproj}/project.pbxproj +55 -79
  109. package/ios/Util/ConfigUtils.swift +209 -0
  110. package/ios/Util/TrackerVersion.swift +3 -0
  111. package/ios/Util/Utilities.swift +37 -0
  112. package/lefthook.yml +11 -0
  113. package/lib/commonjs/api.js +490 -0
  114. package/lib/commonjs/api.js.map +1 -0
  115. package/lib/commonjs/configurations.js +196 -0
  116. package/lib/commonjs/configurations.js.map +1 -0
  117. package/lib/commonjs/constants.js +77 -0
  118. package/lib/commonjs/constants.js.map +1 -0
  119. package/lib/commonjs/events.js +277 -0
  120. package/lib/commonjs/events.js.map +1 -0
  121. package/lib/commonjs/index.js +132 -0
  122. package/lib/commonjs/index.js.map +1 -0
  123. package/lib/commonjs/jsCore.js +427 -0
  124. package/lib/commonjs/jsCore.js.map +1 -0
  125. package/lib/commonjs/native.js +16 -0
  126. package/lib/commonjs/native.js.map +1 -0
  127. package/lib/commonjs/subject.js +235 -0
  128. package/lib/commonjs/subject.js.map +1 -0
  129. package/lib/commonjs/tracker.js +248 -0
  130. package/lib/commonjs/tracker.js.map +1 -0
  131. package/lib/commonjs/types.js +2 -0
  132. package/lib/commonjs/types.js.map +1 -0
  133. package/lib/commonjs/utils.js +72 -0
  134. package/lib/commonjs/utils.js.map +1 -0
  135. package/lib/commonjs/webViewInterface.js +66 -0
  136. package/lib/commonjs/webViewInterface.js.map +1 -0
  137. package/lib/module/api.js +452 -0
  138. package/lib/module/api.js.map +1 -0
  139. package/lib/module/configurations.js +184 -0
  140. package/lib/module/configurations.js.map +1 -0
  141. package/lib/module/constants.js +72 -0
  142. package/lib/module/constants.js.map +1 -0
  143. package/lib/module/events.js +259 -0
  144. package/lib/module/events.js.map +1 -0
  145. package/lib/module/index.js +120 -0
  146. package/lib/module/index.js.map +1 -0
  147. package/lib/module/jsCore.js +424 -0
  148. package/lib/module/jsCore.js.map +1 -0
  149. package/lib/module/native.js +12 -0
  150. package/lib/module/native.js.map +1 -0
  151. package/lib/module/subject.js +222 -0
  152. package/lib/module/subject.js.map +1 -0
  153. package/lib/module/tracker.js +234 -0
  154. package/lib/module/tracker.js.map +1 -0
  155. package/lib/module/types.js +2 -0
  156. package/lib/module/types.js.map +1 -0
  157. package/lib/module/utils.js +66 -0
  158. package/lib/module/utils.js.map +1 -0
  159. package/lib/module/webViewInterface.js +62 -0
  160. package/lib/module/webViewInterface.js.map +1 -0
  161. package/lib/typescript/__tests__/api.test.d.ts +2 -0
  162. package/lib/typescript/__tests__/api.test.d.ts.map +1 -0
  163. package/lib/typescript/__tests__/configurations.test.d.ts +2 -0
  164. package/lib/typescript/__tests__/configurations.test.d.ts.map +1 -0
  165. package/lib/typescript/__tests__/events.test.d.ts +2 -0
  166. package/lib/typescript/__tests__/events.test.d.ts.map +1 -0
  167. package/lib/typescript/__tests__/index.test.d.ts +2 -0
  168. package/lib/typescript/__tests__/index.test.d.ts.map +1 -0
  169. package/lib/typescript/__tests__/jsCore.test.d.ts +2 -0
  170. package/lib/typescript/__tests__/jsCore.test.d.ts.map +1 -0
  171. package/lib/typescript/__tests__/utils.test.d.ts +2 -0
  172. package/lib/typescript/__tests__/utils.test.d.ts.map +1 -0
  173. package/lib/typescript/api.d.ts +240 -0
  174. package/lib/typescript/api.d.ts.map +1 -0
  175. package/lib/typescript/configurations.d.ts +73 -0
  176. package/lib/typescript/configurations.d.ts.map +1 -0
  177. package/lib/typescript/constants.d.ts +64 -0
  178. package/lib/typescript/constants.d.ts.map +1 -0
  179. package/lib/typescript/events.d.ts +115 -0
  180. package/lib/typescript/events.d.ts.map +1 -0
  181. package/lib/typescript/index.d.ts +27 -0
  182. package/lib/typescript/index.d.ts.map +1 -0
  183. package/lib/typescript/jsCore.d.ts +152 -0
  184. package/lib/typescript/jsCore.d.ts.map +1 -0
  185. package/lib/typescript/native.d.ts +4 -0
  186. package/lib/typescript/native.d.ts.map +1 -0
  187. package/lib/typescript/subject.d.ts +91 -0
  188. package/lib/typescript/subject.d.ts.map +1 -0
  189. package/lib/typescript/tracker.d.ts +111 -0
  190. package/lib/typescript/tracker.d.ts.map +1 -0
  191. package/{dist/index.d.ts → lib/typescript/types.d.ts} +264 -73
  192. package/lib/typescript/types.d.ts.map +1 -0
  193. package/lib/typescript/utils.d.ts +35 -0
  194. package/lib/typescript/utils.d.ts.map +1 -0
  195. package/lib/typescript/webViewInterface.d.ts +15 -0
  196. package/lib/typescript/webViewInterface.d.ts.map +1 -0
  197. package/package.json +135 -53
  198. package/scripts/bootstrap.js +29 -0
  199. package/snowplow-react-native-tracker.podspec +42 -0
  200. package/src/__mocks__/react-native.js +7 -0
  201. package/src/__tests__/api.test.ts +21 -0
  202. package/src/__tests__/configurations.test.ts +608 -0
  203. package/src/__tests__/events.test.ts +736 -0
  204. package/src/__tests__/index.test.ts +14 -0
  205. package/src/__tests__/jsCore.test.ts +199 -0
  206. package/src/__tests__/utils.test.ts +10 -0
  207. package/src/api.ts +556 -0
  208. package/src/configurations.ts +325 -0
  209. package/src/constants.ts +97 -0
  210. package/src/events.ts +355 -0
  211. package/src/index.ts +184 -0
  212. package/src/jsCore.ts +603 -0
  213. package/src/native.ts +21 -0
  214. package/src/subject.ts +302 -0
  215. package/src/tracker.ts +377 -0
  216. package/src/types.ts +1162 -0
  217. package/src/utils.ts +65 -0
  218. package/src/webViewInterface.ts +92 -0
  219. package/tsconfig.build.json +5 -0
  220. package/tsconfig.json +28 -0
  221. package/turbo.json +34 -0
  222. package/yarn.lock +9333 -0
  223. package/RNSnowplowTracker.podspec +0 -24
  224. package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerModule.java +0 -750
  225. package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerPackage.java +0 -29
  226. package/android/src/main/java/com/snowplowanalytics/react/util/ConfigUtil.java +0 -351
  227. package/android/src/main/java/com/snowplowanalytics/react/util/EventUtil.java +0 -339
  228. package/android/src/main/java/com/snowplowanalytics/react/util/TrackerVersion.java +0 -7
  229. package/dist/index.js +0 -2026
  230. package/dist/index.js.map +0 -1
  231. package/ios/RNSnowplowTracker.h +0 -34
  232. package/ios/RNSnowplowTracker.m +0 -911
  233. package/ios/Util/NSDictionary+RNSP_TypeMethods.h +0 -33
  234. package/ios/Util/NSDictionary+RNSP_TypeMethods.m +0 -40
  235. package/ios/Util/RNConfigUtils.h +0 -44
  236. package/ios/Util/RNConfigUtils.m +0 -209
  237. package/ios/Util/RNTrackerVersion.h +0 -27
  238. package/ios/Util/RNTrackerVersion.m +0 -27
  239. package/ios/Util/RNUtilities.h +0 -32
  240. package/ios/Util/RNUtilities.m +0 -68
@@ -0,0 +1,325 @@
1
+ 'use strict';
2
+
3
+ import { isObject } from './utils';
4
+ import { isValidSD } from './events';
5
+ import { logMessages } from './constants';
6
+ import type {
7
+ NetworkConfiguration,
8
+ TrackerConfiguration,
9
+ SessionConfiguration,
10
+ EmitterConfiguration,
11
+ SubjectConfiguration,
12
+ GdprConfiguration,
13
+ GCConfiguration,
14
+ GlobalContext,
15
+ InitTrackerConfiguration,
16
+ } from './types';
17
+
18
+ /**
19
+ * Configuration properties
20
+ */
21
+ const networkProps = ['endpoint', 'method', 'customPostPath', 'requestHeaders'];
22
+ const trackerProps = [
23
+ 'appId',
24
+ 'devicePlatform',
25
+ 'base64Encoding',
26
+ 'logLevel',
27
+ 'applicationContext',
28
+ 'platformContext',
29
+ 'geoLocationContext',
30
+ 'sessionContext',
31
+ 'deepLinkContext',
32
+ 'screenContext',
33
+ 'screenViewAutotracking',
34
+ 'screenEngagementAutotracking',
35
+ 'lifecycleAutotracking',
36
+ 'installAutotracking',
37
+ 'exceptionAutotracking',
38
+ 'diagnosticAutotracking',
39
+ 'userAnonymisation',
40
+ ];
41
+ const sessionProps = ['foregroundTimeout', 'backgroundTimeout'];
42
+ const emitterProps = [
43
+ 'bufferOption',
44
+ 'emitRange',
45
+ 'threadPoolSize',
46
+ 'byteLimitPost',
47
+ 'byteLimitGet',
48
+ 'serverAnonymisation',
49
+ ];
50
+ const subjectProps = [
51
+ 'userId',
52
+ 'networkUserId',
53
+ 'domainUserId',
54
+ 'useragent',
55
+ 'ipAddress',
56
+ 'timezone',
57
+ 'language',
58
+ 'screenResolution',
59
+ 'screenViewport',
60
+ 'colorDepth',
61
+ ];
62
+ const gdprProps = [
63
+ 'basisForProcessing',
64
+ 'documentId',
65
+ 'documentVersion',
66
+ 'documentDescription',
67
+ ];
68
+ const gcProps = ['tag', 'globalContexts'];
69
+
70
+ /**
71
+ * Validates whether an object is of valid configuration given its default keys
72
+ *
73
+ * @param config {Object} - the object to validate
74
+ * @param defaultKeys {Array} - the default keys to validate against
75
+ * @returns - boolean
76
+ */
77
+ function isValidConfig<Type extends Record<string, any>>(
78
+ config: Type,
79
+ defaultKeys: Array<string>
80
+ ): config is Type {
81
+ return Object.keys(config).every((key) => defaultKeys.includes(key));
82
+ }
83
+
84
+ /**
85
+ * Validates the networkConfig
86
+ *
87
+ * @param config {Object} - the config to validate
88
+ * @returns - boolean
89
+ */
90
+ function isValidNetworkConf(config: NetworkConfiguration): boolean {
91
+ if (
92
+ !isObject(config) ||
93
+ !isValidConfig(config, networkProps) ||
94
+ typeof config.endpoint !== 'string' ||
95
+ !config.endpoint
96
+ ) {
97
+ return false;
98
+ }
99
+ return true;
100
+ }
101
+
102
+ /**
103
+ * Validates the trackerConfig
104
+ *
105
+ * @param config {Object} - the config to validate
106
+ * @returns - boolean
107
+ */
108
+ function isValidTrackerConf(config: TrackerConfiguration): boolean {
109
+ if (!isObject(config) || !isValidConfig(config, trackerProps)) {
110
+ return false;
111
+ }
112
+ return true;
113
+ }
114
+
115
+ /**
116
+ * Validates the sessionConfig
117
+ *
118
+ * @param config {Object} - the config to validate
119
+ * @returns - boolean
120
+ */
121
+ function isValidSessionConf(config: SessionConfiguration): boolean {
122
+ if (
123
+ !isObject(config) ||
124
+ !isValidConfig(config, sessionProps) ||
125
+ !sessionProps.every((key) =>
126
+ Object.keys(config as SessionConfiguration).includes(key)
127
+ )
128
+ ) {
129
+ return false;
130
+ }
131
+ return true;
132
+ }
133
+
134
+ /**
135
+ * Validates the emitterConfig
136
+ *
137
+ * @param config {Object} - the config to validate
138
+ * @returns - boolean
139
+ */
140
+ function isValidEmitterConf(config: EmitterConfiguration): boolean {
141
+ if (!isObject(config) || !isValidConfig(config, emitterProps)) {
142
+ return false;
143
+ }
144
+ return true;
145
+ }
146
+
147
+ /**
148
+ * Validates whether an object is of ScreenSize type
149
+ *
150
+ * @param arr {Object} - the object to validate
151
+ * @returns - boolean
152
+ */
153
+ function isScreenSize<Type>(arr: Type): boolean {
154
+ return (
155
+ Array.isArray(arr) &&
156
+ arr.length === 2 &&
157
+ arr.every(<Type>(n: Type) => typeof n === 'number')
158
+ );
159
+ }
160
+
161
+ /**
162
+ * Validates the subjectConfig
163
+ *
164
+ * @param config {Object} - the config to validate
165
+ * @returns - boolean
166
+ */
167
+ function isValidSubjectConf(config: SubjectConfiguration): boolean {
168
+ if (!isObject(config) || !isValidConfig(config, subjectProps)) {
169
+ return false;
170
+ }
171
+
172
+ // validating ScreenSize here to simplify array handling in bridge
173
+ if (
174
+ Object.prototype.hasOwnProperty.call(config, 'screenResolution') &&
175
+ config.screenResolution !== null &&
176
+ !isScreenSize(config.screenResolution as unknown)
177
+ ) {
178
+ return false;
179
+ }
180
+
181
+ if (
182
+ Object.prototype.hasOwnProperty.call(config, 'screenViewport') &&
183
+ config.screenViewport !== null &&
184
+ !isScreenSize(config.screenViewport as unknown)
185
+ ) {
186
+ return false;
187
+ }
188
+
189
+ return true;
190
+ }
191
+
192
+ /**
193
+ * Validates the gdprConfig
194
+ *
195
+ * @param config {Object} - the config to validate
196
+ * @returns - boolean
197
+ */
198
+ function isValidGdprConf(config: GdprConfiguration): boolean {
199
+ if (
200
+ !isObject(config) ||
201
+ !isValidConfig(config, gdprProps) ||
202
+ !gdprProps.every((key) =>
203
+ Object.keys(config as GdprConfiguration).includes(key)
204
+ ) ||
205
+ ![
206
+ 'consent',
207
+ 'contract',
208
+ 'legal_obligation',
209
+ 'legitimate_interests',
210
+ 'public_task',
211
+ 'vital_interests',
212
+ ].includes(config.basisForProcessing)
213
+ ) {
214
+ return false;
215
+ }
216
+ return true;
217
+ }
218
+
219
+ /**
220
+ * Validates whether an object is of GlobalContext type
221
+ *
222
+ * @param gc {Object} - the object to validate
223
+ * @returns - boolean
224
+ */
225
+ function isValidGC(gc: GlobalContext): boolean {
226
+ return (
227
+ isObject(gc) &&
228
+ isValidConfig(gc, gcProps) &&
229
+ typeof gc.tag === 'string' &&
230
+ Array.isArray(gc.globalContexts) &&
231
+ gc.globalContexts.every((c) => isValidSD(c))
232
+ );
233
+ }
234
+
235
+ /**
236
+ * Validates the GCConfig (global contexts)
237
+ *
238
+ * @param config {Object} - the config to validate
239
+ * @returns - boolean
240
+ */
241
+ function isValidGCConf(config: GCConfiguration): boolean {
242
+ if (!Array.isArray(config)) {
243
+ return false;
244
+ }
245
+ if (!config.every((gc) => isValidGC(gc as GlobalContext))) {
246
+ return false;
247
+ }
248
+ return true;
249
+ }
250
+
251
+ /**
252
+ * Validates the initTrackerConfiguration
253
+ *
254
+ * @param init {Object} - the config to validate
255
+ * @returns - boolean promise
256
+ */
257
+ function initValidate(init: InitTrackerConfiguration): Promise<boolean> {
258
+ if (typeof init.namespace !== 'string' || !init.namespace) {
259
+ return Promise.reject(new Error(logMessages.namespace));
260
+ }
261
+
262
+ if (
263
+ !Object.prototype.hasOwnProperty.call(init, 'networkConfig') ||
264
+ !isValidNetworkConf(init.networkConfig as NetworkConfiguration)
265
+ ) {
266
+ return Promise.reject(new Error(logMessages.network));
267
+ }
268
+
269
+ if (
270
+ Object.prototype.hasOwnProperty.call(init, 'trackerConfig') &&
271
+ !isValidTrackerConf(init.trackerConfig as TrackerConfiguration)
272
+ ) {
273
+ return Promise.reject(new Error(logMessages.tracker));
274
+ }
275
+
276
+ if (
277
+ Object.prototype.hasOwnProperty.call(init, 'sessionConfig') &&
278
+ !isValidSessionConf(init.sessionConfig as SessionConfiguration)
279
+ ) {
280
+ return Promise.reject(new Error(logMessages.session));
281
+ }
282
+
283
+ if (
284
+ Object.prototype.hasOwnProperty.call(init, 'emitterConfig') &&
285
+ !isValidEmitterConf(init.emitterConfig as EmitterConfiguration)
286
+ ) {
287
+ return Promise.reject(new Error(logMessages.emitter));
288
+ }
289
+
290
+ if (
291
+ Object.prototype.hasOwnProperty.call(init, 'subjectConfig') &&
292
+ !isValidSubjectConf(init.subjectConfig as SubjectConfiguration)
293
+ ) {
294
+ return Promise.reject(new Error(logMessages.subject));
295
+ }
296
+
297
+ if (
298
+ Object.prototype.hasOwnProperty.call(init, 'gdprConfig') &&
299
+ !isValidGdprConf(init.gdprConfig as GdprConfiguration)
300
+ ) {
301
+ return Promise.reject(new Error(logMessages.gdpr));
302
+ }
303
+
304
+ if (
305
+ Object.prototype.hasOwnProperty.call(init, 'gcConfig') &&
306
+ !isValidGCConf(init.gcConfig as GCConfiguration)
307
+ ) {
308
+ return Promise.reject(new Error(logMessages.gc));
309
+ }
310
+
311
+ return Promise.resolve(true);
312
+ }
313
+
314
+ export {
315
+ isValidNetworkConf,
316
+ isValidTrackerConf,
317
+ isValidSessionConf,
318
+ isValidEmitterConf,
319
+ isValidSubjectConf,
320
+ isValidGdprConf,
321
+ isValidGCConf,
322
+ isValidGC,
323
+ isScreenSize,
324
+ initValidate,
325
+ };
@@ -0,0 +1,97 @@
1
+ 'use strict';
2
+
3
+ const logMessages = {
4
+ // configuration errors
5
+ namespace: 'namespace parameter is required to be set',
6
+ endpoint: 'endpoint parameter is required to be set',
7
+ network: 'networkConfig is invalid',
8
+ tracker: 'trackerConfig is invalid',
9
+ session: 'sessionConfig is invalid',
10
+ emitter: 'emitterConfig is invalid',
11
+ subject: 'subjectConfig is invalid',
12
+ gdpr: 'gdprConfig is invalid',
13
+ gc: 'gcConfig is invalid',
14
+
15
+ // event errors
16
+ context: 'invalid contexts parameter',
17
+ selfDesc:
18
+ 'selfDescribing event requires schema and data parameters to be set',
19
+ evType: 'event argument can only be an object',
20
+ screenViewReq: 'screenView event requires name as string parameter to be set',
21
+ listItemViewReq:
22
+ 'listItemView event requires index asn integer parameter to be set',
23
+ structuredReq:
24
+ 'structured event requires category and action parameters to be set',
25
+ pageviewReq: 'pageView event requires pageUrl parameter to be set',
26
+ timingReq:
27
+ 'timing event requires category, variable and timing parameters to be set',
28
+ consentGReq:
29
+ 'consentGranted event requires expiry, documentId and version parameters to be set',
30
+ consentWReq:
31
+ 'consentWithdrawn event requires all, documentId and version parameters to be set',
32
+ ecomReq:
33
+ 'ecommerceTransaction event requires orderId, totalValue to be set and items to be an array of valid ecommerceItems',
34
+ deepLinkReq: 'deepLinkReceived event requires the url parameter to be set',
35
+ messageNotificationReq:
36
+ 'messageNotification event requires title, body, and trigger parameters to be set',
37
+
38
+ // global contexts errors
39
+ gcTagType: 'tag argument is required to be a string',
40
+ gcType: 'global context argument is invalid',
41
+
42
+ // api error prefix
43
+ createTracker: 'createTracker:',
44
+ removeTracker: 'removeTracker: trackerNamespace can only be a string',
45
+
46
+ // methods
47
+ trackSelfDesc: 'trackSelfDescribingEvent:',
48
+ trackScreenView: 'trackScreenViewEvent:',
49
+ trackScrollChanged: 'trackScrollChangedEvent:',
50
+ trackListItemView: 'trackListItemViewEvent:',
51
+ trackStructured: 'trackStructuredEvent:',
52
+ trackPageView: 'trackPageViewEvent:',
53
+ trackTiming: 'trackTimingEvent:',
54
+ trackConsentGranted: 'trackConsentGranted:',
55
+ trackConsentWithdrawn: 'trackConsentWithdrawn:',
56
+ trackEcommerceTransaction: 'trackEcommerceTransaction:',
57
+ trackDeepLinkReceived: 'trackDeepLinkReceivedEvent:',
58
+ trackMessageNotification: 'trackMessageNotificationEvent:',
59
+ removeGlobalContexts: 'removeGlobalContexts:',
60
+ addGlobalContexts: 'addGlobalContexts:',
61
+
62
+ // setters
63
+ setUserId: 'setUserId: userId can only be a string or null',
64
+ setNetworkUserId:
65
+ 'setNetworkUserId: networkUserId can only be a string(UUID) or null',
66
+ setDomainUserId:
67
+ 'setDomainUserId: domainUserId can only be a string(UUID) or null',
68
+ setIpAddress: 'setIpAddress: ipAddress can only be a string or null',
69
+ setUseragent: 'setUseragent: useragent can only be a string or null',
70
+ setTimezone: 'setTimezone: timezone can only be a string or null',
71
+ setLanguage: 'setLanguage: language can only be a string or null',
72
+ setScreenResolution:
73
+ 'setScreenResolution: screenResolution can only be of ScreenSize type or null',
74
+ setScreenViewport:
75
+ 'setScreenViewport: screenViewport can only be of ScreenSize type or null',
76
+ setColorDepth:
77
+ 'setColorDepth: colorDepth can only be a number(integer) or null',
78
+ setSubjectData: 'setSubjectData:',
79
+ };
80
+
81
+ const schemas = {
82
+ payloadData:
83
+ 'iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4',
84
+ timingSchema: 'iglu:com.snowplowanalytics.snowplow/timing/jsonschema/1-0-0',
85
+ deepLinkReceivedSchema:
86
+ 'iglu:com.snowplowanalytics.mobile/deep_link_received/jsonschema/1-0-0',
87
+ messageNotificationSchema:
88
+ 'iglu:com.snowplowanalytics.mobile/message_notification/jsonschema/1-0-0',
89
+ screenViewSchema:
90
+ 'iglu:com.snowplowanalytics.mobile/screen_view/jsonschema/1-0-0',
91
+ scrollChangedSchema:
92
+ 'iglu:com.snowplowanalytics.mobile/scroll_changed/jsonschema/1-0-0',
93
+ listItemViewSchema:
94
+ 'iglu:com.snowplowanalytics.mobile/list_item_view/jsonschema/1-0-0',
95
+ };
96
+
97
+ export { logMessages, schemas };