@snowplow/react-native-tracker 1.3.0 → 2.0.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 +150 -0
  8. package/.github/workflows/deploy.yml +98 -0
  9. package/.github/workflows/e2e-android.yml +121 -0
  10. package/.github/workflows/e2e-ios.yml +90 -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 +166 -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 +704 -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 +271 -0
  32. package/android/src/main/java/com/snowplow/reactnativetracker/util/EventUtil.kt +213 -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 +108 -0
  73. package/example/e2e/environment.js +23 -0
  74. package/example/e2e/helpers/microCommands.js +153 -0
  75. package/example/e2e/helpers/microHelpers.js +346 -0
  76. package/example/e2e/helpers/microHelpers.test.js +308 -0
  77. package/example/e2e/helpers/schemas.js +62 -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 +300 -0
  81. package/example/index.js +5 -0
  82. package/example/ios/.xcode.env +11 -0
  83. package/example/ios/Podfile +64 -0
  84. package/example/ios/Podfile.lock +737 -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 +557 -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 +165 -0
  107. package/ios/ReactNativeTracker.swift +757 -0
  108. package/ios/{RNSnowplowTracker.xcodeproj → ReactNativeTracker.xcodeproj}/project.pbxproj +55 -79
  109. package/ios/Util/ConfigUtils.swift +206 -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 +475 -0
  114. package/lib/commonjs/api.js.map +1 -0
  115. package/lib/commonjs/configurations.js +209 -0
  116. package/lib/commonjs/configurations.js.map +1 -0
  117. package/lib/commonjs/constants.js +85 -0
  118. package/lib/commonjs/constants.js.map +1 -0
  119. package/lib/commonjs/events.js +256 -0
  120. package/lib/commonjs/events.js.map +1 -0
  121. package/lib/commonjs/index.js +141 -0
  122. package/lib/commonjs/index.js.map +1 -0
  123. package/lib/commonjs/jsCore.js +393 -0
  124. package/lib/commonjs/jsCore.js.map +1 -0
  125. package/lib/commonjs/native.js +29 -0
  126. package/lib/commonjs/native.js.map +1 -0
  127. package/lib/commonjs/subject.js +248 -0
  128. package/lib/commonjs/subject.js.map +1 -0
  129. package/lib/commonjs/tracker.js +221 -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 +85 -0
  134. package/lib/commonjs/utils.js.map +1 -0
  135. package/lib/commonjs/webViewInterface.js +79 -0
  136. package/lib/commonjs/webViewInterface.js.map +1 -0
  137. package/lib/module/api.js +439 -0
  138. package/lib/module/api.js.map +1 -0
  139. package/lib/module/configurations.js +197 -0
  140. package/lib/module/configurations.js.map +1 -0
  141. package/lib/module/constants.js +80 -0
  142. package/lib/module/constants.js.map +1 -0
  143. package/lib/module/events.js +240 -0
  144. package/lib/module/events.js.map +1 -0
  145. package/lib/module/index.js +129 -0
  146. package/lib/module/index.js.map +1 -0
  147. package/lib/module/jsCore.js +390 -0
  148. package/lib/module/jsCore.js.map +1 -0
  149. package/lib/module/native.js +25 -0
  150. package/lib/module/native.js.map +1 -0
  151. package/lib/module/subject.js +235 -0
  152. package/lib/module/subject.js.map +1 -0
  153. package/lib/module/tracker.js +209 -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 +79 -0
  158. package/lib/module/utils.js.map +1 -0
  159. package/lib/module/webViewInterface.js +75 -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 +226 -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 +59 -0
  178. package/lib/typescript/constants.d.ts.map +1 -0
  179. package/lib/typescript/events.d.ts +101 -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 +140 -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 +93 -0
  190. package/lib/typescript/tracker.d.ts.map +1 -0
  191. package/{dist/index.d.ts → lib/typescript/types.d.ts} +188 -75
  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 +138 -51
  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 +34 -0
  202. package/src/__tests__/configurations.test.ts +620 -0
  203. package/src/__tests__/events.test.ts +749 -0
  204. package/src/__tests__/index.test.ts +27 -0
  205. package/src/__tests__/jsCore.test.ts +169 -0
  206. package/src/__tests__/utils.test.ts +23 -0
  207. package/src/api.ts +535 -0
  208. package/src/configurations.ts +337 -0
  209. package/src/constants.ts +102 -0
  210. package/src/events.ts +330 -0
  211. package/src/index.ts +189 -0
  212. package/src/jsCore.ts +553 -0
  213. package/src/native.ts +34 -0
  214. package/src/subject.ts +315 -0
  215. package/src/tracker.ts +330 -0
  216. package/src/types.ts +1087 -0
  217. package/src/utils.ts +78 -0
  218. package/src/webViewInterface.ts +105 -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 -1650
  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,337 @@
1
+ /*
2
+ * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
3
+ *
4
+ * This program is licensed to you under the Apache License Version 2.0,
5
+ * and you may not use this file except in compliance with the Apache License Version 2.0.
6
+ * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7
+ *
8
+ * Unless required by applicable law or agreed to in writing,
9
+ * software distributed under the Apache License Version 2.0 is distributed on an
10
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12
+ */
13
+
14
+ 'use strict';
15
+
16
+ import { isObject } from './utils';
17
+ import { isValidSD } from './events';
18
+ import { logMessages } from './constants';
19
+ import type {
20
+ NetworkConfiguration,
21
+ TrackerConfiguration,
22
+ SessionConfiguration,
23
+ EmitterConfiguration,
24
+ SubjectConfiguration,
25
+ GdprConfiguration,
26
+ GCConfiguration,
27
+ GlobalContext,
28
+ InitTrackerConfiguration,
29
+ } from './types';
30
+
31
+ /**
32
+ * Configuration properties
33
+ */
34
+ const networkProps = ['endpoint', 'method', 'customPostPath', 'requestHeaders'];
35
+ const trackerProps = [
36
+ 'appId',
37
+ 'devicePlatform',
38
+ 'base64Encoding',
39
+ 'logLevel',
40
+ 'applicationContext',
41
+ 'platformContext',
42
+ 'geoLocationContext',
43
+ 'sessionContext',
44
+ 'deepLinkContext',
45
+ 'screenContext',
46
+ 'screenViewAutotracking',
47
+ 'lifecycleAutotracking',
48
+ 'installAutotracking',
49
+ 'exceptionAutotracking',
50
+ 'diagnosticAutotracking',
51
+ 'userAnonymisation',
52
+ ];
53
+ const sessionProps = ['foregroundTimeout', 'backgroundTimeout'];
54
+ const emitterProps = [
55
+ 'bufferOption',
56
+ 'emitRange',
57
+ 'threadPoolSize',
58
+ 'byteLimitPost',
59
+ 'byteLimitGet',
60
+ 'serverAnonymisation',
61
+ ];
62
+ const subjectProps = [
63
+ 'userId',
64
+ 'networkUserId',
65
+ 'domainUserId',
66
+ 'useragent',
67
+ 'ipAddress',
68
+ 'timezone',
69
+ 'language',
70
+ 'screenResolution',
71
+ 'screenViewport',
72
+ 'colorDepth',
73
+ ];
74
+ const gdprProps = [
75
+ 'basisForProcessing',
76
+ 'documentId',
77
+ 'documentVersion',
78
+ 'documentDescription',
79
+ ];
80
+ const gcProps = ['tag', 'globalContexts'];
81
+
82
+ /**
83
+ * Validates whether an object is of valid configuration given its default keys
84
+ *
85
+ * @param config {Object} - the object to validate
86
+ * @param defaultKeys {Array} - the default keys to validate against
87
+ * @returns - boolean
88
+ */
89
+ function isValidConfig<Type extends Record<string, any>>(
90
+ config: Type,
91
+ defaultKeys: Array<string>
92
+ ): config is Type {
93
+ return Object.keys(config).every((key) => defaultKeys.includes(key));
94
+ }
95
+
96
+ /**
97
+ * Validates the networkConfig
98
+ *
99
+ * @param config {Object} - the config to validate
100
+ * @returns - boolean
101
+ */
102
+ function isValidNetworkConf(config: NetworkConfiguration): boolean {
103
+ if (
104
+ !isObject(config) ||
105
+ !isValidConfig(config, networkProps) ||
106
+ typeof config.endpoint !== 'string' ||
107
+ !config.endpoint
108
+ ) {
109
+ return false;
110
+ }
111
+ return true;
112
+ }
113
+
114
+ /**
115
+ * Validates the trackerConfig
116
+ *
117
+ * @param config {Object} - the config to validate
118
+ * @returns - boolean
119
+ */
120
+ function isValidTrackerConf(config: TrackerConfiguration): boolean {
121
+ if (!isObject(config) || !isValidConfig(config, trackerProps)) {
122
+ return false;
123
+ }
124
+ return true;
125
+ }
126
+
127
+ /**
128
+ * Validates the sessionConfig
129
+ *
130
+ * @param config {Object} - the config to validate
131
+ * @returns - boolean
132
+ */
133
+ function isValidSessionConf(config: SessionConfiguration): boolean {
134
+ if (
135
+ !isObject(config) ||
136
+ !isValidConfig(config, sessionProps) ||
137
+ !sessionProps.every((key) =>
138
+ Object.keys(config as SessionConfiguration).includes(key)
139
+ )
140
+ ) {
141
+ return false;
142
+ }
143
+ return true;
144
+ }
145
+
146
+ /**
147
+ * Validates the emitterConfig
148
+ *
149
+ * @param config {Object} - the config to validate
150
+ * @returns - boolean
151
+ */
152
+ function isValidEmitterConf(config: EmitterConfiguration): boolean {
153
+ if (!isObject(config) || !isValidConfig(config, emitterProps)) {
154
+ return false;
155
+ }
156
+ return true;
157
+ }
158
+
159
+ /**
160
+ * Validates whether an object is of ScreenSize type
161
+ *
162
+ * @param arr {Object} - the object to validate
163
+ * @returns - boolean
164
+ */
165
+ function isScreenSize<Type>(arr: Type): boolean {
166
+ return (
167
+ Array.isArray(arr) &&
168
+ arr.length === 2 &&
169
+ arr.every(<Type>(n: Type) => typeof n === 'number')
170
+ );
171
+ }
172
+
173
+ /**
174
+ * Validates the subjectConfig
175
+ *
176
+ * @param config {Object} - the config to validate
177
+ * @returns - boolean
178
+ */
179
+ function isValidSubjectConf(config: SubjectConfiguration): boolean {
180
+ if (!isObject(config) || !isValidConfig(config, subjectProps)) {
181
+ return false;
182
+ }
183
+
184
+ // validating ScreenSize here to simplify array handling in bridge
185
+ if (
186
+ Object.prototype.hasOwnProperty.call(config, 'screenResolution') &&
187
+ config.screenResolution !== null &&
188
+ !isScreenSize(config.screenResolution as unknown)
189
+ ) {
190
+ return false;
191
+ }
192
+
193
+ if (
194
+ Object.prototype.hasOwnProperty.call(config, 'screenViewport') &&
195
+ config.screenViewport !== null &&
196
+ !isScreenSize(config.screenViewport as unknown)
197
+ ) {
198
+ return false;
199
+ }
200
+
201
+ return true;
202
+ }
203
+
204
+ /**
205
+ * Validates the gdprConfig
206
+ *
207
+ * @param config {Object} - the config to validate
208
+ * @returns - boolean
209
+ */
210
+ function isValidGdprConf(config: GdprConfiguration): boolean {
211
+ if (
212
+ !isObject(config) ||
213
+ !isValidConfig(config, gdprProps) ||
214
+ !gdprProps.every((key) =>
215
+ Object.keys(config as GdprConfiguration).includes(key)
216
+ ) ||
217
+ ![
218
+ 'consent',
219
+ 'contract',
220
+ 'legal_obligation',
221
+ 'legitimate_interests',
222
+ 'public_task',
223
+ 'vital_interests',
224
+ ].includes(config.basisForProcessing)
225
+ ) {
226
+ return false;
227
+ }
228
+ return true;
229
+ }
230
+
231
+ /**
232
+ * Validates whether an object is of GlobalContext type
233
+ *
234
+ * @param gc {Object} - the object to validate
235
+ * @returns - boolean
236
+ */
237
+ function isValidGC(gc: GlobalContext): boolean {
238
+ return (
239
+ isObject(gc) &&
240
+ isValidConfig(gc, gcProps) &&
241
+ typeof gc.tag === 'string' &&
242
+ Array.isArray(gc.globalContexts) &&
243
+ gc.globalContexts.every((c) => isValidSD(c))
244
+ );
245
+ }
246
+
247
+ /**
248
+ * Validates the GCConfig (global contexts)
249
+ *
250
+ * @param config {Object} - the config to validate
251
+ * @returns - boolean
252
+ */
253
+ function isValidGCConf(config: GCConfiguration): boolean {
254
+ if (!Array.isArray(config)) {
255
+ return false;
256
+ }
257
+ if (!config.every((gc) => isValidGC(gc as GlobalContext))) {
258
+ return false;
259
+ }
260
+ return true;
261
+ }
262
+
263
+ /**
264
+ * Validates the initTrackerConfiguration
265
+ *
266
+ * @param init {Object} - the config to validate
267
+ * @returns - boolean promise
268
+ */
269
+ function initValidate(init: InitTrackerConfiguration): Promise<boolean> {
270
+ if (typeof init.namespace !== 'string' || !init.namespace) {
271
+ return Promise.reject(new Error(logMessages.namespace));
272
+ }
273
+
274
+ if (
275
+ !Object.prototype.hasOwnProperty.call(init, 'networkConfig') ||
276
+ !isValidNetworkConf(init.networkConfig as NetworkConfiguration)
277
+ ) {
278
+ return Promise.reject(new Error(logMessages.network));
279
+ }
280
+
281
+ if (
282
+ Object.prototype.hasOwnProperty.call(init, 'trackerConfig') &&
283
+ !isValidTrackerConf(init.trackerConfig as TrackerConfiguration)
284
+ ) {
285
+ return Promise.reject(new Error(logMessages.tracker));
286
+ }
287
+
288
+ if (
289
+ Object.prototype.hasOwnProperty.call(init, 'sessionConfig') &&
290
+ !isValidSessionConf(init.sessionConfig as SessionConfiguration)
291
+ ) {
292
+ return Promise.reject(new Error(logMessages.session));
293
+ }
294
+
295
+ if (
296
+ Object.prototype.hasOwnProperty.call(init, 'emitterConfig') &&
297
+ !isValidEmitterConf(init.emitterConfig as EmitterConfiguration)
298
+ ) {
299
+ return Promise.reject(new Error(logMessages.emitter));
300
+ }
301
+
302
+ if (
303
+ Object.prototype.hasOwnProperty.call(init, 'subjectConfig') &&
304
+ !isValidSubjectConf(init.subjectConfig as SubjectConfiguration)
305
+ ) {
306
+ return Promise.reject(new Error(logMessages.subject));
307
+ }
308
+
309
+ if (
310
+ Object.prototype.hasOwnProperty.call(init, 'gdprConfig') &&
311
+ !isValidGdprConf(init.gdprConfig as GdprConfiguration)
312
+ ) {
313
+ return Promise.reject(new Error(logMessages.gdpr));
314
+ }
315
+
316
+ if (
317
+ Object.prototype.hasOwnProperty.call(init, 'gcConfig') &&
318
+ !isValidGCConf(init.gcConfig as GCConfiguration)
319
+ ) {
320
+ return Promise.reject(new Error(logMessages.gc));
321
+ }
322
+
323
+ return Promise.resolve(true);
324
+ }
325
+
326
+ export {
327
+ isValidNetworkConf,
328
+ isValidTrackerConf,
329
+ isValidSessionConf,
330
+ isValidEmitterConf,
331
+ isValidSubjectConf,
332
+ isValidGdprConf,
333
+ isValidGCConf,
334
+ isValidGC,
335
+ isScreenSize,
336
+ initValidate,
337
+ };
@@ -0,0 +1,102 @@
1
+ /*
2
+ * Copyright (c) 2020-2023 Snowplow Analytics Ltd. All rights reserved.
3
+ *
4
+ * This program is licensed to you under the Apache License Version 2.0,
5
+ * and you may not use this file except in compliance with the Apache License Version 2.0.
6
+ * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
7
+ *
8
+ * Unless required by applicable law or agreed to in writing,
9
+ * software distributed under the Apache License Version 2.0 is distributed on an
10
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
12
+ */
13
+
14
+ 'use strict';
15
+
16
+ const logMessages = {
17
+ // configuration errors
18
+ namespace: 'namespace parameter is required to be set',
19
+ endpoint: 'endpoint parameter is required to be set',
20
+ network: 'networkConfig is invalid',
21
+ tracker: 'trackerConfig is invalid',
22
+ session: 'sessionConfig is invalid',
23
+ emitter: 'emitterConfig is invalid',
24
+ subject: 'subjectConfig is invalid',
25
+ gdpr: 'gdprConfig is invalid',
26
+ gc: 'gcConfig is invalid',
27
+
28
+ // event errors
29
+ context: 'invalid contexts parameter',
30
+ selfDesc:
31
+ 'selfDescribing event requires schema and data parameters to be set',
32
+ evType: 'event argument can only be an object',
33
+ screenViewReq: 'screenView event requires name as string parameter to be set',
34
+ structuredReq:
35
+ 'structured event requires category and action parameters to be set',
36
+ pageviewReq: 'pageView event requires pageUrl parameter to be set',
37
+ timingReq:
38
+ 'timing event requires category, variable and timing parameters to be set',
39
+ consentGReq:
40
+ 'consentGranted event requires expiry, documentId and version parameters to be set',
41
+ consentWReq:
42
+ 'consentWithdrawn event requires all, documentId and version parameters to be set',
43
+ ecomReq:
44
+ 'ecommerceTransaction event requires orderId, totalValue to be set and items to be an array of valid ecommerceItems',
45
+ deepLinkReq: 'deepLinkReceived event requires the url parameter to be set',
46
+ messageNotificationReq:
47
+ 'messageNotification event requires title, body, and trigger parameters to be set',
48
+
49
+ // global contexts errors
50
+ gcTagType: 'tag argument is required to be a string',
51
+ gcType: 'global context argument is invalid',
52
+
53
+ // api error prefix
54
+ createTracker: 'createTracker:',
55
+ removeTracker: 'removeTracker: trackerNamespace can only be a string',
56
+
57
+ // methods
58
+ trackSelfDesc: 'trackSelfDescribingEvent:',
59
+ trackScreenView: 'trackScreenViewEvent:',
60
+ trackStructured: 'trackStructuredEvent:',
61
+ trackPageView: 'trackPageViewEvent:',
62
+ trackTiming: 'trackTimingEvent:',
63
+ trackConsentGranted: 'trackConsentGranted:',
64
+ trackConsentWithdrawn: 'trackConsentWithdrawn:',
65
+ trackEcommerceTransaction: 'trackEcommerceTransaction:',
66
+ trackDeepLinkReceived: 'trackDeepLinkReceivedEvent:',
67
+ trackMessageNotification: 'trackMessageNotificationEvent:',
68
+ removeGlobalContexts: 'removeGlobalContexts:',
69
+ addGlobalContexts: 'addGlobalContexts:',
70
+
71
+ // setters
72
+ setUserId: 'setUserId: userId can only be a string or null',
73
+ setNetworkUserId:
74
+ 'setNetworkUserId: networkUserId can only be a string(UUID) or null',
75
+ setDomainUserId:
76
+ 'setDomainUserId: domainUserId can only be a string(UUID) or null',
77
+ setIpAddress: 'setIpAddress: ipAddress can only be a string or null',
78
+ setUseragent: 'setUseragent: useragent can only be a string or null',
79
+ setTimezone: 'setTimezone: timezone can only be a string or null',
80
+ setLanguage: 'setLanguage: language can only be a string or null',
81
+ setScreenResolution:
82
+ 'setScreenResolution: screenResolution can only be of ScreenSize type or null',
83
+ setScreenViewport:
84
+ 'setScreenViewport: screenViewport can only be of ScreenSize type or null',
85
+ setColorDepth:
86
+ 'setColorDepth: colorDepth can only be a number(integer) or null',
87
+ setSubjectData: 'setSubjectData:',
88
+ };
89
+
90
+ const schemas = {
91
+ payloadData:
92
+ 'iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4',
93
+ timingSchema: 'iglu:com.snowplowanalytics.snowplow/timing/jsonschema/1-0-0',
94
+ deepLinkReceivedSchema:
95
+ 'iglu:com.snowplowanalytics.mobile/deep_link_received/jsonschema/1-0-0',
96
+ messageNotificationSchema:
97
+ 'iglu:com.snowplowanalytics.mobile/message_notification/jsonschema/1-0-0',
98
+ screenViewSchema:
99
+ 'iglu:com.snowplowanalytics.mobile/screen_view/jsonschema/1-0-0',
100
+ };
101
+
102
+ export { logMessages, schemas };